; Small fixes for some Author: header comments
[emacs.git] / lisp / progmodes / verilog-mode.el
blob2760c4d276e925189bf9e8d54dea727ebc42a90d
1 ;;; verilog-mode.el --- major mode for editing verilog source in Emacs
3 ;; Copyright (C) 1996-2017 Free Software Foundation, Inc.
5 ;; Author: Michael McNamara <mac@verilog.com>
6 ;; Wilson Snyder <wsnyder@wsnyder.org>
7 ;; X-URL: http://www.verilog.com
8 ;; X-URL: http://www.veripool.org
9 ;; Created: 3 Jan 1996
10 ;; Keywords: languages
12 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
13 ;; file on 19/3/2008, and the maintainer agreed that when a bug is
14 ;; filed in the Emacs bug reporting system against this file, a copy
15 ;; of the bug report be sent to the maintainer's email address.
17 ;; This code supports Emacs 21.1 and later
18 ;; And XEmacs 21.1 and later
19 ;; Please do not make changes that break Emacs 21. Thanks!
23 ;; This file is part of GNU Emacs.
25 ;; GNU Emacs is free software: you can redistribute it and/or modify
26 ;; it under the terms of the GNU General Public License as published by
27 ;; the Free Software Foundation, either version 3 of the License, or
28 ;; (at your option) any later version.
30 ;; GNU Emacs is distributed in the hope that it will be useful,
31 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
32 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 ;; GNU General Public License for more details.
35 ;; You should have received a copy of the GNU General Public License
36 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
38 ;;; Commentary:
40 ;; USAGE
41 ;; =====
43 ;; A major mode for editing Verilog and SystemVerilog HDL source code (IEEE
44 ;; 1364-2005 and IEEE 1800-2012 standards). When you have entered Verilog
45 ;; mode, you may get more info by pressing C-h m. You may also get online
46 ;; help describing various functions by: C-h f <Name of function you want
47 ;; described>
49 ;; KNOWN BUGS / BUG REPORTS
50 ;; =======================
52 ;; SystemVerilog is a rapidly evolving language, and hence this mode is
53 ;; under continuous development. Please report any issues to the issue
54 ;; tracker at
56 ;; http://www.veripool.org/verilog-mode
58 ;; Please use verilog-submit-bug-report to submit a report; type C-c
59 ;; C-b to invoke this and as a result we will have a much easier time
60 ;; of reproducing the bug you find, and hence fixing it.
62 ;; INSTALLING THE MODE
63 ;; ===================
65 ;; An older version of this mode may be already installed as a part of
66 ;; your environment, and one method of updating would be to update
67 ;; your Emacs environment. Sometimes this is difficult for local
68 ;; political/control reasons, and hence you can always install a
69 ;; private copy (or even a shared copy) which overrides the system
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"
114 ;; )
117 ;;; History:
119 ;; See commit history at http://www.veripool.org/verilog-mode.html
120 ;; (This section is required to appease checkdoc.)
122 ;;; Code:
125 ;; This variable will always hold the version number of the mode
126 (defconst verilog-mode-version "2017-05-08-b240c8f-vpo-GNU"
127 "Version of this Verilog mode.")
128 (defconst verilog-mode-release-emacs t
129 "If non-nil, this version of Verilog mode was released with Emacs itself.")
131 (defun verilog-version ()
132 "Inform caller of the version of this file."
133 (interactive)
134 (message "Using verilog-mode version %s" verilog-mode-version))
136 ;; Insure we have certain packages, and deal with it if we don't
137 ;; Be sure to note which Emacs flavor and version added each feature.
138 (eval-when-compile
139 ;; Provide stuff if we are XEmacs
140 (when (featurep 'xemacs)
141 (condition-case nil
142 (require 'easymenu)
143 (error nil))
144 (condition-case nil
145 (require 'regexp-opt)
146 (error nil))
147 ;; Bug in 19.28 through 19.30 skeleton.el, not provided.
148 (condition-case nil
149 (load "skeleton")
150 (error nil))
151 (condition-case nil
152 (if (fboundp 'when)
153 nil ; fab
154 (defmacro when (cond &rest body)
155 (list 'if cond (cons 'progn body))))
156 (error nil))
157 (condition-case nil
158 (if (fboundp 'unless)
159 nil ; fab
160 (defmacro unless (cond &rest body)
161 (cons 'if (cons cond (cons nil body)))))
162 (error nil))
163 (condition-case nil
164 (if (fboundp 'store-match-data)
165 nil ; fab
166 (defmacro store-match-data (&rest _args) nil))
167 (error nil))
168 (condition-case nil
169 (if (fboundp 'char-before)
170 nil ; great
171 (defmacro char-before (&rest _body)
172 (char-after (1- (point)))))
173 (error nil))
174 (condition-case nil
175 (if (fboundp 'when)
176 nil ; fab
177 (defsubst point-at-bol (&optional N)
178 (save-excursion (beginning-of-line N) (point))))
179 (error nil))
180 (condition-case nil
181 (if (fboundp 'when)
182 nil ; fab
183 (defsubst point-at-eol (&optional N)
184 (save-excursion (end-of-line N) (point))))
185 (error nil))
186 (condition-case nil
187 (require 'custom)
188 (error nil))
189 (condition-case nil
190 (if (fboundp 'match-string-no-properties)
191 nil ; great
192 (defsubst match-string-no-properties (num &optional string)
193 "Return string of text matched by last search, without text properties.
194 NUM specifies which parenthesized expression in the last regexp.
195 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
196 Zero means the entire text matched by the whole regexp or whole string.
197 STRING should be given if the last search was by `string-match' on STRING."
198 (if (match-beginning num)
199 (if string
200 (let ((result
201 (substring string
202 (match-beginning num) (match-end num))))
203 (set-text-properties 0 (length result) nil result)
204 result)
205 (buffer-substring-no-properties (match-beginning num)
206 (match-end num)
207 (current-buffer)))))
209 (error nil))
210 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
211 nil ; We've got what we needed
212 ;; We have the old custom-library, hack around it!
213 (defmacro defgroup (&rest _args) nil)
214 (defmacro customize (&rest _args)
215 (message
216 "Sorry, Customize is not available with this version of Emacs"))
217 (defmacro defcustom (var value doc &rest _args)
218 `(defvar ,var ,value ,doc))
220 (if (fboundp 'defface)
221 nil ; great!
222 (defmacro defface (var values doc &rest _args)
223 `(make-face ,var))
226 (if (and (featurep 'custom) (fboundp 'customize-group))
227 nil ; We've got what we needed
228 ;; We have an intermediate custom-library, hack around it!
229 (defmacro customize-group (var &rest _args)
230 `(customize ,var))
233 (defvar inhibit-modification-hooks)
234 (defvar inhibit-point-motion-hooks)
235 (defvar deactivate-mark)
238 ;; OK, do this stuff if we are NOT XEmacs:
239 (unless (featurep 'xemacs)
240 (unless (fboundp 'region-active-p)
241 (defmacro region-active-p ()
242 `(and transient-mark-mode mark-active))))
245 ;; Provide a regular expression optimization routine, using regexp-opt
246 ;; if provided by the user's elisp libraries
247 (eval-and-compile
248 ;; The below were disabled when GNU Emacs 22 was released;
249 ;; perhaps some still need to be there to support Emacs 21.
250 (if (featurep 'xemacs)
251 (if (fboundp 'regexp-opt)
252 ;; regexp-opt is defined, does it take 3 or 2 arguments?
253 (if (fboundp 'function-max-args)
254 (let ((args (function-max-args `regexp-opt)))
255 (cond
256 ((eq args 3) ; It takes 3
257 (condition-case nil ; Hide this defun from emacses
258 ; with just a two input regexp
259 (defun verilog-regexp-opt (a b)
260 "Deal with differing number of required arguments for `regexp-opt'.
261 Call `regexp-opt' on A and B."
262 (regexp-opt a b t))
263 (error nil))
265 ((eq args 2) ; It takes 2
266 (defun verilog-regexp-opt (a b)
267 "Call `regexp-opt' on A and B."
268 (regexp-opt a b))
270 (t nil)))
271 ;; We can't tell; assume it takes 2
272 (defun verilog-regexp-opt (a b)
273 "Call `regexp-opt' on A and B."
274 (regexp-opt a b))
276 ;; There is no regexp-opt, provide our own
277 (defun verilog-regexp-opt (strings &optional paren _shy)
278 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
279 (concat open (mapconcat 'regexp-quote strings "\\|") close)))
281 ;; Emacs.
282 (defalias 'verilog-regexp-opt 'regexp-opt)))
284 ;; emacs >=22 has looking-back, but older emacs and xemacs don't.
285 ;; This function is lifted directly from emacs's subr.el
286 ;; so that it can be used by xemacs.
287 ;; The idea for this was borrowed from org-mode via this link:
288 ;; https://lists.gnu.org/archive/html/emacs-orgmode/2009-12/msg00032.html
289 (eval-and-compile
290 (cond
291 ((fboundp 'looking-back)
292 (defalias 'verilog-looking-back 'looking-back))
294 (defun verilog-looking-back (regexp limit &optional greedy)
295 "Return non-nil if text before point matches regular expression REGEXP.
296 Like `looking-at' except matches before point, and is slower.
297 LIMIT if non-nil speeds up the search by specifying a minimum
298 starting position, to avoid checking matches that would start
299 before LIMIT.
301 If GREEDY is non-nil, extend the match backwards as far as
302 possible, stopping when a single additional previous character
303 cannot be part of a match for REGEXP. When the match is
304 extended, its starting position is allowed to occur before
305 LIMIT.
307 As a general recommendation, try to avoid using `looking-back'
308 wherever possible, since it is slow."
309 (let ((start (point))
310 (pos
311 (save-excursion
312 (and (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t)
313 (point)))))
314 (if (and greedy pos)
315 (save-restriction
316 (narrow-to-region (point-min) start)
317 (while (and (> pos (point-min))
318 (save-excursion
319 (goto-char pos)
320 (backward-char 1)
321 (looking-at (concat "\\(?:" regexp "\\)\\'"))))
322 (setq pos (1- pos)))
323 (save-excursion
324 (goto-char pos)
325 (looking-at (concat "\\(?:" regexp "\\)\\'")))))
326 (not (null pos)))))))
328 (eval-and-compile
329 (cond
330 ((fboundp 'restore-buffer-modified-p)
331 ;; Faster, as does not update mode line when nothing changes
332 (defalias 'verilog-restore-buffer-modified-p 'restore-buffer-modified-p))
334 (defalias 'verilog-restore-buffer-modified-p 'set-buffer-modified-p))))
336 (eval-and-compile
337 ;; Both xemacs and emacs
338 (condition-case nil
339 (require 'diff) ; diff-command and diff-switches
340 (error nil))
341 (condition-case nil
342 (require 'compile) ; compilation-error-regexp-alist-alist
343 (error nil))
344 (condition-case nil
345 (unless (fboundp 'buffer-chars-modified-tick) ; Emacs 22 added
346 (defmacro buffer-chars-modified-tick () (buffer-modified-tick)))
347 (error nil))
348 ;; Added in Emacs 24.1
349 (condition-case nil
350 (unless (fboundp 'prog-mode)
351 (define-derived-mode prog-mode fundamental-mode "Prog"))
352 (error nil))
353 ;; Added in Emacs 25.1
354 (condition-case nil
355 (unless (fboundp 'forward-word-strictly)
356 (defalias 'forward-word-strictly 'forward-word))
357 (error nil)))
359 (eval-when-compile
360 (defun verilog-regexp-words (a)
361 "Call `regexp-opt' with word delimiters for the words A."
362 (concat "\\<" (verilog-regexp-opt a t) "\\>")))
363 (defun verilog-regexp-words (a)
364 "Call `regexp-opt' with word delimiters for the words A."
365 ;; The FAQ references this function, so user LISP sometimes calls it
366 (concat "\\<" (verilog-regexp-opt a t) "\\>"))
368 (defun verilog-easy-menu-filter (menu)
369 "Filter `easy-menu-define' MENU to support new features."
370 (cond ((not (featurep 'xemacs))
371 menu) ; GNU Emacs - passthru
372 ;; XEmacs doesn't support :help. Strip it.
373 ;; Recursively filter the a submenu
374 ((listp menu)
375 (mapcar 'verilog-easy-menu-filter menu))
376 ;; Look for [:help "blah"] and remove
377 ((vectorp menu)
378 (let ((i 0) (out []))
379 (while (< i (length menu))
380 (if (equal `:help (aref menu i))
381 (setq i (+ 2 i))
382 (setq out (vconcat out (vector (aref menu i)))
383 i (1+ i))))
384 out))
385 (t menu))) ; Default - ok
386 ;;(verilog-easy-menu-filter
387 ;; `("Verilog" ("MA" ["SAA" nil :help "Help SAA"] ["SAB" nil :help "Help SAA"])
388 ;; "----" ["MB" nil :help "Help MB"]))
390 (defun verilog-define-abbrev-table (tablename definitions &optional docstring &rest props)
391 "Filter `define-abbrev-table' TABLENAME DEFINITIONS
392 Provides DOCSTRING PROPS in newer Emacs (23.1)."
393 (condition-case nil
394 (apply 'define-abbrev-table tablename definitions docstring props)
395 (error
396 (define-abbrev-table tablename definitions))))
398 (defun verilog-define-abbrev (table name expansion &optional hook)
399 "Filter `define-abbrev' TABLE NAME EXPANSION and call HOOK.
400 Provides SYSTEM-FLAG in newer Emacs."
401 (condition-case nil
402 (define-abbrev table name expansion hook 0 t)
403 (error
404 (define-abbrev table name expansion hook))))
406 (defun verilog-customize ()
407 "Customize variables and other settings used by Verilog-Mode."
408 (interactive)
409 (customize-group 'verilog-mode))
411 (defun verilog-font-customize ()
412 "Customize fonts used by Verilog-Mode."
413 (interactive)
414 (if (fboundp 'customize-apropos)
415 (customize-apropos "font-lock-*" 'faces)))
417 (defun verilog-booleanp (value)
418 "Return t if VALUE is boolean.
419 This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs.
420 This function may be removed when Emacs 21 is no longer supported."
421 (or (equal value t) (equal value nil)))
423 (defun verilog-insert-last-command-event ()
424 "Insert the `last-command-event'."
425 (insert (if (featurep 'xemacs)
426 ;; XEmacs 21.5 doesn't like last-command-event
427 last-command-char
428 ;; And GNU Emacs 22 has obsoleted last-command-char
429 last-command-event)))
431 (defvar verilog-no-change-functions nil
432 "True if `after-change-functions' is disabled.
433 Use of `syntax-ppss' may break, as ppss's cache may get corrupted.")
435 (defvar verilog-in-hooks nil
436 "True when within a `verilog-run-hooks' block.")
438 (defmacro verilog-run-hooks (&rest hooks)
439 "Run each hook in HOOKS using `run-hooks'.
440 Set `verilog-in-hooks' during this time, to assist AUTO caches."
441 `(let ((verilog-in-hooks t))
442 (run-hooks ,@hooks)))
444 (defun verilog-syntax-ppss (&optional pos)
445 (when verilog-no-change-functions
446 (if verilog-in-hooks
447 (verilog-scan-cache-flush)
448 ;; else don't let the AUTO code itself get away with flushing the cache,
449 ;; as that'll make things very slow
450 (backtrace)
451 (error "%s: Internal problem; use of syntax-ppss when cache may be corrupt"
452 (verilog-point-text))))
453 (if (fboundp 'syntax-ppss)
454 (syntax-ppss pos)
455 (parse-partial-sexp (point-min) (or pos (point)))))
457 (defgroup verilog-mode nil
458 "Major mode for Verilog source code."
459 :version "22.2"
460 :group 'languages)
462 ;; (defgroup verilog-mode-fonts nil
463 ;; "Facilitates easy customization fonts used in Verilog source text"
464 ;; :link '(customize-apropos "font-lock-*" 'faces)
465 ;; :group 'verilog-mode)
467 (defgroup verilog-mode-indent nil
468 "Customize indentation and highlighting of Verilog source text."
469 :group 'verilog-mode)
471 (defgroup verilog-mode-actions nil
472 "Customize actions on Verilog source text."
473 :group 'verilog-mode)
475 (defgroup verilog-mode-auto nil
476 "Customize AUTO actions when expanding Verilog source text."
477 :group 'verilog-mode)
479 (defvar verilog-debug nil
480 "Non-nil means enable debug messages for `verilog-mode' internals.")
482 (defvar verilog-warn-fatal nil
483 "Non-nil means `verilog-warn-error' warnings are fatal `error's.")
485 (defcustom verilog-linter
486 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
487 "Unix program and arguments to call to run a lint checker on Verilog source.
488 Depending on the `verilog-set-compile-command', this may be invoked when
489 you type \\[compile]. When the compile completes, \\[next-error] will take
490 you to the next lint error."
491 :type 'string
492 :group 'verilog-mode-actions)
493 ;; We don't mark it safe, as it's used as a shell command
495 (defcustom verilog-coverage
496 "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'"
497 "Program and arguments to use to annotate for coverage Verilog source.
498 Depending on the `verilog-set-compile-command', this may be invoked when
499 you type \\[compile]. When the compile completes, \\[next-error] will take
500 you to the next lint error."
501 :type 'string
502 :group 'verilog-mode-actions)
503 ;; We don't mark it safe, as it's used as a shell command
505 (defcustom verilog-simulator
506 "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'"
507 "Program and arguments to use to interpret Verilog source.
508 Depending on the `verilog-set-compile-command', this may be invoked when
509 you type \\[compile]. When the compile completes, \\[next-error] will take
510 you to the next lint error."
511 :type 'string
512 :group 'verilog-mode-actions)
513 ;; We don't mark it safe, as it's used as a shell command
515 (defcustom verilog-compiler
516 "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'"
517 "Program and arguments to use to compile Verilog source.
518 Depending on the `verilog-set-compile-command', this may be invoked when
519 you type \\[compile]. When the compile completes, \\[next-error] will take
520 you to the next lint error."
521 :type 'string
522 :group 'verilog-mode-actions)
523 ;; We don't mark it safe, as it's used as a shell command
525 (defcustom verilog-preprocessor
526 ;; Very few tools give preprocessed output, so we'll default to Verilog-Perl
527 "vppreproc __FLAGS__ __FILE__"
528 "Program and arguments to use to preprocess Verilog source.
529 This is invoked with `verilog-preprocess', and depending on the
530 `verilog-set-compile-command', may also be invoked when you type
531 \\[compile]. When the compile completes, \\[next-error] will
532 take you to the next lint error."
533 :type 'string
534 :group 'verilog-mode-actions)
535 ;; We don't mark it safe, as it's used as a shell command
537 (defvar verilog-preprocess-history nil
538 "History for `verilog-preprocess'.")
540 (defvar verilog-tool 'verilog-linter
541 "Which tool to use for building compiler-command.
542 Either nil, `verilog-linter', `verilog-compiler',
543 `verilog-coverage', `verilog-preprocessor', or `verilog-simulator'.
544 Alternatively use the \"Choose Compilation Action\" menu. See
545 `verilog-set-compile-command' for more information.")
547 (defcustom verilog-highlight-translate-off nil
548 "Non-nil means background-highlight code excluded from translation.
549 That is, all code between \"// synopsys translate_off\" and
550 \"// synopsys translate_on\" is highlighted using a different background color
551 \(face `verilog-font-lock-translate-off-face').
553 Note: This will slow down on-the-fly fontification (and thus editing).
555 Note: Activate the new setting in a Verilog buffer by re-fontifying it (menu
556 entry \"Fontify Buffer\"). XEmacs: turn off and on font locking."
557 :type 'boolean
558 :group 'verilog-mode-indent)
559 ;; Note we don't use :safe, as that would break on Emacsen before 22.0.
560 (put 'verilog-highlight-translate-off 'safe-local-variable 'verilog-booleanp)
562 (defcustom verilog-auto-lineup 'declarations
563 "Type of statements to lineup across multiple lines.
564 If `all' is selected, then all line ups described below are done.
566 If `declarations', then just declarations are lined up with any
567 preceding declarations, taking into account widths and the like,
568 so or example the code:
569 reg [31:0] a;
570 reg b;
571 would become
572 reg [31:0] a;
573 reg b;
575 If `assignment', then assignments are lined up with any preceding
576 assignments, so for example the code
577 a_long_variable <= b + c;
578 d = e + f;
579 would become
580 a_long_variable <= b + c;
581 d = e + f;
583 In order to speed up editing, large blocks of statements are lined up
584 only when a \\[verilog-pretty-expr] is typed; and large blocks of declarations
585 are lineup only when \\[verilog-pretty-declarations] is typed."
587 :type '(radio (const :tag "Line up Assignments and Declarations" all)
588 (const :tag "Line up Assignment statements" assignments )
589 (const :tag "Line up Declarations" declarations)
590 (function :tag "Other"))
591 :group 'verilog-mode-indent )
592 (put 'verilog-auto-lineup 'safe-local-variable
593 '(lambda (x) (memq x '(nil all assignments declarations))))
595 (defcustom verilog-indent-level 3
596 "Indentation of Verilog statements with respect to containing block."
597 :group 'verilog-mode-indent
598 :type 'integer)
599 (put 'verilog-indent-level 'safe-local-variable 'integerp)
601 (defcustom verilog-indent-level-module 3
602 "Indentation of Module level Verilog statements (eg always, initial).
603 Set to 0 to get initial and always statements lined up on the left side of
604 your screen."
605 :group 'verilog-mode-indent
606 :type 'integer)
607 (put 'verilog-indent-level-module 'safe-local-variable 'integerp)
609 (defcustom verilog-indent-level-declaration 3
610 "Indentation of declarations with respect to containing block.
611 Set to 0 to get them list right under containing block."
612 :group 'verilog-mode-indent
613 :type 'integer)
614 (put 'verilog-indent-level-declaration 'safe-local-variable 'integerp)
616 (defcustom verilog-indent-declaration-macros nil
617 "How to treat macro expansions in a declaration.
618 If nil, indent as:
619 input [31:0] a;
620 input \\=`CP;
621 output c;
622 If non nil, treat as:
623 input [31:0] a;
624 input \\=`CP ;
625 output c;"
626 :group 'verilog-mode-indent
627 :type 'boolean)
628 (put 'verilog-indent-declaration-macros 'safe-local-variable 'verilog-booleanp)
630 (defcustom verilog-indent-lists t
631 "How to treat indenting items in a list.
632 If t (the default), indent as:
633 always @( posedge a or
634 reset ) begin
636 If nil, treat as:
637 always @( posedge a or
638 reset ) begin"
639 :group 'verilog-mode-indent
640 :type 'boolean)
641 (put 'verilog-indent-lists 'safe-local-variable 'verilog-booleanp)
643 (defcustom verilog-indent-level-behavioral 3
644 "Absolute indentation of first begin in a task or function block.
645 Set to 0 to get such code to start at the left side of the screen."
646 :group 'verilog-mode-indent
647 :type 'integer)
648 (put 'verilog-indent-level-behavioral 'safe-local-variable 'integerp)
650 (defcustom verilog-indent-level-directive 1
651 "Indentation to add to each level of \\=`ifdef declarations.
652 Set to 0 to have all directives start at the left side of the screen."
653 :group 'verilog-mode-indent
654 :type 'integer)
655 (put 'verilog-indent-level-directive 'safe-local-variable 'integerp)
657 (defcustom verilog-cexp-indent 2
658 "Indentation of Verilog statements split across lines."
659 :group 'verilog-mode-indent
660 :type 'integer)
661 (put 'verilog-cexp-indent 'safe-local-variable 'integerp)
663 (defcustom verilog-case-indent 2
664 "Indentation for case statements."
665 :group 'verilog-mode-indent
666 :type 'integer)
667 (put 'verilog-case-indent 'safe-local-variable 'integerp)
669 (defcustom verilog-auto-newline t
670 "Non-nil means automatically newline after semicolons."
671 :group 'verilog-mode-indent
672 :type 'boolean)
673 (put 'verilog-auto-newline 'safe-local-variable 'verilog-booleanp)
675 (defcustom verilog-auto-indent-on-newline t
676 "Non-nil means automatically indent line after newline."
677 :group 'verilog-mode-indent
678 :type 'boolean)
679 (put 'verilog-auto-indent-on-newline 'safe-local-variable 'verilog-booleanp)
681 (defcustom verilog-tab-always-indent t
682 "Non-nil means TAB should always re-indent the current line.
683 A nil value means TAB will only reindent when at the beginning of the line."
684 :group 'verilog-mode-indent
685 :type 'boolean)
686 (put 'verilog-tab-always-indent 'safe-local-variable 'verilog-booleanp)
688 (defcustom verilog-tab-to-comment nil
689 "Non-nil means TAB moves to the right hand column in preparation for a comment."
690 :group 'verilog-mode-actions
691 :type 'boolean)
692 (put 'verilog-tab-to-comment 'safe-local-variable 'verilog-booleanp)
694 (defcustom verilog-indent-begin-after-if t
695 "Non-nil means indent begin statements following if, else, while, etc.
696 Otherwise, line them up."
697 :group 'verilog-mode-indent
698 :type 'boolean)
699 (put 'verilog-indent-begin-after-if 'safe-local-variable 'verilog-booleanp)
701 (defcustom verilog-align-ifelse nil
702 "Non-nil means align `else' under matching `if'.
703 Otherwise else is lined up with first character on line holding matching if."
704 :group 'verilog-mode-indent
705 :type 'boolean)
706 (put 'verilog-align-ifelse 'safe-local-variable 'verilog-booleanp)
708 (defcustom verilog-minimum-comment-distance 10
709 "Minimum distance (in lines) between begin and end required before a comment.
710 Setting this variable to zero results in every end acquiring a comment; the
711 default avoids too many redundant comments in tight quarters."
712 :group 'verilog-mode-indent
713 :type 'integer)
714 (put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp)
716 (defcustom verilog-highlight-p1800-keywords nil
717 "Non-nil means highlight words newly reserved by IEEE-1800.
718 These will appear in `verilog-font-lock-p1800-face' in order to gently
719 suggest changing where these words are used as variables to something else.
720 A nil value means highlight these words as appropriate for the SystemVerilog
721 IEEE-1800 standard. Note that changing this will require restarting Emacs
722 to see the effect as font color choices are cached by Emacs."
723 :group 'verilog-mode-indent
724 :type 'boolean)
725 (put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp)
727 (defcustom verilog-highlight-grouping-keywords nil
728 "Non-nil means highlight grouping keywords more dramatically.
729 If false, these words are in the `font-lock-type-face'; if True
730 then they are in `verilog-font-lock-grouping-keywords-face'.
731 Some find that special highlighting on these grouping constructs
732 allow the structure of the code to be understood at a glance."
733 :group 'verilog-mode-indent
734 :type 'boolean)
735 (put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp)
737 (defcustom verilog-highlight-modules nil
738 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
739 When true, mousing over module names will allow jumping to the
740 module definition. If false, this is not supported. Setting
741 this is experimental, and may lead to bad performance."
742 :group 'verilog-mode-indent
743 :type 'boolean)
744 (put 'verilog-highlight-modules 'safe-local-variable 'verilog-booleanp)
746 (defcustom verilog-highlight-includes t
747 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
748 When true, mousing over include file names will allow jumping to the
749 file referenced. If false, this is not supported."
750 :group 'verilog-mode-indent
751 :type 'boolean)
752 (put 'verilog-highlight-includes 'safe-local-variable 'verilog-booleanp)
754 (defcustom verilog-auto-declare-nettype nil
755 "Non-nil specifies the data type to use with `verilog-auto-input' etc.
756 Set this to \"wire\" if the Verilog code uses \"\\=`default_nettype
757 none\". Note using \\=`default_nettype none isn't recommended practice; this
758 mode is experimental."
759 :version "24.1" ; rev670
760 :group 'verilog-mode-actions
761 :type 'boolean)
762 (put 'verilog-auto-declare-nettype 'safe-local-variable `stringp)
764 (defcustom verilog-auto-wire-comment t
765 "Non-nil indicates to insert to/from comments with `verilog-auto-wire' etc."
766 :version "25.1"
767 :group 'verilog-mode-actions
768 :type 'boolean)
769 (put 'verilog-auto-wire-comment 'safe-local-variable `verilog-booleanp)
771 (defcustom verilog-auto-wire-type nil
772 "Non-nil specifies the data type to use with `verilog-auto-wire' etc.
773 Set this to \"logic\" for SystemVerilog code, or use `verilog-auto-logic'.
774 Set this to \"wire\" to force use of wire when logic is otherwise appropriate;
775 this is generally only appropriate when making a non-SystemVerilog wrapper
776 containing SystemVerilog cells."
777 :version "24.1" ; rev673
778 :group 'verilog-mode-actions
779 :type 'string)
780 (put 'verilog-auto-wire-type 'safe-local-variable `stringp)
782 (defcustom verilog-auto-endcomments t
783 "Non-nil means insert a comment /* ... */ after `end's.
784 The name of the function or case will be set between the braces."
785 :group 'verilog-mode-actions
786 :type 'boolean)
787 (put 'verilog-auto-endcomments 'safe-local-variable 'verilog-booleanp)
789 (defcustom verilog-auto-delete-trailing-whitespace nil
790 "Non-nil means to `delete-trailing-whitespace' in `verilog-auto'."
791 :version "24.1" ; rev703
792 :group 'verilog-mode-actions
793 :type 'boolean)
794 (put 'verilog-auto-delete-trailing-whitespace 'safe-local-variable 'verilog-booleanp)
796 (defcustom verilog-auto-ignore-concat nil
797 "Non-nil means ignore signals in {...} concatenations for AUTOWIRE etc.
798 This will exclude signals referenced as pin connections in {...}
799 from AUTOWIRE, AUTOOUTPUT and friends. This flag should be set
800 for backward compatibility only and not set in new designs; it
801 may be removed in future versions."
802 :group 'verilog-mode-actions
803 :type 'boolean)
804 (put 'verilog-auto-ignore-concat 'safe-local-variable 'verilog-booleanp)
806 (defcustom verilog-auto-read-includes nil
807 "Non-nil means to automatically read includes before AUTOs.
808 This will do a `verilog-read-defines' and `verilog-read-includes' before
809 each AUTO expansion. This makes it easier to embed defines and includes,
810 but can result in very slow reading times if there are many or large
811 include files."
812 :group 'verilog-mode-actions
813 :type 'boolean)
814 (put 'verilog-auto-read-includes 'safe-local-variable 'verilog-booleanp)
816 (defcustom verilog-auto-save-policy nil
817 "Non-nil indicates action to take when saving a Verilog buffer with AUTOs.
818 A value of `force' will always do a \\[verilog-auto] automatically if
819 needed on every save. A value of `detect' will do \\[verilog-auto]
820 automatically when it thinks necessary. A value of `ask' will query the
821 user when it thinks updating is needed.
823 You should not rely on the `ask' or `detect' policies, they are safeguards
824 only. They do not detect when AUTOINSTs need to be updated because a
825 sub-module's port list has changed."
826 :group 'verilog-mode-actions
827 :type '(choice (const nil) (const ask) (const detect) (const force)))
829 (defcustom verilog-auto-star-expand t
830 "Non-nil means to expand SystemVerilog .* instance ports.
831 They will be expanded in the same way as if there was an AUTOINST in the
832 instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'."
833 :group 'verilog-mode-actions
834 :type 'boolean)
835 (put 'verilog-auto-star-expand 'safe-local-variable 'verilog-booleanp)
837 (defcustom verilog-auto-star-save nil
838 "Non-nil means save to disk SystemVerilog .* instance expansions.
839 A nil value indicates direct connections will be removed before saving.
840 Only meaningful to those created due to `verilog-auto-star-expand' being set.
842 Instead of setting this, you may want to use /*AUTOINST*/, which will
843 always be saved."
844 :group 'verilog-mode-actions
845 :type 'boolean)
846 (put 'verilog-auto-star-save 'safe-local-variable 'verilog-booleanp)
848 (defvar verilog-auto-update-tick nil
849 "Modification tick at which autos were last performed.")
851 (defvar verilog-auto-last-file-locals nil
852 "Text from file-local-variables during last evaluation.")
854 (defvar verilog-diff-function 'verilog-diff-report
855 "Function to run when `verilog-diff-auto' detects differences.
856 Function takes three arguments, the original buffer, the
857 difference buffer, and the point in original buffer with the
858 first difference.")
860 (defvar verilog-diff-ignore-regexp nil
861 "Non-nil specifies regexp which `verilog-diff-auto' will ignore.
862 This is typically nil.")
864 ;;; Compile support:
867 (require 'compile)
869 (defvar verilog-error-regexp-added nil)
871 (defvar verilog-error-regexp-emacs-alist
873 (verilog-xl-1
874 "\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
875 (verilog-xl-2
876 "([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 3)
877 (verilog-IES
878 ".*\\*[WE],[0-9A-Z]+\\(\\[[0-9A-Z_,]+\\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)" 2 3)
879 (verilog-surefire-1
880 "[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2)
881 (verilog-surefire-2
882 "\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\),\\s-+\\(line \\)?\\([0-9]+\\):" 2 4 )
883 (verilog-verbose
885 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
886 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
887 (verilog-xsim
888 "\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3)
889 (verilog-vcs-1
890 "\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3)
891 (verilog-vcs-2
892 "Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2)
893 (verilog-vcs-3
894 "\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3)
895 (verilog-vcs-4
896 "syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
897 (verilog-verilator
898 "%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
899 (verilog-leda
900 "^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 2)
902 "List of regexps for Verilog compilers.
903 See `compilation-error-regexp-alist' for the formatting. For Emacs 22+.")
905 (defvar verilog-error-regexp-xemacs-alist
906 ;; Emacs form is '((v-tool "re" 1 2) ...)
907 ;; XEmacs form is '(verilog ("re" 1 2) ...)
908 ;; So we can just map from Emacs to XEmacs
909 (cons 'verilog (mapcar 'cdr verilog-error-regexp-emacs-alist))
910 "List of regexps for Verilog compilers.
911 See `compilation-error-regexp-alist-alist' for the formatting. For XEmacs.")
913 (defvar verilog-error-font-lock-keywords
915 ;; verilog-xl-1
916 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
917 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
918 ;; verilog-xl-2
919 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 bold t)
920 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 3 bold t)
921 ;; verilog-IES (nc-verilog)
922 (".*\\*[WE],[0-9A-Z]+\\(\\[[0-9A-Z_,]+\\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t)
923 (".*\\*[WE],[0-9A-Z]+\\(\\[[0-9A-Z_,]+\\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 3 bold t)
924 ;; verilog-surefire-1
925 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t)
926 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t)
927 ;; verilog-surefire-2
928 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t)
929 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t)
930 ;; verilog-verbose
932 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
933 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
935 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
936 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
937 ;; verilog-vcs-1
938 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t)
939 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t)
940 ;; verilog-vcs-2
941 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
942 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
943 ;; verilog-vcs-3
944 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
945 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t)
946 ;; verilog-vcs-4
947 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t)
948 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
949 ;; verilog-verilator
950 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t)
951 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t)
952 ;; verilog-leda
953 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 bold t)
954 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 2 bold t)
956 "Keywords to also highlight in Verilog *compilation* buffers.
957 Only used in XEmacs; GNU Emacs uses `verilog-error-regexp-emacs-alist'.")
959 (defcustom verilog-library-flags '("")
960 "List of standard Verilog arguments to use for /*AUTOINST*/.
961 These arguments are used to find files for `verilog-auto', and match
962 the flags accepted by a standard Verilog-XL simulator.
964 -f filename Reads more `verilog-library-flags' from the filename.
965 +incdir+dir Adds the directory to `verilog-library-directories'.
966 -Idir Adds the directory to `verilog-library-directories'.
967 -y dir Adds the directory to `verilog-library-directories'.
968 +libext+.v Adds the extensions to `verilog-library-extensions'.
969 -v filename Adds the filename to `verilog-library-files'.
971 filename Adds the filename to `verilog-library-files'.
972 This is not recommended, -v is a better choice.
974 You might want these defined in each file; put at the *END* of your file
975 something like:
977 // Local Variables:
978 // verilog-library-flags:(\"-y dir -y otherdir\")
979 // End:
981 Verilog-mode attempts to detect changes to this local variable, but they
982 are only insured to be correct when the file is first visited. Thus if you
983 have problems, use \\[find-alternate-file] RET to have these take effect.
985 See also the variables mentioned above."
986 :group 'verilog-mode-auto
987 :type '(repeat string))
988 (put 'verilog-library-flags 'safe-local-variable 'listp)
990 (defcustom verilog-library-directories '(".")
991 "List of directories when looking for files for /*AUTOINST*/.
992 The directory may be relative to the current file, or absolute.
993 Environment variables are also expanded in the directory names.
994 Having at least the current directory is a good idea.
996 You might want these defined in each file; put at the *END* of your file
997 something like:
999 // Local Variables:
1000 // verilog-library-directories:(\".\" \"subdir\" \"subdir2\")
1001 // End:
1003 Verilog-mode attempts to detect changes to this local variable, but they
1004 are only insured to be correct when the file is first visited. Thus if you
1005 have problems, use \\[find-alternate-file] RET to have these take effect.
1007 See also `verilog-library-flags', `verilog-library-files'
1008 and `verilog-library-extensions'."
1009 :group 'verilog-mode-auto
1010 :type '(repeat file))
1011 (put 'verilog-library-directories 'safe-local-variable 'listp)
1013 (defcustom verilog-library-files '()
1014 "List of files to search for modules.
1015 AUTOINST will use this when it needs to resolve a module name.
1016 This is a complete path, usually to a technology file with many standard
1017 cells defined in it.
1019 You might want these defined in each file; put at the *END* of your file
1020 something like:
1022 // Local Variables:
1023 // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\")
1024 // End:
1026 Verilog-mode attempts to detect changes to this local variable, but they
1027 are only insured to be correct when the file is first visited. Thus if you
1028 have problems, use \\[find-alternate-file] RET to have these take effect.
1030 See also `verilog-library-flags', `verilog-library-directories'."
1031 :group 'verilog-mode-auto
1032 :type '(repeat directory))
1033 (put 'verilog-library-files 'safe-local-variable 'listp)
1035 (defcustom verilog-library-extensions '(".v" ".sv")
1036 "List of extensions to use when looking for files for /*AUTOINST*/.
1037 See also `verilog-library-flags', `verilog-library-directories'."
1038 :type '(repeat string)
1039 :group 'verilog-mode-auto)
1040 (put 'verilog-library-extensions 'safe-local-variable 'listp)
1042 (defcustom verilog-active-low-regexp nil
1043 "If true, treat signals matching this regexp as active low.
1044 This is used for AUTORESET and AUTOTIEOFF. For proper behavior,
1045 you will probably also need `verilog-auto-reset-widths' set."
1046 :group 'verilog-mode-auto
1047 :type '(choice (const nil) regexp))
1048 (put 'verilog-active-low-regexp 'safe-local-variable 'stringp)
1050 (defcustom verilog-auto-sense-include-inputs nil
1051 "Non-nil means AUTOSENSE should include all inputs.
1052 If nil, only inputs that are NOT output signals in the same block are
1053 included."
1054 :group 'verilog-mode-auto
1055 :type 'boolean)
1056 (put 'verilog-auto-sense-include-inputs 'safe-local-variable 'verilog-booleanp)
1058 (defcustom verilog-auto-sense-defines-constant nil
1059 "Non-nil means AUTOSENSE should assume all defines represent constants.
1060 When true, the defines will not be included in sensitivity lists. To
1061 maintain compatibility with other sites, this should be set at the bottom
1062 of each Verilog file that requires it, rather than being set globally."
1063 :group 'verilog-mode-auto
1064 :type 'boolean)
1065 (put 'verilog-auto-sense-defines-constant 'safe-local-variable 'verilog-booleanp)
1067 (defcustom verilog-auto-reset-blocking-in-non t
1068 "Non-nil means AUTORESET will reset blocking statements.
1069 When true, AUTORESET will reset in blocking statements those
1070 signals which were assigned with blocking assignments (=) even in
1071 a block with non-blocking assignments (<=).
1073 If nil, all blocking assigned signals are ignored when any
1074 non-blocking assignment is in the AUTORESET block. This allows
1075 blocking assignments to be used for temporary values and not have
1076 those temporaries reset. See example in `verilog-auto-reset'."
1077 :version "24.1" ; rev718
1078 :type 'boolean
1079 :group 'verilog-mode-auto)
1080 (put 'verilog-auto-reset-blocking-in-non 'safe-local-variable 'verilog-booleanp)
1082 (defcustom verilog-auto-reset-widths t
1083 "True means AUTORESET should determine the width of signals.
1084 This is then used to set the width of the zero (32'h0 for example). This
1085 is required by some lint tools that aren't smart enough to ignore widths of
1086 the constant zero. This may result in ugly code when parameters determine
1087 the MSB or LSB of a signal inside an AUTORESET.
1089 If nil, AUTORESET uses \"0\" as the constant.
1091 If `unbased', AUTORESET used the unbased unsized literal \"\\='0\"
1092 as the constant. This setting is strongly recommended for
1093 SystemVerilog designs."
1094 :type 'boolean
1095 :group 'verilog-mode-auto)
1096 (put 'verilog-auto-reset-widths 'safe-local-variable
1097 '(lambda (x) (memq x '(nil t unbased))))
1099 (defcustom verilog-assignment-delay ""
1100 "Text used for delays in delayed assignments. Add a trailing space if set."
1101 :group 'verilog-mode-auto
1102 :type 'string)
1103 (put 'verilog-assignment-delay 'safe-local-variable 'stringp)
1105 (defcustom verilog-auto-arg-format 'packed
1106 "Formatting to use for AUTOARG signal names.
1107 If `packed', then as many inputs and outputs that fit within
1108 `fill-column' will be put onto one line.
1110 If `single', then a single input or output will be put onto each
1111 line."
1112 :version "25.1"
1113 :type '(radio (const :tag "Line up Assignments and Declarations" packed)
1114 (const :tag "Line up Assignment statements" single))
1115 :group 'verilog-mode-auto)
1116 (put 'verilog-auto-arg-format 'safe-local-variable
1117 '(lambda (x) (memq x '(packed single))))
1119 (defcustom verilog-auto-arg-sort nil
1120 "Non-nil means AUTOARG signal names will be sorted, not in declaration order.
1121 Declaration order is advantageous with order based instantiations
1122 and is the default for backward compatibility. Sorted order
1123 reduces changes when declarations are moved around in a file, and
1124 it's bad practice to rely on order based instantiations anyhow.
1126 See also `verilog-auto-inst-sort'."
1127 :group 'verilog-mode-auto
1128 :type 'boolean)
1129 (put 'verilog-auto-arg-sort 'safe-local-variable 'verilog-booleanp)
1131 (defcustom verilog-auto-inst-dot-name nil
1132 "Non-nil means when creating ports with AUTOINST, use .name syntax.
1133 This will use \".port\" instead of \".port(port)\" when possible.
1134 This is only legal in SystemVerilog files, and will confuse older
1135 simulators. Setting `verilog-auto-inst-vector' to nil may also
1136 be desirable to increase how often .name will be used."
1137 :group 'verilog-mode-auto
1138 :type 'boolean)
1139 (put 'verilog-auto-inst-dot-name 'safe-local-variable 'verilog-booleanp)
1141 (defcustom verilog-auto-inst-param-value nil
1142 "Non-nil means AUTOINST will replace parameters with the parameter value.
1143 If nil, leave parameters as symbolic names.
1145 Parameters must be in Verilog 2001 format #(...), and if a parameter is not
1146 listed as such there (as when the default value is acceptable), it will not
1147 be replaced, and will remain symbolic.
1149 For example, imagine a submodule uses parameters to declare the size of its
1150 inputs. This is then used by an upper module:
1152 module InstModule (o,i);
1153 parameter WIDTH;
1154 input [WIDTH-1:0] i;
1155 parameter type OUT_t;
1156 output OUT_t o;
1157 endmodule
1159 module ExampInst;
1160 /*AUTOOUTPUT*/
1161 // Beginning of automatic outputs
1162 output OUT_t o;
1163 // End of automatics
1165 InstModule
1166 #(.WIDTH(10),
1167 ,.OUT_t(upper_t))
1168 instName
1169 (/*AUTOINST*/
1170 .i (i[WIDTH-1:0]),
1171 .o (o));
1173 Note even though WIDTH=10, the AUTOINST has left the parameter as
1174 a symbolic name. Likewise the OUT_t is preserved as the name
1175 from the instantiated module.
1177 If `verilog-auto-inst-param-value' is set, this will
1178 instead expand to:
1180 module ExampInst;
1181 /*AUTOOUTPUT*/
1182 // Beginning of automatic outputs
1183 output upper_t o;
1184 // End of automatics
1186 InstModule
1187 #(.WIDTH(10),
1188 ,.OUT_t(upper_t))
1189 instName
1190 (/*AUTOINST*/
1191 .i (i[9:0]),
1192 .o (o));
1194 Note that the instantiation now has \"i[9:0]\" as the WIDTH
1195 was expanded. Likewise the data type of \"o\" in the AUTOOUTPUT
1196 is now upper_t, from the OUT_t parameter override.
1197 This second expansion of parameter types can be overridden with
1198 `verilog-auto-inst-param-value-type'."
1199 :group 'verilog-mode-auto
1200 :type 'boolean)
1201 (put 'verilog-auto-inst-param-value 'safe-local-variable 'verilog-booleanp)
1203 (defcustom verilog-auto-inst-param-value-type t
1204 "Non-nil means expand parameter type in instantiations.
1205 If nil, leave parameter types as symbolic names.
1207 See `verilog-auto-inst-param-value'."
1208 :version "25.1"
1209 :group 'verilog-mode-auto
1210 :type 'boolean)
1211 (put 'verilog-auto-inst-param-value-type 'safe-local-variable 'verilog-booleanp)
1213 (defcustom verilog-auto-inst-sort nil
1214 "Non-nil means AUTOINST signals will be sorted, not in declaration order.
1215 Also affects AUTOINSTPARAM. Declaration order is the default for
1216 backward compatibility, and as some teams prefer signals that are
1217 declared together to remain together. Sorted order reduces
1218 changes when declarations are moved around in a file.
1220 See also `verilog-auto-arg-sort'."
1221 :version "24.1" ; rev688
1222 :group 'verilog-mode-auto
1223 :type 'boolean)
1224 (put 'verilog-auto-inst-sort 'safe-local-variable 'verilog-booleanp)
1226 (defcustom verilog-auto-inst-vector t
1227 "Non-nil means when creating default ports with AUTOINST, use bus subscripts.
1228 If nil, skip the subscript when it matches the entire bus as declared in
1229 the module (AUTOWIRE signals always are subscripted, you must manually
1230 declare the wire to have the subscripts removed.) Setting this to nil may
1231 speed up some simulators, but is less general and harder to read, so avoid."
1232 :group 'verilog-mode-auto
1233 :type 'boolean)
1234 (put 'verilog-auto-inst-vector 'safe-local-variable 'verilog-booleanp)
1236 (defcustom verilog-auto-inst-template-numbers nil
1237 "If true, when creating templated ports with AUTOINST, add a comment.
1239 If t, the comment will add the line number of the template that
1240 was used for that port declaration. This setting is suggested
1241 only for debugging use, as regular use may cause a large numbers
1242 of merge conflicts.
1244 If `lhs', the comment will show the left hand side of the
1245 AUTO_TEMPLATE rule that is matched. This is less precise than
1246 numbering (t) when multiple rules have the same pin name, but
1247 won't merge conflict."
1248 :group 'verilog-mode-auto
1249 :type '(choice (const nil) (const t) (const lhs)))
1250 (put 'verilog-auto-inst-template-numbers 'safe-local-variable
1251 '(lambda (x) (memq x '(nil t lhs))))
1253 (defcustom verilog-auto-inst-column 40
1254 "Indent-to column number for net name part of AUTOINST created pin."
1255 :group 'verilog-mode-indent
1256 :type 'integer)
1257 (put 'verilog-auto-inst-column 'safe-local-variable 'integerp)
1259 (defcustom verilog-auto-inst-interfaced-ports nil
1260 "Non-nil means include interfaced ports in AUTOINST expansions."
1261 :version "24.3" ; rev773, default change rev815
1262 :group 'verilog-mode-auto
1263 :type 'boolean)
1264 (put 'verilog-auto-inst-interfaced-ports 'safe-local-variable 'verilog-booleanp)
1266 (defcustom verilog-auto-input-ignore-regexp nil
1267 "If non-nil, when creating AUTOINPUT, ignore signals matching this regexp.
1268 See the \\[verilog-faq] for examples on using this."
1269 :group 'verilog-mode-auto
1270 :type '(choice (const nil) regexp))
1271 (put 'verilog-auto-input-ignore-regexp 'safe-local-variable 'stringp)
1273 (defcustom verilog-auto-inout-ignore-regexp nil
1274 "If non-nil, when creating AUTOINOUT, ignore signals matching this regexp.
1275 See the \\[verilog-faq] for examples on using this."
1276 :group 'verilog-mode-auto
1277 :type '(choice (const nil) regexp))
1278 (put 'verilog-auto-inout-ignore-regexp 'safe-local-variable 'stringp)
1280 (defcustom verilog-auto-output-ignore-regexp nil
1281 "If non-nil, when creating AUTOOUTPUT, ignore signals matching this regexp.
1282 See the \\[verilog-faq] for examples on using this."
1283 :group 'verilog-mode-auto
1284 :type '(choice (const nil) regexp))
1285 (put 'verilog-auto-output-ignore-regexp 'safe-local-variable 'stringp)
1287 (defcustom verilog-auto-template-warn-unused nil
1288 "Non-nil means report warning if an AUTO_TEMPLATE line is not used.
1289 This feature is not supported before Emacs 21.1 or XEmacs 21.4."
1290 :version "24.3" ; rev787
1291 :group 'verilog-mode-auto
1292 :type 'boolean)
1293 (put 'verilog-auto-template-warn-unused 'safe-local-variable 'verilog-booleanp)
1295 (defcustom verilog-auto-tieoff-declaration "wire"
1296 "Data type used for the declaration for AUTOTIEOFF.
1297 If \"wire\" then create a wire, if \"assign\" create an
1298 assignment, else the data type for variable creation."
1299 :version "24.1" ; rev713
1300 :group 'verilog-mode-auto
1301 :type 'string)
1302 (put 'verilog-auto-tieoff-declaration 'safe-local-variable 'stringp)
1304 (defcustom verilog-auto-tieoff-ignore-regexp nil
1305 "If non-nil, when creating AUTOTIEOFF, ignore signals matching this regexp.
1306 See the \\[verilog-faq] for examples on using this."
1307 :group 'verilog-mode-auto
1308 :type '(choice (const nil) regexp))
1309 (put 'verilog-auto-tieoff-ignore-regexp 'safe-local-variable 'stringp)
1311 (defcustom verilog-auto-unused-ignore-regexp nil
1312 "If non-nil, when creating AUTOUNUSED, ignore signals matching this regexp.
1313 See the \\[verilog-faq] for examples on using this."
1314 :group 'verilog-mode-auto
1315 :type '(choice (const nil) regexp))
1316 (put 'verilog-auto-unused-ignore-regexp 'safe-local-variable 'stringp)
1318 (defcustom verilog-case-fold t
1319 "Non-nil means `verilog-mode' regexps should ignore case.
1320 This variable is t for backward compatibility; nil is suggested."
1321 :version "24.4"
1322 :group 'verilog-mode
1323 :type 'boolean)
1324 (put 'verilog-case-fold 'safe-local-variable 'verilog-booleanp)
1326 (defcustom verilog-typedef-regexp nil
1327 "If non-nil, regular expression that matches Verilog-2001 typedef names.
1328 For example, \"_t$\" matches typedefs named with _t, as in the C language.
1329 See also `verilog-case-fold'."
1330 :group 'verilog-mode-auto
1331 :type '(choice (const nil) regexp))
1332 (put 'verilog-typedef-regexp 'safe-local-variable 'stringp)
1334 (defcustom verilog-mode-hook 'verilog-set-compile-command
1335 "Hook run after Verilog mode is loaded."
1336 :type 'hook
1337 :group 'verilog-mode)
1339 (defcustom verilog-auto-hook nil
1340 "Hook run after `verilog-mode' updates AUTOs."
1341 :group 'verilog-mode-auto
1342 :type 'hook)
1344 (defcustom verilog-before-auto-hook nil
1345 "Hook run before `verilog-mode' updates AUTOs."
1346 :group 'verilog-mode-auto
1347 :type 'hook)
1349 (defcustom verilog-delete-auto-hook nil
1350 "Hook run after `verilog-mode' deletes AUTOs."
1351 :group 'verilog-mode-auto
1352 :type 'hook)
1354 (defcustom verilog-before-delete-auto-hook nil
1355 "Hook run before `verilog-mode' deletes AUTOs."
1356 :group 'verilog-mode-auto
1357 :type 'hook)
1359 (defcustom verilog-getopt-flags-hook nil
1360 "Hook run after `verilog-getopt-flags' determines the Verilog option lists."
1361 :group 'verilog-mode-auto
1362 :type 'hook)
1364 (defcustom verilog-before-getopt-flags-hook nil
1365 "Hook run before `verilog-getopt-flags' determines the Verilog option lists."
1366 :group 'verilog-mode-auto
1367 :type 'hook)
1369 (defcustom verilog-before-save-font-hook nil
1370 "Hook run before `verilog-save-font-no-change-functions' removes highlighting."
1371 :version "24.3" ; rev735
1372 :group 'verilog-mode-auto
1373 :type 'hook)
1375 (defcustom verilog-after-save-font-hook nil
1376 "Hook run after `verilog-save-font-no-change-functions' restores highlighting."
1377 :version "24.3" ; rev735
1378 :group 'verilog-mode-auto
1379 :type 'hook)
1381 (defvar verilog-imenu-generic-expression
1382 '((nil "^\\s-*\\(?:m\\(?:odule\\|acromodule\\)\\|p\\(?:rimitive\\|rogram\\|ackage\\)\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 1)
1383 ("*Variables*" "^\\s-*\\(reg\\|wire\\|logic\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3)
1384 ("*Classes*" "^\\s-*\\(?:\\(?:virtual\\|interface\\)\\s-+\\)?class\\s-+\\([A-Za-z_][A-Za-z0-9_]+\\)" 1)
1385 ("*Tasks*" "^\\s-*\\(?:\\(?:static\\|pure\\|virtual\\|local\\|protected\\)\\s-+\\)*task\\s-+\\(?:\\(?:static\\|automatic\\)\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_:]+\\)" 1)
1386 ("*Functions*" "^\\s-*\\(?:\\(?:static\\|pure\\|virtual\\|local\\|protected\\)\\s-+\\)*function\\s-+\\(?:\\(?:static\\|automatic\\)\\s-+\\)?\\(?:\\w+\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_:]+\\)" 1)
1387 ("*Interfaces*" "^\\s-*interface\\s-+\\([a-zA-Z_0-9]+\\)" 1)
1388 ("*Types*" "^\\s-*typedef\\s-+.*\\s-+\\([a-zA-Z_0-9]+\\)\\s-*;" 1))
1389 "Imenu expression for Verilog mode. See `imenu-generic-expression'.")
1392 ;; provide a verilog-header function.
1393 ;; Customization variables:
1395 (defvar verilog-date-scientific-format nil
1396 "If non-nil, dates are written in scientific format (e.g. 1997/09/17).
1397 If nil, in European format (e.g. 17.09.1997). The brain-dead American
1398 format (e.g. 09/17/1997) is not supported.")
1400 (defvar verilog-company nil
1401 "Default name of Company for Verilog header.
1402 If set will become buffer local.")
1403 (make-variable-buffer-local 'verilog-company)
1405 (defvar verilog-project nil
1406 "Default name of Project for Verilog header.
1407 If set will become buffer local.")
1408 (make-variable-buffer-local 'verilog-project)
1410 ;;; Keymap and Menu:
1413 (defvar verilog-mode-map
1414 (let ((map (make-sparse-keymap)))
1415 (define-key map ";" 'electric-verilog-semi)
1416 (define-key map [(control 59)] 'electric-verilog-semi-with-comment)
1417 (define-key map ":" 'electric-verilog-colon)
1418 ;;(define-key map "=" 'electric-verilog-equal)
1419 (define-key map "`" 'electric-verilog-tick)
1420 (define-key map "\t" 'electric-verilog-tab)
1421 (define-key map "\r" 'electric-verilog-terminate-line)
1422 ;; backspace/delete key bindings
1423 (define-key map [backspace] 'backward-delete-char-untabify)
1424 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
1425 (define-key map [delete] 'delete-char)
1426 (define-key map [(meta delete)] 'kill-word))
1427 (define-key map "\M-\C-b" 'electric-verilog-backward-sexp)
1428 (define-key map "\M-\C-f" 'electric-verilog-forward-sexp)
1429 (define-key map "\M-\r" `electric-verilog-terminate-and-indent)
1430 (define-key map "\M-\t" (if (fboundp 'completion-at-point)
1431 'completion-at-point 'verilog-complete-word))
1432 (define-key map "\M-?" (if (fboundp 'completion-help-at-point)
1433 'completion-help-at-point 'verilog-show-completions))
1434 ;; Note \C-c and letter are reserved for users
1435 (define-key map "\C-c`" 'verilog-lint-off)
1436 (define-key map "\C-c*" 'verilog-delete-auto-star-implicit)
1437 (define-key map "\C-c?" 'verilog-diff-auto)
1438 (define-key map "\C-c\C-r" 'verilog-label-be)
1439 (define-key map "\C-c\C-i" 'verilog-pretty-declarations)
1440 (define-key map "\C-c=" 'verilog-pretty-expr)
1441 (define-key map "\C-c\C-b" 'verilog-submit-bug-report)
1442 (define-key map "\C-c/" 'verilog-star-comment)
1443 (define-key map "\C-c\C-c" 'verilog-comment-region)
1444 (define-key map "\C-c\C-u" 'verilog-uncomment-region)
1445 (when (featurep 'xemacs)
1446 (define-key map [(meta control h)] 'verilog-mark-defun)
1447 (define-key map "\M-\C-a" 'verilog-beg-of-defun)
1448 (define-key map "\M-\C-e" 'verilog-end-of-defun))
1449 (define-key map "\C-c\C-d" 'verilog-goto-defun)
1450 (define-key map "\C-c\C-k" 'verilog-delete-auto)
1451 (define-key map "\C-c\C-a" 'verilog-auto)
1452 (define-key map "\C-c\C-s" 'verilog-auto-save-compile)
1453 (define-key map "\C-c\C-p" 'verilog-preprocess)
1454 (define-key map "\C-c\C-z" 'verilog-inject-auto)
1455 (define-key map "\C-c\C-e" 'verilog-expand-vector)
1456 (define-key map "\C-c\C-h" 'verilog-header)
1457 map)
1458 "Keymap used in Verilog mode.")
1460 ;; menus
1461 (easy-menu-define
1462 verilog-menu verilog-mode-map "Menu for Verilog mode"
1463 (verilog-easy-menu-filter
1464 `("Verilog"
1465 ("Choose Compilation Action"
1466 ["None"
1467 (progn
1468 (setq verilog-tool nil)
1469 (verilog-set-compile-command))
1470 :style radio
1471 :selected (equal verilog-tool nil)
1472 :help "When invoking compilation, use compile-command"]
1473 ["Lint"
1474 (progn
1475 (setq verilog-tool 'verilog-linter)
1476 (verilog-set-compile-command))
1477 :style radio
1478 :selected (equal verilog-tool `verilog-linter)
1479 :help "When invoking compilation, use lint checker"]
1480 ["Coverage"
1481 (progn
1482 (setq verilog-tool 'verilog-coverage)
1483 (verilog-set-compile-command))
1484 :style radio
1485 :selected (equal verilog-tool `verilog-coverage)
1486 :help "When invoking compilation, annotate for coverage"]
1487 ["Simulator"
1488 (progn
1489 (setq verilog-tool 'verilog-simulator)
1490 (verilog-set-compile-command))
1491 :style radio
1492 :selected (equal verilog-tool `verilog-simulator)
1493 :help "When invoking compilation, interpret Verilog source"]
1494 ["Compiler"
1495 (progn
1496 (setq verilog-tool 'verilog-compiler)
1497 (verilog-set-compile-command))
1498 :style radio
1499 :selected (equal verilog-tool `verilog-compiler)
1500 :help "When invoking compilation, compile Verilog source"]
1501 ["Preprocessor"
1502 (progn
1503 (setq verilog-tool 'verilog-preprocessor)
1504 (verilog-set-compile-command))
1505 :style radio
1506 :selected (equal verilog-tool `verilog-preprocessor)
1507 :help "When invoking compilation, preprocess Verilog source, see also `verilog-preprocess'"]
1509 ("Move"
1510 ["Beginning of function" verilog-beg-of-defun
1511 :keys "C-M-a"
1512 :help "Move backward to the beginning of the current function or procedure"]
1513 ["End of function" verilog-end-of-defun
1514 :keys "C-M-e"
1515 :help "Move forward to the end of the current function or procedure"]
1516 ["Mark function" verilog-mark-defun
1517 :keys "C-M-h"
1518 :help "Mark the current Verilog function or procedure"]
1519 ["Goto function/module" verilog-goto-defun
1520 :help "Move to specified Verilog module/task/function"]
1521 ["Move to beginning of block" electric-verilog-backward-sexp
1522 :help "Move backward over one balanced expression"]
1523 ["Move to end of block" electric-verilog-forward-sexp
1524 :help "Move forward over one balanced expression"]
1526 ("Comments"
1527 ["Comment Region" verilog-comment-region
1528 :help "Put marked area into a comment"]
1529 ["UnComment Region" verilog-uncomment-region
1530 :help "Uncomment an area commented with Comment Region"]
1531 ["Multi-line comment insert" verilog-star-comment
1532 :help "Insert Verilog /* */ comment at point"]
1533 ["Lint error to comment" verilog-lint-off
1534 :help "Convert a Verilog linter warning line into a disable statement"]
1536 "----"
1537 ["Compile" compile
1538 :help "Perform compilation-action (above) on the current buffer"]
1539 ["AUTO, Save, Compile" verilog-auto-save-compile
1540 :help "Recompute AUTOs, save buffer, and compile"]
1541 ["Next Compile Error" next-error
1542 :help "Visit next compilation error message and corresponding source code"]
1543 ["Ignore Lint Warning at point" verilog-lint-off
1544 :help "Convert a Verilog linter warning line into a disable statement"]
1545 "----"
1546 ["Line up declarations around point" verilog-pretty-declarations
1547 :help "Line up declarations around point"]
1548 ["Line up equations around point" verilog-pretty-expr
1549 :help "Line up expressions around point"]
1550 ["Redo/insert comments on every end" verilog-label-be
1551 :help "Label matching begin ... end statements"]
1552 ["Expand [x:y] vector line" verilog-expand-vector
1553 :help "Take a signal vector on the current line and expand it to multiple lines"]
1554 ["Insert begin-end block" verilog-insert-block
1555 :help "Insert begin ... end"]
1556 ["Complete word" ,(if (fboundp 'completion-at-point)
1557 'completion-at-point 'verilog-complete-word)
1558 :help "Complete word at point"]
1559 "----"
1560 ["Recompute AUTOs" verilog-auto
1561 :help "Expand AUTO meta-comment statements"]
1562 ["Kill AUTOs" verilog-delete-auto
1563 :help "Remove AUTO expansions"]
1564 ["Diff AUTOs" verilog-diff-auto
1565 :help "Show differences in AUTO expansions"]
1566 ["Inject AUTOs" verilog-inject-auto
1567 :help "Inject AUTOs into legacy non-AUTO buffer"]
1568 ("AUTO Help..."
1569 ["AUTO General" (describe-function 'verilog-auto)
1570 :help "Help introduction on AUTOs"]
1571 ["AUTO Library Flags" (describe-variable 'verilog-library-flags)
1572 :help "Help on verilog-library-flags"]
1573 ["AUTO Library Path" (describe-variable 'verilog-library-directories)
1574 :help "Help on verilog-library-directories"]
1575 ["AUTO Library Files" (describe-variable 'verilog-library-files)
1576 :help "Help on verilog-library-files"]
1577 ["AUTO Library Extensions" (describe-variable 'verilog-library-extensions)
1578 :help "Help on verilog-library-extensions"]
1579 ["AUTO `define Reading" (describe-function 'verilog-read-defines)
1580 :help "Help on reading `defines"]
1581 ["AUTO `include Reading" (describe-function 'verilog-read-includes)
1582 :help "Help on parsing `includes"]
1583 ["AUTOARG" (describe-function 'verilog-auto-arg)
1584 :help "Help on AUTOARG - declaring module port list"]
1585 ["AUTOASCIIENUM" (describe-function 'verilog-auto-ascii-enum)
1586 :help "Help on AUTOASCIIENUM - creating ASCII for enumerations"]
1587 ["AUTOASSIGNMODPORT" (describe-function 'verilog-auto-assign-modport)
1588 :help "Help on AUTOASSIGNMODPORT - creating assignments to/from modports"]
1589 ["AUTOINOUT" (describe-function 'verilog-auto-inout)
1590 :help "Help on AUTOINOUT - adding inouts from cells"]
1591 ["AUTOINOUTCOMP" (describe-function 'verilog-auto-inout-comp)
1592 :help "Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
1593 ["AUTOINOUTIN" (describe-function 'verilog-auto-inout-in)
1594 :help "Help on AUTOINOUTIN - copying i/o from another file as all inputs"]
1595 ["AUTOINOUTMODPORT" (describe-function 'verilog-auto-inout-modport)
1596 :help "Help on AUTOINOUTMODPORT - copying i/o from an interface modport"]
1597 ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module)
1598 :help "Help on AUTOINOUTMODULE - copying i/o from another file"]
1599 ["AUTOINOUTPARAM" (describe-function 'verilog-auto-inout-param)
1600 :help "Help on AUTOINOUTPARAM - copying parameters from another file"]
1601 ["AUTOINPUT" (describe-function 'verilog-auto-input)
1602 :help "Help on AUTOINPUT - adding inputs from cells"]
1603 ["AUTOINSERTLISP" (describe-function 'verilog-auto-insert-lisp)
1604 :help "Help on AUTOINSERTLISP - insert text from a lisp function"]
1605 ["AUTOINSERTLAST" (describe-function 'verilog-auto-insert-last)
1606 :help "Help on AUTOINSERTLISPLAST - insert text from a lisp function"]
1607 ["AUTOINST" (describe-function 'verilog-auto-inst)
1608 :help "Help on AUTOINST - adding pins for cells"]
1609 ["AUTOINST (.*)" (describe-function 'verilog-auto-star)
1610 :help "Help on expanding Verilog-2001 .* pins"]
1611 ["AUTOINSTPARAM" (describe-function 'verilog-auto-inst-param)
1612 :help "Help on AUTOINSTPARAM - adding parameter pins to cells"]
1613 ["AUTOLOGIC" (describe-function 'verilog-auto-logic)
1614 :help "Help on AUTOLOGIC - declaring logic signals"]
1615 ["AUTOOUTPUT" (describe-function 'verilog-auto-output)
1616 :help "Help on AUTOOUTPUT - adding outputs from cells"]
1617 ["AUTOOUTPUTEVERY" (describe-function 'verilog-auto-output-every)
1618 :help "Help on AUTOOUTPUTEVERY - adding outputs of all signals"]
1619 ["AUTOREG" (describe-function 'verilog-auto-reg)
1620 :help "Help on AUTOREG - declaring registers for non-wires"]
1621 ["AUTOREGINPUT" (describe-function 'verilog-auto-reg-input)
1622 :help "Help on AUTOREGINPUT - declaring inputs for non-wires"]
1623 ["AUTORESET" (describe-function 'verilog-auto-reset)
1624 :help "Help on AUTORESET - resetting always blocks"]
1625 ["AUTOSENSE or AS" (describe-function 'verilog-auto-sense)
1626 :help "Help on AUTOSENSE - sensitivity lists for always blocks"]
1627 ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff)
1628 :help "Help on AUTOTIEOFF - tying off unused outputs"]
1629 ["AUTOUNDEF" (describe-function 'verilog-auto-undef)
1630 :help "Help on AUTOUNDEF - undefine all local defines"]
1631 ["AUTOUNUSED" (describe-function 'verilog-auto-unused)
1632 :help "Help on AUTOUNUSED - terminating unused inputs"]
1633 ["AUTOWIRE" (describe-function 'verilog-auto-wire)
1634 :help "Help on AUTOWIRE - declaring wires for cells"]
1636 "----"
1637 ["Submit bug report" verilog-submit-bug-report
1638 :help "Submit via mail a bug report on verilog-mode.el"]
1639 ["Version and FAQ" verilog-faq
1640 :help "Show the current version, and where to get the FAQ etc"]
1641 ["Customize Verilog Mode..." verilog-customize
1642 :help "Customize variables and other settings used by Verilog-Mode"]
1643 ["Customize Verilog Fonts & Colors" verilog-font-customize
1644 :help "Customize fonts used by Verilog-Mode."])))
1646 (easy-menu-define
1647 verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog."
1648 (verilog-easy-menu-filter
1649 '("Statements"
1650 ["Header" verilog-sk-header
1651 :help "Insert a header block at the top of file"]
1652 ["Comment" verilog-sk-comment
1653 :help "Insert a comment block"]
1654 "----"
1655 ["Module" verilog-sk-module
1656 :help "Insert a module .. (/*AUTOARG*/);.. endmodule block"]
1657 ["OVM Class" verilog-sk-ovm-class
1658 :help "Insert an OVM class block"]
1659 ["UVM Object" verilog-sk-uvm-object
1660 :help "Insert an UVM object block"]
1661 ["UVM Component" verilog-sk-uvm-component
1662 :help "Insert an UVM component block"]
1663 ["Primitive" verilog-sk-primitive
1664 :help "Insert a primitive .. (.. );.. endprimitive block"]
1665 "----"
1666 ["Input" verilog-sk-input
1667 :help "Insert an input declaration"]
1668 ["Output" verilog-sk-output
1669 :help "Insert an output declaration"]
1670 ["Inout" verilog-sk-inout
1671 :help "Insert an inout declaration"]
1672 ["Wire" verilog-sk-wire
1673 :help "Insert a wire declaration"]
1674 ["Reg" verilog-sk-reg
1675 :help "Insert a register declaration"]
1676 ["Define thing under point as a register" verilog-sk-define-signal
1677 :help "Define signal under point as a register at the top of the module"]
1678 "----"
1679 ["Initial" verilog-sk-initial
1680 :help "Insert an initial begin .. end block"]
1681 ["Always" verilog-sk-always
1682 :help "Insert an always @(AS) begin .. end block"]
1683 ["Function" verilog-sk-function
1684 :help "Insert a function .. begin .. end endfunction block"]
1685 ["Task" verilog-sk-task
1686 :help "Insert a task .. begin .. end endtask block"]
1687 ["Specify" verilog-sk-specify
1688 :help "Insert a specify .. endspecify block"]
1689 ["Generate" verilog-sk-generate
1690 :help "Insert a generate .. endgenerate block"]
1691 "----"
1692 ["Begin" verilog-sk-begin
1693 :help "Insert a begin .. end block"]
1694 ["If" verilog-sk-if
1695 :help "Insert an if (..) begin .. end block"]
1696 ["(if) else" verilog-sk-else-if
1697 :help "Insert an else if (..) begin .. end block"]
1698 ["For" verilog-sk-for
1699 :help "Insert a for (...) begin .. end block"]
1700 ["While" verilog-sk-while
1701 :help "Insert a while (...) begin .. end block"]
1702 ["Fork" verilog-sk-fork
1703 :help "Insert a fork begin .. end .. join block"]
1704 ["Repeat" verilog-sk-repeat
1705 :help "Insert a repeat (..) begin .. end block"]
1706 ["Case" verilog-sk-case
1707 :help "Insert a case block, prompting for details"]
1708 ["Casex" verilog-sk-casex
1709 :help "Insert a casex (...) item: begin.. end endcase block"]
1710 ["Casez" verilog-sk-casez
1711 :help "Insert a casez (...) item: begin.. end endcase block"])))
1713 (defvar verilog-mode-abbrev-table nil
1714 "Abbrev table in use in Verilog-mode buffers.")
1716 ;;(makunbound 'verilog-mode-abbrev-table) ; For testing, clear out old defvar
1717 (verilog-define-abbrev-table
1718 'verilog-mode-abbrev-table ()
1719 "Abbrev table for Verilog mode skeletons."
1720 :case-fixed t
1721 ;; Only expand in code.
1722 :enable-function (lambda () (not (verilog-in-comment-or-string-p))))
1723 (verilog-define-abbrev verilog-mode-abbrev-table "class" "" 'verilog-sk-ovm-class)
1724 (verilog-define-abbrev verilog-mode-abbrev-table "always" "" 'verilog-sk-always)
1725 (verilog-define-abbrev verilog-mode-abbrev-table "begin" nil `verilog-sk-begin)
1726 (verilog-define-abbrev verilog-mode-abbrev-table "case" "" `verilog-sk-case)
1727 (verilog-define-abbrev verilog-mode-abbrev-table "for" "" `verilog-sk-for)
1728 (verilog-define-abbrev verilog-mode-abbrev-table "generate" "" `verilog-sk-generate)
1729 (verilog-define-abbrev verilog-mode-abbrev-table "initial" "" `verilog-sk-initial)
1730 (verilog-define-abbrev verilog-mode-abbrev-table "fork" "" `verilog-sk-fork)
1731 (verilog-define-abbrev verilog-mode-abbrev-table "module" "" `verilog-sk-module)
1732 (verilog-define-abbrev verilog-mode-abbrev-table "primitive" "" `verilog-sk-primitive)
1733 (verilog-define-abbrev verilog-mode-abbrev-table "repeat" "" `verilog-sk-repeat)
1734 (verilog-define-abbrev verilog-mode-abbrev-table "specify" "" `verilog-sk-specify)
1735 (verilog-define-abbrev verilog-mode-abbrev-table "task" "" `verilog-sk-task)
1736 (verilog-define-abbrev verilog-mode-abbrev-table "while" "" `verilog-sk-while)
1737 (verilog-define-abbrev verilog-mode-abbrev-table "casex" "" `verilog-sk-casex)
1738 (verilog-define-abbrev verilog-mode-abbrev-table "casez" "" `verilog-sk-casez)
1739 (verilog-define-abbrev verilog-mode-abbrev-table "if" "" `verilog-sk-if)
1740 (verilog-define-abbrev verilog-mode-abbrev-table "else if" "" `verilog-sk-else-if)
1741 (verilog-define-abbrev verilog-mode-abbrev-table "assign" "" `verilog-sk-assign)
1742 (verilog-define-abbrev verilog-mode-abbrev-table "function" "" `verilog-sk-function)
1743 (verilog-define-abbrev verilog-mode-abbrev-table "input" "" `verilog-sk-input)
1744 (verilog-define-abbrev verilog-mode-abbrev-table "output" "" `verilog-sk-output)
1745 (verilog-define-abbrev verilog-mode-abbrev-table "inout" "" `verilog-sk-inout)
1746 (verilog-define-abbrev verilog-mode-abbrev-table "wire" "" `verilog-sk-wire)
1747 (verilog-define-abbrev verilog-mode-abbrev-table "reg" "" `verilog-sk-reg)
1750 ;; Macros
1753 (defsubst verilog-within-string ()
1754 (nth 3 (parse-partial-sexp (point-at-bol) (point))))
1756 (defsubst verilog-string-match-fold (regexp string &optional start)
1757 "Like `string-match', but use `verilog-case-fold'.
1758 Return index of start of first match for REGEXP in STRING, or nil.
1759 Matching ignores case if `verilog-case-fold' is non-nil.
1760 If third arg START is non-nil, start search at that index in STRING."
1761 (let ((case-fold-search verilog-case-fold))
1762 (string-match regexp string start)))
1764 (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string)
1765 "Replace occurrences of FROM-STRING with TO-STRING.
1766 FIXEDCASE and LITERAL as in `replace-match'. STRING is what to replace.
1767 The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\")
1768 will break, as the o's continuously replace. xa -> x works ok though."
1769 ;; Hopefully soon to an Emacs built-in
1770 ;; Also note \ in the replacement prevent multiple replacements; IE
1771 ;; (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil "wire@_@")
1772 ;; Gives "wire\([0-9]+\)_@" not "wire\([0-9]+\)_\([0-9]+\)"
1773 (let ((start 0))
1774 (while (string-match from-string string start)
1775 (setq string (replace-match to-string fixedcase literal string)
1776 start (min (length string) (+ (match-beginning 0) (length to-string)))))
1777 string))
1779 (defsubst verilog-string-remove-spaces (string)
1780 "Remove spaces surrounding STRING."
1781 (save-match-data
1782 (setq string (verilog-string-replace-matches "^\\s-+" "" nil nil string))
1783 (setq string (verilog-string-replace-matches "\\s-+$" "" nil nil string))
1784 string))
1786 (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR)
1787 ;; checkdoc-params: (REGEXP BOUND NOERROR)
1788 "Like `re-search-forward', but skips over match in comments or strings."
1789 (let ((mdata '(nil nil))) ; So match-end will return nil if no matches found
1790 (while (and
1791 (re-search-forward REGEXP BOUND NOERROR)
1792 (setq mdata (match-data))
1793 (and (verilog-skip-forward-comment-or-string)
1794 (progn
1795 (setq mdata '(nil nil))
1796 (if BOUND
1797 (< (point) BOUND)
1798 t)))))
1799 (store-match-data mdata)
1800 (match-end 0)))
1802 (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR)
1803 ;; checkdoc-params: (REGEXP BOUND NOERROR)
1804 "Like `re-search-backward', but skips over match in comments or strings."
1805 (let ((mdata '(nil nil))) ; So match-end will return nil if no matches found
1806 (while (and
1807 (re-search-backward REGEXP BOUND NOERROR)
1808 (setq mdata (match-data))
1809 (and (verilog-skip-backward-comment-or-string)
1810 (progn
1811 (setq mdata '(nil nil))
1812 (if BOUND
1813 (> (point) BOUND)
1814 t)))))
1815 (store-match-data mdata)
1816 (match-end 0)))
1818 (defsubst verilog-re-search-forward-quick (regexp bound noerror)
1819 "Like `verilog-re-search-forward', including use of REGEXP BOUND and NOERROR,
1820 but trashes match data and is faster for REGEXP that doesn't match often.
1821 This uses `verilog-scan' and text properties to ignore comments,
1822 so there may be a large up front penalty for the first search."
1823 (let (pt)
1824 (while (and (not pt)
1825 (re-search-forward regexp bound noerror))
1826 (if (verilog-inside-comment-or-string-p (match-beginning 0))
1827 (re-search-forward "[/\"\n]" nil t) ; Only way a comment or quote can end
1828 (setq pt (match-end 0))))
1829 pt))
1831 (defsubst verilog-re-search-backward-quick (regexp bound noerror)
1832 ;; checkdoc-params: (REGEXP BOUND NOERROR)
1833 "Like `verilog-re-search-backward', including use of REGEXP BOUND and NOERROR,
1834 but trashes match data and is faster for REGEXP that doesn't match often.
1835 This uses `verilog-scan' and text properties to ignore comments,
1836 so there may be a large up front penalty for the first search."
1837 (let (pt)
1838 (while (and (not pt)
1839 (re-search-backward regexp bound noerror))
1840 (if (verilog-inside-comment-or-string-p (match-beginning 0))
1841 (re-search-backward "[/\"]" nil t) ; Only way a comment or quote can begin
1842 (setq pt (match-beginning 0))))
1843 pt))
1845 (defsubst verilog-re-search-forward-substr (substr regexp bound noerror)
1846 "Like `re-search-forward', but first search for SUBSTR constant.
1847 Then searched for the normal REGEXP (which contains SUBSTR), with given
1848 BOUND and NOERROR. The REGEXP must fit within a single line.
1849 This speeds up complicated regexp matches."
1850 ;; Problem with overlap: search-forward BAR then FOOBARBAZ won't match.
1851 ;; thus require matches to be on one line, and use beginning-of-line.
1852 (let (done)
1853 (while (and (not done)
1854 (search-forward substr bound noerror))
1855 (save-excursion
1856 (beginning-of-line)
1857 (setq done (re-search-forward regexp (point-at-eol) noerror)))
1858 (unless (and (<= (match-beginning 0) (point))
1859 (>= (match-end 0) (point)))
1860 (setq done nil)))
1861 (when done (goto-char done))
1862 done))
1863 ;;(verilog-re-search-forward-substr "-end" "get-end-of" nil t) ; -end (test bait)
1865 (defsubst verilog-re-search-backward-substr (substr regexp bound noerror)
1866 "Like `re-search-backward', but first search for SUBSTR constant.
1867 Then searched for the normal REGEXP (which contains SUBSTR), with given
1868 BOUND and NOERROR. The REGEXP must fit within a single line.
1869 This speeds up complicated regexp matches."
1870 ;; Problem with overlap: search-backward BAR then FOOBARBAZ won't match.
1871 ;; thus require matches to be on one line, and use beginning-of-line.
1872 (let (done)
1873 (while (and (not done)
1874 (search-backward substr bound noerror))
1875 (save-excursion
1876 (end-of-line)
1877 (setq done (re-search-backward regexp (point-at-bol) noerror)))
1878 (unless (and (<= (match-beginning 0) (point))
1879 (>= (match-end 0) (point)))
1880 (setq done nil)))
1881 (when done (goto-char done))
1882 done))
1883 ;;(verilog-re-search-backward-substr "-end" "get-end-of" nil t) ; -end (test bait)
1885 (defun verilog-delete-trailing-whitespace ()
1886 "Delete trailing spaces or tabs, but not newlines nor linefeeds.
1887 Also add missing final newline.
1889 To call this from the command line, see \\[verilog-batch-diff-auto].
1891 To call on \\[verilog-auto], set `verilog-auto-delete-trailing-whitespace'."
1892 ;; Similar to `delete-trailing-whitespace' but that's not present in XEmacs
1893 (save-excursion
1894 (goto-char (point-min))
1895 (while (re-search-forward "[ \t]+$" nil t) ; Not syntactic WS as no formfeed
1896 (replace-match "" nil nil))
1897 (goto-char (point-max))
1898 (unless (bolp) (insert "\n"))))
1900 (defvar compile-command)
1901 (defvar create-lockfiles) ; Emacs 24
1903 ;; compilation program
1904 (defun verilog-set-compile-command ()
1905 "Function to compute shell command to compile Verilog.
1907 This reads `verilog-tool' and sets `compile-command'. This specifies the
1908 program that executes when you type \\[compile] or
1909 \\[verilog-auto-save-compile].
1911 By default `verilog-tool' uses a Makefile if one exists in the
1912 current directory. If not, it is set to the `verilog-linter',
1913 `verilog-compiler', `verilog-coverage', `verilog-preprocessor',
1914 or `verilog-simulator' variables, as selected with the Verilog ->
1915 \"Choose Compilation Action\" menu.
1917 You should set `verilog-tool' or the other variables to the path and
1918 arguments for your Verilog simulator. For example:
1919 \"vcs -p123 -O\"
1920 or a string like:
1921 \"(cd /tmp; surecov %s)\".
1923 In the former case, the path to the current buffer is concat'ed to the
1924 value of `verilog-tool'; in the later, the path to the current buffer is
1925 substituted for the %s.
1927 Where __FLAGS__ appears in the string `verilog-current-flags'
1928 will be substituted.
1930 Where __FILE__ appears in the string, the variable
1931 `buffer-file-name' of the current buffer, without the directory
1932 portion, will be substituted."
1933 (interactive)
1934 (cond
1935 ((or (file-exists-p "makefile") ;If there is a makefile, use it
1936 (file-exists-p "Makefile"))
1937 (set (make-local-variable 'compile-command) "make "))
1939 (set (make-local-variable 'compile-command)
1940 (if verilog-tool
1941 (if (string-match "%s" (eval verilog-tool))
1942 (format (eval verilog-tool) (or buffer-file-name ""))
1943 (concat (eval verilog-tool) " " (or buffer-file-name "")))
1944 ""))))
1945 (verilog-modify-compile-command))
1947 (defun verilog-expand-command (command)
1948 "Replace meta-information in COMMAND and return it.
1949 Where __FLAGS__ appears in the string `verilog-current-flags'
1950 will be substituted. Where __FILE__ appears in the string, the
1951 current buffer's file-name, without the directory portion, will
1952 be substituted."
1953 (setq command (verilog-string-replace-matches
1954 ;; Note \\b only works if under verilog syntax table
1955 "\\b__FLAGS__\\b" (verilog-current-flags)
1956 t t command))
1957 (setq command (verilog-string-replace-matches
1958 "\\b__FILE__\\b" (file-name-nondirectory
1959 (or (buffer-file-name) ""))
1960 t t command))
1961 command)
1963 ;; Eliminate compile warning
1964 (defvar verilog-compile-command-pre-mod)
1965 (defvar verilog-compile-command-post-mod)
1967 (defun verilog-modify-compile-command ()
1968 "Update `compile-command' using `verilog-expand-command'."
1969 ;; Entry into verilog-mode a call to this before Local Variables exist
1970 ;; Likewise user may have hook or something that changes the flags.
1971 ;; So, remember we're responsible for the expansion and on re-entry
1972 ;; recompute __FLAGS__ on each reentry.
1973 (when (stringp compile-command)
1974 (when (and
1975 (boundp 'verilog-compile-command-post-mod)
1976 (equal compile-command verilog-compile-command-post-mod))
1977 (setq compile-command verilog-compile-command-pre-mod))
1978 (when (and
1979 (string-match "\\b\\(__FLAGS__\\|__FILE__\\)\\b" compile-command))
1980 (set (make-local-variable 'verilog-compile-command-pre-mod)
1981 compile-command)
1982 (set (make-local-variable 'compile-command)
1983 (verilog-expand-command compile-command))
1984 (set (make-local-variable 'verilog-compile-command-post-mod)
1985 compile-command))))
1987 (if (featurep 'xemacs)
1988 ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling.
1989 (defun verilog-error-regexp-add-xemacs ()
1990 "Teach XEmacs about verilog errors.
1991 Called by `compilation-mode-hook'. This allows \\[next-error] to
1992 find the errors."
1993 (interactive)
1994 (if (boundp 'compilation-error-regexp-systems-alist)
1995 (if (and
1996 (not (equal compilation-error-regexp-systems-list 'all))
1997 (not (member compilation-error-regexp-systems-list 'verilog)))
1998 (push 'verilog compilation-error-regexp-systems-list)))
1999 (if (boundp 'compilation-error-regexp-alist-alist)
2000 (if (not (assoc 'verilog compilation-error-regexp-alist-alist))
2001 (setcdr compilation-error-regexp-alist-alist
2002 (cons verilog-error-regexp-xemacs-alist
2003 (cdr compilation-error-regexp-alist-alist)))))
2004 (if (boundp 'compilation-font-lock-keywords)
2005 (progn
2006 (set (make-local-variable 'compilation-font-lock-keywords)
2007 verilog-error-font-lock-keywords)
2008 (font-lock-set-defaults)))
2009 ;; Need to re-run compilation-error-regexp builder
2010 (if (fboundp 'compilation-build-compilation-error-regexp-alist)
2011 (compilation-build-compilation-error-regexp-alist))
2014 ;; Following code only gets called from compilation-mode-hook on Emacs to add error handling.
2015 (defun verilog-error-regexp-add-emacs ()
2016 "Tell Emacs compile that we are Verilog.
2017 Called by `compilation-mode-hook'. This allows \\[next-error] to
2018 find the errors."
2019 (interactive)
2020 (when (boundp 'compilation-error-regexp-alist-alist)
2021 (when (not (assoc 'verilog-xl-1 compilation-error-regexp-alist-alist))
2022 (mapcar
2023 (lambda (item)
2024 (push (car item) compilation-error-regexp-alist)
2025 (push item compilation-error-regexp-alist-alist))
2026 verilog-error-regexp-emacs-alist))))
2028 (if (featurep 'xemacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-xemacs))
2029 (if (featurep 'emacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-emacs))
2031 (defconst verilog-compiler-directives
2032 (eval-when-compile
2034 ;; compiler directives, from IEEE 1800-2012 section 22.1
2035 "`__FILE__" "`__LINE" "`begin_keywords" "`celldefine" "`default_nettype"
2036 "`define" "`else" "`elsif" "`end_keywords" "`endcelldefine" "`endif"
2037 "`ifdef" "`ifndef" "`include" "`line" "`nounconnected_drive" "`pragma"
2038 "`resetall" "`timescale" "`unconnected_drive" "`undef" "`undefineall"
2039 ;; compiler directives not covered by IEEE 1800
2040 "`case" "`default" "`endfor" "`endprotect" "`endswitch" "`endwhile" "`for"
2041 "`format" "`if" "`let" "`protect" "`switch" "`timescale" "`time_scale"
2042 "`while"
2044 "List of Verilog compiler directives.")
2046 (defconst verilog-directive-re
2047 (verilog-regexp-words verilog-compiler-directives))
2049 (defconst verilog-directive-re-1
2050 (concat "[ \t]*" verilog-directive-re))
2052 (defconst verilog-directive-begin
2053 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>")
2055 (defconst verilog-directive-middle
2056 "\\<`\\(else\\|elsif\\|default\\|case\\)\\>")
2058 (defconst verilog-directive-end
2059 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>")
2061 (defconst verilog-ovm-begin-re
2062 (eval-when-compile
2063 (verilog-regexp-opt
2065 "`ovm_component_utils_begin"
2066 "`ovm_component_param_utils_begin"
2067 "`ovm_field_utils_begin"
2068 "`ovm_object_utils_begin"
2069 "`ovm_object_param_utils_begin"
2070 "`ovm_sequence_utils_begin"
2071 "`ovm_sequencer_utils_begin"
2072 ) nil )))
2074 (defconst verilog-ovm-end-re
2075 (eval-when-compile
2076 (verilog-regexp-opt
2078 "`ovm_component_utils_end"
2079 "`ovm_field_utils_end"
2080 "`ovm_object_utils_end"
2081 "`ovm_sequence_utils_end"
2082 "`ovm_sequencer_utils_end"
2083 ) nil )))
2085 (defconst verilog-uvm-begin-re
2086 (eval-when-compile
2087 (verilog-regexp-opt
2089 "`uvm_component_utils_begin"
2090 "`uvm_component_param_utils_begin"
2091 "`uvm_field_utils_begin"
2092 "`uvm_object_utils_begin"
2093 "`uvm_object_param_utils_begin"
2094 "`uvm_sequence_utils_begin"
2095 "`uvm_sequencer_utils_begin"
2096 ) nil )))
2098 (defconst verilog-uvm-end-re
2099 (eval-when-compile
2100 (verilog-regexp-opt
2102 "`uvm_component_utils_end"
2103 "`uvm_field_utils_end"
2104 "`uvm_object_utils_end"
2105 "`uvm_sequence_utils_end"
2106 "`uvm_sequencer_utils_end"
2107 ) nil )))
2109 (defconst verilog-vmm-begin-re
2110 (eval-when-compile
2111 (verilog-regexp-opt
2113 "`vmm_data_member_begin"
2114 "`vmm_env_member_begin"
2115 "`vmm_scenario_member_begin"
2116 "`vmm_subenv_member_begin"
2117 "`vmm_xactor_member_begin"
2118 ) nil ) ) )
2120 (defconst verilog-vmm-end-re
2121 (eval-when-compile
2122 (verilog-regexp-opt
2124 "`vmm_data_member_end"
2125 "`vmm_env_member_end"
2126 "`vmm_scenario_member_end"
2127 "`vmm_subenv_member_end"
2128 "`vmm_xactor_member_end"
2129 ) nil ) ) )
2131 (defconst verilog-vmm-statement-re
2132 (eval-when-compile
2133 (verilog-regexp-opt
2135 "`vmm_\\(data\\|env\\|scenario\\|subenv\\|xactor\\)_member_\\(scalar\\|string\\|enum\\|vmm_data\\|channel\\|xactor\\|subenv\\|user_defined\\)\\(_array\\)?"
2136 ;; "`vmm_xactor_member_enum_array"
2137 ;; "`vmm_xactor_member_scalar_array"
2138 ;; "`vmm_xactor_member_scalar"
2139 ) nil )))
2141 (defconst verilog-ovm-statement-re
2142 (eval-when-compile
2143 (verilog-regexp-opt
2145 ;; Statements
2146 "`DUT_ERROR"
2147 "`MESSAGE"
2148 "`dut_error"
2149 "`message"
2150 "`ovm_analysis_imp_decl"
2151 "`ovm_blocking_get_imp_decl"
2152 "`ovm_blocking_get_peek_imp_decl"
2153 "`ovm_blocking_master_imp_decl"
2154 "`ovm_blocking_peek_imp_decl"
2155 "`ovm_blocking_put_imp_decl"
2156 "`ovm_blocking_slave_imp_decl"
2157 "`ovm_blocking_transport_imp_decl"
2158 "`ovm_component_registry"
2159 "`ovm_component_registry_param"
2160 "`ovm_component_utils"
2161 "`ovm_create"
2162 "`ovm_create_seq"
2163 "`ovm_declare_sequence_lib"
2164 "`ovm_do"
2165 "`ovm_do_seq"
2166 "`ovm_do_seq_with"
2167 "`ovm_do_with"
2168 "`ovm_error"
2169 "`ovm_fatal"
2170 "`ovm_field_aa_int_byte"
2171 "`ovm_field_aa_int_byte_unsigned"
2172 "`ovm_field_aa_int_int"
2173 "`ovm_field_aa_int_int_unsigned"
2174 "`ovm_field_aa_int_integer"
2175 "`ovm_field_aa_int_integer_unsigned"
2176 "`ovm_field_aa_int_key"
2177 "`ovm_field_aa_int_longint"
2178 "`ovm_field_aa_int_longint_unsigned"
2179 "`ovm_field_aa_int_shortint"
2180 "`ovm_field_aa_int_shortint_unsigned"
2181 "`ovm_field_aa_int_string"
2182 "`ovm_field_aa_object_int"
2183 "`ovm_field_aa_object_string"
2184 "`ovm_field_aa_string_int"
2185 "`ovm_field_aa_string_string"
2186 "`ovm_field_array_int"
2187 "`ovm_field_array_object"
2188 "`ovm_field_array_string"
2189 "`ovm_field_enum"
2190 "`ovm_field_event"
2191 "`ovm_field_int"
2192 "`ovm_field_object"
2193 "`ovm_field_queue_int"
2194 "`ovm_field_queue_object"
2195 "`ovm_field_queue_string"
2196 "`ovm_field_sarray_int"
2197 "`ovm_field_string"
2198 "`ovm_field_utils"
2199 "`ovm_file"
2200 "`ovm_get_imp_decl"
2201 "`ovm_get_peek_imp_decl"
2202 "`ovm_info"
2203 "`ovm_info1"
2204 "`ovm_info2"
2205 "`ovm_info3"
2206 "`ovm_info4"
2207 "`ovm_line"
2208 "`ovm_master_imp_decl"
2209 "`ovm_msg_detail"
2210 "`ovm_non_blocking_transport_imp_decl"
2211 "`ovm_nonblocking_get_imp_decl"
2212 "`ovm_nonblocking_get_peek_imp_decl"
2213 "`ovm_nonblocking_master_imp_decl"
2214 "`ovm_nonblocking_peek_imp_decl"
2215 "`ovm_nonblocking_put_imp_decl"
2216 "`ovm_nonblocking_slave_imp_decl"
2217 "`ovm_object_registry"
2218 "`ovm_object_registry_param"
2219 "`ovm_object_utils"
2220 "`ovm_peek_imp_decl"
2221 "`ovm_phase_func_decl"
2222 "`ovm_phase_task_decl"
2223 "`ovm_print_aa_int_object"
2224 "`ovm_print_aa_string_int"
2225 "`ovm_print_aa_string_object"
2226 "`ovm_print_aa_string_string"
2227 "`ovm_print_array_int"
2228 "`ovm_print_array_object"
2229 "`ovm_print_array_string"
2230 "`ovm_print_object_queue"
2231 "`ovm_print_queue_int"
2232 "`ovm_print_string_queue"
2233 "`ovm_put_imp_decl"
2234 "`ovm_rand_send"
2235 "`ovm_rand_send_with"
2236 "`ovm_send"
2237 "`ovm_sequence_utils"
2238 "`ovm_slave_imp_decl"
2239 "`ovm_transport_imp_decl"
2240 "`ovm_update_sequence_lib"
2241 "`ovm_update_sequence_lib_and_item"
2242 "`ovm_warning"
2243 "`static_dut_error"
2244 "`static_message") nil )))
2246 (defconst verilog-uvm-statement-re
2247 (eval-when-compile
2248 (verilog-regexp-opt
2250 ;; Statements
2251 "`uvm_analysis_imp_decl"
2252 "`uvm_blocking_get_imp_decl"
2253 "`uvm_blocking_get_peek_imp_decl"
2254 "`uvm_blocking_master_imp_decl"
2255 "`uvm_blocking_peek_imp_decl"
2256 "`uvm_blocking_put_imp_decl"
2257 "`uvm_blocking_slave_imp_decl"
2258 "`uvm_blocking_transport_imp_decl"
2259 "`uvm_component_param_utils"
2260 "`uvm_component_registry"
2261 "`uvm_component_registry_param"
2262 "`uvm_component_utils"
2263 "`uvm_create"
2264 "`uvm_create_on"
2265 "`uvm_create_seq" ; Undocumented in 1.1
2266 "`uvm_declare_p_sequencer"
2267 "`uvm_declare_sequence_lib" ; Deprecated in 1.1
2268 "`uvm_do"
2269 "`uvm_do_callbacks"
2270 "`uvm_do_callbacks_exit_on"
2271 "`uvm_do_obj_callbacks"
2272 "`uvm_do_obj_callbacks_exit_on"
2273 "`uvm_do_on"
2274 "`uvm_do_on_pri"
2275 "`uvm_do_on_pri_with"
2276 "`uvm_do_on_with"
2277 "`uvm_do_pri"
2278 "`uvm_do_pri_with"
2279 "`uvm_do_seq" ; Undocumented in 1.1
2280 "`uvm_do_seq_with" ; Undocumented in 1.1
2281 "`uvm_do_with"
2282 "`uvm_error"
2283 "`uvm_error_context"
2284 "`uvm_fatal"
2285 "`uvm_fatal_context"
2286 "`uvm_field_aa_int_byte"
2287 "`uvm_field_aa_int_byte_unsigned"
2288 "`uvm_field_aa_int_enum"
2289 "`uvm_field_aa_int_int"
2290 "`uvm_field_aa_int_int_unsigned"
2291 "`uvm_field_aa_int_integer"
2292 "`uvm_field_aa_int_integer_unsigned"
2293 "`uvm_field_aa_int_key"
2294 "`uvm_field_aa_int_longint"
2295 "`uvm_field_aa_int_longint_unsigned"
2296 "`uvm_field_aa_int_shortint"
2297 "`uvm_field_aa_int_shortint_unsigned"
2298 "`uvm_field_aa_int_string"
2299 "`uvm_field_aa_object_int"
2300 "`uvm_field_aa_object_string"
2301 "`uvm_field_aa_string_int"
2302 "`uvm_field_aa_string_string"
2303 "`uvm_field_array_enum"
2304 "`uvm_field_array_int"
2305 "`uvm_field_array_object"
2306 "`uvm_field_array_string"
2307 "`uvm_field_enum"
2308 "`uvm_field_event"
2309 "`uvm_field_int"
2310 "`uvm_field_object"
2311 "`uvm_field_queue_enum"
2312 "`uvm_field_queue_int"
2313 "`uvm_field_queue_object"
2314 "`uvm_field_queue_string"
2315 "`uvm_field_real"
2316 "`uvm_field_sarray_enum"
2317 "`uvm_field_sarray_int"
2318 "`uvm_field_sarray_object"
2319 "`uvm_field_sarray_string"
2320 "`uvm_field_string"
2321 "`uvm_field_utils"
2322 "`uvm_file" ; Undocumented in 1.1, use `__FILE__
2323 "`uvm_get_imp_decl"
2324 "`uvm_get_peek_imp_decl"
2325 "`uvm_info"
2326 "`uvm_info_context"
2327 "`uvm_line" ; Undocumented in 1.1, use `__LINE__
2328 "`uvm_master_imp_decl"
2329 "`uvm_non_blocking_transport_imp_decl" ; Deprecated in 1.1
2330 "`uvm_nonblocking_get_imp_decl"
2331 "`uvm_nonblocking_get_peek_imp_decl"
2332 "`uvm_nonblocking_master_imp_decl"
2333 "`uvm_nonblocking_peek_imp_decl"
2334 "`uvm_nonblocking_put_imp_decl"
2335 "`uvm_nonblocking_slave_imp_decl"
2336 "`uvm_nonblocking_transport_imp_decl"
2337 "`uvm_object_param_utils"
2338 "`uvm_object_registry"
2339 "`uvm_object_registry_param" ; Undocumented in 1.1
2340 "`uvm_object_utils"
2341 "`uvm_pack_array"
2342 "`uvm_pack_arrayN"
2343 "`uvm_pack_enum"
2344 "`uvm_pack_enumN"
2345 "`uvm_pack_int"
2346 "`uvm_pack_intN"
2347 "`uvm_pack_queue"
2348 "`uvm_pack_queueN"
2349 "`uvm_pack_real"
2350 "`uvm_pack_sarray"
2351 "`uvm_pack_sarrayN"
2352 "`uvm_pack_string"
2353 "`uvm_peek_imp_decl"
2354 "`uvm_put_imp_decl"
2355 "`uvm_rand_send"
2356 "`uvm_rand_send_pri"
2357 "`uvm_rand_send_pri_with"
2358 "`uvm_rand_send_with"
2359 "`uvm_record_attribute"
2360 "`uvm_record_field"
2361 "`uvm_register_cb"
2362 "`uvm_send"
2363 "`uvm_send_pri"
2364 "`uvm_sequence_utils" ; Deprecated in 1.1
2365 "`uvm_set_super_type"
2366 "`uvm_slave_imp_decl"
2367 "`uvm_transport_imp_decl"
2368 "`uvm_unpack_array"
2369 "`uvm_unpack_arrayN"
2370 "`uvm_unpack_enum"
2371 "`uvm_unpack_enumN"
2372 "`uvm_unpack_int"
2373 "`uvm_unpack_intN"
2374 "`uvm_unpack_queue"
2375 "`uvm_unpack_queueN"
2376 "`uvm_unpack_real"
2377 "`uvm_unpack_sarray"
2378 "`uvm_unpack_sarrayN"
2379 "`uvm_unpack_string"
2380 "`uvm_update_sequence_lib" ; Deprecated in 1.1
2381 "`uvm_update_sequence_lib_and_item" ; Deprecated in 1.1
2382 "`uvm_warning"
2383 "`uvm_warning_context") nil )))
2387 ;; Regular expressions used to calculate indent, etc.
2389 (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
2390 ;; Want to match
2391 ;; aa :
2392 ;; aa,bb :
2393 ;; a[34:32] :
2394 ;; a,
2395 ;; b :
2396 (defconst verilog-assignment-operator-re
2397 (eval-when-compile
2398 (verilog-regexp-opt
2400 ;; blocking assignment_operator
2401 "=" "+=" "-=" "*=" "/=" "%=" "&=" "|=" "^=" "<<=" ">>=" "<<<=" ">>>="
2402 ;; non blocking assignment operator
2403 "<="
2404 ;; comparison
2405 "==" "!=" "===" "!==" "<=" ">=" "==?" "!=?" "<->"
2406 ;; event_trigger
2407 "->" "->>"
2408 ;; property_expr
2409 "|->" "|=>" "#-#" "#=#"
2410 ;; distribution weighting
2411 ":=" ":/"
2412 ) 't
2414 (defconst verilog-assignment-operation-re
2415 (concat
2416 ;; "\\(^\\s-*[A-Za-z0-9_]+\\(\\[\\([A-Za-z0-9_]+\\)\\]\\)*\\s-*\\)"
2417 ;; "\\(^\\s-*[^=<>+-*/%&|^:\\s-]+[^=<>+-*/%&|^\n]*?\\)"
2418 "\\(^.*?\\)" "\\B" verilog-assignment-operator-re "\\B" ))
2420 (defconst verilog-label-re (concat verilog-symbol-re "\\s-*:\\s-*"))
2421 (defconst verilog-property-re
2422 (concat "\\(" verilog-label-re "\\)?"
2423 ;; "\\(assert\\|assume\\|cover\\)\\s-+property\\>"
2424 "\\(\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(assert\\)"))
2426 (defconst verilog-no-indent-begin-re
2427 (eval-when-compile
2428 (verilog-regexp-words
2429 '("always" "always_comb" "always_ff" "always_latch" "initial" "final" ; procedural blocks
2430 "if" "else" ; conditional statements
2431 "while" "for" "foreach" "repeat" "do" "forever" )))) ; loop statements
2433 (defconst verilog-ends-re
2434 ;; Parenthesis indicate type of keyword found
2435 (concat
2436 "\\(\\<else\\>\\)\\|" ; 1
2437 "\\(\\<if\\>\\)\\|" ; 2
2438 "\\(\\<assert\\>\\)\\|" ; 3
2439 "\\(\\<end\\>\\)\\|" ; 3.1
2440 "\\(\\<endcase\\>\\)\\|" ; 4
2441 "\\(\\<endfunction\\>\\)\\|" ; 5
2442 "\\(\\<endtask\\>\\)\\|" ; 6
2443 "\\(\\<endspecify\\>\\)\\|" ; 7
2444 "\\(\\<endtable\\>\\)\\|" ; 8
2445 "\\(\\<endgenerate\\>\\)\\|" ; 9
2446 "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10
2447 "\\(\\<endclass\\>\\)\\|" ; 11
2448 "\\(\\<endgroup\\>\\)\\|" ; 12
2449 ;; VMM
2450 "\\(\\<`vmm_data_member_end\\>\\)\\|"
2451 "\\(\\<`vmm_env_member_end\\>\\)\\|"
2452 "\\(\\<`vmm_scenario_member_end\\>\\)\\|"
2453 "\\(\\<`vmm_subenv_member_end\\>\\)\\|"
2454 "\\(\\<`vmm_xactor_member_end\\>\\)\\|"
2455 ;; OVM
2456 "\\(\\<`ovm_component_utils_end\\>\\)\\|"
2457 "\\(\\<`ovm_field_utils_end\\>\\)\\|"
2458 "\\(\\<`ovm_object_utils_end\\>\\)\\|"
2459 "\\(\\<`ovm_sequence_utils_end\\>\\)\\|"
2460 "\\(\\<`ovm_sequencer_utils_end\\>\\)"
2461 ;; UVM
2462 "\\(\\<`uvm_component_utils_end\\>\\)\\|"
2463 "\\(\\<`uvm_field_utils_end\\>\\)\\|"
2464 "\\(\\<`uvm_object_utils_end\\>\\)\\|"
2465 "\\(\\<`uvm_sequence_utils_end\\>\\)\\|"
2466 "\\(\\<`uvm_sequencer_utils_end\\>\\)"
2469 (defconst verilog-auto-end-comment-lines-re
2470 ;; Matches to names in this list cause auto-end-commenting
2471 (concat "\\("
2472 verilog-directive-re "\\)\\|\\("
2473 (eval-when-compile
2474 (verilog-regexp-words
2475 `( "begin"
2476 "else"
2477 "end"
2478 "endcase"
2479 "endclass"
2480 "endclocking"
2481 "endgroup"
2482 "endfunction"
2483 "endmodule"
2484 "endprogram"
2485 "endprimitive"
2486 "endinterface"
2487 "endpackage"
2488 "endsequence"
2489 "endproperty"
2490 "endspecify"
2491 "endtable"
2492 "endtask"
2493 "join"
2494 "join_any"
2495 "join_none"
2496 "module"
2497 "macromodule"
2498 "primitive"
2499 "interface"
2500 "package")))
2501 "\\)"))
2503 ;; NOTE: verilog-leap-to-head expects that verilog-end-block-re and
2504 ;; verilog-end-block-ordered-re matches exactly the same strings.
2505 (defconst verilog-end-block-ordered-re
2506 ;; Parenthesis indicate type of keyword found
2507 (concat "\\(\\<endcase\\>\\)\\|" ; 1
2508 "\\(\\<end\\>\\)\\|" ; 2
2509 "\\(\\<end" ; 3, but not used
2510 "\\(" ; 4, but not used
2511 "\\(function\\)\\|" ; 5
2512 "\\(task\\)\\|" ; 6
2513 "\\(module\\)\\|" ; 7
2514 "\\(primitive\\)\\|" ; 8
2515 "\\(interface\\)\\|" ; 9
2516 "\\(package\\)\\|" ; 10
2517 "\\(class\\)\\|" ; 11
2518 "\\(group\\)\\|" ; 12
2519 "\\(program\\)\\|" ; 13
2520 "\\(sequence\\)\\|" ; 14
2521 "\\(clocking\\)\\|" ; 15
2522 "\\(property\\)\\|" ; 16
2523 "\\)\\>\\)"))
2524 (defconst verilog-end-block-re
2525 (eval-when-compile
2526 (verilog-regexp-words
2528 `("end" ; closes begin
2529 "endcase" ; closes any of case, casex casez or randcase
2530 "join" "join_any" "join_none" ; closes fork
2531 "endclass"
2532 "endtable"
2533 "endspecify"
2534 "endfunction"
2535 "endgenerate"
2536 "endtask"
2537 "endgroup"
2538 "endproperty"
2539 "endinterface"
2540 "endpackage"
2541 "endprogram"
2542 "endsequence"
2543 "endclocking"
2544 ;; OVM
2545 "`ovm_component_utils_end"
2546 "`ovm_field_utils_end"
2547 "`ovm_object_utils_end"
2548 "`ovm_sequence_utils_end"
2549 "`ovm_sequencer_utils_end"
2550 ;; UVM
2551 "`uvm_component_utils_end"
2552 "`uvm_field_utils_end"
2553 "`uvm_object_utils_end"
2554 "`uvm_sequence_utils_end"
2555 "`uvm_sequencer_utils_end"
2556 ;; VMM
2557 "`vmm_data_member_end"
2558 "`vmm_env_member_end"
2559 "`vmm_scenario_member_end"
2560 "`vmm_subenv_member_end"
2561 "`vmm_xactor_member_end"
2562 ))))
2565 (defconst verilog-endcomment-reason-re
2566 ;; Parenthesis indicate type of keyword found
2567 (concat
2568 "\\(\\<begin\\>\\)\\|" ; 1
2569 "\\(\\<else\\>\\)\\|" ; 2
2570 "\\(\\<end\\>\\s-+\\<else\\>\\)\\|" ; 3
2571 "\\(\\<always\\(?:_ff\\)?\\>\\(?:[ \t]*@\\)\\)\\|" ; 4 (matches always or always_ff w/ @...)
2572 "\\(\\<always\\(?:_comb\\|_latch\\)?\\>\\)\\|" ; 5 (matches always, always_comb, always_latch w/o @...)
2573 "\\(\\<fork\\>\\)\\|" ; 7
2574 "\\(\\<if\\>\\)\\|"
2575 verilog-property-re "\\|"
2576 "\\(\\(" verilog-label-re "\\)?\\<assert\\>\\)\\|"
2577 "\\(\\<clocking\\>\\)\\|"
2578 "\\(\\<task\\>\\)\\|"
2579 "\\(\\<function\\>\\)\\|"
2580 "\\(\\<initial\\>\\)\\|"
2581 "\\(\\<interface\\>\\)\\|"
2582 "\\(\\<package\\>\\)\\|"
2583 "\\(\\<final\\>\\)\\|"
2584 "\\(@\\)\\|"
2585 "\\(\\<while\\>\\)\\|\\(\\<do\\>\\)\\|"
2586 "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|"
2587 "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|"
2588 "#"))
2590 (defconst verilog-named-block-re "begin[ \t]*:")
2592 ;; These words begin a block which can occur inside a module which should be indented,
2593 ;; and closed with the respective word from the end-block list
2595 (defconst verilog-beg-block-re
2596 (eval-when-compile
2597 (verilog-regexp-words
2598 `("begin"
2599 "case" "casex" "casez" "randcase"
2600 "clocking"
2601 "generate"
2602 "fork"
2603 "function"
2604 "property"
2605 "specify"
2606 "table"
2607 "task"
2608 ;; OVM
2609 "`ovm_component_utils_begin"
2610 "`ovm_component_param_utils_begin"
2611 "`ovm_field_utils_begin"
2612 "`ovm_object_utils_begin"
2613 "`ovm_object_param_utils_begin"
2614 "`ovm_sequence_utils_begin"
2615 "`ovm_sequencer_utils_begin"
2616 ;; UVM
2617 "`uvm_component_utils_begin"
2618 "`uvm_component_param_utils_begin"
2619 "`uvm_field_utils_begin"
2620 "`uvm_object_utils_begin"
2621 "`uvm_object_param_utils_begin"
2622 "`uvm_sequence_utils_begin"
2623 "`uvm_sequencer_utils_begin"
2624 ;; VMM
2625 "`vmm_data_member_begin"
2626 "`vmm_env_member_begin"
2627 "`vmm_scenario_member_begin"
2628 "`vmm_subenv_member_begin"
2629 "`vmm_xactor_member_begin"
2630 ))))
2631 ;; These are the same words, in a specific order in the regular
2632 ;; expression so that matching will work nicely for
2633 ;; verilog-forward-sexp and verilog-calc-indent
2634 (defconst verilog-beg-block-re-ordered
2635 ( concat "\\(\\<begin\\>\\)" ;1
2636 "\\|\\(\\<randcase\\>\\|\\(\\<unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\>\\)" ; 2,3
2637 "\\|\\(\\(\\<disable\\>\\s-+\\|\\<wait\\>\\s-+\\)?fork\\>\\)" ;4,5
2638 "\\|\\(\\<class\\>\\)" ;6
2639 "\\|\\(\\<table\\>\\)" ;7
2640 "\\|\\(\\<specify\\>\\)" ;8
2641 "\\|\\(\\<function\\>\\)" ;9
2642 "\\|\\(\\(?:\\<\\(?:virtual\\|protected\\|static\\)\\>\\s-+\\)*\\<function\\>\\)" ;10
2643 "\\|\\(\\<task\\>\\)" ;11
2644 "\\|\\(\\(?:\\<\\(?:virtual\\|protected\\|static\\)\\>\\s-+\\)*\\<task\\>\\)" ;12
2645 "\\|\\(\\<generate\\>\\)" ;13
2646 "\\|\\(\\<covergroup\\>\\)" ;14
2647 "\\|\\(\\(?:\\(?:\\<cover\\>\\s-+\\)\\|\\(?:\\<assert\\>\\s-+\\)\\)*\\<property\\>\\)" ;15
2648 "\\|\\(\\<\\(?:rand\\)?sequence\\>\\)" ;16
2649 "\\|\\(\\<clocking\\>\\)" ;17
2650 "\\|\\(\\<`[ou]vm_[a-z_]+_begin\\>\\)" ;18
2651 "\\|\\(\\<`vmm_[a-z_]+_member_begin\\>\\)"
2655 (defconst verilog-end-block-ordered-rry
2656 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2657 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)"
2658 "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2659 "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)"
2660 "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)"
2661 "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)"
2662 "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)"
2663 "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)"
2664 "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)"
2665 "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)"
2666 "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)"
2667 "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)"
2668 "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)"
2671 (defconst verilog-nameable-item-re
2672 (eval-when-compile
2673 (verilog-regexp-words
2674 `("begin"
2675 "fork"
2676 "join" "join_any" "join_none"
2677 "end"
2678 "endcase"
2679 "endchecker"
2680 "endclass"
2681 "endclocking"
2682 "endconfig"
2683 "endfunction"
2684 "endgenerate"
2685 "endgroup"
2686 "endmodule"
2687 "endprimitive"
2688 "endinterface"
2689 "endpackage"
2690 "endprogram"
2691 "endproperty"
2692 "endsequence"
2693 "endspecify"
2694 "endtable"
2695 "endtask" )
2698 (defconst verilog-declaration-opener
2699 (eval-when-compile
2700 (verilog-regexp-words
2701 `("module" "begin" "task" "function"))))
2703 (defconst verilog-declaration-prefix-re
2704 (eval-when-compile
2705 (verilog-regexp-words
2707 ;; port direction
2708 "inout" "input" "output" "ref"
2709 ;; changeableness
2710 "const" "static" "protected" "local"
2711 ;; parameters
2712 "localparam" "parameter" "var"
2713 ;; type creation
2714 "typedef"
2715 ))))
2716 (defconst verilog-declaration-core-re
2717 (eval-when-compile
2718 (verilog-regexp-words
2720 ;; port direction (by themselves)
2721 "inout" "input" "output"
2722 ;; integer_atom_type
2723 "byte" "shortint" "int" "longint" "integer" "time"
2724 ;; integer_vector_type
2725 "bit" "logic" "reg"
2726 ;; non_integer_type
2727 "shortreal" "real" "realtime"
2728 ;; net_type
2729 "supply0" "supply1" "tri" "triand" "trior" "trireg" "tri0" "tri1" "uwire" "wire" "wand" "wor"
2730 ;; misc
2731 "string" "event" "chandle" "virtual" "enum" "genvar"
2732 "struct" "union"
2733 ;; builtin classes
2734 "mailbox" "semaphore"
2735 ))))
2736 (defconst verilog-declaration-re
2737 (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re))
2738 (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+")
2739 (defconst verilog-optional-signed-re "\\s-*\\(\\(un\\)?signed\\)?")
2740 (defconst verilog-optional-signed-range-re
2741 (concat
2742 "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<\\(un\\)?signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?"))
2743 (defconst verilog-macroexp-re "`\\sw+")
2745 (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)")
2746 (defconst verilog-declaration-re-2-no-macro
2747 (concat "\\s-*" verilog-declaration-re
2748 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2749 "\\)?"))
2750 (defconst verilog-declaration-re-2-macro
2751 (concat "\\s-*" verilog-declaration-re
2752 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2753 "\\|\\(" verilog-macroexp-re "\\)"
2754 "\\)?"))
2755 (defconst verilog-declaration-re-1-macro
2756 (concat "^" verilog-declaration-re-2-macro))
2758 (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro))
2760 (defconst verilog-defun-re
2761 (eval-when-compile (verilog-regexp-words `("macromodule" "module" "class" "program" "interface" "package" "primitive" "config"))))
2762 (defconst verilog-end-defun-re
2763 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig"))))
2764 (defconst verilog-zero-indent-re
2765 (concat verilog-defun-re "\\|" verilog-end-defun-re))
2766 (defconst verilog-inst-comment-re
2767 (eval-when-compile (verilog-regexp-words `("Outputs" "Inouts" "Inputs" "Interfaces" "Interfaced"))))
2769 (defconst verilog-behavioral-block-beg-re
2770 (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff"
2771 "function" "task"))))
2772 (defconst verilog-coverpoint-re "\\w+\\s*:\\s*\\(coverpoint\\|cross\\constraint\\)" )
2773 (defconst verilog-in-constraint-re ; keywords legal in constraint blocks starting a statement/block
2774 (eval-when-compile (verilog-regexp-words `("if" "else" "solve" "foreach"))))
2776 (defconst verilog-indent-re
2777 (eval-when-compile
2778 (verilog-regexp-words
2781 "always" "always_latch" "always_ff" "always_comb"
2782 "begin" "end"
2783 ;; "unique" "priority"
2784 "case" "casex" "casez" "randcase" "endcase"
2785 "class" "endclass"
2786 "clocking" "endclocking"
2787 "config" "endconfig"
2788 "covergroup" "endgroup"
2789 "fork" "join" "join_any" "join_none"
2790 "function" "endfunction"
2791 "final"
2792 "generate" "endgenerate"
2793 "initial"
2794 "interface" "endinterface"
2795 "module" "macromodule" "endmodule"
2796 "package" "endpackage"
2797 "primitive" "endprimitive"
2798 "program" "endprogram"
2799 "property" "endproperty"
2800 "sequence" "randsequence" "endsequence"
2801 "specify" "endspecify"
2802 "table" "endtable"
2803 "task" "endtask"
2804 "virtual"
2805 "`case"
2806 "`default"
2807 "`define" "`undef"
2808 "`if" "`ifdef" "`ifndef" "`else" "`elsif" "`endif"
2809 "`while" "`endwhile"
2810 "`for" "`endfor"
2811 "`format"
2812 "`include"
2813 "`let"
2814 "`protect" "`endprotect"
2815 "`switch" "`endswitch"
2816 "`timescale"
2817 "`time_scale"
2818 ;; OVM Begin tokens
2819 "`ovm_component_utils_begin"
2820 "`ovm_component_param_utils_begin"
2821 "`ovm_field_utils_begin"
2822 "`ovm_object_utils_begin"
2823 "`ovm_object_param_utils_begin"
2824 "`ovm_sequence_utils_begin"
2825 "`ovm_sequencer_utils_begin"
2826 ;; OVM End tokens
2827 "`ovm_component_utils_end"
2828 "`ovm_field_utils_end"
2829 "`ovm_object_utils_end"
2830 "`ovm_sequence_utils_end"
2831 "`ovm_sequencer_utils_end"
2832 ;; UVM Begin tokens
2833 "`uvm_component_utils_begin"
2834 "`uvm_component_param_utils_begin"
2835 "`uvm_field_utils_begin"
2836 "`uvm_object_utils_begin"
2837 "`uvm_object_param_utils_begin"
2838 "`uvm_sequence_utils_begin"
2839 "`uvm_sequencer_utils_begin"
2840 ;; UVM End tokens
2841 "`uvm_component_utils_end" ; Typo in spec, it's not uvm_component_end
2842 "`uvm_field_utils_end"
2843 "`uvm_object_utils_end"
2844 "`uvm_sequence_utils_end"
2845 "`uvm_sequencer_utils_end"
2846 ;; VMM Begin tokens
2847 "`vmm_data_member_begin"
2848 "`vmm_env_member_begin"
2849 "`vmm_scenario_member_begin"
2850 "`vmm_subenv_member_begin"
2851 "`vmm_xactor_member_begin"
2852 ;; VMM End tokens
2853 "`vmm_data_member_end"
2854 "`vmm_env_member_end"
2855 "`vmm_scenario_member_end"
2856 "`vmm_subenv_member_end"
2857 "`vmm_xactor_member_end"
2858 ))))
2860 (defconst verilog-defun-level-not-generate-re
2861 (eval-when-compile
2862 (verilog-regexp-words
2863 `( "module" "macromodule" "primitive" "class" "program"
2864 "interface" "package" "config"))))
2866 (defconst verilog-defun-level-re
2867 (eval-when-compile
2868 (verilog-regexp-words
2869 (append
2870 `( "module" "macromodule" "primitive" "class" "program"
2871 "interface" "package" "config")
2872 `( "initial" "final" "always" "always_comb" "always_ff"
2873 "always_latch" "endtask" "endfunction" )))))
2875 (defconst verilog-defun-level-generate-only-re
2876 (eval-when-compile
2877 (verilog-regexp-words
2878 `( "initial" "final" "always" "always_comb" "always_ff"
2879 "always_latch" "endtask" "endfunction" ))))
2881 (defconst verilog-cpp-level-re
2882 (eval-when-compile
2883 (verilog-regexp-words
2885 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
2886 ))))
2888 (defconst verilog-dpi-import-export-re
2889 (eval-when-compile
2890 "\\(\\<\\(import\\|export\\)\\>\\s-+\"DPI\\(-C\\)?\"\\s-+\\(\\<\\(context\\|pure\\)\\>\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_]*\\s-*=\\s-*\\)?\\<\\(function\\|task\\)\\>\\)"
2893 (defconst verilog-default-clocking-re "\\<default\\s-+clocking\\>")
2894 (defconst verilog-disable-fork-re "\\(disable\\|wait\\)\\s-+fork\\>")
2895 (defconst verilog-extended-case-re "\\(\\(unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\|randcase\\)")
2896 (defconst verilog-extended-complete-re
2897 ;; verilog-beg-of-statement also looks backward one token to extend this match
2898 (concat "\\(\\(\\<extern\\s-+\\|\\<\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\|\\<static\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)\\)"
2899 "\\|\\(\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)\\)"
2900 "\\|\\(\\(\\<\\(import\\|export\\)\\>\\s-+\\)?\\(\"DPI\\(-C\\)?\"\\s-+\\)?\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_]*\\s-*=\\s-*\\)?\\(function\\>\\|task\\>\\)\\)"
2901 "\\|" verilog-extended-case-re ))
2902 (defconst verilog-basic-complete-re
2903 (eval-when-compile
2904 (verilog-regexp-words
2906 "always" "assign" "always_latch" "always_ff" "always_comb" "constraint"
2907 "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while"
2908 "if" "for" "forever" "foreach" "else" "parameter" "do" "localparam" "assert"
2909 ))))
2910 (defconst verilog-complete-reg
2911 (concat
2912 verilog-extended-complete-re "\\|\\(" verilog-basic-complete-re "\\)"))
2914 (defconst verilog-end-statement-re
2915 (concat "\\(" verilog-beg-block-re "\\)\\|\\("
2916 verilog-end-block-re "\\)"))
2918 (defconst verilog-endcase-re
2919 (concat verilog-extended-case-re "\\|"
2920 "\\(endcase\\)\\|"
2921 verilog-defun-re
2924 (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----"
2925 "String used to mark beginning of excluded text.")
2926 (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */"
2927 "String used to mark end of excluded text.")
2928 (defconst verilog-preprocessor-re
2929 (eval-when-compile
2930 (concat
2931 ;; single words
2932 "\\(?:"
2933 (verilog-regexp-words
2934 `("`__FILE__"
2935 "`__LINE__"
2936 "`celldefine"
2937 "`else"
2938 "`end_keywords"
2939 "`endcelldefine"
2940 "`endif"
2941 "`nounconnected_drive"
2942 "`resetall"
2943 "`unconnected_drive"
2944 "`undefineall"))
2945 "\\)\\|\\(?:"
2946 ;; two words: i.e. `ifdef DEFINE
2947 "\\<\\(`elsif\\|`ifn?def\\|`undef\\|`default_nettype\\|`begin_keywords\\)\\>\\s-"
2948 "\\)\\|\\(?:"
2949 ;; `line number "filename" level
2950 "\\<\\(`line\\)\\>\\s-+[0-9]+\\s-+\"[^\"]+\"\\s-+[012]"
2951 "\\)\\|\\(?:"
2952 ;;`include "file" or `include <file>
2953 "\\<\\(`include\\)\\>\\s-+\\(?:\"[^\"]+\"\\|<[^>]+>\\)"
2954 "\\)\\|\\(?:"
2955 ;; `pragma <stuff> (no mention in IEEE 1800-2012 that pragma can span multiple lines
2956 "\\<\\(`pragma\\)\\>\\s-+.+$"
2957 "\\)\\|\\(?:"
2958 ;; `timescale time_unit / time_precision
2959 "\\<\\(`timescale\\)\\>\\s-+10\\{0,2\\}\\s-*[munpf]?s\\s-*\\/\\s-*10\\{0,2\\}\\s-*[munpf]?s"
2960 "\\)\\|\\(?:"
2961 ;; `define and `if can span multiple lines if line ends in '\'. NOTE: `if is not IEEE 1800-2012
2962 ;; from http://www.emacswiki.org/emacs/MultilineRegexp
2963 (concat "\\<\\(`define\\|`if\\)\\>" ; directive
2964 "\\s-+" ; separator
2965 "\\(?:.*?\\(?:\n.*\\)*?\\)" ; definition: to end of line, then maybe more lines (excludes any trailing \n)
2966 "\\(?:\n\\s-*\n\\|\\'\\)") ; blank line or EOF
2967 "\\)\\|\\(?:"
2968 ;; `<macro>() : i.e. `uvm_info(a,b,c) or any other pre-defined macro
2969 ;; Since parameters inside the macro can have parentheses, and
2970 ;; the macro can span multiple lines, just look for the opening
2971 ;; parentheses and then continue to the end of the first
2972 ;; non-escaped EOL
2973 (concat "\\<`\\w+\\>\\s-*("
2974 "\\(?:.*?\\(?:\n.*\\)*?\\)" ; definition: to end of line, then maybe more lines (excludes any trailing \n)
2975 "\\(?:\n\\s-*\n\\|\\'\\)") ; blank line or EOF
2976 "\\)"
2979 (defconst verilog-keywords
2980 (append verilog-compiler-directives
2982 "after" "alias" "always" "always_comb" "always_ff" "always_latch" "and"
2983 "assert" "assign" "assume" "automatic" "before" "begin" "bind"
2984 "bins" "binsof" "bit" "break" "buf" "bufif0" "bufif1" "byte"
2985 "case" "casex" "casez" "cell" "chandle" "class" "clocking" "cmos"
2986 "config" "const" "constraint" "context" "continue" "cover"
2987 "covergroup" "coverpoint" "cross" "deassign" "default" "defparam"
2988 "design" "disable" "dist" "do" "edge" "else" "end" "endcase"
2989 "endclass" "endclocking" "endconfig" "endfunction" "endgenerate"
2990 "endgroup" "endinterface" "endmodule" "endpackage" "endprimitive"
2991 "endprogram" "endproperty" "endspecify" "endsequence" "endtable"
2992 "endtask" "enum" "event" "expect" "export" "extends" "extern"
2993 "final" "first_match" "for" "force" "foreach" "forever" "fork"
2994 "forkjoin" "function" "generate" "genvar" "highz0" "highz1" "if"
2995 "iff" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir"
2996 "include" "initial" "inout" "input" "inside" "instance" "int"
2997 "integer" "interface" "intersect" "join" "join_any" "join_none"
2998 "large" "liblist" "library" "local" "localparam" "logic"
2999 "longint" "macromodule" "mailbox" "matches" "medium" "modport" "module"
3000 "nand" "negedge" "new" "nmos" "nor" "noshowcancelled" "not"
3001 "notif0" "notif1" "null" "or" "output" "package" "packed"
3002 "parameter" "pmos" "posedge" "primitive" "priority" "program"
3003 "property" "protected" "pull0" "pull1" "pulldown" "pullup"
3004 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
3005 "randcase" "randsequence" "rcmos" "real" "realtime" "ref" "reg"
3006 "release" "repeat" "return" "rnmos" "rpmos" "rtran" "rtranif0"
3007 "rtranif1" "scalared" "semaphore" "sequence" "shortint" "shortreal"
3008 "showcancelled" "signed" "small" "solve" "specify" "specparam"
3009 "static" "string" "strong0" "strong1" "struct" "super" "supply0"
3010 "supply1" "table" "tagged" "task" "this" "throughout" "time"
3011 "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri"
3012 "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union"
3013 "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void"
3014 "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard"
3015 "wire" "with" "within" "wor" "xnor" "xor"
3016 ;; 1800-2009
3017 "accept_on" "checker" "endchecker" "eventually" "global" "implies"
3018 "let" "nexttime" "reject_on" "restrict" "s_always" "s_eventually"
3019 "s_nexttime" "s_until" "s_until_with" "strong" "sync_accept_on"
3020 "sync_reject_on" "unique0" "until" "until_with" "untyped" "weak"
3021 ;; 1800-2012
3022 "implements" "interconnect" "nettype" "soft"
3024 "List of Verilog keywords.")
3026 (defconst verilog-comment-start-regexp "//\\|/\\*"
3027 "Dual comment value for `comment-start-regexp'.")
3029 (defvar verilog-mode-syntax-table
3030 (let ((table (make-syntax-table)))
3031 ;; Populate the syntax TABLE.
3032 (modify-syntax-entry ?\\ "\\" table)
3033 (modify-syntax-entry ?+ "." table)
3034 (modify-syntax-entry ?- "." table)
3035 (modify-syntax-entry ?= "." table)
3036 (modify-syntax-entry ?% "." table)
3037 (modify-syntax-entry ?< "." table)
3038 (modify-syntax-entry ?> "." table)
3039 (modify-syntax-entry ?& "." table)
3040 (modify-syntax-entry ?| "." table)
3041 (modify-syntax-entry ?` "w" table) ; ` is part of definition symbols in Verilog
3042 (modify-syntax-entry ?_ "w" table)
3043 (modify-syntax-entry ?\' "." table)
3045 ;; Set up TABLE to handle block and line style comments.
3046 (if (featurep 'xemacs)
3047 (progn
3048 ;; XEmacs (formerly Lucid) has the best implementation
3049 (modify-syntax-entry ?/ ". 1456" table)
3050 (modify-syntax-entry ?* ". 23" table)
3051 (modify-syntax-entry ?\n "> b" table))
3052 ;; Emacs does things differently, but we can work with it
3053 (modify-syntax-entry ?/ ". 124b" table)
3054 (modify-syntax-entry ?* ". 23" table)
3055 (modify-syntax-entry ?\n "> b" table))
3056 table)
3057 "Syntax table used in Verilog mode buffers.")
3059 (defvar verilog-font-lock-keywords nil
3060 "Default highlighting for Verilog mode.")
3062 (defvar verilog-font-lock-keywords-1 nil
3063 "Subdued level highlighting for Verilog mode.")
3065 (defvar verilog-font-lock-keywords-2 nil
3066 "Medium level highlighting for Verilog mode.
3067 See also `verilog-font-lock-extra-types'.")
3069 (defvar verilog-font-lock-keywords-3 nil
3070 "Gaudy level highlighting for Verilog mode.
3071 See also `verilog-font-lock-extra-types'.")
3073 (defvar verilog-font-lock-translate-off-face
3074 'verilog-font-lock-translate-off-face
3075 "Font to use for translated off regions.")
3076 (defface verilog-font-lock-translate-off-face
3077 '((((class color)
3078 (background light))
3079 (:background "gray90" :italic t ))
3080 (((class color)
3081 (background dark))
3082 (:background "gray10" :italic t ))
3083 (((class grayscale) (background light))
3084 (:foreground "DimGray" :italic t))
3085 (((class grayscale) (background dark))
3086 (:foreground "LightGray" :italic t))
3087 (t (:italis t)))
3088 "Font lock mode face used to background highlight translate-off regions."
3089 :group 'font-lock-highlighting-faces)
3091 (defvar verilog-font-lock-p1800-face
3092 'verilog-font-lock-p1800-face
3093 "Font to use for p1800 keywords.")
3094 (defface verilog-font-lock-p1800-face
3095 '((((class color)
3096 (background light))
3097 (:foreground "DarkOrange3" :bold t ))
3098 (((class color)
3099 (background dark))
3100 (:foreground "orange1" :bold t ))
3101 (t (:italic t)))
3102 "Font lock mode face used to highlight P1800 keywords."
3103 :group 'font-lock-highlighting-faces)
3105 (defvar verilog-font-lock-ams-face
3106 'verilog-font-lock-ams-face
3107 "Font to use for Analog/Mixed Signal keywords.")
3108 (defface verilog-font-lock-ams-face
3109 '((((class color)
3110 (background light))
3111 (:foreground "Purple" :bold t ))
3112 (((class color)
3113 (background dark))
3114 (:foreground "orange1" :bold t ))
3115 (t (:italic t)))
3116 "Font lock mode face used to highlight AMS keywords."
3117 :group 'font-lock-highlighting-faces)
3119 (defvar verilog-font-lock-grouping-keywords-face
3120 'verilog-font-lock-grouping-keywords-face
3121 "Font to use for Verilog Grouping Keywords (such as begin..end).")
3122 (defface verilog-font-lock-grouping-keywords-face
3123 '((((class color)
3124 (background light))
3125 (:foreground "Purple" :bold t ))
3126 (((class color)
3127 (background dark))
3128 (:foreground "orange1" :bold t ))
3129 (t (:italic t)))
3130 "Font lock mode face used to highlight verilog grouping keywords."
3131 :group 'font-lock-highlighting-faces)
3133 (let* ((verilog-type-font-keywords
3134 (eval-when-compile
3135 (verilog-regexp-opt
3137 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
3138 "event" "genvar" "inout" "input" "integer" "localparam"
3139 "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0" "notif1" "or"
3140 "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
3141 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran"
3142 "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply"
3143 "supply0" "supply1" "time" "tran" "tranif0" "tranif1"
3144 "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef"
3145 "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor"
3146 ) nil )))
3148 (verilog-pragma-keywords
3149 (eval-when-compile
3150 (verilog-regexp-opt
3151 '("surefire" "auto" "synopsys" "rtl_synthesis" "verilint" "leda" "0in"
3152 ) nil )))
3154 (verilog-1800-2005-keywords
3155 (eval-when-compile
3156 (verilog-regexp-opt
3157 '("alias" "assert" "assume" "automatic" "before" "bind"
3158 "bins" "binsof" "break" "byte" "cell" "chandle" "class"
3159 "clocking" "config" "const" "constraint" "context" "continue"
3160 "cover" "covergroup" "coverpoint" "cross" "deassign" "design"
3161 "dist" "do" "edge" "endclass" "endclocking" "endconfig"
3162 "endgroup" "endprogram" "endproperty" "endsequence" "enum"
3163 "expect" "export" "extends" "extern" "first_match" "foreach"
3164 "forkjoin" "genvar" "highz0" "highz1" "ifnone" "ignore_bins"
3165 "illegal_bins" "import" "incdir" "include" "inside" "instance"
3166 "int" "intersect" "large" "liblist" "library" "local" "longint"
3167 "matches" "medium" "modport" "new" "noshowcancelled" "null"
3168 "packed" "program" "property" "protected" "pull0" "pull1"
3169 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
3170 "randcase" "randsequence" "ref" "release" "return" "scalared"
3171 "sequence" "shortint" "shortreal" "showcancelled" "small" "solve"
3172 "specparam" "static" "string" "strong0" "strong1" "struct"
3173 "super" "tagged" "this" "throughout" "timeprecision" "timeunit"
3174 "type" "union" "unsigned" "use" "var" "virtual" "void"
3175 "wait_order" "weak0" "weak1" "wildcard" "with" "within"
3176 ) nil )))
3178 (verilog-1800-2009-keywords
3179 (eval-when-compile
3180 (verilog-regexp-opt
3181 '("accept_on" "checker" "endchecker" "eventually" "global"
3182 "implies" "let" "nexttime" "reject_on" "restrict" "s_always"
3183 "s_eventually" "s_nexttime" "s_until" "s_until_with" "strong"
3184 "sync_accept_on" "sync_reject_on" "unique0" "until"
3185 "until_with" "untyped" "weak" ) nil )))
3187 (verilog-1800-2012-keywords
3188 (eval-when-compile
3189 (verilog-regexp-opt
3190 '("implements" "interconnect" "nettype" "soft" ) nil )))
3192 (verilog-ams-keywords
3193 (eval-when-compile
3194 (verilog-regexp-opt
3195 '("above" "abs" "absdelay" "acos" "acosh" "ac_stim"
3196 "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh"
3197 "branch" "ceil" "connectmodule" "connectrules" "cos" "cosh" "ddt"
3198 "ddx" "discipline" "driver_update" "enddiscipline" "endconnectrules"
3199 "endnature" "endparamset" "exclude" "exp" "final_step" "flicker_noise"
3200 "floor" "flow" "from" "ground" "hypot" "idt" "idtmod" "inf"
3201 "initial_step" "laplace_nd" "laplace_np" "laplace_zd" "laplace_zp"
3202 "last_crossing" "limexp" "ln" "log" "max" "min" "nature"
3203 "net_resolution" "noise_table" "paramset" "potential" "pow" "sin"
3204 "sinh" "slew" "sqrt" "tan" "tanh" "timer" "transition" "white_noise"
3205 "wreal" "zi_nd" "zi_np" "zi_zd" ) nil )))
3207 (verilog-font-keywords
3208 (eval-when-compile
3209 (verilog-regexp-opt
3211 "assign" "case" "casex" "casez" "randcase" "deassign"
3212 "default" "disable" "else" "endcase" "endfunction"
3213 "endgenerate" "endinterface" "endmodule" "endprimitive"
3214 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break"
3215 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial"
3216 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge"
3217 "package" "endpackage" "always" "always_comb" "always_ff"
3218 "always_latch" "posedge" "primitive" "priority" "release"
3219 "repeat" "specify" "table" "task" "unique" "wait" "while"
3220 "class" "program" "endclass" "endprogram"
3221 ) nil )))
3223 (verilog-font-grouping-keywords
3224 (eval-when-compile
3225 (verilog-regexp-opt
3226 '( "begin" "end" ) nil ))))
3228 (setq verilog-font-lock-keywords
3229 (list
3230 ;; Fontify all builtin keywords
3231 (concat "\\<\\(" verilog-font-keywords "\\|"
3232 ;; And user/system tasks and functions
3233 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*"
3234 "\\)\\>")
3235 ;; Fontify all types
3236 (if verilog-highlight-grouping-keywords
3237 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
3238 'verilog-font-lock-grouping-keywords-face)
3239 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
3240 'font-lock-type-face))
3241 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>")
3242 'font-lock-type-face)
3243 ;; Fontify IEEE-1800-2005 keywords appropriately
3244 (if verilog-highlight-p1800-keywords
3245 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
3246 'verilog-font-lock-p1800-face)
3247 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
3248 'font-lock-type-face))
3249 ;; Fontify IEEE-1800-2009 keywords appropriately
3250 (if verilog-highlight-p1800-keywords
3251 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
3252 'verilog-font-lock-p1800-face)
3253 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
3254 'font-lock-type-face))
3255 ;; Fontify IEEE-1800-2012 keywords appropriately
3256 (if verilog-highlight-p1800-keywords
3257 (cons (concat "\\<\\(" verilog-1800-2012-keywords "\\)\\>")
3258 'verilog-font-lock-p1800-face)
3259 (cons (concat "\\<\\(" verilog-1800-2012-keywords "\\)\\>")
3260 'font-lock-type-face))
3261 ;; Fontify Verilog-AMS keywords
3262 (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>")
3263 'verilog-font-lock-ams-face)))
3265 (setq verilog-font-lock-keywords-1
3266 (append verilog-font-lock-keywords
3267 (list
3268 ;; Fontify module definitions
3269 (list
3270 "\\<\\(\\(macro\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)"
3271 '(1 font-lock-keyword-face)
3272 '(3 font-lock-function-name-face 'prepend))
3273 ;; Fontify function definitions
3274 (list
3275 (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" )
3276 '(1 font-lock-keyword-face)
3277 '(3 font-lock-constant-face prepend))
3278 '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)"
3279 (1 font-lock-keyword-face)
3280 (2 font-lock-constant-face append))
3281 '("\\<function\\>\\s-+\\(\\sw+\\)"
3282 1 'font-lock-constant-face append))))
3284 (setq verilog-font-lock-keywords-2
3285 (append verilog-font-lock-keywords-1
3286 (list
3287 ;; Fontify pragmas
3288 (concat "\\(//\\s-*\\(" verilog-pragma-keywords "\\)\\s-.*\\)")
3289 ;; Fontify escaped names
3290 '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face)
3291 ;; Fontify macro definitions/ uses
3292 '("`\\s-*[A-Za-z][A-Za-z0-9_]*" 0 (if (boundp 'font-lock-preprocessor-face)
3293 'font-lock-preprocessor-face
3294 'font-lock-type-face))
3295 ;; Fontify delays/numbers
3296 '("\\(@\\)\\|\\([ \t\n\f\r]#\\s-*\\(\\([0-9_.]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)"
3297 0 font-lock-type-face append)
3298 ;; Fontify property/sequence cycle delays - these start with '##'
3299 '("\\(##\\(\\sw+\\|\\[[^]]+\\]\\)\\)"
3300 0 font-lock-type-face append)
3301 ;; Fontify instantiation names
3302 '("\\([A-Za-z][A-Za-z0-9_]*\\)\\s-*(" 1 font-lock-function-name-face)
3305 (setq verilog-font-lock-keywords-3
3306 (append verilog-font-lock-keywords-2
3307 (when verilog-highlight-translate-off
3308 (list
3309 ;; Fontify things in translate off regions
3310 '(verilog-match-translate-off
3311 (0 'verilog-font-lock-translate-off-face prepend))
3312 )))))
3315 ;; Buffer state preservation
3317 (defmacro verilog-save-buffer-state (&rest body)
3318 "Execute BODY forms, saving state around insignificant change.
3319 Changes in text properties like `face' or `syntax-table' are
3320 considered insignificant. This macro allows text properties to
3321 be changed, even in a read-only buffer.
3323 A change is considered significant if it affects the buffer text
3324 in any way that isn't completely restored again. Any
3325 user-visible changes to the buffer must not be within a
3326 `verilog-save-buffer-state'."
3327 `(let ((inhibit-point-motion-hooks t)
3328 (verilog-no-change-functions t))
3329 ,(if (fboundp 'with-silent-modifications)
3330 `(with-silent-modifications ,@body)
3331 ;; Backward compatible version of with-silent-modifications
3332 `(let* ((modified (buffer-modified-p))
3333 (buffer-undo-list t)
3334 (inhibit-read-only t)
3335 (inhibit-modification-hooks t)
3336 ;; XEmacs ignores inhibit-modification-hooks.
3337 before-change-functions after-change-functions
3338 deactivate-mark
3339 buffer-file-name ; Prevent primitives checking
3340 buffer-file-truename) ; for file modification
3341 (unwind-protect
3342 (progn ,@body)
3343 (and (not modified)
3344 (buffer-modified-p)
3345 (verilog-restore-buffer-modified-p nil)))))))
3348 (defvar verilog-save-font-mod-hooked nil
3349 "Local variable when inside a `verilog-save-font-no-change-functions' block.")
3350 (make-variable-buffer-local 'verilog-save-font-mod-hooked)
3352 (defmacro verilog-save-font-no-change-functions (&rest body)
3353 "Execute BODY forms, disabling all change hooks in BODY.
3354 Includes temporary disabling of `font-lock' to restore the buffer
3355 to full text form for parsing. Additional actions may be specified with
3356 `verilog-before-save-font-hook' and `verilog-after-save-font-hook'.
3357 For insignificant changes, see instead `verilog-save-buffer-state'."
3358 `(if verilog-save-font-mod-hooked ; Short-circuit a recursive call
3359 (progn ,@body)
3360 ;; Before version 20, match-string with font-lock returns a
3361 ;; vector that is not equal to the string. IE if on "input"
3362 ;; nil==(equal "input" (progn (looking-at "input") (match-string 0)))
3363 ;; Therefore we must remove and restore font-lock mode
3364 (verilog-run-hooks 'verilog-before-save-font-hook)
3365 (let* ((verilog-save-font-mod-hooked (- (point-max) (point-min)))
3366 ;; Significant speed savings with no font-lock properties
3367 (fontlocked (when (and (boundp 'font-lock-mode) font-lock-mode)
3368 (font-lock-mode 0)
3369 t)))
3370 (run-hook-with-args 'before-change-functions (point-min) (point-max))
3371 (unwind-protect
3372 ;; Must inhibit and restore hooks before restoring font-lock
3373 (let* ((inhibit-point-motion-hooks t)
3374 (inhibit-modification-hooks t)
3375 (verilog-no-change-functions t)
3376 ;; XEmacs and pre-Emacs 21 ignore inhibit-modification-hooks.
3377 before-change-functions after-change-functions)
3378 (progn ,@body))
3379 ;; Unwind forms
3380 (run-hook-with-args 'after-change-functions (point-min) (point-max)
3381 verilog-save-font-mod-hooked) ; old length
3382 (when fontlocked (font-lock-mode t))
3383 (verilog-run-hooks 'verilog-after-save-font-hook)))))
3386 ;; Comment detection and caching
3388 (defvar verilog-scan-cache-preserving nil
3389 "If true, the specified buffer's comment properties are static.
3390 Buffer changes will be ignored. See `verilog-inside-comment-or-string-p'
3391 and `verilog-scan'.")
3393 (defvar verilog-scan-cache-tick nil
3394 "Modification tick at which `verilog-scan' was last completed.")
3395 (make-variable-buffer-local 'verilog-scan-cache-tick)
3397 (defun verilog-scan-cache-flush ()
3398 "Flush the `verilog-scan' cache."
3399 (setq verilog-scan-cache-tick nil))
3401 (defun verilog-scan-cache-ok-p ()
3402 "Return t if the scan cache is up to date."
3403 (or (and verilog-scan-cache-preserving
3404 (eq verilog-scan-cache-preserving (current-buffer))
3405 verilog-scan-cache-tick)
3406 (equal verilog-scan-cache-tick (buffer-chars-modified-tick))))
3408 (defmacro verilog-save-scan-cache (&rest body)
3409 "Execute the BODY forms, allowing scan cache preservation within BODY.
3410 This requires that insertions must use `verilog-insert'."
3411 ;; If the buffer is out of date, trash it, as we'll not check later the tick
3412 ;; Note this must work properly if there's multiple layers of calls
3413 ;; to verilog-save-scan-cache even with differing ticks.
3414 `(progn
3415 (unless (verilog-scan-cache-ok-p) ; Must be before let
3416 (setq verilog-scan-cache-tick nil))
3417 (let* ((verilog-scan-cache-preserving (current-buffer)))
3418 (progn ,@body))))
3420 (defun verilog-scan-region (beg end)
3421 "Parse between BEG and END for `verilog-inside-comment-or-string-p'.
3422 This creates v-cmts properties where comments are in force."
3423 ;; Why properties and not overlays? Overlays have much slower non O(1)
3424 ;; lookup times.
3425 ;; This function is warm - called on every verilog-insert
3426 (save-excursion
3427 (save-match-data
3428 (verilog-save-buffer-state
3429 (let (pt)
3430 (goto-char beg)
3431 (while (< (point) end)
3432 (cond ((looking-at "//")
3433 (setq pt (point))
3434 (or (search-forward "\n" end t)
3435 (goto-char end))
3436 ;; "1+": The leading // or /* itself isn't considered as
3437 ;; being "inside" the comment, so that a (search-backward)
3438 ;; that lands at the start of the // won't mis-indicate
3439 ;; it's inside a comment. Also otherwise it would be
3440 ;; hard to find a commented out /*AS*/ vs one that isn't
3441 (put-text-property (1+ pt) (point) 'v-cmts t))
3442 ((looking-at "/\\*")
3443 (setq pt (point))
3444 (or (search-forward "*/" end t)
3445 ;; No error - let later code indicate it so we can
3446 ;; use inside functions on-the-fly
3447 ;;(error "%s: Unmatched /* */, at char %d"
3448 ;; (verilog-point-text) (point))
3449 (goto-char end))
3450 (put-text-property (1+ pt) (point) 'v-cmts t))
3451 ((looking-at "\"")
3452 (setq pt (point))
3453 (or (re-search-forward "[^\\]\"" end t) ; don't forward-char first, since we look for a non backslash first
3454 ;; No error - let later code indicate it so we can
3455 (goto-char end))
3456 (put-text-property (1+ pt) (point) 'v-cmts t))
3458 (forward-char 1)
3459 (if (re-search-forward "[/\"]" end t)
3460 (backward-char 1)
3461 (goto-char end))))))))))
3463 (defun verilog-scan ()
3464 "Parse the buffer, marking all comments with properties.
3465 Also assumes any text inserted since `verilog-scan-cache-tick'
3466 either is ok to parse as a non-comment, or `verilog-insert' was used."
3467 ;; See also `verilog-scan-debug' and `verilog-scan-and-debug'
3468 (unless (verilog-scan-cache-ok-p)
3469 (save-excursion
3470 (verilog-save-buffer-state
3471 (when verilog-debug
3472 (message "Scanning %s cache=%s cachetick=%S tick=%S" (current-buffer)
3473 verilog-scan-cache-preserving verilog-scan-cache-tick
3474 (buffer-chars-modified-tick)))
3475 (remove-text-properties (point-min) (point-max) '(v-cmts nil))
3476 (verilog-scan-region (point-min) (point-max))
3477 (setq verilog-scan-cache-tick (buffer-chars-modified-tick))
3478 (when verilog-debug (message "Scanning... done"))))))
3480 (defun verilog-scan-debug ()
3481 "For debugging, show with display face results of `verilog-scan'."
3482 (font-lock-mode 0)
3483 ;;(if dbg (setq dbg (concat dbg (format "verilog-scan-debug\n"))))
3484 (save-excursion
3485 (goto-char (point-min))
3486 (remove-text-properties (point-min) (point-max) '(face nil))
3487 (while (not (eobp))
3488 (cond ((get-text-property (point) 'v-cmts)
3489 (put-text-property (point) (1+ (point)) `face 'underline)
3490 ;;(if dbg (setq dbg (concat dbg (format " v-cmts at %S\n" (point)))))
3491 (forward-char 1))
3493 (goto-char (or (next-property-change (point)) (point-max))))))))
3495 (defun verilog-scan-and-debug ()
3496 "For debugging, run `verilog-scan' and `verilog-scan-debug'."
3497 (let (verilog-scan-cache-preserving
3498 verilog-scan-cache-tick)
3499 (goto-char (point-min))
3500 (verilog-scan)
3501 (verilog-scan-debug)))
3503 (defun verilog-inside-comment-or-string-p (&optional pos)
3504 "Check if optional point POS is inside a comment.
3505 This may require a slow pre-parse of the buffer with `verilog-scan'
3506 to establish comment properties on all text."
3507 ;; This function is very hot
3508 (verilog-scan)
3509 (if pos
3510 (and (>= pos (point-min))
3511 (get-text-property pos 'v-cmts))
3512 (get-text-property (point) 'v-cmts)))
3514 (defun verilog-insert (&rest stuff)
3515 "Insert STUFF arguments, tracking for `verilog-inside-comment-or-string-p'.
3516 Any insert that includes a comment must have the entire comment
3517 inserted using a single call to `verilog-insert'."
3518 (let ((pt (point)))
3519 (while stuff
3520 (insert (car stuff))
3521 (setq stuff (cdr stuff)))
3522 (verilog-scan-region pt (point))))
3524 ;; More searching
3526 (defun verilog-declaration-end ()
3527 (search-forward ";"))
3529 (defun verilog-point-text (&optional pointnum)
3530 "Return text describing where POINTNUM or current point is (for errors).
3531 Use filename, if current buffer being edited shorten to just buffer name."
3532 (concat (or (and (equal (window-buffer) (current-buffer))
3533 (buffer-name))
3534 buffer-file-name
3535 (buffer-name))
3536 ":" (int-to-string (1+ (count-lines (point-min) (or pointnum (point)))))))
3538 (defun electric-verilog-backward-sexp ()
3539 "Move backward over one balanced expression."
3540 (interactive)
3541 ;; before that see if we are in a comment
3542 (verilog-backward-sexp))
3544 (defun electric-verilog-forward-sexp ()
3545 "Move forward over one balanced expression."
3546 (interactive)
3547 ;; before that see if we are in a comment
3548 (verilog-forward-sexp))
3550 (defun verilog-forward-sexp-function (arg)
3551 "Move forward ARG sexps."
3552 ;; Used by hs-minor-mode
3553 (if (< arg 0)
3554 (verilog-backward-sexp)
3555 (verilog-forward-sexp)))
3557 (defun verilog-backward-sexp ()
3558 (let ((reg)
3559 (elsec 1)
3560 (found nil)
3561 (st (point)))
3562 (if (not (looking-at "\\<"))
3563 (forward-word-strictly -1))
3564 (cond
3565 ((verilog-skip-backward-comment-or-string))
3566 ((looking-at "\\<else\\>")
3567 (setq reg (concat
3568 verilog-end-block-re
3569 "\\|\\(\\<else\\>\\)"
3570 "\\|\\(\\<if\\>\\)"))
3571 (while (and (not found)
3572 (verilog-re-search-backward reg nil 'move))
3573 (cond
3574 ((match-end 1) ; matched verilog-end-block-re
3575 ;; try to leap back to matching outward block by striding across
3576 ;; indent level changing tokens then immediately
3577 ;; previous line governs indentation.
3578 (verilog-leap-to-head))
3579 ((match-end 2) ; else, we're in deep
3580 (setq elsec (1+ elsec)))
3581 ((match-end 3) ; found it
3582 (setq elsec (1- elsec))
3583 (if (= 0 elsec)
3584 ;; Now previous line describes syntax
3585 (setq found 't))))))
3586 ((looking-at verilog-end-block-re)
3587 (verilog-leap-to-head))
3588 ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)\\|\\(\\<endclass\\>\\)\\|\\(\\<endprogram\\>\\)\\|\\(\\<endinterface\\>\\)\\|\\(\\<endpackage\\>\\)")
3589 (cond
3590 ((match-end 1)
3591 (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move))
3592 ((match-end 2)
3593 (verilog-re-search-backward "\\<primitive\\>" nil 'move))
3594 ((match-end 3)
3595 (verilog-re-search-backward "\\<class\\>" nil 'move))
3596 ((match-end 4)
3597 (verilog-re-search-backward "\\<program\\>" nil 'move))
3598 ((match-end 5)
3599 (verilog-re-search-backward "\\<interface\\>" nil 'move))
3600 ((match-end 6)
3601 (verilog-re-search-backward "\\<package\\>" nil 'move))
3603 (goto-char st)
3604 (backward-sexp 1))))
3606 (goto-char st)
3607 (backward-sexp)))))
3609 (defun verilog-forward-sexp ()
3610 (let ((reg)
3611 (md 2)
3612 (st (point))
3613 (nest 'yes))
3614 (if (not (looking-at "\\<"))
3615 (forward-word-strictly -1))
3616 (cond
3617 ((verilog-skip-forward-comment-or-string)
3618 (verilog-forward-syntactic-ws))
3619 ((looking-at verilog-beg-block-re-ordered)
3620 (cond
3621 ((match-end 1);
3622 ;; Search forward for matching end
3623 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
3624 ((match-end 2)
3625 ;; Search forward for matching endcase
3626 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique0?\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
3627 (setq md 3) ; ender is third item in regexp
3629 ((match-end 4)
3630 ;; might be "disable fork" or "wait fork"
3631 (let
3632 (here)
3633 (if (or
3634 (looking-at verilog-disable-fork-re)
3635 (and (looking-at "fork")
3636 (progn
3637 (setq here (point)) ; sometimes a fork is just a fork
3638 (forward-word-strictly -1)
3639 (looking-at verilog-disable-fork-re))))
3640 (progn ; it is a disable fork; ignore it
3641 (goto-char (match-end 0))
3642 (forward-word-strictly 1)
3643 (setq reg nil))
3644 (progn ; it is a nice simple fork
3645 (goto-char here) ; return from looking for "disable fork"
3646 ;; Search forward for matching join
3647 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))))
3648 ((match-end 6)
3649 ;; Search forward for matching endclass
3650 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
3652 ((match-end 7)
3653 ;; Search forward for matching endtable
3654 (setq reg "\\<endtable\\>" )
3655 (setq nest 'no))
3656 ((match-end 8)
3657 ;; Search forward for matching endspecify
3658 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
3659 ((match-end 9)
3660 ;; Search forward for matching endfunction
3661 (setq reg "\\<endfunction\\>" )
3662 (setq nest 'no))
3663 ((match-end 10)
3664 ;; Search forward for matching endfunction
3665 (setq reg "\\<endfunction\\>" )
3666 (setq nest 'no))
3667 ((match-end 11)
3668 ;; Search forward for matching endtask
3669 (setq reg "\\<endtask\\>" )
3670 (setq nest 'no))
3671 ((match-end 12)
3672 ;; Search forward for matching endtask
3673 (setq reg "\\<endtask\\>" )
3674 (setq nest 'no))
3675 ((match-end 12)
3676 ;; Search forward for matching endgenerate
3677 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
3678 ((match-end 13)
3679 ;; Search forward for matching endgroup
3680 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
3681 ((match-end 14)
3682 ;; Search forward for matching endproperty
3683 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
3684 ((match-end 15)
3685 ;; Search forward for matching endsequence
3686 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )
3687 (setq md 3)) ; 3 to get to endsequence in the reg above
3688 ((match-end 17)
3689 ;; Search forward for matching endclocking
3690 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )))
3691 (if (and reg
3692 (forward-word-strictly 1))
3693 (catch 'skip
3694 (if (eq nest 'yes)
3695 (let ((depth 1)
3696 here)
3697 (while (verilog-re-search-forward reg nil 'move)
3698 (cond
3699 ((match-end md) ; a closer in regular expression, so we are climbing out
3700 (setq depth (1- depth))
3701 (if (= 0 depth) ; we are out!
3702 (throw 'skip 1)))
3703 ((match-end 1) ; an opener in the r-e, so we are in deeper now
3704 (setq here (point)) ; remember where we started
3705 (goto-char (match-beginning 1))
3706 (cond
3707 ((if (or
3708 (looking-at verilog-disable-fork-re)
3709 (and (looking-at "fork")
3710 (progn
3711 (forward-word-strictly -1)
3712 (looking-at verilog-disable-fork-re))))
3713 (progn ; it is a disable fork; another false alarm
3714 (goto-char (match-end 0)))
3715 (progn ; it is a simple fork (or has nothing to do with fork)
3716 (goto-char here)
3717 (setq depth (1+ depth))))))))))
3718 (if (verilog-re-search-forward reg nil 'move)
3719 (throw 'skip 1))))))
3721 ((looking-at (concat
3722 "\\(\\<\\(macro\\)?module\\>\\)\\|"
3723 "\\(\\<primitive\\>\\)\\|"
3724 "\\(\\<class\\>\\)\\|"
3725 "\\(\\<program\\>\\)\\|"
3726 "\\(\\<interface\\>\\)\\|"
3727 "\\(\\<package\\>\\)"))
3728 (cond
3729 ((match-end 1)
3730 (verilog-re-search-forward "\\<endmodule\\>" nil 'move))
3731 ((match-end 2)
3732 (verilog-re-search-forward "\\<endprimitive\\>" nil 'move))
3733 ((match-end 3)
3734 (verilog-re-search-forward "\\<endclass\\>" nil 'move))
3735 ((match-end 4)
3736 (verilog-re-search-forward "\\<endprogram\\>" nil 'move))
3737 ((match-end 5)
3738 (verilog-re-search-forward "\\<endinterface\\>" nil 'move))
3739 ((match-end 6)
3740 (verilog-re-search-forward "\\<endpackage\\>" nil 'move))
3742 (goto-char st)
3743 (if (= (following-char) ?\) )
3744 (forward-char 1)
3745 (forward-sexp 1)))))
3747 (goto-char st)
3748 (if (= (following-char) ?\) )
3749 (forward-char 1)
3750 (forward-sexp 1))))))
3752 (defun verilog-declaration-beg ()
3753 (verilog-re-search-backward verilog-declaration-re (bobp) t))
3757 ;; Mode
3759 (defvar verilog-which-tool 1)
3760 ;;;###autoload
3761 (define-derived-mode verilog-mode prog-mode "Verilog"
3762 "Major mode for editing Verilog code.
3763 \\<verilog-mode-map>
3764 See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how
3765 AUTOs can improve coding efficiency.
3767 Use \\[verilog-faq] for a pointer to frequently asked questions.
3769 NEWLINE, TAB indents for Verilog code.
3770 Delete converts tabs to spaces as it moves back.
3772 Supports highlighting.
3774 Turning on Verilog mode calls the value of the variable `verilog-mode-hook'
3775 with no args, if that value is non-nil.
3777 Variables controlling indentation/edit style:
3779 variable `verilog-indent-level' (default 3)
3780 Indentation of Verilog statements with respect to containing block.
3781 `verilog-indent-level-module' (default 3)
3782 Absolute indentation of Module level Verilog statements.
3783 Set to 0 to get initial and always statements lined up
3784 on the left side of your screen.
3785 `verilog-indent-level-declaration' (default 3)
3786 Indentation of declarations with respect to containing block.
3787 Set to 0 to get them list right under containing block.
3788 `verilog-indent-level-behavioral' (default 3)
3789 Indentation of first begin in a task or function block
3790 Set to 0 to get such code to lined up underneath the task or
3791 function keyword.
3792 `verilog-indent-level-directive' (default 1)
3793 Indentation of \\=`ifdef/\\=`endif blocks.
3794 `verilog-cexp-indent' (default 1)
3795 Indentation of Verilog statements broken across lines i.e.:
3796 if (a)
3797 begin
3798 `verilog-case-indent' (default 2)
3799 Indentation for case statements.
3800 `verilog-auto-newline' (default nil)
3801 Non-nil means automatically newline after semicolons and the punctuation
3802 mark after an end.
3803 `verilog-auto-indent-on-newline' (default t)
3804 Non-nil means automatically indent line after newline.
3805 `verilog-tab-always-indent' (default t)
3806 Non-nil means TAB in Verilog mode should always reindent the current line,
3807 regardless of where in the line point is when the TAB command is used.
3808 `verilog-indent-begin-after-if' (default t)
3809 Non-nil means to indent begin statements following a preceding
3810 if, else, while, for and repeat statements, if any. Otherwise,
3811 the begin is lined up with the preceding token. If t, you get:
3812 if (a)
3813 begin // amount of indent based on `verilog-cexp-indent'
3814 otherwise you get:
3815 if (a)
3816 begin
3817 `verilog-auto-endcomments' (default t)
3818 Non-nil means a comment /* ... */ is set after the ends which ends
3819 cases, tasks, functions and modules.
3820 The type and name of the object will be set between the braces.
3821 `verilog-minimum-comment-distance' (default 10)
3822 Minimum distance (in lines) between begin and end required before a comment
3823 will be inserted. Setting this variable to zero results in every
3824 end acquiring a comment; the default avoids too many redundant
3825 comments in tight quarters.
3826 `verilog-auto-lineup' (default `declarations')
3827 List of contexts where auto lineup of code should be done.
3829 Variables controlling other actions:
3831 `verilog-linter' (default `surelint')
3832 Unix program to call to run the lint checker. This is the default
3833 command for \\[compile-command] and \\[verilog-auto-save-compile].
3835 See \\[customize] for the complete list of variables.
3837 AUTO expansion functions are, in part:
3839 \\[verilog-auto] Expand AUTO statements.
3840 \\[verilog-delete-auto] Remove the AUTOs.
3841 \\[verilog-inject-auto] Insert AUTOs for the first time.
3843 Some other functions are:
3845 \\[completion-at-point] Complete word with appropriate possibilities.
3846 \\[verilog-mark-defun] Mark function.
3847 \\[verilog-beg-of-defun] Move to beginning of current function.
3848 \\[verilog-end-of-defun] Move to end of current function.
3849 \\[verilog-label-be] Label matching begin ... end, fork ... join, etc statements.
3851 \\[verilog-comment-region] Put marked area in a comment.
3852 \\[verilog-uncomment-region] Uncomment an area commented with \\[verilog-comment-region].
3853 \\[verilog-insert-block] Insert begin ... end.
3854 \\[verilog-star-comment] Insert /* ... */.
3856 \\[verilog-sk-always] Insert an always @(AS) begin .. end block.
3857 \\[verilog-sk-begin] Insert a begin .. end block.
3858 \\[verilog-sk-case] Insert a case block, prompting for details.
3859 \\[verilog-sk-for] Insert a for (...) begin .. end block, prompting for details.
3860 \\[verilog-sk-generate] Insert a generate .. endgenerate block.
3861 \\[verilog-sk-header] Insert a header block at the top of file.
3862 \\[verilog-sk-initial] Insert an initial begin .. end block.
3863 \\[verilog-sk-fork] Insert a fork begin .. end .. join block.
3864 \\[verilog-sk-module] Insert a module .. (/*AUTOARG*/);.. endmodule block.
3865 \\[verilog-sk-ovm-class] Insert an OVM Class block.
3866 \\[verilog-sk-uvm-object] Insert an UVM Object block.
3867 \\[verilog-sk-uvm-component] Insert an UVM Component block.
3868 \\[verilog-sk-primitive] Insert a primitive .. (.. );.. endprimitive block.
3869 \\[verilog-sk-repeat] Insert a repeat (..) begin .. end block.
3870 \\[verilog-sk-specify] Insert a specify .. endspecify block.
3871 \\[verilog-sk-task] Insert a task .. begin .. end endtask block.
3872 \\[verilog-sk-while] Insert a while (...) begin .. end block, prompting for details.
3873 \\[verilog-sk-casex] Insert a casex (...) item: begin.. end endcase block, prompting for details.
3874 \\[verilog-sk-casez] Insert a casez (...) item: begin.. end endcase block, prompting for details.
3875 \\[verilog-sk-if] Insert an if (..) begin .. end block.
3876 \\[verilog-sk-else-if] Insert an else if (..) begin .. end block.
3877 \\[verilog-sk-comment] Insert a comment block.
3878 \\[verilog-sk-assign] Insert an assign .. = ..; statement.
3879 \\[verilog-sk-function] Insert a function .. begin .. end endfunction block.
3880 \\[verilog-sk-input] Insert an input declaration, prompting for details.
3881 \\[verilog-sk-output] Insert an output declaration, prompting for details.
3882 \\[verilog-sk-state-machine] Insert a state machine definition, prompting for details.
3883 \\[verilog-sk-inout] Insert an inout declaration, prompting for details.
3884 \\[verilog-sk-wire] Insert a wire declaration, prompting for details.
3885 \\[verilog-sk-reg] Insert a register declaration, prompting for details.
3886 \\[verilog-sk-define-signal] Define signal under point as a register at the top of the module.
3888 All key bindings can be seen in a Verilog-buffer with \\[describe-bindings].
3889 Key bindings specific to `verilog-mode-map' are:
3891 \\{verilog-mode-map}"
3892 :abbrev-table verilog-mode-abbrev-table
3893 (set (make-local-variable 'beginning-of-defun-function)
3894 'verilog-beg-of-defun)
3895 (set (make-local-variable 'end-of-defun-function)
3896 'verilog-end-of-defun)
3897 (set-syntax-table verilog-mode-syntax-table)
3898 (set (make-local-variable 'indent-line-function)
3899 #'verilog-indent-line-relative)
3900 (set (make-local-variable 'comment-indent-function) 'verilog-comment-indent)
3901 (set (make-local-variable 'parse-sexp-ignore-comments) nil)
3902 (set (make-local-variable 'comment-start) "// ")
3903 (set (make-local-variable 'comment-end) "")
3904 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *")
3905 (set (make-local-variable 'comment-multi-line) nil)
3906 ;; Set up for compilation
3907 (setq verilog-which-tool 1)
3908 (setq verilog-tool 'verilog-linter)
3909 (verilog-set-compile-command)
3910 (when (boundp 'hack-local-variables-hook) ; Also modify any file-local-variables
3911 (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t))
3913 ;; Setting up menus
3914 (when (featurep 'xemacs)
3915 (easy-menu-add verilog-stmt-menu)
3916 (easy-menu-add verilog-menu)
3917 (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu)))
3919 ;; Stuff for GNU Emacs
3920 (set (make-local-variable 'font-lock-defaults)
3921 `((verilog-font-lock-keywords
3922 verilog-font-lock-keywords-1
3923 verilog-font-lock-keywords-2
3924 verilog-font-lock-keywords-3)
3925 nil nil nil
3926 ,(if (functionp 'syntax-ppss)
3927 ;; verilog-beg-of-defun uses syntax-ppss, and syntax-ppss uses
3928 ;; font-lock-beginning-of-syntax-function, so
3929 ;; font-lock-beginning-of-syntax-function, can't use
3930 ;; verilog-beg-of-defun.
3932 'verilog-beg-of-defun)))
3933 ;;------------------------------------------------------------
3934 ;; now hook in 'verilog-highlight-include-files (eldo-mode.el&spice-mode.el)
3935 ;; all buffer local:
3936 (unless noninteractive ; Else can't see the result, and change hooks are slow
3937 (when (featurep 'xemacs)
3938 (make-local-hook 'font-lock-mode-hook)
3939 (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in Emacs
3940 (make-local-hook 'after-change-functions))
3941 (add-hook 'font-lock-mode-hook 'verilog-highlight-buffer t t)
3942 (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-highlight-buffer t t) ; not in Emacs
3943 (add-hook 'after-change-functions 'verilog-highlight-region t t))
3945 ;; Tell imenu how to handle Verilog.
3946 (set (make-local-variable 'imenu-generic-expression)
3947 verilog-imenu-generic-expression)
3948 ;; Tell which-func-modes that imenu knows about verilog
3949 (when (and (boundp 'which-func-modes) (listp which-func-modes))
3950 (add-to-list 'which-func-modes 'verilog-mode))
3951 ;; hideshow support
3952 (when (boundp 'hs-special-modes-alist)
3953 (unless (assq 'verilog-mode hs-special-modes-alist)
3954 (setq hs-special-modes-alist
3955 (cons '(verilog-mode-mode "\\<begin\\>" "\\<end\\>" nil
3956 verilog-forward-sexp-function)
3957 hs-special-modes-alist))))
3959 (add-hook 'completion-at-point-functions
3960 #'verilog-completion-at-point nil 'local)
3962 ;; Stuff for autos
3963 (add-hook 'write-contents-hooks 'verilog-auto-save-check nil 'local)
3964 ;; verilog-mode-hook call added by define-derived-mode
3967 ;;; Integration with the speedbar
3970 ;; Avoid problems with XEmacs byte-compiles.
3971 ;; For GNU Emacs, the eval-after-load will handle if it isn't loaded yet.
3972 (when (eval-when-compile (fboundp 'declare-function))
3973 (declare-function speedbar-add-supported-extension "speedbar" (extension)))
3975 (defun verilog-speedbar-initialize ()
3976 "Initialize speedbar to understand `verilog-mode'."
3977 ;; Set Verilog file extensions (extracted from `auto-mode-alist')
3978 (let ((mode-alist auto-mode-alist))
3979 (while mode-alist
3980 (when (eq (cdar mode-alist) 'verilog-mode)
3981 (speedbar-add-supported-extension (caar mode-alist)))
3982 (setq mode-alist (cdr mode-alist)))))
3984 ;; If the speedbar is loaded, execute initialization instructions right away,
3985 ;; otherwise add the initialization instructions to the speedbar loader.
3986 (eval-after-load "speedbar" '(verilog-speedbar-initialize))
3989 ;;; Electric functions:
3992 (defun electric-verilog-terminate-line (&optional arg)
3993 "Terminate line and indent next line.
3994 With optional ARG, remove existing end of line comments."
3995 (interactive)
3996 ;; before that see if we are in a comment
3997 (let ((state (save-excursion (verilog-syntax-ppss))))
3998 (cond
3999 ((nth 7 state) ; Inside // comment
4000 (if (eolp)
4001 (progn
4002 (delete-horizontal-space)
4003 (newline))
4004 (progn
4005 (newline)
4006 (insert "// ")
4007 (beginning-of-line)))
4008 (verilog-indent-line))
4009 ((nth 4 state) ; Inside any comment (hence /**/)
4010 (newline)
4011 (verilog-more-comment))
4012 ((eolp)
4013 ;; First, check if current line should be indented
4014 (if (save-excursion
4015 (delete-horizontal-space)
4016 (beginning-of-line)
4017 (skip-chars-forward " \t")
4018 (if (looking-at verilog-auto-end-comment-lines-re)
4019 (let ((indent-str (verilog-indent-line)))
4020 ;; Maybe we should set some endcomments
4021 (if verilog-auto-endcomments
4022 (verilog-set-auto-endcomments indent-str arg))
4023 (end-of-line)
4024 (delete-horizontal-space)
4025 (if arg
4027 (newline))
4028 nil)
4029 (progn
4030 (end-of-line)
4031 (delete-horizontal-space)
4032 't)))
4033 ;; see if we should line up assignments
4034 (progn
4035 (if (or (eq 'all verilog-auto-lineup)
4036 (eq 'assignments verilog-auto-lineup))
4037 (verilog-pretty-expr t "\\(<\\|:\\)?=" ))
4038 (newline))
4039 (forward-line 1))
4040 ;; Indent next line
4041 (if verilog-auto-indent-on-newline
4042 (verilog-indent-line)))
4044 (newline)))))
4046 (defun electric-verilog-terminate-and-indent ()
4047 "Insert a newline and indent for the next statement."
4048 (interactive)
4049 (electric-verilog-terminate-line 1))
4051 (defun electric-verilog-semi ()
4052 "Insert `;' character and reindent the line."
4053 (interactive)
4054 (verilog-insert-last-command-event)
4056 (if (or (verilog-in-comment-or-string-p)
4057 (verilog-in-escaped-name-p))
4059 (save-excursion
4060 (beginning-of-line)
4061 (verilog-forward-ws&directives)
4062 (verilog-indent-line))
4063 (if (and verilog-auto-newline
4064 (not (verilog-parenthesis-depth)))
4065 (electric-verilog-terminate-line))))
4067 (defun electric-verilog-semi-with-comment ()
4068 "Insert `;' character, reindent the line and indent for comment."
4069 (interactive)
4070 (insert ";")
4071 (save-excursion
4072 (beginning-of-line)
4073 (verilog-indent-line))
4074 (indent-for-comment))
4076 (defun electric-verilog-colon ()
4077 "Insert `:' and do all indentations except line indent on this line."
4078 (interactive)
4079 (verilog-insert-last-command-event)
4080 ;; Do nothing if within string.
4081 (if (or
4082 (verilog-within-string)
4083 (not (verilog-in-case-region-p)))
4085 (save-excursion
4086 (let ((p (point))
4087 (lim (progn (verilog-beg-of-statement) (point))))
4088 (goto-char p)
4089 (verilog-backward-case-item lim)
4090 (verilog-indent-line)))
4091 ;; (let ((verilog-tab-always-indent nil))
4092 ;; (verilog-indent-line))
4095 ;;(defun electric-verilog-equal ()
4096 ;; "Insert `=', and do indentation if within block."
4097 ;; (interactive)
4098 ;; (verilog-insert-last-command-event)
4099 ;; Could auto line up expressions, but not yet
4100 ;; (if (eq (car (verilog-calculate-indent)) 'block)
4101 ;; (let ((verilog-tab-always-indent nil))
4102 ;; (verilog-indent-command)))
4103 ;; )
4105 (defun electric-verilog-tick ()
4106 "Insert back-tick, and indent to column 0 if this is a CPP directive."
4107 (interactive)
4108 (verilog-insert-last-command-event)
4109 (save-excursion
4110 (if (verilog-in-directive-p)
4111 (verilog-indent-line))))
4113 (defun electric-verilog-tab ()
4114 "Function called when TAB is pressed in Verilog mode."
4115 (interactive)
4116 ;; If verilog-tab-always-indent, indent the beginning of the line.
4117 (cond
4118 ;; The region is active, indent it.
4119 ((and (region-active-p)
4120 (not (eq (region-beginning) (region-end))))
4121 (indent-region (region-beginning) (region-end) nil))
4122 ((or verilog-tab-always-indent
4123 (save-excursion
4124 (skip-chars-backward " \t")
4125 (bolp)))
4126 (let* ((oldpnt (point))
4127 (boi-point
4128 (save-excursion
4129 (beginning-of-line)
4130 (skip-chars-forward " \t")
4131 (verilog-indent-line)
4132 (back-to-indentation)
4133 (point))))
4134 (if (< (point) boi-point)
4135 (back-to-indentation)
4136 (cond ((not verilog-tab-to-comment))
4137 ((not (eolp))
4138 (end-of-line))
4140 (indent-for-comment)
4141 (when (and (eolp) (= oldpnt (point)))
4142 ;; kill existing comment
4143 (beginning-of-line)
4144 (re-search-forward comment-start-skip oldpnt 'move)
4145 (goto-char (match-beginning 0))
4146 (skip-chars-backward " \t")
4147 (kill-region (point) oldpnt)))))))
4148 (t (progn (insert "\t")))))
4151 ;;; Interactive functions:
4154 (defun verilog-indent-buffer ()
4155 "Indent-region the entire buffer as Verilog code.
4156 To call this from the command line, see \\[verilog-batch-indent]."
4157 (interactive)
4158 (verilog-mode)
4159 (indent-region (point-min) (point-max) nil))
4161 (defun verilog-insert-block ()
4162 "Insert Verilog begin ... end; block in the code with right indentation."
4163 (interactive)
4164 (verilog-indent-line)
4165 (insert "begin")
4166 (electric-verilog-terminate-line)
4167 (save-excursion
4168 (electric-verilog-terminate-line)
4169 (insert "end")
4170 (beginning-of-line)
4171 (verilog-indent-line)))
4173 (defun verilog-star-comment ()
4174 "Insert Verilog star comment at point."
4175 (interactive)
4176 (verilog-indent-line)
4177 (insert "/*")
4178 (save-excursion
4179 (newline)
4180 (insert " */"))
4181 (newline)
4182 (insert " * "))
4184 (defun verilog-insert-1 (fmt max)
4185 "Use format string FMT to insert integers 0 to MAX - 1.
4186 Inserts one integer per line, at the current column. Stops early
4187 if it reaches the end of the buffer."
4188 (let ((col (current-column))
4189 (n 0))
4190 (save-excursion
4191 (while (< n max)
4192 (insert (format fmt n))
4193 (forward-line 1)
4194 ;; Note that this function does not bother to check for lines
4195 ;; shorter than col.
4196 (if (eobp)
4197 (setq n max)
4198 (setq n (1+ n))
4199 (move-to-column col))))))
4201 (defun verilog-insert-indices (max)
4202 "Insert a set of indices into a rectangle.
4203 The upper left corner is defined by point. Indices begin with 0
4204 and extend to the MAX - 1. If no prefix arg is given, the user
4205 is prompted for a value. The indices are surrounded by square
4206 brackets []. For example, the following code with the point
4207 located after the first `a' gives:
4209 a = b a[ 0] = b
4210 a = b a[ 1] = b
4211 a = b a[ 2] = b
4212 a = b a[ 3] = b
4213 a = b ==> insert-indices ==> a[ 4] = b
4214 a = b a[ 5] = b
4215 a = b a[ 6] = b
4216 a = b a[ 7] = b
4217 a = b a[ 8] = b"
4219 (interactive "NMAX: ")
4220 (verilog-insert-1 "[%3d]" max))
4222 (defun verilog-generate-numbers (max)
4223 "Insert a set of generated numbers into a rectangle.
4224 The upper left corner is defined by point. The numbers are padded to three
4225 digits, starting with 000 and extending to (MAX - 1). If no prefix argument
4226 is supplied, then the user is prompted for the MAX number. Consider the
4227 following code fragment:
4229 buf buf buf buf000
4230 buf buf buf buf001
4231 buf buf buf buf002
4232 buf buf buf buf003
4233 buf buf ==> generate-numbers ==> buf buf004
4234 buf buf buf buf005
4235 buf buf buf buf006
4236 buf buf buf buf007
4237 buf buf buf buf008"
4239 (interactive "NMAX: ")
4240 (verilog-insert-1 "%3.3d" max))
4242 (defun verilog-mark-defun ()
4243 "Mark the current Verilog function (or procedure).
4244 This puts the mark at the end, and point at the beginning."
4245 (interactive)
4246 (if (featurep 'xemacs)
4247 (progn
4248 (push-mark)
4249 (verilog-end-of-defun)
4250 (push-mark)
4251 (verilog-beg-of-defun)
4252 (if (fboundp 'zmacs-activate-region)
4253 (zmacs-activate-region)))
4254 (mark-defun)))
4256 (defun verilog-comment-region (start end)
4257 ;; checkdoc-params: (start end)
4258 "Put the region into a Verilog comment.
4259 The comments that are in this area are \"deformed\":
4260 `*)' becomes `!(*' and `}' becomes `!{'.
4261 These deformed comments are returned to normal if you use
4262 \\[verilog-uncomment-region] to undo the commenting.
4264 The commented area starts with `verilog-exclude-str-start', and ends with
4265 `verilog-exclude-str-end'. But if you change these variables,
4266 \\[verilog-uncomment-region] won't recognize the comments."
4267 (interactive "r")
4268 (save-excursion
4269 ;; Insert start and endcomments
4270 (goto-char end)
4271 (if (and (save-excursion (skip-chars-forward " \t") (eolp))
4272 (not (save-excursion (skip-chars-backward " \t") (bolp))))
4273 (forward-line 1)
4274 (beginning-of-line))
4275 (insert verilog-exclude-str-end)
4276 (setq end (point))
4277 (newline)
4278 (goto-char start)
4279 (beginning-of-line)
4280 (insert verilog-exclude-str-start)
4281 (newline)
4282 ;; Replace end-comments within commented area
4283 (goto-char end)
4284 (save-excursion
4285 (while (re-search-backward "\\*/" start t)
4286 (replace-match "*-/" t t)))
4287 (save-excursion
4288 (let ((s+1 (1+ start)))
4289 (while (re-search-backward "/\\*" s+1 t)
4290 (replace-match "/-*" t t))))))
4292 (defun verilog-uncomment-region ()
4293 "Uncomment a commented area; change deformed comments back to normal.
4294 This command does nothing if the pointer is not in a commented
4295 area. See also `verilog-comment-region'."
4296 (interactive)
4297 (save-excursion
4298 (let ((start (point))
4299 (end (point)))
4300 ;; Find the boundaries of the comment
4301 (save-excursion
4302 (setq start (progn (search-backward verilog-exclude-str-start nil t)
4303 (point)))
4304 (setq end (progn (search-forward verilog-exclude-str-end nil t)
4305 (point))))
4306 ;; Check if we're really inside a comment
4307 (if (or (equal start (point)) (<= end (point)))
4308 (message "Not standing within commented area.")
4309 (progn
4310 ;; Remove endcomment
4311 (goto-char end)
4312 (beginning-of-line)
4313 (let ((pos (point)))
4314 (end-of-line)
4315 (delete-region pos (1+ (point))))
4316 ;; Change comments back to normal
4317 (save-excursion
4318 (while (re-search-backward "\\*-/" start t)
4319 (replace-match "*/" t t)))
4320 (save-excursion
4321 (while (re-search-backward "/-\\*" start t)
4322 (replace-match "/*" t t)))
4323 ;; Remove start comment
4324 (goto-char start)
4325 (beginning-of-line)
4326 (let ((pos (point)))
4327 (end-of-line)
4328 (delete-region pos (1+ (point)))))))))
4330 (defun verilog-beg-of-defun ()
4331 "Move backward to the beginning of the current function or procedure."
4332 (interactive)
4333 (verilog-re-search-backward verilog-defun-re nil 'move))
4335 (defun verilog-beg-of-defun-quick ()
4336 "Move backward to the beginning of the current function or procedure.
4337 Uses `verilog-scan' cache."
4338 (interactive)
4339 (verilog-re-search-backward-quick verilog-defun-re nil 'move))
4341 (defun verilog-end-of-defun ()
4342 "Move forward to the end of the current function or procedure."
4343 (interactive)
4344 (verilog-re-search-forward verilog-end-defun-re nil 'move))
4346 (defun verilog-get-end-of-defun ()
4347 (save-excursion
4348 (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t)
4349 (point))
4351 (error "%s: Can't find endmodule" (verilog-point-text))
4352 (point-max)))))
4354 (defun verilog-label-be ()
4355 "Label matching begin ... end, fork ... join and case ... endcase statements."
4356 (interactive)
4357 (let ((cnt 0)
4358 (case-fold-search nil)
4359 (oldpos (point))
4360 (b (progn
4361 (verilog-beg-of-defun)
4362 (point-marker)))
4363 (e (progn
4364 (verilog-end-of-defun)
4365 (point-marker))))
4366 (goto-char (marker-position b))
4367 (if (> (- e b) 200)
4368 (message "Relabeling module..."))
4369 (while (and
4370 (> (marker-position e) (point))
4371 (verilog-re-search-forward
4372 verilog-auto-end-comment-lines-re
4373 nil 'move))
4374 (goto-char (match-beginning 0))
4375 (let ((indent-str (verilog-indent-line)))
4376 (verilog-set-auto-endcomments indent-str 't)
4377 (end-of-line)
4378 (delete-horizontal-space))
4379 (setq cnt (1+ cnt))
4380 (if (= 9 (% cnt 10))
4381 (message "%d..." cnt)))
4382 (goto-char oldpos)
4383 (if (or
4384 (> (- e b) 200)
4385 (> cnt 20))
4386 (message "%d lines auto commented" cnt))))
4388 (defun verilog-beg-of-statement ()
4389 "Move backward to beginning of statement."
4390 (interactive)
4391 ;; Move back token by token until we see the end
4392 ;; of some earlier line.
4393 (let (h)
4394 (while
4395 ;; If the current point does not begin a new
4396 ;; statement, as in the character ahead of us is a ';', or SOF
4397 ;; or the string after us unambiguously starts a statement,
4398 ;; or the token before us unambiguously ends a statement,
4399 ;; then move back a token and test again.
4400 (not (or
4401 ;; stop if beginning of buffer
4402 (bobp)
4403 ;; stop if looking at a pre-processor directive
4404 (looking-at "`\\w+")
4405 ;; stop if we find a ;
4406 (= (preceding-char) ?\;)
4407 ;; stop if we see a named coverpoint
4408 (looking-at "\\w+\\W*:\\W*\\(coverpoint\\|cross\\|constraint\\)")
4409 ;; keep going if we are in the middle of a word
4410 (not (or (looking-at "\\<") (forward-word-strictly -1)))
4411 ;; stop if we see an assertion (perhaps labeled)
4412 (and
4413 (looking-at "\\(\\w+\\W*:\\W*\\)?\\(\\<\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(\\<assert\\>\\)")
4414 (progn
4415 (setq h (point))
4416 (save-excursion
4417 (verilog-backward-token)
4418 (if (and (looking-at verilog-label-re)
4419 (not (looking-at verilog-end-block-re)))
4420 (setq h (point))))
4421 (goto-char h)))
4422 ;; stop if we see an extended complete reg, perhaps a complete one
4423 (and
4424 (looking-at verilog-complete-reg)
4425 (let* ((p (point)))
4426 (while (and (looking-at verilog-extended-complete-re)
4427 (progn (setq p (point))
4428 (verilog-backward-token)
4429 (/= p (point)))))
4430 (goto-char p)))
4431 ;; stop if we see a complete reg (previous found extended ones)
4432 (looking-at verilog-basic-complete-re)
4433 ;; stop if previous token is an ender
4434 (save-excursion
4435 (verilog-backward-token)
4436 (looking-at verilog-end-block-re))))
4437 (verilog-backward-syntactic-ws)
4438 (verilog-backward-token))
4439 ;; Now point is where the previous line ended.
4440 (verilog-forward-syntactic-ws)
4441 ;; Skip forward over any preprocessor directives, as they have wacky indentation
4442 (if (looking-at verilog-preprocessor-re)
4443 (progn (goto-char (match-end 0))
4444 (verilog-forward-syntactic-ws)))))
4446 (defun verilog-beg-of-statement-1 ()
4447 "Move backward to beginning of statement."
4448 (interactive)
4449 (if (verilog-in-comment-p)
4450 (verilog-backward-syntactic-ws))
4451 (let ((pt (point)))
4452 (catch 'done
4453 (while (not (looking-at verilog-complete-reg))
4454 (setq pt (point))
4455 (verilog-backward-syntactic-ws)
4456 (if (or (bolp)
4457 (= (preceding-char) ?\;)
4458 (progn
4459 (verilog-backward-token)
4460 (looking-at verilog-ends-re)))
4461 (progn
4462 (goto-char pt)
4463 (throw 'done t)))))
4464 (verilog-forward-syntactic-ws)))
4466 ;; (while (and
4467 ;; (not (looking-at verilog-complete-reg))
4468 ;; (not (bolp))
4469 ;; (not (= (preceding-char) ?\;)))
4470 ;; (verilog-backward-token)
4471 ;; (verilog-backward-syntactic-ws)
4472 ;; (setq pt (point)))
4473 ;; (goto-char pt)
4474 ;; ;(verilog-forward-syntactic-ws)
4476 (defun verilog-end-of-statement ()
4477 "Move forward to end of current statement."
4478 (interactive)
4479 (let ((nest 0) pos)
4480 (cond
4481 ((verilog-in-directive-p)
4482 (forward-line 1)
4483 (backward-char 1))
4485 ((looking-at verilog-beg-block-re)
4486 (verilog-forward-sexp))
4488 ((equal (char-after) ?\})
4489 (forward-char))
4491 ;; Skip to end of statement
4492 ((condition-case nil
4493 (setq pos
4494 (catch 'found
4495 (while t
4496 (forward-sexp 1)
4497 (verilog-skip-forward-comment-or-string)
4498 (if (eolp)
4499 (forward-line 1))
4500 (cond ((looking-at "[ \t]*;")
4501 (skip-chars-forward "^;")
4502 (forward-char 1)
4503 (throw 'found (point)))
4504 ((save-excursion
4505 (forward-sexp -1)
4506 (looking-at verilog-beg-block-re))
4507 (goto-char (match-beginning 0))
4508 (throw 'found nil))
4509 ((looking-at "[ \t]*)")
4510 (throw 'found (point)))
4511 ((eobp)
4512 (throw 'found (point)))
4516 (error nil))
4517 (if (not pos)
4518 ;; Skip a whole block
4519 (catch 'found
4520 (while t
4521 (verilog-re-search-forward verilog-end-statement-re nil 'move)
4522 (setq nest (if (match-end 1)
4523 (1+ nest)
4524 (1- nest)))
4525 (cond ((eobp)
4526 (throw 'found (point)))
4527 ((= 0 nest)
4528 (throw 'found (verilog-end-of-statement))))))
4529 pos)))))
4531 (defun verilog-in-case-region-p ()
4532 "Return true if in a case region.
4533 More specifically, point @ in the line foo : @ begin"
4534 (interactive)
4535 (save-excursion
4536 (if (and
4537 (progn (verilog-forward-syntactic-ws)
4538 (looking-at "\\<begin\\>"))
4539 (progn (verilog-backward-syntactic-ws)
4540 (= (preceding-char) ?\:)))
4541 (catch 'found
4542 (let ((nest 1))
4543 (while t
4544 (verilog-re-search-backward
4545 (concat "\\(\\<module\\>\\)\\|\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|"
4546 "\\(\\<endcase\\>\\)\\>")
4547 nil 'move)
4548 (cond
4549 ((match-end 3)
4550 (setq nest (1+ nest)))
4551 ((match-end 2)
4552 (if (= nest 1)
4553 (throw 'found 1))
4554 (setq nest (1- nest)))
4556 (throw 'found (= nest 0)))))))
4557 nil)))
4559 (defun verilog-backward-up-list (arg)
4560 "Call `backward-up-list' ARG, ignoring comments."
4561 (let ((parse-sexp-ignore-comments t))
4562 (backward-up-list arg)))
4564 (defun verilog-forward-sexp-cmt (arg)
4565 "Call `forward-sexp' ARG, inside comments."
4566 (let ((parse-sexp-ignore-comments nil))
4567 (forward-sexp arg)))
4569 (defun verilog-forward-sexp-ign-cmt (arg)
4570 "Call `forward-sexp' ARG, ignoring comments."
4571 (let ((parse-sexp-ignore-comments t))
4572 (forward-sexp arg)))
4574 (defun verilog-in-generate-region-p ()
4575 "Return true if in a generate region.
4576 More specifically, after a generate and before an endgenerate."
4577 (interactive)
4578 (let ((nest 1))
4579 (save-excursion
4580 (catch 'done
4581 (while (and
4582 (/= nest 0)
4583 (verilog-re-search-backward
4584 "\\<\\(module\\)\\|\\(generate\\)\\|\\(endgenerate\\)\\>" nil 'move)
4585 (cond
4586 ((match-end 1) ; module - we have crawled out
4587 (throw 'done 1))
4588 ((match-end 2) ; generate
4589 (setq nest (1- nest)))
4590 ((match-end 3) ; endgenerate
4591 (setq nest (1+ nest))))))))
4592 (= nest 0) )) ; return nest
4594 (defun verilog-in-fork-region-p ()
4595 "Return true if between a fork and join."
4596 (interactive)
4597 (let ((lim (save-excursion (verilog-beg-of-defun) (point)))
4598 (nest 1))
4599 (save-excursion
4600 (while (and
4601 (/= nest 0)
4602 (verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\(_any\\|_none\\)?\\)\\>" lim 'move)
4603 (cond
4604 ((match-end 1) ; fork
4605 (setq nest (1- nest)))
4606 ((match-end 2) ; join
4607 (setq nest (1+ nest)))))))
4608 (= nest 0) )) ; return nest
4610 (defun verilog-in-deferred-immediate-final-p ()
4611 "Return true if inside an `assert/assume/cover final' statement."
4612 (interactive)
4613 (and (looking-at "final")
4614 (verilog-looking-back "\\<\\(?:assert\\|assume\\|cover\\)\\>\\s-+" nil))
4617 (defun verilog-backward-case-item (lim)
4618 "Skip backward to nearest enclosing case item.
4619 Limit search to point LIM."
4620 (interactive)
4621 (let ((str 'nil)
4622 (lim1
4623 (progn
4624 (save-excursion
4625 (verilog-re-search-backward verilog-endcomment-reason-re
4626 lim 'move)
4627 (point)))))
4628 ;; Try to find the real :
4629 (if (save-excursion (search-backward ":" lim1 t))
4630 (let ((colon 0)
4631 b e )
4632 (while
4633 (and
4634 (< colon 1)
4635 (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)"
4636 lim1 'move))
4637 (cond
4638 ((match-end 1) ; [
4639 (setq colon (1+ colon))
4640 (if (>= colon 0)
4641 (error "%s: unbalanced [" (verilog-point-text))))
4642 ((match-end 2) ; ]
4643 (setq colon (1- colon)))
4645 ((match-end 3) ; :
4646 (setq colon (1+ colon)))))
4647 ;; Skip back to beginning of case item
4648 (skip-chars-backward "\t ")
4649 (verilog-skip-backward-comment-or-string)
4650 (setq e (point))
4651 (setq b
4652 (progn
4654 (verilog-re-search-backward
4655 "\\<\\(randcase\\|case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move)
4656 (progn
4657 (cond
4658 ((match-end 1)
4659 (goto-char (match-end 1))
4660 (verilog-forward-ws&directives)
4661 (if (looking-at "(")
4662 (progn
4663 (forward-sexp)
4664 (verilog-forward-ws&directives)))
4665 (point))
4667 (goto-char (match-end 0))
4668 (verilog-forward-ws&directives)
4669 (point))))
4670 (error "Malformed case item"))))
4671 (setq str (buffer-substring b e))
4673 (setq e
4674 (string-match
4675 "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
4676 (setq str (concat (substring str 0 e) "...")))
4677 str)
4678 'nil)))
4680 ;;; Other functions:
4683 (defun verilog-kill-existing-comment ()
4684 "Kill auto comment on this line."
4685 (save-excursion
4686 (let* (
4687 (e (progn
4688 (end-of-line)
4689 (point)))
4690 (b (progn
4691 (beginning-of-line)
4692 (search-forward "//" e t))))
4693 (if b
4694 (delete-region (- b 2) e)))))
4696 (defconst verilog-directive-nest-re
4697 (concat "\\(`else\\>\\)\\|"
4698 "\\(`endif\\>\\)\\|"
4699 "\\(`if\\>\\)\\|"
4700 "\\(`ifdef\\>\\)\\|"
4701 "\\(`ifndef\\>\\)\\|"
4702 "\\(`elsif\\>\\)"))
4704 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment)
4705 "Add ending comment with given INDENT-STR.
4706 With KILL-EXISTING-COMMENT, remove what was there before.
4707 Insert `// case: 7 ' or `// NAME ' on this line if appropriate.
4708 Insert `// case expr ' if this line ends a case block.
4709 Insert `// ifdef FOO ' if this line ends code conditional on FOO.
4710 Insert `// NAME ' if this line ends a function, task, module,
4711 primitive or interface named NAME."
4712 (save-excursion
4713 (cond
4714 (; Comment close preprocessor directives
4715 (and
4716 (looking-at "\\(`endif\\)\\|\\(`else\\)")
4717 (or kill-existing-comment
4718 (not (save-excursion
4719 (end-of-line)
4720 (search-backward "//" (point-at-bol) t)))))
4721 (let ((nest 1) b e
4723 (else (if (match-end 2) "!" " ")))
4724 (end-of-line)
4725 (if kill-existing-comment
4726 (verilog-kill-existing-comment))
4727 (delete-horizontal-space)
4728 (save-excursion
4729 (backward-sexp 1)
4730 (while (and (/= nest 0)
4731 (verilog-re-search-backward verilog-directive-nest-re nil 'move))
4732 (cond
4733 ((match-end 1) ; `else
4734 (if (= nest 1)
4735 (setq else "!")))
4736 ((match-end 2) ; `endif
4737 (setq nest (1+ nest)))
4738 ((match-end 3) ; `if
4739 (setq nest (1- nest)))
4740 ((match-end 4) ; `ifdef
4741 (setq nest (1- nest)))
4742 ((match-end 5) ; `ifndef
4743 (setq nest (1- nest)))
4744 ((match-end 6) ; `elsif
4745 (if (= nest 1)
4746 (progn
4747 (setq else "!")
4748 (setq nest 0))))))
4749 (if (match-end 0)
4750 (setq
4751 m (buffer-substring
4752 (match-beginning 0)
4753 (match-end 0))
4754 b (progn
4755 (skip-chars-forward "^ \t")
4756 (verilog-forward-syntactic-ws)
4757 (point))
4758 e (progn
4759 (skip-chars-forward "a-zA-Z0-9_")
4760 (point)))))
4761 (if b
4762 (if (> (count-lines (point) b) verilog-minimum-comment-distance)
4763 (insert (concat " // " else m " " (buffer-substring b e))))
4764 (progn
4765 (insert " // unmatched `else, `elsif or `endif")
4766 (ding 't)))))
4768 (; Comment close case/class/function/task/module and named block
4769 (and (looking-at "\\<end")
4770 (or kill-existing-comment
4771 (not (save-excursion
4772 (end-of-line)
4773 (search-backward "//" (point-at-bol) t)))))
4774 (let ((type (car indent-str)))
4775 (unless (eq type 'declaration)
4776 (unless (looking-at (concat "\\(" verilog-end-block-ordered-re "\\)[ \t]*:")) ; ignore named ends
4777 (if (looking-at verilog-end-block-ordered-re)
4778 (cond
4779 (;- This is a case block; search back for the start of this case
4780 (match-end 1) ; of verilog-end-block-ordered-re
4782 (let ((err 't)
4783 (str "UNMATCHED!!"))
4784 (save-excursion
4785 (verilog-leap-to-head)
4786 (cond
4787 ((looking-at "\\<randcase\\>")
4788 (setq str "randcase")
4789 (setq err nil))
4790 ((looking-at "\\(\\(unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
4791 (goto-char (match-end 0))
4792 (setq str (concat (match-string 0) " " (verilog-get-expr)))
4793 (setq err nil))
4795 (end-of-line)
4796 (if kill-existing-comment
4797 (verilog-kill-existing-comment))
4798 (delete-horizontal-space)
4799 (insert (concat " // " str ))
4800 (if err (ding 't))))
4802 (;- This is a begin..end block
4803 (match-end 2) ; of verilog-end-block-ordered-re
4804 (let ((str " // UNMATCHED !!")
4805 (err 't)
4806 (here (point))
4807 there
4808 cntx)
4809 (save-excursion
4810 (verilog-leap-to-head)
4811 (setq there (point))
4812 (if (not (match-end 0))
4813 (progn
4814 (goto-char here)
4815 (end-of-line)
4816 (if kill-existing-comment
4817 (verilog-kill-existing-comment))
4818 (delete-horizontal-space)
4819 (insert str)
4820 (ding 't))
4821 (let ((lim
4822 (save-excursion (verilog-beg-of-defun) (point)))
4823 (here (point)))
4824 (cond
4825 (;-- handle named block differently
4826 (looking-at verilog-named-block-re)
4827 (search-forward ":")
4828 (setq there (point))
4829 (setq str (verilog-get-expr))
4830 (setq err nil)
4831 (setq str (concat " // block: " str )))
4833 ((verilog-in-case-region-p) ;-- handle case item differently
4834 (goto-char here)
4835 (setq str (verilog-backward-case-item lim))
4836 (setq there (point))
4837 (setq err nil)
4838 (setq str (concat " // case: " str )))
4840 (;- try to find "reason" for this begin
4841 (cond
4843 (eq here (progn
4844 ;; (verilog-backward-token)
4845 (verilog-beg-of-statement)
4846 (point)))
4847 (setq err nil)
4848 (setq str ""))
4849 ((looking-at verilog-endcomment-reason-re)
4850 (setq there (match-end 0))
4851 (setq cntx (concat (match-string 0) " "))
4852 (cond
4853 (;- begin
4854 (match-end 1)
4855 (setq err nil)
4856 (save-excursion
4857 (if (and (verilog-continued-line)
4858 (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>"))
4859 (progn
4860 (goto-char (match-end 0))
4861 (setq there (point))
4862 (setq str
4863 (concat " // " (match-string 0) " " (verilog-get-expr))))
4864 (setq str ""))))
4866 (;- else
4867 (match-end 2)
4868 (let ((nest 0)
4869 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4870 (catch 'skip
4871 (while (verilog-re-search-backward reg nil 'move)
4872 (cond
4873 ((match-end 1) ; begin
4874 (setq nest (1- nest)))
4875 ((match-end 2) ; end
4876 (setq nest (1+ nest)))
4877 ((match-end 3)
4878 (if (= 0 nest)
4879 (progn
4880 (goto-char (match-end 0))
4881 (setq there (point))
4882 (setq err nil)
4883 (setq str (verilog-get-expr))
4884 (setq str (concat " // else: !if" str ))
4885 (throw 'skip 1))))
4886 ((match-end 4)
4887 (if (= 0 nest)
4888 (progn
4889 (goto-char (match-end 0))
4890 (setq there (point))
4891 (setq err nil)
4892 (setq str (verilog-get-expr))
4893 (setq str (concat " // else: !assert " str ))
4894 (throw 'skip 1)))))))))
4895 (;- end else
4896 (match-end 3)
4897 (goto-char there)
4898 (let ((nest 0)
4899 (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4900 (catch 'skip
4901 (while (verilog-re-search-backward reg nil 'move)
4902 (cond
4903 ((match-end 1) ; begin
4904 (setq nest (1- nest)))
4905 ((match-end 2) ; end
4906 (setq nest (1+ nest)))
4907 ((match-end 3)
4908 (if (= 0 nest)
4909 (progn
4910 (goto-char (match-end 0))
4911 (setq there (point))
4912 (setq err nil)
4913 (setq str (verilog-get-expr))
4914 (setq str (concat " // else: !if" str ))
4915 (throw 'skip 1))))
4916 ((match-end 4)
4917 (if (= 0 nest)
4918 (progn
4919 (goto-char (match-end 0))
4920 (setq there (point))
4921 (setq err nil)
4922 (setq str (verilog-get-expr))
4923 (setq str (concat " // else: !assert " str ))
4924 (throw 'skip 1)))))))))
4926 (; always, always_comb, always_latch w/o @...
4927 (match-end 5)
4928 (goto-char (match-end 0))
4929 (setq there (point))
4930 (setq err nil)
4931 (setq str (concat " // " cntx )))
4933 (;- task/function/initial et cetera
4935 (match-end 0)
4936 (goto-char (match-end 0))
4937 (setq there (point))
4938 (setq err nil)
4939 (setq str (concat " // " cntx (verilog-get-expr))))
4941 (;-- otherwise...
4942 (setq str " // auto-endcomment confused "))))
4944 ((and
4945 (verilog-in-case-region-p) ;-- handle case item differently
4946 (progn
4947 (setq there (point))
4948 (goto-char here)
4949 (setq str (verilog-backward-case-item lim))))
4950 (setq err nil)
4951 (setq str (concat " // case: " str )))
4953 ((verilog-in-fork-region-p)
4954 (setq err nil)
4955 (setq str " // fork branch" ))
4957 ((looking-at "\\<end\\>")
4958 ;; HERE
4959 (forward-word-strictly 1)
4960 (verilog-forward-syntactic-ws)
4961 (setq err nil)
4962 (setq str (verilog-get-expr))
4963 (setq str (concat " // " cntx str )))
4965 ))))
4966 (goto-char here)
4967 (end-of-line)
4968 (if kill-existing-comment
4969 (verilog-kill-existing-comment))
4970 (delete-horizontal-space)
4971 (if (or err
4972 (> (count-lines here there) verilog-minimum-comment-distance))
4973 (insert str))
4974 (if err (ding 't))
4975 ))))
4976 (;- this is endclass, which can be nested
4977 (match-end 11) ; of verilog-end-block-ordered-re
4978 ;;(goto-char there)
4979 (let ((nest 0)
4980 (reg "\\<\\(class\\)\\|\\(endclass\\)\\|\\(package\\|primitive\\|\\(macro\\)?module\\)\\>")
4981 string)
4982 (save-excursion
4983 (catch 'skip
4984 (while (verilog-re-search-backward reg nil 'move)
4985 (cond
4986 ((match-end 3) ; endclass
4987 (ding 't)
4988 (setq string "unmatched endclass")
4989 (throw 'skip 1))
4991 ((match-end 2) ; endclass
4992 (setq nest (1+ nest)))
4994 ((match-end 1) ; class
4995 (setq nest (1- nest))
4996 (if (< nest 0)
4997 (progn
4998 (goto-char (match-end 0))
4999 (let (b e)
5000 (setq b (progn
5001 (skip-chars-forward "^ \t")
5002 (verilog-forward-ws&directives)
5003 (point))
5004 e (progn
5005 (skip-chars-forward "a-zA-Z0-9_")
5006 (point)))
5007 (setq string (buffer-substring b e)))
5008 (throw 'skip 1))))
5009 ))))
5010 (end-of-line)
5011 (if kill-existing-comment
5012 (verilog-kill-existing-comment))
5013 (delete-horizontal-space)
5014 (insert (concat " // " string ))))
5016 (; - this is end{function,generate,task,module,primitive,table,generate}
5017 ;; - which can not be nested.
5019 (let (string reg (name-re nil))
5020 (end-of-line)
5021 (if kill-existing-comment
5022 (save-match-data
5023 (verilog-kill-existing-comment)))
5024 (delete-horizontal-space)
5025 (backward-sexp)
5026 (cond
5027 ((match-end 5) ; of verilog-end-block-ordered-re
5028 (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
5029 (setq name-re "\\w+\\(?:\n\\|\\s-\\)*[(;]"))
5030 ((match-end 6) ; of verilog-end-block-ordered-re
5031 (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
5032 (setq name-re "\\w+\\(?:\n\\|\\s-\\)*[(;]"))
5033 ((match-end 7) ; of verilog-end-block-ordered-re
5034 (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>"))
5035 ((match-end 8) ; of verilog-end-block-ordered-re
5036 (setq reg "\\(\\<primitive\\>\\)\\|\\(\\<\\(endprimitive\\|package\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5037 ((match-end 9) ; of verilog-end-block-ordered-re
5038 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<\\(endinterface\\|package\\|primitive\\|\\(macro\\)?module\\)\\>\\)"))
5039 ((match-end 10) ; of verilog-end-block-ordered-re
5040 (setq reg "\\(\\<package\\>\\)\\|\\(\\<\\(endpackage\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5041 ((match-end 11) ; of verilog-end-block-ordered-re
5042 (setq reg "\\(\\<class\\>\\)\\|\\(\\<\\(endclass\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5043 ((match-end 12) ; of verilog-end-block-ordered-re
5044 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<\\(endcovergroup\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5045 ((match-end 13) ; of verilog-end-block-ordered-re
5046 (setq reg "\\(\\<program\\>\\)\\|\\(\\<\\(endprogram\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5047 ((match-end 14) ; of verilog-end-block-ordered-re
5048 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<\\(endsequence\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5049 ((match-end 15) ; of verilog-end-block-ordered-re
5050 (setq reg "\\(\\<clocking\\>\\)\\|\\<endclocking\\>"))
5051 ((match-end 16) ; of verilog-end-block-ordered-re
5052 (setq reg "\\(\\<property\\>\\)\\|\\<endproperty\\>"))
5054 (t (error "Problem in verilog-set-auto-endcomments")))
5055 (let (b e)
5056 (save-excursion
5057 (verilog-re-search-backward reg nil 'move)
5058 (cond
5059 ((match-end 1)
5060 (setq b (progn
5061 (skip-chars-forward "^ \t")
5062 (verilog-forward-ws&directives)
5063 (if (looking-at "static\\|automatic")
5064 (progn
5065 (goto-char (match-end 0))
5066 (verilog-forward-ws&directives)))
5067 (if (and name-re (verilog-re-search-forward name-re nil 'move))
5068 (progn
5069 (goto-char (match-beginning 0))
5070 (verilog-forward-ws&directives)))
5071 (point))
5072 e (progn
5073 (skip-chars-forward "a-zA-Z0-9_")
5074 (point)))
5075 (setq string (buffer-substring b e)))
5077 (ding 't)
5078 (setq string "unmatched end(function|task|module|primitive|interface|package|class|clocking)")))))
5079 (end-of-line)
5080 (insert (concat " // " string )))
5081 ))))))))))
5083 (defun verilog-get-expr()
5084 "Grab expression at point, e.g., case ( a | b & (c ^d))."
5085 (let* ((b (progn
5086 (verilog-forward-syntactic-ws)
5087 (skip-chars-forward " \t")
5088 (point)))
5089 (e (let ((par 1))
5090 (cond
5091 ((looking-at "@")
5092 (forward-char 1)
5093 (verilog-forward-syntactic-ws)
5094 (if (looking-at "(")
5095 (progn
5096 (forward-char 1)
5097 (while (and (/= par 0)
5098 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
5099 (cond
5100 ((match-end 1)
5101 (setq par (1+ par)))
5102 ((match-end 2)
5103 (setq par (1- par)))))))
5104 (point))
5105 ((looking-at "(")
5106 (forward-char 1)
5107 (while (and (/= par 0)
5108 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
5109 (cond
5110 ((match-end 1)
5111 (setq par (1+ par)))
5112 ((match-end 2)
5113 (setq par (1- par)))))
5114 (point))
5115 ((looking-at "\\[")
5116 (forward-char 1)
5117 (while (and (/= par 0)
5118 (verilog-re-search-forward "\\(\\[\\)\\|\\(\\]\\)" nil 'move))
5119 (cond
5120 ((match-end 1)
5121 (setq par (1+ par)))
5122 ((match-end 2)
5123 (setq par (1- par)))))
5124 (verilog-forward-syntactic-ws)
5125 (skip-chars-forward "^ \t\n\f")
5126 (point))
5127 ((looking-at "/[/\\*]")
5130 (skip-chars-forward "^: \t\n\f")
5131 (point)))))
5132 (str (buffer-substring b e)))
5133 (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
5134 (setq str (concat (substring str 0 e) "...")))
5135 str))
5137 (defun verilog-expand-vector ()
5138 "Take a signal vector on the current line and expand it to multiple lines.
5139 Useful for creating tri's and other expanded fields."
5140 (interactive)
5141 (verilog-expand-vector-internal "[" "]"))
5143 (defun verilog-expand-vector-internal (bra ket)
5144 "Given BRA, the start brace and KET, the end brace, expand one line into many lines."
5145 (save-excursion
5146 (forward-line 0)
5147 (let ((signal-string (buffer-substring (point)
5148 (progn
5149 (end-of-line) (point)))))
5150 (if (string-match
5151 (concat "\\(.*\\)"
5152 (regexp-quote bra)
5153 "\\([0-9]*\\)\\(:[0-9]*\\|\\)\\(::[0-9---]*\\|\\)"
5154 (regexp-quote ket)
5155 "\\(.*\\)$") signal-string)
5156 (let* ((sig-head (match-string 1 signal-string))
5157 (vec-start (string-to-number (match-string 2 signal-string)))
5158 (vec-end (if (= (match-beginning 3) (match-end 3))
5159 vec-start
5160 (string-to-number
5161 (substring signal-string (1+ (match-beginning 3))
5162 (match-end 3)))))
5163 (vec-range
5164 (if (= (match-beginning 4) (match-end 4))
5166 (string-to-number
5167 (substring signal-string (+ 2 (match-beginning 4))
5168 (match-end 4)))))
5169 (sig-tail (match-string 5 signal-string))
5170 vec)
5171 ;; Decode vectors
5172 (setq vec nil)
5173 (if (< vec-range 0)
5174 (let ((tmp vec-start))
5175 (setq vec-start vec-end
5176 vec-end tmp
5177 vec-range (- vec-range))))
5178 (if (< vec-end vec-start)
5179 (while (<= vec-end vec-start)
5180 (setq vec (append vec (list vec-start)))
5181 (setq vec-start (- vec-start vec-range)))
5182 (while (<= vec-start vec-end)
5183 (setq vec (append vec (list vec-start)))
5184 (setq vec-start (+ vec-start vec-range))))
5186 ;; Delete current line
5187 (delete-region (point) (progn (forward-line 0) (point)))
5189 ;; Expand vector
5190 (while vec
5191 (insert (concat sig-head bra
5192 (int-to-string (car vec)) ket sig-tail "\n"))
5193 (setq vec (cdr vec)))
5194 (delete-char -1)
5196 )))))
5198 (defun verilog-strip-comments ()
5199 "Strip all comments from the Verilog code."
5200 (interactive)
5201 (goto-char (point-min))
5202 (while (re-search-forward "//" nil t)
5203 (if (verilog-within-string)
5204 (re-search-forward "\"" nil t)
5205 (if (verilog-in-star-comment-p)
5206 (re-search-forward "\\*/" nil t)
5207 (let ((bpt (- (point) 2)))
5208 (end-of-line)
5209 (delete-region bpt (point))))))
5211 (goto-char (point-min))
5212 (while (re-search-forward "/\\*" nil t)
5213 (if (verilog-within-string)
5214 (re-search-forward "\"" nil t)
5215 (let ((bpt (- (point) 2)))
5216 (re-search-forward "\\*/")
5217 (delete-region bpt (point))))))
5219 (defun verilog-one-line ()
5220 "Convert structural Verilog instances to occupy one line."
5221 (interactive)
5222 (goto-char (point-min))
5223 (while (re-search-forward "\\([^;]\\)[ \t]*\n[ \t]*" nil t)
5224 (replace-match "\\1 " nil nil)))
5226 (defun verilog-linter-name ()
5227 "Return name of linter, either surelint or verilint."
5228 (let ((compile-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
5229 compile-command))
5230 (lint-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
5231 verilog-linter)))
5232 (cond ((equal compile-word1 "surelint") `surelint)
5233 ((equal compile-word1 "verilint") `verilint)
5234 ((equal lint-word1 "surelint") `surelint)
5235 ((equal lint-word1 "verilint") `verilint)
5236 (t `surelint)))) ; back compatibility
5238 (defun verilog-lint-off ()
5239 "Convert a Verilog linter warning line into a disable statement.
5240 For example:
5241 pci_bfm_null.v, line 46: Unused input: pci_rst_
5242 becomes a comment for the appropriate tool.
5244 The first word of the `compile-command' or `verilog-linter'
5245 variables is used to determine which product is being used.
5247 See \\[verilog-surelint-off] and \\[verilog-verilint-off]."
5248 (interactive)
5249 (let ((linter (verilog-linter-name)))
5250 (cond ((equal linter `surelint)
5251 (verilog-surelint-off))
5252 ((equal linter `verilint)
5253 (verilog-verilint-off))
5254 (t (error "Linter name not set")))))
5256 (defvar compilation-last-buffer)
5257 (defvar next-error-last-buffer)
5259 (defun verilog-surelint-off ()
5260 "Convert a SureLint warning line into a disable statement.
5261 Run from Verilog source window; assumes there is a *compile* buffer
5262 with point set appropriately.
5264 For example:
5265 WARNING [STD-UDDONX]: xx.v, line 8: output out is never assigned.
5266 becomes:
5267 // surefire lint_line_off UDDONX"
5268 (interactive)
5269 (let ((buff (if (boundp 'next-error-last-buffer)
5270 next-error-last-buffer
5271 compilation-last-buffer)))
5272 (when (buffer-live-p buff)
5273 (save-excursion
5274 (switch-to-buffer buff)
5275 (beginning-of-line)
5276 (when
5277 (looking-at "\\(INFO\\|WARNING\\|ERROR\\) \\[[^-]+-\\([^]]+\\)\\]: \\([^,]+\\), line \\([0-9]+\\): \\(.*\\)$")
5278 (let* ((code (match-string 2))
5279 (file (match-string 3))
5280 (line (match-string 4))
5281 (buffer (get-file-buffer file))
5282 dir filename)
5283 (unless buffer
5284 (progn
5285 (setq buffer
5286 (and (file-exists-p file)
5287 (find-file-noselect file)))
5288 (or buffer
5289 (let* ((pop-up-windows t))
5290 (let ((name (expand-file-name
5291 (read-file-name
5292 (format "Find this error in: (default %s) "
5293 file)
5294 dir file t))))
5295 (if (file-directory-p name)
5296 (setq name (expand-file-name filename name)))
5297 (setq buffer
5298 (and (file-exists-p name)
5299 (find-file-noselect name))))))))
5300 (switch-to-buffer buffer)
5301 (goto-char (point-min))
5302 (forward-line (- (string-to-number line)))
5303 (end-of-line)
5304 (catch 'already
5305 (cond
5306 ((verilog-in-slash-comment-p)
5307 (re-search-backward "//")
5308 (cond
5309 ((looking-at "// surefire lint_off_line ")
5310 (goto-char (match-end 0))
5311 (let ((lim (point-at-eol)))
5312 (if (re-search-forward code lim 'move)
5313 (throw 'already t)
5314 (insert (concat " " code)))))
5317 ((verilog-in-star-comment-p)
5318 (re-search-backward "/\\*")
5319 (insert (format " // surefire lint_off_line %6s" code )))
5321 (insert (format " // surefire lint_off_line %6s" code ))
5322 )))))))))
5324 (defun verilog-verilint-off ()
5325 "Convert a Verilint warning line into a disable statement.
5327 For example:
5328 (W240) pci_bfm_null.v, line 46: Unused input: pci_rst_
5329 becomes:
5330 //Verilint 240 off // WARNING: Unused input"
5331 (interactive)
5332 (save-excursion
5333 (beginning-of-line)
5334 (when (looking-at "\\(.*\\)([WE]\\([0-9A-Z]+\\)).*,\\s +line\\s +[0-9]+:\\s +\\([^:\n]+\\):?.*$")
5335 (replace-match (format
5336 ;; %3s makes numbers 1-999 line up nicely
5337 "\\1//Verilint %3s off // WARNING: \\3"
5338 (match-string 2)))
5339 (beginning-of-line)
5340 (verilog-indent-line))))
5342 (defun verilog-auto-save-compile ()
5343 "Update automatics with \\[verilog-auto], save the buffer, and compile."
5344 (interactive)
5345 (verilog-auto) ; Always do it for safety
5346 (save-buffer)
5347 (compile compile-command))
5349 (defun verilog-preprocess (&optional command filename)
5350 "Preprocess the buffer, similar to `compile', but put output in Verilog-Mode.
5351 Takes optional COMMAND or defaults to `verilog-preprocessor', and
5352 FILENAME to find directory to run in, or defaults to `buffer-file-name'."
5353 (interactive
5354 (list
5355 (let ((default (verilog-expand-command verilog-preprocessor)))
5356 (set (make-local-variable `verilog-preprocessor)
5357 (read-from-minibuffer "Run Preprocessor (like this): "
5358 default nil nil
5359 'verilog-preprocess-history default)))))
5360 (unless command (setq command (verilog-expand-command verilog-preprocessor)))
5361 (let* ((fontlocked (and (boundp 'font-lock-mode) font-lock-mode))
5362 (dir (file-name-directory (or filename buffer-file-name)))
5363 (cmd (concat "cd " dir "; " command)))
5364 (with-output-to-temp-buffer "*Verilog-Preprocessed*"
5365 (with-current-buffer (get-buffer "*Verilog-Preprocessed*")
5366 (insert (concat "// " cmd "\n"))
5367 (call-process shell-file-name nil t nil shell-command-switch cmd)
5368 (verilog-mode)
5369 ;; Without this force, it takes a few idle seconds
5370 ;; to get the color, which is very jarring
5371 (unless (fboundp 'font-lock-ensure)
5372 ;; We should use font-lock-ensure in preference to
5373 ;; font-lock-fontify-buffer, but IIUC the problem this is supposed to
5374 ;; solve only appears in Emacsen older than font-lock-ensure anyway.
5375 ;; So avoid bytecomp's interactive-only by going through intern.
5376 (when fontlocked (funcall (intern "font-lock-fontify-buffer"))))))))
5378 ;;; Batch:
5381 (defun verilog-warn (string &rest args)
5382 "Print a warning with `format' using STRING and optional ARGS."
5383 (apply 'message (concat "%%Warning: " string) args))
5385 (defun verilog-warn-error (string &rest args)
5386 "Call `error' using STRING and optional ARGS.
5387 If `verilog-warn-fatal' is non-nil, call `verilog-warn' instead."
5388 (if verilog-warn-fatal
5389 (apply 'error string args)
5390 (apply 'verilog-warn string args)))
5392 (defmacro verilog-batch-error-wrapper (&rest body)
5393 "Execute BODY and add error prefix to any errors found.
5394 This lets programs calling batch mode to easily extract error messages."
5395 `(let ((verilog-warn-fatal nil))
5396 (condition-case err
5397 (progn ,@body)
5398 (error
5399 (error "%%Error: %s%s" (error-message-string err)
5400 (if (featurep 'xemacs) "\n" "")))))) ; XEmacs forgets to add a newline
5402 (defun verilog-batch-execute-func (funref &optional no-save)
5403 "Internal processing of a batch command.
5404 Runs FUNREF on all command arguments.
5405 Save the result unless optional NO-SAVE is t."
5406 (verilog-batch-error-wrapper
5407 ;; Setting global variables like that is *VERY NASTY* !!! --Stef
5408 ;; However, this function is called only when Emacs is being used as
5409 ;; a standalone language instead of as an editor, so we'll live.
5411 ;; General globals needed
5412 (setq make-backup-files nil)
5413 (setq-default make-backup-files nil)
5414 (setq enable-local-variables t)
5415 (setq enable-local-eval t)
5416 (setq create-lockfiles nil)
5417 ;; Make sure any sub-files we read get proper mode
5418 (setq-default major-mode 'verilog-mode)
5419 ;; Ditto files already read in
5420 ;; Remember buffer list, so don't later pickup any verilog-getopt files
5421 (let ((orig-buffer-list (buffer-list)))
5422 (mapc (lambda (buf)
5423 (when (buffer-file-name buf)
5424 (with-current-buffer buf
5425 (verilog-mode)
5426 (verilog-auto-reeval-locals)
5427 (verilog-getopt-flags))))
5428 orig-buffer-list)
5429 ;; Process the files
5430 (mapcar (lambda (buf)
5431 (when (buffer-file-name buf)
5432 (save-excursion
5433 (if (not (file-exists-p (buffer-file-name buf)))
5434 (error
5435 "File not found: %s" (buffer-file-name buf)))
5436 (message "Processing %s" (buffer-file-name buf))
5437 (set-buffer buf)
5438 (funcall funref)
5439 (when (and (not no-save)
5440 (buffer-modified-p)) ; Avoid "no changes to be saved"
5441 (save-buffer)))))
5442 orig-buffer-list))))
5444 (defun verilog-batch-auto ()
5445 "For use with --batch, perform automatic expansions as a stand-alone tool.
5446 This sets up the appropriate Verilog mode environment, updates automatics
5447 with \\[verilog-auto] on all command-line files, and saves the buffers.
5448 For proper results, multiple filenames need to be passed on the command
5449 line in bottom-up order."
5450 (unless noninteractive
5451 (error "Use verilog-batch-auto only with --batch")) ; Otherwise we'd mess up buffer modes
5452 (verilog-batch-execute-func `verilog-auto))
5454 (defun verilog-batch-delete-auto ()
5455 "For use with --batch, perform automatic deletion as a stand-alone tool.
5456 This sets up the appropriate Verilog mode environment, deletes automatics
5457 with \\[verilog-delete-auto] on all command-line files, and saves the buffers."
5458 (unless noninteractive
5459 (error "Use verilog-batch-delete-auto only with --batch")) ; Otherwise we'd mess up buffer modes
5460 (verilog-batch-execute-func `verilog-delete-auto))
5462 (defun verilog-batch-delete-trailing-whitespace ()
5463 "For use with --batch, perform whitespace deletion as a stand-alone tool.
5464 This sets up the appropriate Verilog mode environment, removes
5465 whitespace with \\[verilog-delete-trailing-whitespace] on all
5466 command-line files, and saves the buffers."
5467 (unless noninteractive
5468 (error "Use verilog-batch-delete-trailing-whitespace only with --batch")) ; Otherwise we'd mess up buffer modes
5469 (verilog-batch-execute-func `verilog-delete-trailing-whitespace))
5471 (defun verilog-batch-diff-auto ()
5472 "For use with --batch, perform automatic differences as a stand-alone tool.
5473 This sets up the appropriate Verilog mode environment, expand automatics
5474 with \\[verilog-diff-auto] on all command-line files, and reports an error
5475 if any differences are observed. This is appropriate for adding to regressions
5476 to insure automatics are always properly maintained."
5477 (unless noninteractive
5478 (error "Use verilog-batch-diff-auto only with --batch")) ; Otherwise we'd mess up buffer modes
5479 (verilog-batch-execute-func `verilog-diff-auto t))
5481 (defun verilog-batch-inject-auto ()
5482 "For use with --batch, perform automatic injection as a stand-alone tool.
5483 This sets up the appropriate Verilog mode environment, injects new automatics
5484 with \\[verilog-inject-auto] on all command-line files, and saves the buffers.
5485 For proper results, multiple filenames need to be passed on the command
5486 line in bottom-up order."
5487 (unless noninteractive
5488 (error "Use verilog-batch-inject-auto only with --batch")) ; Otherwise we'd mess up buffer modes
5489 (verilog-batch-execute-func `verilog-inject-auto))
5491 (defun verilog-batch-indent ()
5492 "For use with --batch, reindent an entire file as a stand-alone tool.
5493 This sets up the appropriate Verilog mode environment, calls
5494 \\[verilog-indent-buffer] on all command-line files, and saves the buffers."
5495 (unless noninteractive
5496 (error "Use verilog-batch-indent only with --batch")) ; Otherwise we'd mess up buffer modes
5497 (verilog-batch-execute-func `verilog-indent-buffer))
5499 ;;; Indentation:
5501 (defconst verilog-indent-alist
5502 '((block . (+ ind verilog-indent-level))
5503 (case . (+ ind verilog-case-indent))
5504 (cparenexp . (+ ind verilog-indent-level))
5505 (cexp . (+ ind verilog-cexp-indent))
5506 (defun . verilog-indent-level-module)
5507 (declaration . verilog-indent-level-declaration)
5508 (directive . (verilog-calculate-indent-directive))
5509 (tf . verilog-indent-level)
5510 (behavioral . (+ verilog-indent-level-behavioral verilog-indent-level-module))
5511 (statement . ind)
5512 (cpp . 0)
5513 (comment . (verilog-comment-indent))
5514 (unknown . 3)
5515 (string . 0)))
5517 (defun verilog-continued-line-1 (lim)
5518 "Return true if this is a continued line.
5519 Set point to where line starts. Limit search to point LIM."
5520 (let ((continued 't))
5521 (if (eq 0 (forward-line -1))
5522 (progn
5523 (end-of-line)
5524 (verilog-backward-ws&directives lim)
5525 (if (bobp)
5526 (setq continued nil)
5527 (setq continued (verilog-backward-token))))
5528 (setq continued nil))
5529 continued))
5531 (defun verilog-calculate-indent ()
5532 "Calculate the indent of the current Verilog line.
5533 Examine previous lines. Once a line is found that is definitive as to the
5534 type of the current line, return that lines' indent level and its type.
5535 Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
5536 (save-excursion
5537 (let* ((starting_position (point))
5538 (case-fold-search nil)
5539 (par 0)
5540 (begin (looking-at "[ \t]*begin\\>"))
5541 (lim (save-excursion (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil t)))
5542 (structres nil)
5543 (type (catch 'nesting
5544 ;; Keep working backwards until we can figure out
5545 ;; what type of statement this is.
5546 ;; Basically we need to figure out
5547 ;; 1) if this is a continuation of the previous line;
5548 ;; 2) are we in a block scope (begin..end)
5550 ;; if we are in a comment, done.
5551 (if (verilog-in-star-comment-p)
5552 (throw 'nesting 'comment))
5554 ;; if we have a directive, done.
5555 (if (save-excursion (beginning-of-line)
5556 (and (looking-at verilog-directive-re-1)
5557 (not (or (looking-at "[ \t]*`[ou]vm_")
5558 (looking-at "[ \t]*`vmm_")))))
5559 (throw 'nesting 'directive))
5560 ;; indent structs as if there were module level
5561 (setq structres (verilog-in-struct-nested-p))
5562 (cond ((not structres) nil)
5563 ;;((and structres (equal (char-after) ?\})) (throw 'nesting 'struct-close))
5564 ((> structres 0) (throw 'nesting 'nested-struct))
5565 ((= structres 0) (throw 'nesting 'block))
5566 (t nil))
5568 ;; if we are in a parenthesized list, and the user likes to indent these, return.
5569 ;; unless we are in the newfangled coverpoint or constraint blocks
5570 (if (and
5571 verilog-indent-lists
5572 (verilog-in-paren)
5573 (not (verilog-in-coverage-p))
5575 (progn (setq par 1)
5576 (throw 'nesting 'block)))
5578 ;; See if we are continuing a previous line
5579 (while t
5580 ;; trap out if we crawl off the top of the buffer
5581 (if (bobp) (throw 'nesting 'cpp))
5583 (if (and (verilog-continued-line-1 lim)
5584 (or (not (verilog-in-coverage-p))
5585 (looking-at verilog-in-constraint-re) )) ; may still get hosed if concat in constraint
5586 (let ((sp (point)))
5587 (if (and
5588 (not (looking-at verilog-complete-reg))
5589 (verilog-continued-line-1 lim))
5590 (progn (goto-char sp)
5591 (throw 'nesting 'cexp))
5593 (goto-char sp))
5594 (if (and (verilog-in-coverage-p)
5595 (looking-at verilog-in-constraint-re))
5596 (progn
5597 (beginning-of-line)
5598 (skip-chars-forward " \t")
5599 (throw 'nesting 'constraint)))
5600 (if (and begin
5601 (not verilog-indent-begin-after-if)
5602 (looking-at verilog-no-indent-begin-re))
5603 (progn
5604 (beginning-of-line)
5605 (skip-chars-forward " \t")
5606 (throw 'nesting 'statement))
5607 (progn
5608 (throw 'nesting 'cexp))))
5609 ;; not a continued line
5610 (goto-char starting_position))
5612 (if (looking-at "\\<else\\>")
5613 ;; search back for governing if, striding across begin..end pairs
5614 ;; appropriately
5615 (let ((elsec 1))
5616 (while (verilog-re-search-backward verilog-ends-re nil 'move)
5617 (cond
5618 ((match-end 1) ; else, we're in deep
5619 (setq elsec (1+ elsec)))
5620 ((match-end 2) ; if
5621 (setq elsec (1- elsec))
5622 (if (= 0 elsec)
5623 (if verilog-align-ifelse
5624 (throw 'nesting 'statement)
5625 (progn ; back up to first word on this line
5626 (beginning-of-line)
5627 (verilog-forward-syntactic-ws)
5628 (throw 'nesting 'statement)))))
5629 ((match-end 3) ; assert block
5630 (setq elsec (1- elsec))
5631 (verilog-beg-of-statement) ; doesn't get to beginning
5632 (if (looking-at verilog-property-re)
5633 (throw 'nesting 'statement) ; We don't need an endproperty for these
5634 (throw 'nesting 'block) ; We still need an endproperty
5636 (t ; endblock
5637 ;; try to leap back to matching outward block by striding across
5638 ;; indent level changing tokens then immediately
5639 ;; previous line governs indentation.
5640 (let (( reg) (nest 1))
5641 ;; verilog-ends => else|if|end|join(_any|_none|)|endcase|endclass|endtable|endspecify|endfunction|endtask|endgenerate|endgroup
5642 (cond
5643 ((match-end 4) ; end
5644 ;; Search back for matching begin
5645 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
5646 ((match-end 5) ; endcase
5647 ;; Search back for matching case
5648 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
5649 ((match-end 6) ; endfunction
5650 ;; Search back for matching function
5651 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
5652 ((match-end 7) ; endtask
5653 ;; Search back for matching task
5654 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" ))
5655 ((match-end 8) ; endspecify
5656 ;; Search back for matching specify
5657 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
5658 ((match-end 9) ; endtable
5659 ;; Search back for matching table
5660 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
5661 ((match-end 10) ; endgenerate
5662 ;; Search back for matching generate
5663 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
5664 ((match-end 11) ; joins
5665 ;; Search back for matching fork
5666 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|none\\)?\\>\\)" ))
5667 ((match-end 12) ; class
5668 ;; Search back for matching class
5669 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
5670 ((match-end 13) ; covergroup
5671 ;; Search back for matching covergroup
5672 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )))
5673 (catch 'skip
5674 (while (verilog-re-search-backward reg nil 'move)
5675 (cond
5676 ((match-end 1) ; begin
5677 (setq nest (1- nest))
5678 (if (= 0 nest)
5679 (throw 'skip 1)))
5680 ((match-end 2) ; end
5681 (setq nest (1+ nest)))))
5682 )))))))
5683 (throw 'nesting (verilog-calc-1)))
5684 ) ; catch nesting
5685 ) ; type
5687 ;; Return type of block and indent level.
5688 (if (not type)
5689 (setq type 'cpp))
5690 (if (> par 0) ; Unclosed Parenthesis
5691 (list 'cparenexp par)
5692 (cond
5693 ((eq type 'case)
5694 (list type (verilog-case-indent-level)))
5695 ((eq type 'statement)
5696 (list type (current-column)))
5697 ((eq type 'defun)
5698 (list type 0))
5699 ((eq type 'constraint)
5700 (list 'block (current-column)))
5701 ((eq type 'nested-struct)
5702 (list 'block structres))
5704 (list type (verilog-current-indent-level))))))))
5706 (defun verilog-wai ()
5707 "Show matching nesting block for debugging."
5708 (interactive)
5709 (save-excursion
5710 (let* ((type (verilog-calc-1))
5711 depth)
5712 ;; Return type of block and indent level.
5713 (if (not type)
5714 (setq type 'cpp))
5715 (if (and
5716 verilog-indent-lists
5717 (not(or (verilog-in-coverage-p)
5718 (verilog-in-struct-p)))
5719 (verilog-in-paren))
5720 (setq depth 1)
5721 (cond
5722 ((eq type 'case)
5723 (setq depth (verilog-case-indent-level)))
5724 ((eq type 'statement)
5725 (setq depth (current-column)))
5726 ((eq type 'defun)
5727 (setq depth 0))
5729 (setq depth (verilog-current-indent-level)))))
5730 (message "You are at nesting %s depth %d" type depth))))
5732 (defun verilog-calc-1 ()
5733 (catch 'nesting
5734 (let ((re (concat "\\({\\|}\\|" verilog-indent-re "\\)"))
5735 (inconstraint (verilog-in-coverage-p)))
5736 (while (verilog-re-search-backward re nil 'move)
5737 (catch 'continue
5738 (cond
5739 ((equal (char-after) ?\{)
5740 ;; block type returned based on outer constraint { or inner
5741 (if (verilog-at-constraint-p)
5742 (cond (inconstraint
5743 (beginning-of-line nil)
5744 (skip-chars-forward " \t")
5745 (throw 'nesting 'constraint))
5747 (throw 'nesting 'statement)))))
5748 ((equal (char-after) ?\})
5749 (let (par-pos
5750 (there (verilog-at-close-constraint-p)))
5751 (if there ; we are at the } that closes a constraint. Find the { that opens it
5752 (progn
5753 (if (> (verilog-in-paren-count) 0)
5754 (forward-char 1))
5755 (setq par-pos (verilog-parenthesis-depth))
5756 (cond (par-pos
5757 (goto-char par-pos)
5758 (forward-char 1))
5760 (backward-char 1)))))))
5762 ((looking-at verilog-beg-block-re-ordered)
5763 (cond
5764 ((match-end 2) ; *sigh* could be "unique case" or "priority casex"
5765 (let ((here (point)))
5766 (verilog-beg-of-statement)
5767 (if (looking-at verilog-extended-case-re)
5768 (throw 'nesting 'case)
5769 (goto-char here)))
5770 (throw 'nesting 'case))
5772 ((match-end 4) ; *sigh* could be "disable fork"
5773 (let ((here (point)))
5774 (verilog-beg-of-statement)
5775 (if (looking-at verilog-disable-fork-re)
5776 t ; this is a normal statement
5777 (progn ; or is fork, starts a new block
5778 (goto-char here)
5779 (throw 'nesting 'block)))))
5781 ((match-end 17) ; *sigh* might be a clocking declaration
5782 (let ((here (point)))
5783 (cond ((verilog-in-paren)
5784 t) ; this is a normal statement
5785 ((save-excursion
5786 (verilog-beg-of-statement)
5787 (looking-at verilog-default-clocking-re))
5788 t) ; default clocking, normal statement
5790 (goto-char here) ; or is clocking, starts a new block
5791 (throw 'nesting 'block)))))
5793 ;; need to consider typedef struct here...
5794 ((looking-at "\\<class\\|struct\\|function\\|task\\>")
5795 ;; *sigh* These words have an optional prefix:
5796 ;; extern {virtual|protected}? function a();
5797 ;; typedef class foo;
5798 ;; and we don't want to confuse this with
5799 ;; function a();
5800 ;; property
5801 ;; ...
5802 ;; endfunction
5803 (verilog-beg-of-statement)
5804 (cond
5805 ((looking-at verilog-dpi-import-export-re)
5806 (throw 'continue 'foo))
5807 ((looking-at "\\<pure\\>\\s-+\\<virtual\\>\\s-+\\(?:\\<\\(local\\|protected\\|static\\)\\>\\s-+\\)?\\<\\(function\\|task\\)\\>\\s-+")
5808 (throw 'nesting 'statement))
5809 ((looking-at verilog-beg-block-re-ordered)
5810 (throw 'nesting 'block))
5812 (throw 'nesting 'defun))))
5815 ((looking-at "\\<property\\>")
5816 ;; *sigh*
5817 ;; {assert|assume|cover} property (); are complete
5818 ;; and could also be labeled: - foo: assert property
5819 ;; but
5820 ;; property ID () ... needs end_property
5821 (verilog-beg-of-statement)
5822 (if (looking-at verilog-property-re)
5823 (throw 'continue 'statement) ; We don't need an endproperty for these
5824 (throw 'nesting 'block) ;We still need an endproperty
5827 (t (throw 'nesting 'block))))
5829 ((looking-at verilog-end-block-re)
5830 (verilog-leap-to-head)
5831 (if (verilog-in-case-region-p)
5832 (progn
5833 (verilog-leap-to-case-head)
5834 (if (looking-at verilog-extended-case-re)
5835 (throw 'nesting 'case)))))
5837 ((looking-at verilog-defun-level-re)
5838 (if (looking-at verilog-defun-level-generate-only-re)
5839 (if (or (verilog-in-generate-region-p)
5840 (verilog-in-deferred-immediate-final-p))
5841 (throw 'continue 'foo) ; always block in a generate - keep looking
5842 (throw 'nesting 'defun))
5843 (throw 'nesting 'defun)))
5845 ((looking-at verilog-cpp-level-re)
5846 (throw 'nesting 'cpp))
5848 ((bobp)
5849 (throw 'nesting 'cpp)))))
5851 (throw 'nesting 'cpp))))
5853 (defun verilog-calculate-indent-directive ()
5854 "Return indentation level for directive.
5855 For speed, the searcher looks at the last directive, not the indent
5856 of the appropriate enclosing block."
5857 (let ((base -1) ; Indent of the line that determines our indentation
5858 (ind 0)) ; Relative offset caused by other directives (like `endif on same line as `else)
5859 ;; Start at current location, scan back for another directive
5861 (save-excursion
5862 (beginning-of-line)
5863 (while (and (< base 0)
5864 (verilog-re-search-backward verilog-directive-re nil t))
5865 (cond ((save-excursion (skip-chars-backward " \t") (bolp))
5866 (setq base (current-indentation))))
5867 (cond ((and (looking-at verilog-directive-end) (< base 0)) ; Only matters when not at BOL
5868 (setq ind (- ind verilog-indent-level-directive)))
5869 ((and (looking-at verilog-directive-middle) (>= base 0)) ; Only matters when at BOL
5870 (setq ind (+ ind verilog-indent-level-directive)))
5871 ((looking-at verilog-directive-begin)
5872 (setq ind (+ ind verilog-indent-level-directive)))))
5873 ;; Adjust indent to starting indent of critical line
5874 (setq ind (max 0 (+ ind base))))
5876 (save-excursion
5877 (beginning-of-line)
5878 (skip-chars-forward " \t")
5879 (cond ((or (looking-at verilog-directive-middle)
5880 (looking-at verilog-directive-end))
5881 (setq ind (max 0 (- ind verilog-indent-level-directive))))))
5882 ind))
5884 (defun verilog-leap-to-case-head ()
5885 (let ((nest 1))
5886 (while (/= 0 nest)
5887 (verilog-re-search-backward
5888 (concat
5889 "\\(\\<randcase\\>\\|\\(\\<unique0?\\s-+\\|priority\\s-+\\)?\\<case[xz]?\\>\\)"
5890 "\\|\\(\\<endcase\\>\\)" )
5891 nil 'move)
5892 (cond
5893 ((match-end 1)
5894 (let ((here (point)))
5895 (verilog-beg-of-statement)
5896 (unless (looking-at verilog-extended-case-re)
5897 (goto-char here)))
5898 (setq nest (1- nest)))
5899 ((match-end 3)
5900 (setq nest (1+ nest)))
5901 ((bobp)
5902 (ding 't)
5903 (setq nest 0))))))
5905 (defun verilog-leap-to-head ()
5906 "Move point to the head of this block.
5907 Jump from end to matching begin, from endcase to matching case, and so on."
5908 (let ((reg nil)
5909 snest
5910 (nesting 'yes)
5911 (nest 1))
5912 (cond
5913 ((looking-at "\\<end\\>")
5914 ;; 1: Search back for matching begin
5915 (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|"
5916 "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))
5917 ((looking-at "\\<endtask\\>")
5918 ;; 2: Search back for matching task
5919 (setq reg "\\(\\<task\\>\\)\\|\\(\\(\\<\\(virtual\\|protected\\|static\\)\\>\\s-+\\)+\\<task\\>\\)")
5920 (setq nesting 'no))
5921 ((looking-at "\\<endcase\\>")
5922 (catch 'nesting
5923 (verilog-leap-to-case-head) )
5924 (setq reg nil) ; to force skip
5927 ((looking-at "\\<join\\(_any\\|_none\\)?\\>")
5928 ;; 4: Search back for matching fork
5929 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
5930 ((looking-at "\\<endclass\\>")
5931 ;; 5: Search back for matching class
5932 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
5933 ((looking-at "\\<endtable\\>")
5934 ;; 6: Search back for matching table
5935 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
5936 ((looking-at "\\<endspecify\\>")
5937 ;; 7: Search back for matching specify
5938 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
5939 ((looking-at "\\<endfunction\\>")
5940 ;; 8: Search back for matching function
5941 (setq reg "\\(\\<function\\>\\)\\|\\(\\(\\<\\(virtual\\|protected\\|static\\)\\>\\s-+\\)+\\<function\\>\\)")
5942 (setq nesting 'no))
5943 ;;(setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
5944 ((looking-at "\\<endgenerate\\>")
5945 ;; 8: Search back for matching generate
5946 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
5947 ((looking-at "\\<endgroup\\>")
5948 ;; 10: Search back for matching covergroup
5949 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
5950 ((looking-at "\\<endproperty\\>")
5951 ;; 11: Search back for matching property
5952 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
5953 ((looking-at verilog-uvm-end-re)
5954 ;; 12: Search back for matching sequence
5955 (setq reg (concat "\\(" verilog-uvm-begin-re "\\|" verilog-uvm-end-re "\\)")))
5956 ((looking-at verilog-ovm-end-re)
5957 ;; 12: Search back for matching sequence
5958 (setq reg (concat "\\(" verilog-ovm-begin-re "\\|" verilog-ovm-end-re "\\)")))
5959 ((looking-at verilog-vmm-end-re)
5960 ;; 12: Search back for matching sequence
5961 (setq reg (concat "\\(" verilog-vmm-begin-re "\\|" verilog-vmm-end-re "\\)")))
5962 ((looking-at "\\<endinterface\\>")
5963 ;; 12: Search back for matching interface
5964 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" ))
5965 ((looking-at "\\<endsequence\\>")
5966 ;; 12: Search back for matching sequence
5967 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ))
5968 ((looking-at "\\<endclocking\\>")
5969 ;; 12: Search back for matching clocking
5970 (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" )))
5971 (if reg
5972 (catch 'skip
5973 (if (eq nesting 'yes)
5974 (let (sreg)
5975 (while (verilog-re-search-backward reg nil 'move)
5976 (cond
5977 ((match-end 1) ; begin
5978 (if (looking-at "fork")
5979 (let ((here (point)))
5980 (verilog-beg-of-statement)
5981 (unless (looking-at verilog-disable-fork-re)
5982 (goto-char here)
5983 (setq nest (1- nest))))
5984 (setq nest (1- nest)))
5985 (if (= 0 nest)
5986 ;; Now previous line describes syntax
5987 (throw 'skip 1))
5988 (if (and snest
5989 (= snest nest))
5990 (setq reg sreg)))
5991 ((match-end 2) ; end
5992 (setq nest (1+ nest)))
5993 ((match-end 3)
5994 ;; endcase, jump to case
5995 (setq snest nest)
5996 (setq nest (1+ nest))
5997 (setq sreg reg)
5998 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
5999 ((match-end 4)
6000 ;; join, jump to fork
6001 (setq snest nest)
6002 (setq nest (1+ nest))
6003 (setq sreg reg)
6004 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
6006 ;; no nesting
6007 (if (and
6008 (verilog-re-search-backward reg nil 'move)
6009 (match-end 1)) ; task -> could be virtual and/or protected
6010 (progn
6011 (verilog-beg-of-statement)
6012 (throw 'skip 1))
6013 (throw 'skip 1)))))))
6015 (defun verilog-continued-line ()
6016 "Return true if this is a continued line.
6017 Set point to where line starts."
6018 (let ((continued 't))
6019 (if (eq 0 (forward-line -1))
6020 (progn
6021 (end-of-line)
6022 (verilog-backward-ws&directives)
6023 (if (bobp)
6024 (setq continued nil)
6025 (while (and continued
6026 (save-excursion
6027 (skip-chars-backward " \t")
6028 (not (bolp))))
6029 (setq continued (verilog-backward-token)))))
6030 (setq continued nil))
6031 continued))
6033 (defun verilog-backward-token ()
6034 "Step backward token, returning true if this is a continued line."
6035 (interactive)
6036 (verilog-backward-syntactic-ws)
6037 (cond
6038 ((bolp)
6039 nil)
6040 (;-- Anything ending in a ; is complete
6041 (= (preceding-char) ?\;)
6042 nil)
6043 (; If a "}" is prefixed by a ";", then this is a complete statement
6044 ;; i.e.: constraint foo { a = b; }
6045 (= (preceding-char) ?\})
6046 (progn
6047 (backward-char)
6048 (not(verilog-at-close-constraint-p))))
6049 (;-- constraint foo { a = b }
6050 ;; is a complete statement. *sigh*
6051 (= (preceding-char) ?\{)
6052 (progn
6053 (backward-char)
6054 (not (verilog-at-constraint-p))))
6055 (;" string "
6056 (= (preceding-char) ?\")
6057 (backward-char)
6058 (verilog-skip-backward-comment-or-string)
6059 nil)
6061 (; [3:4]
6062 (= (preceding-char) ?\])
6063 (backward-char)
6064 (verilog-backward-open-bracket)
6067 (;-- Could be 'case (foo)' or 'always @(bar)' which is complete
6068 ;; also could be simply '@(foo)'
6069 ;; or foo u1 #(a=8)
6070 ;; (b, ... which ISN'T complete
6071 ;; Do we need this???
6072 (= (preceding-char) ?\))
6073 (progn
6074 (backward-char)
6075 (verilog-backward-up-list 1)
6076 (verilog-backward-syntactic-ws)
6077 (let ((back (point)))
6078 (forward-word-strictly -1)
6079 (cond
6080 ;;XX
6081 ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>")
6082 (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]")))
6083 ((looking-at verilog-uvm-statement-re)
6084 nil)
6085 ((looking-at verilog-uvm-begin-re)
6087 ((looking-at verilog-uvm-end-re)
6089 ((looking-at verilog-ovm-statement-re)
6090 nil)
6091 ((looking-at verilog-ovm-begin-re)
6093 ((looking-at verilog-ovm-end-re)
6095 ;; JBA find VMM macros
6096 ((looking-at verilog-vmm-statement-re)
6097 nil )
6098 ((looking-at verilog-vmm-begin-re)
6100 ((looking-at verilog-vmm-end-re)
6101 nil)
6102 ;; JBA trying to catch macro lines with no ; at end
6103 ((looking-at "\\<`")
6104 nil)
6106 (goto-char back)
6107 (cond
6108 ((= (preceding-char) ?\@)
6109 (backward-char)
6110 (save-excursion
6111 (verilog-backward-token)
6112 (not (looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|initial\\|while\\)\\>"))))
6113 ((= (preceding-char) ?\#)
6114 (backward-char))
6115 (t t)))))))
6117 (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete
6119 (forward-word-strictly -1)
6120 (while (or (= (preceding-char) ?\_)
6121 (= (preceding-char) ?\@)
6122 (= (preceding-char) ?\.))
6123 (forward-word-strictly -1))
6124 (cond
6125 ((looking-at "\\<else\\>")
6127 ((looking-at verilog-behavioral-block-beg-re)
6129 ((looking-at verilog-indent-re)
6130 nil)
6132 (let
6133 ((back (point)))
6134 (verilog-backward-syntactic-ws)
6135 (cond
6136 ((= (preceding-char) ?\:)
6137 (backward-char)
6138 (verilog-backward-syntactic-ws)
6139 (backward-sexp)
6140 (if (looking-at verilog-nameable-item-re )
6143 ((= (preceding-char) ?\#)
6144 (backward-char)
6146 ((= (preceding-char) ?\`)
6147 (backward-char)
6151 (goto-char back)
6152 t))))))))
6154 (defun verilog-backward-syntactic-ws ()
6155 "Move backwards putting point after first non-whitespace non-comment."
6156 (verilog-skip-backward-comments)
6157 (forward-comment (- (buffer-size))))
6159 (defun verilog-backward-syntactic-ws-quick ()
6160 "As with `verilog-backward-syntactic-ws' but use `verilog-scan' cache."
6161 (while (cond ((bobp)
6162 nil) ; Done
6163 ((< (skip-syntax-backward " ") 0)
6165 ((eq (preceding-char) ?\n) ; \n's terminate // so aren't space syntax
6166 (forward-char -1)
6168 ((or (verilog-inside-comment-or-string-p (1- (point)))
6169 (verilog-inside-comment-or-string-p (point)))
6170 (re-search-backward "[/\"]" nil t) ; Only way a comment or quote can begin
6171 t))))
6173 (defun verilog-forward-syntactic-ws ()
6174 (verilog-skip-forward-comment-p)
6175 (forward-comment (buffer-size)))
6177 (defun verilog-backward-ws&directives (&optional bound)
6178 "Backward skip over syntactic whitespace and compiler directives for Emacs 19.
6179 Optional BOUND limits search."
6180 (save-restriction
6181 (let* ((bound (or bound (point-min)))
6182 (here bound)
6183 (p nil) )
6184 (if (< bound (point))
6185 (progn
6186 (let ((state (save-excursion (verilog-syntax-ppss))))
6187 (cond
6188 ((nth 7 state) ; in // comment
6189 (verilog-re-search-backward "//" nil 'move)
6190 (skip-chars-backward "/"))
6191 ((nth 4 state) ; in /* */ comment
6192 (verilog-re-search-backward "/\\*" nil 'move))))
6193 (narrow-to-region bound (point))
6194 (while (/= here (point))
6195 (setq here (point))
6196 (verilog-skip-backward-comments)
6197 (setq p
6198 (save-excursion
6199 (beginning-of-line)
6200 ;; for as long as we're right after a continued line, keep moving up
6201 (while (and (verilog-looking-back "\\\\[\n\r\f]" nil)
6202 (forward-line -1)))
6203 (cond
6204 ((and verilog-highlight-translate-off
6205 (verilog-within-translate-off))
6206 (verilog-back-to-start-translate-off (point-min)))
6207 ((looking-at verilog-directive-re-1)
6208 (point))
6210 nil))))
6211 (if p (goto-char p))))))))
6213 (defun verilog-forward-ws&directives (&optional bound)
6214 "Forward skip over syntactic whitespace and compiler directives for Emacs 19.
6215 Optional BOUND limits search."
6216 (save-restriction
6217 (let* ((bound (or bound (point-max)))
6218 (here bound)
6219 jump)
6220 (if (> bound (point))
6221 (progn
6222 (let ((state (save-excursion (verilog-syntax-ppss))))
6223 (cond
6224 ((nth 7 state) ; in // comment
6225 (end-of-line)
6226 (forward-char 1)
6227 (skip-chars-forward " \t\n\f")
6229 ((nth 4 state) ; in /* */ comment
6230 (verilog-re-search-forward "\\*/\\s-*" nil 'move))))
6231 (narrow-to-region (point) bound)
6232 (while (/= here (point))
6233 (setq here (point)
6234 jump nil)
6235 (forward-comment (buffer-size))
6236 (and (looking-at "\\s-*(\\*.*\\*)\\s-*") ; Attribute
6237 (goto-char (match-end 0)))
6238 (save-excursion
6239 (beginning-of-line)
6240 (if (looking-at verilog-directive-re-1)
6241 (setq jump t)))
6242 (if jump
6243 (beginning-of-line 2))))))))
6245 (defun verilog-in-comment-p ()
6246 "Return true if in a star or // comment."
6247 (let ((state (save-excursion (verilog-syntax-ppss))))
6248 (or (nth 4 state) (nth 7 state))))
6250 (defun verilog-in-star-comment-p ()
6251 "Return true if in a star comment."
6252 (let ((state (save-excursion (verilog-syntax-ppss))))
6253 (and
6254 (nth 4 state) ; t if in a comment of style a // or b /**/
6255 (not
6256 (nth 7 state) ; t if in a comment of style b /**/
6257 ))))
6259 (defun verilog-in-slash-comment-p ()
6260 "Return true if in a slash comment."
6261 (let ((state (save-excursion (verilog-syntax-ppss))))
6262 (nth 7 state)))
6264 (defun verilog-in-comment-or-string-p ()
6265 "Return true if in a string or comment."
6266 (let ((state (save-excursion (verilog-syntax-ppss))))
6267 (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment)
6269 (defun verilog-in-attribute-p ()
6270 "Return true if point is in an attribute (* [] attribute *)."
6271 (save-match-data
6272 (save-excursion
6273 (verilog-re-search-backward "\\((\\*\\)\\|\\(\\*)\\)" nil 'move)
6274 (cond
6275 ((match-end 1)
6276 (progn (goto-char (match-end 1))
6277 (not (looking-at "\\s-*)")))
6278 nil)
6279 ((match-end 2)
6280 (progn (goto-char (match-beginning 2))
6281 (not (looking-at "(\\s-*")))
6282 nil)
6283 (t nil)))))
6285 (defun verilog-in-parameter-p ()
6286 "Return true if point is in a parameter assignment #( p1=1, p2=5)."
6287 (save-match-data
6288 (save-excursion
6289 (verilog-re-search-backward "\\(#(\\)\\|\\()\\)" nil 'move)
6290 (numberp (match-beginning 1)))))
6292 (defun verilog-in-escaped-name-p ()
6293 "Return true if in an escaped name."
6294 (save-excursion
6295 (backward-char)
6296 (skip-chars-backward "^ \t\n\f")
6297 (if (equal (char-after (point) ) ?\\ )
6299 nil)))
6301 (defun verilog-in-directive-p ()
6302 "Return true if in a directive."
6303 (save-excursion
6304 (beginning-of-line)
6305 (looking-at verilog-directive-re-1)))
6307 (defun verilog-in-parenthesis-p ()
6308 "Return true if in a ( ) expression (but not { } or [ ])."
6309 (save-match-data
6310 (save-excursion
6311 (verilog-re-search-backward "\\((\\)\\|\\()\\)" nil 'move)
6312 (numberp (match-beginning 1)))))
6314 (defun verilog-in-paren ()
6315 "Return true if in a parenthetical expression.
6316 May cache result using `verilog-syntax-ppss'."
6317 (let ((state (save-excursion (verilog-syntax-ppss))))
6318 (> (nth 0 state) 0 )))
6320 (defun verilog-in-paren-count ()
6321 "Return paren depth, floor to 0.
6322 May cache result using `verilog-syntax-ppss'."
6323 (let ((state (save-excursion (verilog-syntax-ppss))))
6324 (if (> (nth 0 state) 0)
6325 (nth 0 state)
6326 0 )))
6328 (defun verilog-in-paren-quick ()
6329 "Return true if in a parenthetical expression.
6330 Always starts from `point-min', to allow inserts with hooks disabled."
6331 ;; The -quick refers to its use alongside the other -quick functions,
6332 ;; not that it's likely to be faster than verilog-in-paren.
6333 (let ((state (save-excursion (parse-partial-sexp (point-min) (point)))))
6334 (> (nth 0 state) 0 )))
6336 (defun verilog-in-struct-p ()
6337 "Return true if in a struct declaration."
6338 (interactive)
6339 (save-excursion
6340 (if (verilog-in-paren)
6341 (progn
6342 (verilog-backward-up-list 1)
6343 (verilog-at-struct-p)
6345 nil)))
6347 (defun verilog-in-struct-nested-p ()
6348 "Return nil for not in struct.
6349 Return 0 for in non-nested struct.
6350 Return >0 for nested struct."
6351 (interactive)
6352 (let (col)
6353 (save-excursion
6354 (if (verilog-in-paren)
6355 (progn
6356 (verilog-backward-up-list 1)
6357 (setq col (verilog-at-struct-mv-p))
6358 (if col
6359 (if (verilog-in-struct-p) (current-column) 0)))
6360 nil))))
6362 (defun verilog-in-coverage-p ()
6363 "Return true if in a constraint or coverpoint expression."
6364 (interactive)
6365 (save-excursion
6366 (if (verilog-in-paren)
6367 (progn
6368 (verilog-backward-up-list 1)
6369 (verilog-at-constraint-p)
6371 nil)))
6373 (defun verilog-at-close-constraint-p ()
6374 "If at the } that closes a constraint or covergroup, return true."
6375 (if (and
6376 (equal (char-after) ?\})
6377 (verilog-in-coverage-p))
6379 (save-excursion
6380 (verilog-backward-ws&directives)
6381 (if (or (equal (char-before) ?\;)
6382 (equal (char-before) ?\}) ; can end with inner constraint { } block or ;
6383 (equal (char-before) ?\{)) ; empty constraint block
6384 (point)
6385 nil))))
6387 (defun verilog-at-constraint-p ()
6388 "If at the { of a constraint or coverpoint definition, return true, moving point to constraint."
6389 (if (save-excursion
6390 (let ((p (point)))
6391 (and
6392 (equal (char-after) ?\{)
6393 (ignore-errors (forward-list))
6394 (progn (backward-char 1)
6395 (verilog-backward-ws&directives)
6396 (and
6397 (or (equal (char-before) ?\{) ; empty case
6398 (equal (char-before) ?\;)
6399 (equal (char-before) ?\}))
6400 ;; skip what looks like bus repetition operator {#{
6401 (not (string-match "^{\\s-*[0-9]+\\s-*{" (buffer-substring p (point)))))))))
6402 (progn
6403 (let ( (pt (point)) (pass 0))
6404 (verilog-backward-ws&directives)
6405 (verilog-backward-token)
6406 (if (looking-at (concat "\\<constraint\\|coverpoint\\|cross\\|with\\>\\|" verilog-in-constraint-re))
6407 (progn (setq pass 1)
6408 (if (looking-at "\\<with\\>")
6409 (progn (verilog-backward-ws&directives)
6410 (beginning-of-line) ; 1
6411 (verilog-forward-ws&directives)
6413 (verilog-beg-of-statement)
6415 ;; if first word token not keyword, it maybe the instance name
6416 ;; check next word token
6417 (if (looking-at "\\<\\w+\\>\\|\\s-*(\\s-*\\S-+")
6418 (progn (verilog-beg-of-statement)
6419 (if (looking-at (concat "\\<\\(constraint\\|"
6420 "\\(?:\\w+\\s-*:\\s-*\\)?\\(coverpoint\\|cross\\)"
6421 "\\|with\\)\\>\\|" verilog-in-constraint-re))
6422 (setq pass 1)))))
6423 (if (eq pass 0)
6424 (progn (goto-char pt) nil) 1)))
6425 ;; not
6426 nil))
6428 (defun verilog-at-struct-p ()
6429 "If at the { of a struct, return true, not moving point."
6430 (save-excursion
6431 (if (and (equal (char-after) ?\{)
6432 (verilog-backward-token))
6433 (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
6434 nil)))
6436 (defun verilog-at-struct-mv-p ()
6437 "If at the { of a struct, return true, moving point to struct."
6438 (let ((pt (point)))
6439 (if (and (equal (char-after) ?\{)
6440 (verilog-backward-token))
6441 (if (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
6442 (progn (verilog-beg-of-statement) (point))
6443 (progn (goto-char pt) nil))
6444 (progn (goto-char pt) nil))))
6446 (defun verilog-at-close-struct-p ()
6447 "If at the } that closes a struct, return true."
6448 (if (and
6449 (equal (char-after) ?\})
6450 (verilog-in-struct-p))
6451 ;; true
6452 (save-excursion
6453 (if (looking-at "}\\(?:\\s-*\\w+\\s-*\\)?;") 1))
6454 ;; false
6455 nil))
6457 (defun verilog-parenthesis-depth ()
6458 "Return non zero if in parenthetical-expression."
6459 (save-excursion (nth 1 (verilog-syntax-ppss))))
6462 (defun verilog-skip-forward-comment-or-string ()
6463 "Return true if in a string or comment."
6464 (let ((state (save-excursion (verilog-syntax-ppss))))
6465 (cond
6466 ((nth 3 state) ;Inside string
6467 (search-forward "\"")
6469 ((nth 7 state) ;Inside // comment
6470 (forward-line 1)
6472 ((nth 4 state) ;Inside any comment (hence /**/)
6473 (search-forward "*/"))
6475 nil))))
6477 (defun verilog-skip-backward-comment-or-string ()
6478 "Return true if in a string or comment."
6479 (let ((state (save-excursion (verilog-syntax-ppss))))
6480 (cond
6481 ((nth 3 state) ;Inside string
6482 (search-backward "\"")
6484 ((nth 7 state) ;Inside // comment
6485 (search-backward "//")
6486 (skip-chars-backward "/")
6488 ((nth 4 state) ;Inside /* */ comment
6489 (search-backward "/*")
6492 nil))))
6494 (defun verilog-skip-backward-comments ()
6495 "Return true if a comment was skipped."
6496 (let ((more t))
6497 (while more
6498 (setq more
6499 (let ((state (save-excursion (verilog-syntax-ppss))))
6500 (cond
6501 ((nth 7 state) ;Inside // comment
6502 (search-backward "//")
6503 (skip-chars-backward "/")
6504 (skip-chars-backward " \t\n\f")
6506 ((nth 4 state) ;Inside /* */ comment
6507 (search-backward "/*")
6508 (skip-chars-backward " \t\n\f")
6510 ((and (not (bobp))
6511 (= (char-before) ?\/)
6512 (= (char-before (1- (point))) ?\*))
6513 (goto-char (- (point) 2))
6514 t) ; Let nth 4 state handle the rest
6515 ((and (not (bobp))
6516 ;;(verilog-looking-back "\\*)" nil) ;; super slow, use two char-before instead
6517 (= (char-before) ?\))
6518 (= (char-before (1- (point))) ?\*)
6519 (not (verilog-looking-back "(\\s-*\\*)" nil))) ;; slow but unlikely to be called
6520 (goto-char (- (point) 2))
6521 (if (search-backward "(*" nil t)
6522 (progn
6523 (skip-chars-backward " \t\n\f")
6525 (progn
6526 (goto-char (+ (point) 2))
6527 nil)))
6529 (/= (skip-chars-backward " \t\n\f") 0))))))))
6531 (defun verilog-skip-forward-comment-p ()
6532 "If in comment, move to end and return true."
6533 (let* (h
6534 (state (save-excursion (verilog-syntax-ppss)))
6535 (skip (cond
6536 ((nth 3 state) ;Inside string
6538 ((nth 7 state) ;Inside // comment
6539 (end-of-line)
6540 (forward-char 1)
6542 ((nth 4 state) ;Inside /* comment
6543 (search-forward "*/")
6545 ((verilog-in-attribute-p) ;Inside (* attribute
6546 (search-forward "*)" nil t)
6548 (t nil))))
6549 (skip-chars-forward " \t\n\f")
6550 (while
6551 (cond
6552 ((looking-at "\\/\\*")
6553 (progn
6554 (setq h (point))
6555 (goto-char (match-end 0))
6556 (if (search-forward "*/" nil t)
6557 (progn
6558 (skip-chars-forward " \t\n\f")
6559 (setq skip 't))
6560 (progn
6561 (goto-char h)
6562 nil))))
6563 ((and (looking-at "(\\*") ; attribute start, but not an event (*) or (* )
6564 (not (looking-at "(\\*\\s-*)")))
6565 (progn
6566 (setq h (point))
6567 (goto-char (match-end 0))
6568 (if (search-forward "*)" nil t)
6569 (progn
6570 (skip-chars-forward " \t\n\f")
6571 (setq skip 't))
6572 (progn
6573 (goto-char h)
6574 nil))))
6575 (t nil)))
6576 skip))
6578 (defun verilog-indent-line-relative ()
6579 "Cheap version of indent line.
6580 Only look at a few lines to determine indent level."
6581 (interactive)
6582 (let ((indent-str)
6583 (sp (point)))
6584 (if (looking-at "^[ \t]*$")
6585 (cond ;- A blank line; No need to be too smart.
6586 ((bobp)
6587 (setq indent-str (list 'cpp 0)))
6588 ((verilog-continued-line)
6589 (let ((sp1 (point)))
6590 (if (verilog-continued-line)
6591 (progn
6592 (goto-char sp)
6593 (setq indent-str
6594 (list 'statement (verilog-current-indent-level))))
6595 (goto-char sp1)
6596 (setq indent-str (list 'block (verilog-current-indent-level)))))
6597 (goto-char sp))
6598 ((goto-char sp)
6599 (setq indent-str (verilog-calculate-indent))))
6600 (progn (skip-chars-forward " \t")
6601 (setq indent-str (verilog-calculate-indent))))
6602 (verilog-do-indent indent-str)))
6604 (defun verilog-indent-line ()
6605 "Indent for special part of code."
6606 (verilog-do-indent (verilog-calculate-indent)))
6608 (defun verilog-do-indent (indent-str)
6609 (let ((type (car indent-str))
6610 (ind (car (cdr indent-str))))
6611 (cond
6612 (; handle continued exp
6613 (eq type 'cexp)
6614 (let ((here (point)))
6615 (verilog-backward-syntactic-ws)
6616 (cond
6617 ((or
6618 (= (preceding-char) ?\,)
6619 (save-excursion
6620 (verilog-beg-of-statement-1)
6621 (looking-at verilog-declaration-re)))
6622 (let* ( fst
6623 (val
6624 (save-excursion
6625 (backward-char 1)
6626 (verilog-beg-of-statement-1)
6627 (setq fst (point))
6628 (if (looking-at verilog-declaration-re)
6629 (progn ; we have multiple words
6630 (goto-char (match-end 0))
6631 (skip-chars-forward " \t")
6632 (cond
6633 ((and verilog-indent-declaration-macros
6634 (= (following-char) ?\`))
6635 (progn
6636 (forward-char 1)
6637 (forward-word-strictly 1)
6638 (skip-chars-forward " \t")))
6639 ((= (following-char) ?\[)
6640 (progn
6641 (forward-char 1)
6642 (verilog-backward-up-list -1)
6643 (skip-chars-forward " \t"))))
6644 (current-column))
6645 (progn
6646 (goto-char fst)
6647 (+ (current-column) verilog-cexp-indent))))))
6648 (goto-char here)
6649 (indent-line-to val)
6650 (if (and (not verilog-indent-lists)
6651 (verilog-in-paren))
6652 (verilog-pretty-declarations-auto))
6654 ((= (preceding-char) ?\) )
6655 (goto-char here)
6656 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6657 (indent-line-to val)))
6659 (goto-char here)
6660 (let ((val))
6661 (verilog-beg-of-statement-1)
6662 (if (and (< (point) here)
6663 (verilog-re-search-forward "=[ \\t]*" here 'move)
6664 ;; not at a |=>, #=#, or [=n] operator
6665 (not (string-match "\\[=.\\|#=#\\||=>"
6666 (or (buffer-substring (- (point) 2) (1+ (point)))
6667 "")))) ; don't let buffer over/under-run spoil the party
6668 (setq val (current-column))
6669 (setq val (eval (cdr (assoc type verilog-indent-alist)))))
6670 (goto-char here)
6671 (indent-line-to val))))))
6673 (; handle inside parenthetical expressions
6674 (eq type 'cparenexp)
6675 (let* ( here
6676 (val (save-excursion
6677 (verilog-backward-up-list 1)
6678 (forward-char 1)
6679 (if verilog-indent-lists
6680 (skip-chars-forward " \t")
6681 (verilog-forward-syntactic-ws))
6682 (setq here (point))
6683 (current-column)))
6685 (decl (save-excursion
6686 (goto-char here)
6687 (verilog-forward-syntactic-ws)
6688 (setq here (point))
6689 (looking-at verilog-declaration-re))))
6690 (indent-line-to val)
6691 (if decl
6692 (verilog-pretty-declarations-auto))))
6694 (;-- Handle the ends
6696 (looking-at verilog-end-block-re)
6697 (verilog-at-close-constraint-p)
6698 (verilog-at-close-struct-p))
6699 (let ((val (if (eq type 'statement)
6700 (- ind verilog-indent-level)
6701 ind)))
6702 (indent-line-to val)))
6704 (;-- Case -- maybe line 'em up
6705 (and (eq type 'case) (not (looking-at "^[ \t]*$")))
6706 (progn
6707 (cond
6708 ((looking-at "\\<endcase\\>")
6709 (indent-line-to ind))
6711 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6712 (indent-line-to val))))))
6714 (;-- defun
6715 (and (eq type 'defun)
6716 (looking-at verilog-zero-indent-re))
6717 (indent-line-to 0))
6719 (;-- declaration
6720 (and (or
6721 (eq type 'defun)
6722 (eq type 'block))
6723 (looking-at verilog-declaration-re)
6724 ;; Do not consider "virtual function", "virtual task", "virtual class"
6725 ;; as declarations
6726 (not (looking-at (concat verilog-declaration-re
6727 "\\s-+\\(function\\|task\\|class\\)\\b"))))
6728 (verilog-indent-declaration ind))
6730 (;-- form feeds - ignored as bug in indent-line-to in < 24.5
6731 (looking-at "\f"))
6733 (;-- Everything else
6735 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6736 (indent-line-to val))))
6738 (if (looking-at "[ \t]+$")
6739 (skip-chars-forward " \t"))
6740 indent-str ; Return indent data
6743 (defun verilog-current-indent-level ()
6744 "Return the indent-level of the current statement."
6745 (save-excursion
6746 (let (par-pos)
6747 (beginning-of-line)
6748 (setq par-pos (verilog-parenthesis-depth))
6749 (while par-pos
6750 (goto-char par-pos)
6751 (beginning-of-line)
6752 (setq par-pos (verilog-parenthesis-depth)))
6753 (skip-chars-forward " \t")
6754 (current-column))))
6756 (defun verilog-case-indent-level ()
6757 "Return the indent-level of the current statement.
6758 Do not count named blocks or case-statements."
6759 (save-excursion
6760 (skip-chars-forward " \t")
6761 (cond
6762 ((looking-at verilog-named-block-re)
6763 (current-column))
6764 ((and (not (looking-at verilog-extended-case-re))
6765 (looking-at "^[^:;]+[ \t]*:"))
6766 (verilog-re-search-forward ":" nil t)
6767 (skip-chars-forward " \t")
6768 (current-column))
6770 (current-column)))))
6772 (defun verilog-indent-comment ()
6773 "Indent current line as comment."
6774 (let* ((stcol
6775 (cond
6776 ((verilog-in-star-comment-p)
6777 (save-excursion
6778 (re-search-backward "/\\*" nil t)
6779 (1+(current-column))))
6780 (comment-column
6781 comment-column )
6783 (save-excursion
6784 (re-search-backward "//" nil t)
6785 (current-column))))))
6786 (indent-line-to stcol)
6787 stcol))
6789 (defun verilog-more-comment ()
6790 "Make more comment lines like the previous."
6791 (let* ((star 0)
6792 (stcol
6793 (cond
6794 ((verilog-in-star-comment-p)
6795 (save-excursion
6796 (setq star 1)
6797 (re-search-backward "/\\*" nil t)
6798 (1+(current-column))))
6799 (comment-column
6800 comment-column )
6802 (save-excursion
6803 (re-search-backward "//" nil t)
6804 (current-column))))))
6805 (progn
6806 (indent-to stcol)
6807 (if (and star
6808 (save-excursion
6809 (forward-line -1)
6810 (skip-chars-forward " \t")
6811 (looking-at "\\*")))
6812 (insert "* ")))))
6814 (defun verilog-comment-indent (&optional _arg)
6815 "Return the column number the line should be indented to.
6816 _ARG is ignored, for `comment-indent-function' compatibility."
6817 (cond
6818 ((verilog-in-star-comment-p)
6819 (save-excursion
6820 (re-search-backward "/\\*" nil t)
6821 (1+(current-column))))
6822 ( comment-column
6823 comment-column )
6825 (save-excursion
6826 (re-search-backward "//" nil t)
6827 (current-column)))))
6831 (defun verilog-pretty-declarations-auto (&optional quiet)
6832 "Call `verilog-pretty-declarations' QUIET based on `verilog-auto-lineup'."
6833 (when (or (eq 'all verilog-auto-lineup)
6834 (eq 'declarations verilog-auto-lineup))
6835 (verilog-pretty-declarations quiet)))
6837 (defun verilog-pretty-declarations (&optional quiet)
6838 "Line up declarations around point.
6839 Be verbose about progress unless optional QUIET set."
6840 (interactive)
6841 (let* ((m1 (make-marker))
6842 (e (point))
6845 (here (point))
6847 start
6848 startpos
6850 endpos
6851 base-ind
6853 (save-excursion
6854 (if (progn
6855 ;; (verilog-beg-of-statement-1)
6856 (beginning-of-line)
6857 (verilog-forward-syntactic-ws)
6858 (and (not (verilog-in-directive-p)) ; could have `define input foo
6859 (looking-at verilog-declaration-re)))
6860 (progn
6861 (if (verilog-parenthesis-depth)
6862 ;; in an argument list or parameter block
6863 (setq el (verilog-backward-up-list -1)
6864 start (progn
6865 (goto-char e)
6866 (verilog-backward-up-list 1)
6867 (forward-line) ; ignore ( input foo,
6868 (verilog-re-search-forward verilog-declaration-re el 'move)
6869 (goto-char (match-beginning 0))
6870 (skip-chars-backward " \t")
6871 (point))
6872 startpos (set-marker (make-marker) start)
6873 end (progn
6874 (goto-char start)
6875 (verilog-backward-up-list -1)
6876 (forward-char -1)
6877 (verilog-backward-syntactic-ws)
6878 (point))
6879 endpos (set-marker (make-marker) end)
6880 base-ind (progn
6881 (goto-char start)
6882 (forward-char 1)
6883 (skip-chars-forward " \t")
6884 (current-column)))
6885 ;; in a declaration block (not in argument list)
6886 (setq
6887 start (progn
6888 (verilog-beg-of-statement-1)
6889 (while (and (looking-at verilog-declaration-re)
6890 (not (bobp)))
6891 (skip-chars-backward " \t")
6892 (setq e (point))
6893 (beginning-of-line)
6894 (verilog-backward-syntactic-ws)
6895 (backward-char)
6896 (verilog-beg-of-statement-1))
6898 startpos (set-marker (make-marker) start)
6899 end (progn
6900 (goto-char here)
6901 (verilog-end-of-statement)
6902 (setq e (point)) ;Might be on last line
6903 (verilog-forward-syntactic-ws)
6904 (while (looking-at verilog-declaration-re)
6905 (verilog-end-of-statement)
6906 (setq e (point))
6907 (verilog-forward-syntactic-ws))
6909 endpos (set-marker (make-marker) end)
6910 base-ind (progn
6911 (goto-char start)
6912 (verilog-do-indent (verilog-calculate-indent))
6913 (verilog-forward-ws&directives)
6914 (current-column))))
6915 ;; OK, start and end are set
6916 (goto-char (marker-position startpos))
6917 (if (and (not quiet)
6918 (> (- end start) 100))
6919 (message "Lining up declarations..(please stand by)"))
6920 ;; Get the beginning of line indent first
6921 (while (progn (setq e (marker-position endpos))
6922 (< (point) e))
6923 (cond
6924 ((save-excursion (skip-chars-backward " \t")
6925 (bolp))
6926 (verilog-forward-ws&directives)
6927 (indent-line-to base-ind)
6928 (verilog-forward-ws&directives)
6929 (if (< (point) e)
6930 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
6932 (just-one-space)
6933 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
6934 ;;(forward-line)
6936 ;; Now find biggest prefix
6937 (setq ind (verilog-get-lineup-indent (marker-position startpos) endpos))
6938 ;; Now indent each line.
6939 (goto-char (marker-position startpos))
6940 (while (progn (setq e (marker-position endpos))
6941 (setq r (- e (point)))
6942 (> r 0))
6943 (setq e (point))
6944 (unless quiet (message "%d" r))
6945 ;; (verilog-do-indent (verilog-calculate-indent)))
6946 (verilog-forward-ws&directives)
6947 (cond
6948 ((or (and verilog-indent-declaration-macros
6949 (looking-at verilog-declaration-re-2-macro))
6950 (looking-at verilog-declaration-re-2-no-macro))
6951 (let ((p (match-end 0)))
6952 (set-marker m1 p)
6953 (if (verilog-re-search-forward "[[#`]" p 'move)
6954 (progn
6955 (forward-char -1)
6956 (just-one-space)
6957 (goto-char (marker-position m1))
6958 (just-one-space)
6959 (indent-to ind))
6960 (progn
6961 (just-one-space)
6962 (indent-to ind)))))
6963 ((verilog-continued-line-1 (marker-position startpos))
6964 (goto-char e)
6965 (indent-line-to ind))
6966 ((verilog-in-struct-p)
6967 ;; could have a declaration of a user defined item
6968 (goto-char e)
6969 (verilog-end-of-statement))
6970 (t ; Must be comment or white space
6971 (goto-char e)
6972 (verilog-forward-ws&directives)
6973 (forward-line -1)))
6974 (forward-line 1))
6975 (unless quiet (message "")))))))
6977 (defun verilog-pretty-expr (&optional quiet _myre)
6978 "Line up expressions around point, optionally QUIET with regexp _MYRE ignored."
6979 (interactive)
6980 (if (not (verilog-in-comment-or-string-p))
6981 (save-excursion
6982 (let ( (rexp (concat "^\\s-*" verilog-complete-reg))
6983 (rexp1 (concat "^\\s-*" verilog-basic-complete-re)))
6984 (beginning-of-line)
6985 (if (and (not (looking-at rexp ))
6986 (looking-at verilog-assignment-operation-re)
6987 (save-excursion
6988 (goto-char (match-end 2))
6989 (and (not (verilog-in-attribute-p))
6990 (not (verilog-in-parameter-p))
6991 (not (verilog-in-comment-or-string-p)))))
6992 (let* ((here (point))
6993 (e) (r)
6994 (start
6995 (progn
6996 (beginning-of-line)
6997 (setq e (point))
6998 (verilog-backward-syntactic-ws)
6999 (beginning-of-line)
7000 (while (and (not (looking-at rexp1))
7001 (looking-at verilog-assignment-operation-re)
7002 (not (bobp))
7004 (setq e (point))
7005 (verilog-backward-syntactic-ws)
7006 (beginning-of-line)
7007 ) ;Ack, need to grok `define
7009 (end
7010 (progn
7011 (goto-char here)
7012 (end-of-line)
7013 (setq e (point)) ;Might be on last line
7014 (verilog-forward-syntactic-ws)
7015 (beginning-of-line)
7016 (while (and
7017 (not (looking-at rexp1 ))
7018 (looking-at verilog-assignment-operation-re)
7019 (progn
7020 (end-of-line)
7021 (not (eq e (point)))))
7022 (setq e (point))
7023 (verilog-forward-syntactic-ws)
7024 (beginning-of-line)
7027 (endpos (set-marker (make-marker) end))
7028 (ind)
7030 (goto-char start)
7031 (verilog-do-indent (verilog-calculate-indent))
7032 (if (and (not quiet)
7033 (> (- end start) 100))
7034 (message "Lining up expressions..(please stand by)"))
7036 ;; Set indent to minimum throughout region
7037 (while (< (point) (marker-position endpos))
7038 (beginning-of-line)
7039 (verilog-just-one-space verilog-assignment-operation-re)
7040 (beginning-of-line)
7041 (verilog-do-indent (verilog-calculate-indent))
7042 (end-of-line)
7043 (verilog-forward-syntactic-ws)
7046 ;; Now find biggest prefix
7047 (setq ind (verilog-get-lineup-indent-2 verilog-assignment-operation-re start endpos))
7049 ;; Now indent each line.
7050 (goto-char start)
7051 (while (progn (setq e (marker-position endpos))
7052 (setq r (- e (point)))
7053 (> r 0))
7054 (setq e (point))
7055 (if (not quiet) (message "%d" r))
7056 (cond
7057 ((looking-at verilog-assignment-operation-re)
7058 (goto-char (match-beginning 2))
7059 (if (not (or (verilog-in-parenthesis-p) ; leave attributes and comparisons alone
7060 (verilog-in-coverage-p)))
7061 (if (eq (char-after) ?=)
7062 (indent-to (1+ ind)) ; line up the = of the <= with surrounding =
7063 (indent-to ind)
7066 ((verilog-continued-line-1 start)
7067 (goto-char e)
7068 (indent-line-to ind))
7069 (t ; Must be comment or white space
7070 (goto-char e)
7071 (verilog-forward-ws&directives)
7072 (forward-line -1))
7074 (forward-line 1))
7075 (unless quiet (message ""))
7076 ))))))
7078 (defun verilog-just-one-space (myre)
7079 "Remove extra spaces around regular expression MYRE."
7080 (interactive)
7081 (if (and (not(looking-at verilog-complete-reg))
7082 (looking-at myre))
7083 (let ((p1 (match-end 1))
7084 (p2 (match-end 2)))
7085 (progn
7086 (goto-char p2)
7087 (just-one-space)
7088 (goto-char p1)
7089 (just-one-space)))))
7091 (defun verilog-indent-declaration (baseind)
7092 "Indent current lines as declaration.
7093 Line up the variable names based on previous declaration's indentation.
7094 BASEIND is the base indent to offset everything."
7095 (interactive)
7096 (let ((pos (point-marker))
7097 (lim (save-excursion
7098 ;; (verilog-re-search-backward verilog-declaration-opener nil 'move)
7099 (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)\\|\\(\\<task\\>\\)" nil 'move)
7100 (point)))
7101 (ind)
7102 (val)
7103 (m1 (make-marker)))
7104 (setq val
7105 (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist)))))
7106 (indent-line-to val)
7108 ;; Use previous declaration (in this module) as template.
7109 (if (or (eq 'all verilog-auto-lineup)
7110 (eq 'declarations verilog-auto-lineup))
7111 (if (verilog-re-search-backward
7112 (or (and verilog-indent-declaration-macros
7113 verilog-declaration-re-1-macro)
7114 verilog-declaration-re-1-no-macro) lim t)
7115 (progn
7116 (goto-char (match-end 0))
7117 (skip-chars-forward " \t")
7118 (setq ind (current-column))
7119 (goto-char pos)
7120 (setq val
7121 (+ baseind
7122 (eval (cdr (assoc 'declaration verilog-indent-alist)))))
7123 (indent-line-to val)
7124 (if (and verilog-indent-declaration-macros
7125 (looking-at verilog-declaration-re-2-macro))
7126 (let ((p (match-end 0)))
7127 (set-marker m1 p)
7128 (if (verilog-re-search-forward "[[#`]" p 'move)
7129 (progn
7130 (forward-char -1)
7131 (just-one-space)
7132 (goto-char (marker-position m1))
7133 (just-one-space)
7134 (indent-to ind))
7135 (if (/= (current-column) ind)
7136 (progn
7137 (just-one-space)
7138 (indent-to ind)))))
7139 (if (looking-at verilog-declaration-re-2-no-macro)
7140 (let ((p (match-end 0)))
7141 (set-marker m1 p)
7142 (if (verilog-re-search-forward "[[`#]" p 'move)
7143 (progn
7144 (forward-char -1)
7145 (just-one-space)
7146 (goto-char (marker-position m1))
7147 (just-one-space)
7148 (indent-to ind))
7149 (if (/= (current-column) ind)
7150 (progn
7151 (just-one-space)
7152 (indent-to ind))))))))))
7153 (goto-char pos)))
7155 (defun verilog-get-lineup-indent (b edpos)
7156 "Return the indent level that will line up several lines within the region.
7157 Region is defined by B and EDPOS."
7158 (save-excursion
7159 (let ((ind 0) e)
7160 (goto-char b)
7161 ;; Get rightmost position
7162 (while (progn (setq e (marker-position edpos))
7163 (< (point) e))
7164 (if (verilog-re-search-forward
7165 (or (and verilog-indent-declaration-macros
7166 verilog-declaration-re-1-macro)
7167 verilog-declaration-re-1-no-macro) e 'move)
7168 (progn
7169 (goto-char (match-end 0))
7170 (verilog-backward-syntactic-ws)
7171 (if (> (current-column) ind)
7172 (setq ind (current-column)))
7173 (goto-char (match-end 0)))))
7174 (if (> ind 0)
7175 (1+ ind)
7176 ;; No lineup-string found
7177 (goto-char b)
7178 (end-of-line)
7179 (verilog-backward-syntactic-ws)
7180 ;;(skip-chars-backward " \t")
7181 (1+ (current-column))))))
7183 (defun verilog-get-lineup-indent-2 (myre b edpos)
7184 "Return the indent level that will line up several lines within the region."
7185 (save-excursion
7186 (let ((ind 0) e)
7187 (goto-char b)
7188 ;; Get rightmost position
7189 (while (progn (setq e (marker-position edpos))
7190 (< (point) e))
7191 (if (and (verilog-re-search-forward myre e 'move)
7192 (not (verilog-in-attribute-p))) ; skip attribute exprs
7193 (progn
7194 (goto-char (match-beginning 2))
7195 (verilog-backward-syntactic-ws)
7196 (if (> (current-column) ind)
7197 (setq ind (current-column)))
7198 (goto-char (match-end 0)))
7200 (if (> ind 0)
7201 (1+ ind)
7202 ;; No lineup-string found
7203 (goto-char b)
7204 (end-of-line)
7205 (skip-chars-backward " \t")
7206 (1+ (current-column))))))
7208 (defun verilog-comment-depth (type val)
7209 "A useful mode debugging aide. TYPE and VAL are comments for insertion."
7210 (save-excursion
7211 (let
7212 ((b (prog2
7213 (beginning-of-line)
7214 (point-marker)
7215 (end-of-line))))
7216 (if (re-search-backward " /\\* [#-]# [a-zA-Z]+ [0-9]+ ## \\*/" b t)
7217 (progn
7218 (replace-match " /* -# ## */")
7219 (end-of-line))
7220 (progn
7221 (end-of-line)
7222 (insert " /* ## ## */"))))
7223 (backward-char 6)
7224 (insert
7225 (format "%s %d" type val))))
7228 ;;; Completion:
7230 (defvar verilog-str nil)
7231 (defvar verilog-all nil)
7232 (defvar verilog-pred nil)
7233 (defvar verilog-buffer-to-use nil)
7234 (defvar verilog-flag nil)
7235 (defvar verilog-toggle-completions nil
7236 "True means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one.
7237 Repeated use of \\[verilog-complete-word] will show you all of them.
7238 Normally, when there is more than one possible completion,
7239 it displays a list of all possible completions.")
7240 (when (boundp 'completion-cycle-threshold)
7241 (make-obsolete-variable
7242 'verilog-toggle-completions 'completion-cycle-threshold "26.1"))
7245 (defvar verilog-type-keywords
7247 "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input"
7248 "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0"
7249 "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
7250 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0"
7251 "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
7252 "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor"
7254 "Keywords for types used when completing a word in a declaration or parmlist.
7255 \(integer, real, reg...)")
7257 (defvar verilog-cpp-keywords
7258 '("module" "macromodule" "primitive" "timescale" "define" "ifdef" "ifndef" "else"
7259 "endif")
7260 "Keywords to complete when at first word of a line in declarative scope.
7261 \(initial, always, begin, assign...)
7262 The procedures and variables defined within the Verilog program
7263 will be completed at runtime and should not be added to this list.")
7265 (defvar verilog-defun-keywords
7266 (append
7268 "always" "always_comb" "always_ff" "always_latch" "assign"
7269 "begin" "end" "generate" "endgenerate" "module" "endmodule"
7270 "specify" "endspecify" "function" "endfunction" "initial" "final"
7271 "task" "endtask" "primitive" "endprimitive"
7273 verilog-type-keywords)
7274 "Keywords to complete when at first word of a line in declarative scope.
7275 \(initial, always, begin, assign...)
7276 The procedures and variables defined within the Verilog program
7277 will be completed at runtime and should not be added to this list.")
7279 (defvar verilog-block-keywords
7281 "begin" "break" "case" "continue" "else" "end" "endfunction"
7282 "endgenerate" "endinterface" "endpackage" "endspecify" "endtask"
7283 "for" "fork" "if" "join" "join_any" "join_none" "repeat" "return"
7284 "while")
7285 "Keywords to complete when at first word of a line in behavioral scope.
7286 \(begin, if, then, else, for, fork...)
7287 The procedures and variables defined within the Verilog program
7288 will be completed at runtime and should not be added to this list.")
7290 (defvar verilog-tf-keywords
7291 '("begin" "break" "fork" "join" "join_any" "join_none" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat")
7292 "Keywords to complete when at first word of a line in a task or function.
7293 \(begin, if, then, else, for, fork.)
7294 The procedures and variables defined within the Verilog program
7295 will be completed at runtime and should not be added to this list.")
7297 (defvar verilog-case-keywords
7298 '("begin" "fork" "join" "join_any" "join_none" "case" "end" "endcase" "if" "else" "for" "repeat")
7299 "Keywords to complete when at first word of a line in case scope.
7300 \(begin, if, then, else, for, fork...)
7301 The procedures and variables defined within the Verilog program
7302 will be completed at runtime and should not be added to this list.")
7304 (defvar verilog-separator-keywords
7305 '("else" "then" "begin")
7306 "Keywords to complete when NOT standing at the first word of a statement.
7307 \(else, then, begin...)
7308 Variables and function names defined within the Verilog program
7309 will be completed at runtime and should not be added to this list.")
7311 (defvar verilog-gate-ios
7312 ;; All these have an implied {"input"...} at the end
7313 '(("and" "output")
7314 ("buf" "output")
7315 ("bufif0" "output")
7316 ("bufif1" "output")
7317 ("cmos" "output")
7318 ("nand" "output")
7319 ("nmos" "output")
7320 ("nor" "output")
7321 ("not" "output")
7322 ("notif0" "output")
7323 ("notif1" "output")
7324 ("or" "output")
7325 ("pmos" "output")
7326 ("pulldown" "output")
7327 ("pullup" "output")
7328 ("rcmos" "output")
7329 ("rnmos" "output")
7330 ("rpmos" "output")
7331 ("rtran" "inout" "inout")
7332 ("rtranif0" "inout" "inout")
7333 ("rtranif1" "inout" "inout")
7334 ("tran" "inout" "inout")
7335 ("tranif0" "inout" "inout")
7336 ("tranif1" "inout" "inout")
7337 ("xnor" "output")
7338 ("xor" "output"))
7339 "Map of direction for each positional argument to each gate primitive.")
7341 (defvar verilog-gate-keywords (mapcar `car verilog-gate-ios)
7342 "Keywords for gate primitives.")
7344 (defun verilog-string-diff (str1 str2)
7345 "Return index of first letter where STR1 and STR2 differs."
7346 (catch 'done
7347 (let ((diff 0))
7348 (while t
7349 (if (or (> (1+ diff) (length str1))
7350 (> (1+ diff) (length str2)))
7351 (throw 'done diff))
7352 (or (equal (aref str1 diff) (aref str2 diff))
7353 (throw 'done diff))
7354 (setq diff (1+ diff))))))
7356 ;; Calculate all possible completions for functions if argument is `function',
7357 ;; completions for procedures if argument is `procedure' or both functions and
7358 ;; procedures otherwise.
7360 (defun verilog-func-completion (type)
7361 "Build regular expression for module/task/function names.
7362 TYPE is `module', `tf' for task or function, or t if unknown."
7363 (if (string= verilog-str "")
7364 (setq verilog-str "[a-zA-Z_]"))
7365 (let ((verilog-str (concat (cond
7366 ((eq type 'module) "\\<\\(module\\)\\s +")
7367 ((eq type 'tf) "\\<\\(task\\|function\\)\\s +")
7368 (t "\\<\\(task\\|function\\|module\\)\\s +"))
7369 "\\<\\(" verilog-str "[a-zA-Z0-9_.]*\\)\\>"))
7370 match)
7372 (if (not (looking-at verilog-defun-re))
7373 (verilog-re-search-backward verilog-defun-re nil t))
7374 (forward-char 1)
7376 ;; Search through all reachable functions
7377 (goto-char (point-min))
7378 (while (verilog-re-search-forward verilog-str (point-max) t)
7379 (progn (setq match (buffer-substring (match-beginning 2)
7380 (match-end 2)))
7381 (if (or (null verilog-pred)
7382 (funcall verilog-pred match))
7383 (setq verilog-all (cons match verilog-all)))))
7384 (if (match-beginning 0)
7385 (goto-char (match-beginning 0)))))
7387 (defun verilog-get-completion-decl (end)
7388 "Macro for searching through current declaration (var, type or const)
7389 for matches of `str' and adding the occurrence tp `all' through point END."
7390 (let ((re (or (and verilog-indent-declaration-macros
7391 verilog-declaration-re-2-macro)
7392 verilog-declaration-re-2-no-macro))
7393 decl-end match)
7394 ;; Traverse lines
7395 (while (and (< (point) end)
7396 (verilog-re-search-forward re end t))
7397 ;; Traverse current line
7398 (setq decl-end (save-excursion (verilog-declaration-end)))
7399 (while (and (verilog-re-search-forward verilog-symbol-re decl-end t)
7400 (not (match-end 1)))
7401 (setq match (buffer-substring (match-beginning 0) (match-end 0)))
7402 (if (string-match (concat "\\<" verilog-str) match)
7403 (if (or (null verilog-pred)
7404 (funcall verilog-pred match))
7405 (setq verilog-all (cons match verilog-all)))))
7406 (forward-line 1)))
7407 verilog-all)
7409 (defun verilog-var-completion ()
7410 "Calculate all possible completions for variables (or constants)."
7411 (let ((start (point)))
7412 ;; Search for all reachable var declarations
7413 (verilog-beg-of-defun)
7414 (save-excursion
7415 ;; Check var declarations
7416 (verilog-get-completion-decl start))))
7418 (defun verilog-keyword-completion (keyword-list)
7419 "Give list of all possible completions of keywords in KEYWORD-LIST."
7420 (mapcar (lambda (s)
7421 (if (string-match (concat "\\<" verilog-str) s)
7422 (if (or (null verilog-pred)
7423 (funcall verilog-pred s))
7424 (setq verilog-all (cons s verilog-all)))))
7425 keyword-list))
7428 (defun verilog-completion (verilog-str verilog-pred verilog-flag)
7429 "Function passed to `completing-read', `try-completion' or `all-completions'.
7430 Called to get completion on VERILOG-STR. If VERILOG-PRED is non-nil, it
7431 must be a function to be called for every match to check if this should
7432 really be a match. If VERILOG-FLAG is t, the function returns a list of
7433 all possible completions. If VERILOG-FLAG is nil it returns a string,
7434 the longest possible completion, or t if VERILOG-STR is an exact match.
7435 If VERILOG-FLAG is `lambda', the function returns t if VERILOG-STR is an
7436 exact match, nil otherwise."
7437 (save-excursion
7438 (let ((verilog-all nil))
7439 ;; Set buffer to use for searching labels. This should be set
7440 ;; within functions which use verilog-completions
7441 (set-buffer verilog-buffer-to-use)
7443 ;; Determine what should be completed
7444 (let ((state (car (verilog-calculate-indent))))
7445 (cond ((eq state 'defun)
7446 (save-excursion (verilog-var-completion))
7447 (verilog-func-completion 'module)
7448 (verilog-keyword-completion verilog-defun-keywords))
7450 ((eq state 'behavioral)
7451 (save-excursion (verilog-var-completion))
7452 (verilog-func-completion 'module)
7453 (verilog-keyword-completion verilog-defun-keywords))
7455 ((eq state 'block)
7456 (save-excursion (verilog-var-completion))
7457 (verilog-func-completion 'tf)
7458 (verilog-keyword-completion verilog-block-keywords))
7460 ((eq state 'case)
7461 (save-excursion (verilog-var-completion))
7462 (verilog-func-completion 'tf)
7463 (verilog-keyword-completion verilog-case-keywords))
7465 ((eq state 'tf)
7466 (save-excursion (verilog-var-completion))
7467 (verilog-func-completion 'tf)
7468 (verilog-keyword-completion verilog-tf-keywords))
7470 ((eq state 'cpp)
7471 (save-excursion (verilog-var-completion))
7472 (verilog-keyword-completion verilog-cpp-keywords))
7474 ((eq state 'cparenexp)
7475 (save-excursion (verilog-var-completion)))
7477 (t;--Anywhere else
7478 (save-excursion (verilog-var-completion))
7479 (verilog-func-completion 'both)
7480 (verilog-keyword-completion verilog-separator-keywords))))
7482 ;; Now we have built a list of all matches. Give response to caller
7483 (verilog-completion-response))))
7485 (defun verilog-completion-response ()
7486 (cond ((or (equal verilog-flag 'lambda) (null verilog-flag))
7487 ;; This was not called by all-completions
7488 (if (null verilog-all)
7489 ;; Return nil if there was no matching label
7491 ;; Get longest string common in the labels
7492 ;; FIXME: Why not use `try-completion'?
7493 (let* ((elm (cdr verilog-all))
7494 (match (car verilog-all))
7495 (min (length match))
7496 tmp)
7497 (if (string= match verilog-str)
7498 ;; Return t if first match was an exact match
7499 (setq match t)
7500 (while (not (null elm))
7501 ;; Find longest common string
7502 (if (< (setq tmp (verilog-string-diff match (car elm))) min)
7503 (progn
7504 (setq min tmp)
7505 (setq match (substring match 0 min))))
7506 ;; Terminate with match=t if this is an exact match
7507 (if (string= (car elm) verilog-str)
7508 (progn
7509 (setq match t)
7510 (setq elm nil))
7511 (setq elm (cdr elm)))))
7512 ;; If this is a test just for exact match, return nil ot t
7513 (if (and (equal verilog-flag 'lambda) (not (equal match 't)))
7515 match))))
7516 ;; If flag is t, this was called by all-completions. Return
7517 ;; list of all possible completions
7518 (verilog-flag
7519 verilog-all)))
7521 (defvar verilog-last-word-numb 0)
7522 (defvar verilog-last-word-shown nil)
7523 (defvar verilog-last-completions nil)
7525 (defun verilog-completion-at-point ()
7526 "Used as an element of `completion-at-point-functions'.
7527 \(See also `verilog-type-keywords' and
7528 `verilog-separator-keywords'.)"
7529 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
7530 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
7531 (verilog-str (buffer-substring b e))
7532 ;; The following variable is used in verilog-completion
7533 (verilog-buffer-to-use (current-buffer))
7534 (allcomp (if (and verilog-toggle-completions
7535 (string= verilog-last-word-shown verilog-str))
7536 verilog-last-completions
7537 (all-completions verilog-str 'verilog-completion))))
7538 (list b e allcomp)))
7540 (defun verilog-complete-word ()
7541 "Complete word at current point.
7542 \(See also `verilog-toggle-completions', `verilog-type-keywords',
7543 and `verilog-separator-keywords'.)"
7544 ;; NOTE: This is just a fallback for Emacs versions lacking
7545 ;; `completion-at-point'.
7546 (interactive)
7547 (let* ((comp-info (verilog-completion-at-point))
7548 (b (nth 0 comp-info))
7549 (e (nth 1 comp-info))
7550 (verilog-str (buffer-substring b e))
7551 (allcomp (nth 2 comp-info))
7552 (match (if verilog-toggle-completions
7553 "" (try-completion
7554 verilog-str (mapcar (lambda (elm)
7555 (cons elm 0)) allcomp)))))
7556 ;; Delete old string
7557 (delete-region b e)
7559 ;; Toggle-completions inserts whole labels
7560 (if verilog-toggle-completions
7561 (progn
7562 ;; Update entry number in list
7563 (setq verilog-last-completions allcomp
7564 verilog-last-word-numb
7565 (if (>= verilog-last-word-numb (1- (length allcomp)))
7567 (1+ verilog-last-word-numb)))
7568 (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb))
7569 ;; Display next match or same string if no match was found
7570 (if (not (null allcomp))
7571 (insert "" verilog-last-word-shown)
7572 (insert "" verilog-str)
7573 (message "(No match)")))
7574 ;; The other form of completion does not necessarily do that.
7576 ;; Insert match if found, or the original string if no match
7577 (if (or (null match) (equal match 't))
7578 (progn (insert "" verilog-str)
7579 (message "(No match)"))
7580 (insert "" match))
7581 ;; Give message about current status of completion
7582 (cond ((equal match 't)
7583 (if (not (null (cdr allcomp)))
7584 (message "(Complete but not unique)")
7585 (message "(Sole completion)")))
7586 ;; Display buffer if the current completion didn't help
7587 ;; on completing the label.
7588 ((and (not (null (cdr allcomp))) (= (length verilog-str)
7589 (length match)))
7590 (with-output-to-temp-buffer "*Completions*"
7591 (display-completion-list allcomp))
7592 ;; Wait for a key press. Then delete *Completion* window
7593 (momentary-string-display "" (point))
7594 (delete-window (get-buffer-window (get-buffer "*Completions*")))
7595 )))))
7597 (defun verilog-show-completions ()
7598 "Show all possible completions at current point."
7599 ;; NOTE: This is just a fallback for Emacs versions lacking
7600 ;; `completion-help-at-point'.
7601 (interactive)
7602 ;; Show possible completions in a temporary buffer.
7603 (with-output-to-temp-buffer "*Completions*"
7604 (display-completion-list (nth 2 (verilog-completion-at-point))))
7605 ;; Wait for a key press. Then delete *Completion* window
7606 (momentary-string-display "" (point))
7607 (delete-window (get-buffer-window (get-buffer "*Completions*"))))
7609 (defun verilog-get-default-symbol ()
7610 "Return symbol around current point as a string."
7611 (save-excursion
7612 (buffer-substring (progn
7613 (skip-chars-backward " \t")
7614 (skip-chars-backward "a-zA-Z0-9_")
7615 (point))
7616 (progn
7617 (skip-chars-forward "a-zA-Z0-9_")
7618 (point)))))
7620 (defun verilog-build-defun-re (str &optional arg)
7621 "Return function/task/module starting with STR as regular expression.
7622 With optional second ARG non-nil, STR is the complete name of the instruction."
7623 (if arg
7624 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "\\)\\>")
7625 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>")))
7627 (defun verilog-comp-defun (verilog-str verilog-pred verilog-flag)
7628 "Function passed to `completing-read', `try-completion' or `all-completions'.
7629 Returns a completion on any function name based on VERILOG-STR prefix. If
7630 VERILOG-PRED is non-nil, it must be a function to be called for every match
7631 to check if this should really be a match. If VERILOG-FLAG is t, the
7632 function returns a list of all possible completions. If it is nil it
7633 returns a string, the longest possible completion, or t if VERILOG-STR is
7634 an exact match. If VERILOG-FLAG is `lambda', the function returns t if
7635 VERILOG-STR is an exact match, nil otherwise."
7636 (save-excursion
7637 (let ((verilog-all nil)
7638 match)
7640 ;; Set buffer to use for searching labels. This should be set
7641 ;; within functions which use verilog-completions
7642 (set-buffer verilog-buffer-to-use)
7644 (let ((verilog-str verilog-str))
7645 ;; Build regular expression for functions
7646 (if (string= verilog-str "")
7647 (setq verilog-str (verilog-build-defun-re "[a-zA-Z_]"))
7648 (setq verilog-str (verilog-build-defun-re verilog-str)))
7649 (goto-char (point-min))
7651 ;; Build a list of all possible completions
7652 (while (verilog-re-search-forward verilog-str nil t)
7653 (setq match (buffer-substring (match-beginning 2) (match-end 2)))
7654 (if (or (null verilog-pred)
7655 (funcall verilog-pred match))
7656 (setq verilog-all (cons match verilog-all)))))
7658 ;; Now we have built a list of all matches. Give response to caller
7659 (verilog-completion-response))))
7661 (defun verilog-goto-defun ()
7662 "Move to specified Verilog module/interface/task/function.
7663 The default is a name found in the buffer around point.
7664 If search fails, other files are checked based on
7665 `verilog-library-flags'."
7666 (interactive)
7667 (let* ((default (verilog-get-default-symbol))
7668 ;; The following variable is used in verilog-comp-function
7669 (verilog-buffer-to-use (current-buffer))
7670 (label (if (not (string= default ""))
7671 ;; Do completion with default
7672 (completing-read (concat "Goto-Label: (default "
7673 default ") ")
7674 'verilog-comp-defun nil nil "")
7675 ;; There is no default value. Complete without it
7676 (completing-read "Goto-Label: "
7677 'verilog-comp-defun nil nil "")))
7679 ;; Make sure library paths are correct, in case need to resolve module
7680 (verilog-auto-reeval-locals)
7681 (verilog-getopt-flags)
7682 ;; If there was no response on prompt, use default value
7683 (if (string= label "")
7684 (setq label default))
7685 ;; Goto right place in buffer if label is not an empty string
7686 (or (string= label "")
7687 (progn
7688 (save-excursion
7689 (goto-char (point-min))
7690 (setq pt
7691 (re-search-forward (verilog-build-defun-re label t) nil t)))
7692 (when pt
7693 (goto-char pt)
7694 (beginning-of-line))
7696 (verilog-goto-defun-file label))))
7698 ;; Eliminate compile warning
7699 (defvar occur-pos-list)
7701 (defun verilog-showscopes ()
7702 "List all scopes in this module."
7703 (interactive)
7704 (let ((buffer (current-buffer))
7705 (linenum 1)
7706 (nlines 0)
7707 (first 1)
7708 (prevpos (point-min))
7709 (final-context-start (make-marker))
7710 (regexp "\\(module\\s-+\\w+\\s-*(\\)\\|\\(\\w+\\s-+\\w+\\s-*(\\)"))
7711 (with-output-to-temp-buffer "*Occur*"
7712 (save-excursion
7713 (message "Searching for %s ..." regexp)
7714 ;; Find next match, but give up if prev match was at end of buffer.
7715 (while (and (not (= prevpos (point-max)))
7716 (verilog-re-search-forward regexp nil t))
7717 (goto-char (match-beginning 0))
7718 (beginning-of-line)
7719 (save-match-data
7720 (setq linenum (+ linenum (count-lines prevpos (point)))))
7721 (setq prevpos (point))
7722 (goto-char (match-end 0))
7723 (let* ((start (save-excursion
7724 (goto-char (match-beginning 0))
7725 (forward-line (if (< nlines 0) nlines (- nlines)))
7726 (point)))
7727 (end (save-excursion
7728 (goto-char (match-end 0))
7729 (if (> nlines 0)
7730 (forward-line (1+ nlines))
7731 (forward-line 1))
7732 (point)))
7733 (tag (format "%3d" linenum))
7734 (empty (make-string (length tag) ?\ ))
7735 tem)
7736 (save-excursion
7737 (setq tem (make-marker))
7738 (set-marker tem (point))
7739 (set-buffer standard-output)
7740 (setq occur-pos-list (cons tem occur-pos-list))
7741 (or first (zerop nlines)
7742 (insert "--------\n"))
7743 (setq first nil)
7744 (insert-buffer-substring buffer start end)
7745 (backward-char (- end start))
7746 (setq tem (if (< nlines 0) (- nlines) nlines))
7747 (while (> tem 0)
7748 (insert empty ?:)
7749 (forward-line 1)
7750 (setq tem (1- tem)))
7751 (let ((this-linenum linenum))
7752 (set-marker final-context-start
7753 (+ (point) (- (match-end 0) (match-beginning 0))))
7754 (while (< (point) final-context-start)
7755 (if (null tag)
7756 (setq tag (format "%3d" this-linenum)))
7757 (insert tag ?:)))))))
7758 (set-buffer-modified-p nil))))
7761 ;; Highlight helper functions
7762 (defconst verilog-directive-regexp "\\(translate\\|coverage\\|lint\\)_")
7764 (defun verilog-within-translate-off ()
7765 "Return point if within translate-off region, else nil."
7766 (and (save-excursion
7767 (re-search-backward
7768 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>")
7769 nil t))
7770 (equal "off" (match-string 2))
7771 (point)))
7773 (defun verilog-start-translate-off (limit)
7774 "Return point before translate-off directive if before LIMIT, else nil."
7775 (when (re-search-forward
7776 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
7777 limit t)
7778 (match-beginning 0)))
7780 (defun verilog-back-to-start-translate-off (limit)
7781 "Return point before translate-off directive if before LIMIT, else nil."
7782 (when (re-search-backward
7783 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
7784 limit t)
7785 (match-beginning 0)))
7787 (defun verilog-end-translate-off (limit)
7788 "Return point after translate-on directive if before LIMIT, else nil."
7790 (re-search-forward (concat
7791 "//\\s-*.*\\s-*" verilog-directive-regexp "on\\>") limit t))
7793 (defun verilog-match-translate-off (limit)
7794 "Match a translate-off block, setting `match-data' and returning t, else nil.
7795 Bound search by LIMIT."
7796 (when (< (point) limit)
7797 (let ((start (or (verilog-within-translate-off)
7798 (verilog-start-translate-off limit)))
7799 (case-fold-search t))
7800 (when start
7801 (let ((end (or (verilog-end-translate-off limit) limit)))
7802 (set-match-data (list start end))
7803 (goto-char end))))))
7805 (defun verilog-font-lock-match-item (limit)
7806 "Match, and move over, any declaration item after point.
7807 Bound search by LIMIT. Adapted from
7808 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
7809 (condition-case nil
7810 (save-restriction
7811 (narrow-to-region (point-min) limit)
7812 ;; match item
7813 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
7814 (save-match-data
7815 (goto-char (match-end 1))
7816 ;; move to next item
7817 (if (looking-at "\\(\\s-*,\\)")
7818 (goto-char (match-end 1))
7819 (end-of-line) t))))
7820 (error nil)))
7823 ;; Added by Subbu Meiyappan for Header
7825 (defun verilog-header ()
7826 "Insert a standard Verilog file header.
7827 See also `verilog-sk-header' for an alternative format."
7828 (interactive)
7829 (let ((start (point)))
7830 (insert "\
7831 //-----------------------------------------------------------------------------
7832 // Title : <title>
7833 // Project : <project>
7834 //-----------------------------------------------------------------------------
7835 // File : <filename>
7836 // Author : <author>
7837 // Created : <credate>
7838 // Last modified : <moddate>
7839 //-----------------------------------------------------------------------------
7840 // Description :
7841 // <description>
7842 //-----------------------------------------------------------------------------
7843 // Copyright (c) <copydate> by <company> This model is the confidential and
7844 // proprietary property of <company> and the possession or use of this
7845 // file requires a written license from <company>.
7846 //------------------------------------------------------------------------------
7847 // Modification history :
7848 // <modhist>
7849 //-----------------------------------------------------------------------------
7852 (goto-char start)
7853 (search-forward "<filename>")
7854 (replace-match (buffer-name) t t)
7855 (search-forward "<author>") (replace-match "" t t)
7856 (insert (user-full-name))
7857 (insert " <" (user-login-name) "@" (system-name) ">")
7858 (search-forward "<credate>") (replace-match "" t t)
7859 (verilog-insert-date)
7860 (search-forward "<moddate>") (replace-match "" t t)
7861 (verilog-insert-date)
7862 (search-forward "<copydate>") (replace-match "" t t)
7863 (verilog-insert-year)
7864 (search-forward "<modhist>") (replace-match "" t t)
7865 (verilog-insert-date)
7866 (insert " : created")
7867 (goto-char start)
7868 (let (string)
7869 (setq string (read-string "title: "))
7870 (search-forward "<title>")
7871 (replace-match string t t)
7872 (setq string (read-string "project: " verilog-project))
7873 (setq verilog-project string)
7874 (search-forward "<project>")
7875 (replace-match string t t)
7876 (setq string (read-string "Company: " verilog-company))
7877 (setq verilog-company string)
7878 (search-forward "<company>")
7879 (replace-match string t t)
7880 (search-forward "<company>")
7881 (replace-match string t t)
7882 (search-forward "<company>")
7883 (replace-match string t t)
7884 (search-backward "<description>")
7885 (replace-match "" t t))))
7887 ;; verilog-header Uses the verilog-insert-date function
7889 (defun verilog-insert-date ()
7890 "Insert date from the system."
7891 (interactive)
7892 (if verilog-date-scientific-format
7893 (insert (format-time-string "%Y/%m/%d"))
7894 (insert (format-time-string "%d.%m.%Y"))))
7896 (defun verilog-insert-year ()
7897 "Insert year from the system."
7898 (interactive)
7899 (insert (format-time-string "%Y")))
7902 ;;; Signal list parsing:
7905 ;; Elements of a signal list
7906 ;; Unfortunately we use 'assoc' on this, so can't be a vector
7907 (defsubst verilog-sig-new (name bits comment mem enum signed type multidim modport)
7908 (list name bits comment mem enum signed type multidim modport))
7909 (defsubst verilog-sig-name (sig)
7910 (car sig))
7911 (defsubst verilog-sig-bits (sig) ; First element of packed array (pre signal-name)
7912 (nth 1 sig))
7913 (defsubst verilog-sig-comment (sig)
7914 (nth 2 sig))
7915 (defsubst verilog-sig-memory (sig) ; Unpacked array (post signal-name)
7916 (nth 3 sig))
7917 (defsubst verilog-sig-enum (sig)
7918 (nth 4 sig))
7919 (defsubst verilog-sig-signed (sig)
7920 (nth 5 sig))
7921 (defsubst verilog-sig-type (sig)
7922 (nth 6 sig))
7923 (defsubst verilog-sig-type-set (sig type)
7924 (setcar (nthcdr 6 sig) type))
7925 (defsubst verilog-sig-multidim (sig) ; Second and additional elements of packed array
7926 (nth 7 sig))
7927 (defsubst verilog-sig-multidim-string (sig)
7928 (if (verilog-sig-multidim sig)
7929 (let ((str "") (args (verilog-sig-multidim sig)))
7930 (while args
7931 (setq str (concat (car args) str))
7932 (setq args (cdr args)))
7933 str)))
7934 (defsubst verilog-sig-modport (sig)
7935 (nth 8 sig))
7936 (defsubst verilog-sig-width (sig)
7937 (verilog-make-width-expression (verilog-sig-bits sig)))
7939 (defsubst verilog-alw-new (outputs-del outputs-imm temps inputs)
7940 (vector outputs-del outputs-imm temps inputs))
7941 (defsubst verilog-alw-get-outputs-delayed (sigs)
7942 (aref sigs 0))
7943 (defsubst verilog-alw-get-outputs-immediate (sigs)
7944 (aref sigs 1))
7945 (defsubst verilog-alw-get-temps (sigs)
7946 (aref sigs 2))
7947 (defsubst verilog-alw-get-inputs (sigs)
7948 (aref sigs 3))
7949 (defsubst verilog-alw-get-uses-delayed (sigs)
7950 (aref sigs 0))
7952 (defsubst verilog-modport-new (name clockings decls)
7953 (list name clockings decls))
7954 (defsubst verilog-modport-name (sig)
7955 (car sig))
7956 (defsubst verilog-modport-clockings (sig)
7957 (nth 1 sig)) ; Returns list of names
7958 (defsubst verilog-modport-clockings-add (sig val)
7959 (setcar (nthcdr 1 sig) (cons val (nth 1 sig))))
7960 (defsubst verilog-modport-decls (sig)
7961 (nth 2 sig)) ; Returns verilog-decls-* structure
7962 (defsubst verilog-modport-decls-set (sig val)
7963 (setcar (nthcdr 2 sig) val))
7965 (defsubst verilog-modi-new (name fob pt type)
7966 (vector name fob pt type))
7967 (defsubst verilog-modi-name (modi)
7968 (aref modi 0))
7969 (defsubst verilog-modi-file-or-buffer (modi)
7970 (aref modi 1))
7971 (defsubst verilog-modi-get-point (modi)
7972 (aref modi 2))
7973 (defsubst verilog-modi-get-type (modi) ; "module" or "interface"
7974 (aref modi 3))
7975 (defsubst verilog-modi-get-decls (modi)
7976 (verilog-modi-cache-results modi 'verilog-read-decls))
7977 (defsubst verilog-modi-get-sub-decls (modi)
7978 (verilog-modi-cache-results modi 'verilog-read-sub-decls))
7980 ;; Signal reading for given module
7981 ;; Note these all take modi's - as returned from verilog-modi-current
7982 (defsubst verilog-decls-new (out inout in vars modports assigns consts gparams interfaces)
7983 (vector out inout in vars modports assigns consts gparams interfaces))
7984 (defsubst verilog-decls-append (a b)
7985 (cond ((not a) b) ((not b) a)
7986 (t (vector (append (aref a 0) (aref b 0)) (append (aref a 1) (aref b 1))
7987 (append (aref a 2) (aref b 2)) (append (aref a 3) (aref b 3))
7988 (append (aref a 4) (aref b 4)) (append (aref a 5) (aref b 5))
7989 (append (aref a 6) (aref b 6)) (append (aref a 7) (aref b 7))
7990 (append (aref a 8) (aref b 8))))))
7991 (defsubst verilog-decls-get-outputs (decls)
7992 (aref decls 0))
7993 (defsubst verilog-decls-get-inouts (decls)
7994 (aref decls 1))
7995 (defsubst verilog-decls-get-inputs (decls)
7996 (aref decls 2))
7997 (defsubst verilog-decls-get-vars (decls)
7998 (aref decls 3))
7999 (defsubst verilog-decls-get-modports (decls) ; Also for clocking blocks; contains another verilog-decls struct
8000 (aref decls 4)) ; Returns verilog-modport* structure
8001 (defsubst verilog-decls-get-assigns (decls)
8002 (aref decls 5))
8003 (defsubst verilog-decls-get-consts (decls)
8004 (aref decls 6))
8005 (defsubst verilog-decls-get-gparams (decls)
8006 (aref decls 7))
8007 (defsubst verilog-decls-get-interfaces (decls)
8008 (aref decls 8))
8011 (defsubst verilog-subdecls-new (out inout in intf intfd)
8012 (vector out inout in intf intfd))
8013 (defsubst verilog-subdecls-get-outputs (subdecls)
8014 (aref subdecls 0))
8015 (defsubst verilog-subdecls-get-inouts (subdecls)
8016 (aref subdecls 1))
8017 (defsubst verilog-subdecls-get-inputs (subdecls)
8018 (aref subdecls 2))
8019 (defsubst verilog-subdecls-get-interfaces (subdecls)
8020 (aref subdecls 3))
8021 (defsubst verilog-subdecls-get-interfaced (subdecls)
8022 (aref subdecls 4))
8024 (defun verilog-signals-from-signame (signame-list)
8025 "Return signals in standard form from SIGNAME-LIST, a simple list of names."
8026 (mapcar (lambda (name) (verilog-sig-new name nil nil nil nil nil nil nil nil))
8027 signame-list))
8029 (defun verilog-signals-in (in-list not-list)
8030 "Return list of signals in IN-LIST that are also in NOT-LIST.
8031 Also remove any duplicates in IN-LIST.
8032 Signals must be in standard (base vector) form."
8033 ;; This function is hot, so implemented as O(1)
8034 (cond ((eval-when-compile (fboundp 'make-hash-table))
8035 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
8036 (ht-not (make-hash-table :test 'equal :rehash-size 4.0))
8037 out-list)
8038 (while not-list
8039 (puthash (car (car not-list)) t ht-not)
8040 (setq not-list (cdr not-list)))
8041 (while in-list
8042 (when (and (gethash (verilog-sig-name (car in-list)) ht-not)
8043 (not (gethash (verilog-sig-name (car in-list)) ht)))
8044 (setq out-list (cons (car in-list) out-list))
8045 (puthash (verilog-sig-name (car in-list)) t ht))
8046 (setq in-list (cdr in-list)))
8047 (nreverse out-list)))
8048 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
8050 (let (out-list)
8051 (while in-list
8052 (if (and (assoc (verilog-sig-name (car in-list)) not-list)
8053 (not (assoc (verilog-sig-name (car in-list)) out-list)))
8054 (setq out-list (cons (car in-list) out-list)))
8055 (setq in-list (cdr in-list)))
8056 (nreverse out-list)))))
8057 ;;(verilog-signals-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("C" "")))
8059 (defun verilog-signals-not-in (in-list not-list)
8060 "Return list of signals in IN-LIST that aren't also in NOT-LIST.
8061 Also remove any duplicates in IN-LIST.
8062 Signals must be in standard (base vector) form."
8063 ;; This function is hot, so implemented as O(1)
8064 (cond ((eval-when-compile (fboundp 'make-hash-table))
8065 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
8066 out-list)
8067 (while not-list
8068 (puthash (car (car not-list)) t ht)
8069 (setq not-list (cdr not-list)))
8070 (while in-list
8071 (when (not (gethash (verilog-sig-name (car in-list)) ht))
8072 (setq out-list (cons (car in-list) out-list))
8073 (puthash (verilog-sig-name (car in-list)) t ht))
8074 (setq in-list (cdr in-list)))
8075 (nreverse out-list)))
8076 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
8078 (let (out-list)
8079 (while in-list
8080 (if (and (not (assoc (verilog-sig-name (car in-list)) not-list))
8081 (not (assoc (verilog-sig-name (car in-list)) out-list)))
8082 (setq out-list (cons (car in-list) out-list)))
8083 (setq in-list (cdr in-list)))
8084 (nreverse out-list)))))
8085 ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" "")))
8087 (defun verilog-signals-not-in-struct (in-list not-list)
8088 "Return list of signals in IN-LIST that aren't also in NOT-LIST.
8089 Also remove any duplicates in IN-LIST.
8090 Any structure in not-list will remove all members in in-list.
8091 Signals must be in standard (base vector) form."
8092 (cond ((eval-when-compile (fboundp 'make-hash-table))
8093 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
8094 out-list addit nm)
8095 (while not-list
8096 (puthash (car (car not-list)) t ht)
8097 (setq not-list (cdr not-list)))
8098 (while in-list
8099 (setq nm (verilog-sig-name (car in-list)))
8100 (when (not (gethash nm ht))
8101 (setq addit t)
8102 (while (string-match "^\\([^\\].*\\)\\.[^.]+$" nm)
8103 (setq nm (match-string 1 nm))
8104 (setq addit (and addit
8105 (not (gethash nm ht)))))
8106 (when addit
8107 (setq out-list (cons (car in-list) out-list))
8108 (puthash (verilog-sig-name (car in-list)) t ht)))
8109 (setq in-list (cdr in-list)))
8110 (nreverse out-list)))
8111 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
8113 (let (out-list addit nm)
8114 (while in-list
8115 (setq nm (verilog-sig-name (car in-list)))
8116 (when (and (not (assoc nm not-list))
8117 (not (assoc nm out-list)))
8118 (setq addit t)
8119 (while (string-match "^\\([^\\].*\\)\\.[^.]+$" nm)
8120 (setq nm (match-string 1 nm))
8121 (setq addit (and addit
8122 (not (assoc nm not-list)))))
8123 (when addit
8124 (setq out-list (cons (car in-list) out-list))))
8125 (setq in-list (cdr in-list)))
8126 (nreverse out-list)))))
8127 ;;(verilog-signals-not-in-struct '(("A" "") ("B" "") ("DEL.SUB.A" "[2:3]")) '(("DEL.SUB" "") ("EXT" "")))
8129 (defun verilog-signals-memory (in-list)
8130 "Return list of signals in IN-LIST that are memorized (multidimensional)."
8131 (let (out-list)
8132 (while in-list
8133 (if (nth 3 (car in-list))
8134 (setq out-list (cons (car in-list) out-list)))
8135 (setq in-list (cdr in-list)))
8136 out-list))
8137 ;;(verilog-signals-memory '(("A" nil nil "[3:0]")) '(("B" nil nil nil)))
8139 (defun verilog-signals-sort-compare (a b)
8140 "Compare signal A and B for sorting."
8141 (string< (verilog-sig-name a) (verilog-sig-name b)))
8143 (defun verilog-signals-not-params (in-list)
8144 "Return list of signals in IN-LIST that aren't parameters or numeric constants."
8145 (let (out-list)
8146 (while in-list
8147 ;; Namespace intentionally short for AUTOs and compatibility
8148 (unless (boundp (intern (concat "vh-" (verilog-sig-name (car in-list)))))
8149 (setq out-list (cons (car in-list) out-list)))
8150 (setq in-list (cdr in-list)))
8151 (nreverse out-list)))
8153 (defun verilog-signals-with (func in-list)
8154 "Return list of signals where FUNC is true executed on each signal in IN-LIST."
8155 (let (out-list)
8156 (while in-list
8157 (when (funcall func (car in-list))
8158 (setq out-list (cons (car in-list) out-list)))
8159 (setq in-list (cdr in-list)))
8160 (nreverse out-list)))
8162 (defun verilog-signals-combine-bus (in-list)
8163 "Return a list of signals in IN-LIST, with buses combined.
8164 Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]."
8165 (let (combo
8166 buswarn
8167 out-list
8168 sig highbit lowbit ; Temp information about current signal
8169 sv-name sv-highbit sv-lowbit ; Details about signal we are forming
8170 sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring
8171 sv-modport
8172 bus)
8173 ;; Shove signals so duplicated signals will be adjacent
8174 (setq in-list (sort in-list `verilog-signals-sort-compare))
8175 (while in-list
8176 (setq sig (car in-list))
8177 ;; No current signal; form from existing details
8178 (unless sv-name
8179 (setq sv-name (verilog-sig-name sig)
8180 sv-highbit nil
8181 sv-busstring nil
8182 sv-comment (verilog-sig-comment sig)
8183 sv-memory (verilog-sig-memory sig)
8184 sv-enum (verilog-sig-enum sig)
8185 sv-signed (verilog-sig-signed sig)
8186 sv-type (verilog-sig-type sig)
8187 sv-multidim (verilog-sig-multidim sig)
8188 sv-modport (verilog-sig-modport sig)
8189 combo ""
8190 buswarn ""))
8191 ;; Extract bus details
8192 (setq bus (verilog-sig-bits sig))
8193 (setq bus (and bus (verilog-simplify-range-expression bus)))
8194 (cond ((and bus
8195 (or (and (string-match "\\[\\([0-9]+\\):\\([0-9]+\\)\\]" bus)
8196 (setq highbit (string-to-number (match-string 1 bus))
8197 lowbit (string-to-number
8198 (match-string 2 bus))))
8199 (and (string-match "\\[\\([0-9]+\\)\\]" bus)
8200 (setq highbit (string-to-number (match-string 1 bus))
8201 lowbit highbit))))
8202 ;; Combine bits in bus
8203 (if sv-highbit
8204 (setq sv-highbit (max highbit sv-highbit)
8205 sv-lowbit (min lowbit sv-lowbit))
8206 (setq sv-highbit highbit
8207 sv-lowbit lowbit)))
8208 (bus
8209 ;; String, probably something like `preproc:0
8210 (setq sv-busstring bus)))
8211 ;; Peek ahead to next signal
8212 (setq in-list (cdr in-list))
8213 (setq sig (car in-list))
8214 (cond ((and sig (equal sv-name (verilog-sig-name sig)))
8215 ;; Combine with this signal
8216 (when (and sv-busstring
8217 (not (equal sv-busstring (verilog-sig-bits sig))))
8218 (when nil ; Debugging
8219 (message (concat "Warning, can't merge into single bus `%s%s'"
8220 ", the AUTOs may be wrong")
8221 sv-name bus))
8222 (setq buswarn ", Couldn't Merge"))
8223 (if (verilog-sig-comment sig) (setq combo ", ..."))
8224 (setq sv-memory (or sv-memory (verilog-sig-memory sig))
8225 sv-enum (or sv-enum (verilog-sig-enum sig))
8226 sv-signed (or sv-signed (verilog-sig-signed sig))
8227 sv-type (or sv-type (verilog-sig-type sig))
8228 sv-multidim (or sv-multidim (verilog-sig-multidim sig))
8229 sv-modport (or sv-modport (verilog-sig-modport sig))))
8230 ;; Doesn't match next signal, add to queue, zero in prep for next
8231 ;; Note sig may also be nil for the last signal in the list
8233 (setq out-list
8234 (cons (verilog-sig-new
8235 sv-name
8236 (or sv-busstring
8237 (if sv-highbit
8238 (concat "[" (int-to-string sv-highbit) ":"
8239 (int-to-string sv-lowbit) "]")))
8240 (concat sv-comment combo buswarn)
8241 sv-memory sv-enum sv-signed sv-type sv-multidim sv-modport)
8242 out-list)
8243 sv-name nil))))
8245 out-list))
8247 (defun verilog-sig-tieoff (sig)
8248 "Return tieoff expression for given SIG, with appropriate width.
8249 Tieoff value uses `verilog-active-low-regexp' and
8250 `verilog-auto-reset-widths'."
8251 (concat
8252 (if (and verilog-active-low-regexp
8253 (verilog-string-match-fold verilog-active-low-regexp (verilog-sig-name sig)))
8254 "~" "")
8255 (cond ((not verilog-auto-reset-widths)
8256 "0")
8257 ((equal verilog-auto-reset-widths 'unbased)
8258 "'0")
8259 ;; Else presume verilog-auto-reset-widths is true
8261 (let* ((width (verilog-sig-width sig)))
8262 (cond ((not width)
8263 "`0/*NOWIDTH*/")
8264 ((string-match "^[0-9]+$" width)
8265 (concat width (if (verilog-sig-signed sig) "'sh0" "'h0")))
8267 (concat "{" width "{1'b0}}"))))))))
8270 ;; Dumping
8273 (defun verilog-decls-princ (decls &optional header prefix)
8274 "For debug, dump the `verilog-read-decls' structure DECLS.
8275 Use optional HEADER and PREFIX."
8276 (when decls
8277 (if header (princ header))
8278 (setq prefix (or prefix ""))
8279 (verilog-signals-princ (verilog-decls-get-outputs decls)
8280 (concat prefix "Outputs:\n") (concat prefix " "))
8281 (verilog-signals-princ (verilog-decls-get-inouts decls)
8282 (concat prefix "Inout:\n") (concat prefix " "))
8283 (verilog-signals-princ (verilog-decls-get-inputs decls)
8284 (concat prefix "Inputs:\n") (concat prefix " "))
8285 (verilog-signals-princ (verilog-decls-get-vars decls)
8286 (concat prefix "Vars:\n") (concat prefix " "))
8287 (verilog-signals-princ (verilog-decls-get-assigns decls)
8288 (concat prefix "Assigns:\n") (concat prefix " "))
8289 (verilog-signals-princ (verilog-decls-get-consts decls)
8290 (concat prefix "Consts:\n") (concat prefix " "))
8291 (verilog-signals-princ (verilog-decls-get-gparams decls)
8292 (concat prefix "Gparams:\n") (concat prefix " "))
8293 (verilog-signals-princ (verilog-decls-get-interfaces decls)
8294 (concat prefix "Interfaces:\n") (concat prefix " "))
8295 (verilog-modport-princ (verilog-decls-get-modports decls)
8296 (concat prefix "Modports:\n") (concat prefix " "))
8297 (princ "\n")))
8299 (defun verilog-signals-princ (signals &optional header prefix)
8300 "For debug, dump internal SIGNALS structures, with HEADER and PREFIX."
8301 (when signals
8302 (if header (princ header))
8303 (while signals
8304 (let ((sig (car signals)))
8305 (setq signals (cdr signals))
8306 (princ prefix)
8307 (princ "\"") (princ (verilog-sig-name sig)) (princ "\"")
8308 (princ " bits=") (princ (verilog-sig-bits sig))
8309 (princ " cmt=") (princ (verilog-sig-comment sig))
8310 (princ " mem=") (princ (verilog-sig-memory sig))
8311 (princ " enum=") (princ (verilog-sig-enum sig))
8312 (princ " sign=") (princ (verilog-sig-signed sig))
8313 (princ " type=") (princ (verilog-sig-type sig))
8314 (princ " dim=") (princ (verilog-sig-multidim sig))
8315 (princ " modp=") (princ (verilog-sig-modport sig))
8316 (princ "\n")))))
8318 (defun verilog-modport-princ (modports &optional header prefix)
8319 "For debug, dump internal MODPORTS structures, with HEADER and PREFIX."
8320 (when modports
8321 (if header (princ header))
8322 (while modports
8323 (let ((sig (car modports)))
8324 (setq modports (cdr modports))
8325 (princ prefix)
8326 (princ "\"") (princ (verilog-modport-name sig)) (princ "\"")
8327 (princ " clockings=") (princ (verilog-modport-clockings sig))
8328 (princ "\n")
8329 (verilog-decls-princ (verilog-modport-decls sig)
8330 (concat prefix " syms:\n")
8331 (concat prefix " "))))))
8334 ;; Port/Wire/Etc Reading
8337 (defun verilog-read-inst-backward-name ()
8338 "Internal. Move point back to beginning of inst-name."
8339 (verilog-backward-open-paren)
8340 (let (done)
8341 (while (not done)
8342 (verilog-re-search-backward-quick "\\()\\|\\b[a-zA-Z0-9`_$]\\|\\]\\)" nil nil) ; ] isn't word boundary
8343 (cond ((looking-at ")")
8344 (verilog-backward-open-paren))
8345 (t (setq done t)))))
8346 (while (looking-at "\\]")
8347 (verilog-backward-open-bracket)
8348 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_$]\\|\\]\\)" nil nil))
8349 (skip-chars-backward "a-zA-Z0-9`_$"))
8351 (defun verilog-read-inst-module-matcher ()
8352 "Set match data 0 with module_name when point is inside instantiation."
8353 (verilog-read-inst-backward-name)
8354 ;; Skip over instantiation name
8355 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_$]\\|)\\)" nil nil) ; ) isn't word boundary
8356 ;; Check for parameterized instantiations
8357 (when (looking-at ")")
8358 (verilog-backward-open-paren)
8359 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_$]" nil nil))
8360 (skip-chars-backward "a-zA-Z0-9'_$")
8361 ;; #1 is legal syntax for gate primitives
8362 (when (save-excursion
8363 (verilog-backward-syntactic-ws-quick)
8364 (eq ?# (char-before)))
8365 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_$]" nil nil)
8366 (skip-chars-backward "a-zA-Z0-9'_$"))
8367 (looking-at "[a-zA-Z0-9`_$]+")
8368 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
8369 (buffer-substring-no-properties (match-beginning 0) (match-end 0))
8370 ;; Caller assumes match-beginning/match-end is still set
8373 (defun verilog-read-inst-module ()
8374 "Return module_name when point is inside instantiation."
8375 (save-excursion
8376 (verilog-read-inst-module-matcher)))
8378 (defun verilog-read-inst-name ()
8379 "Return instance_name when point is inside instantiation."
8380 (save-excursion
8381 (verilog-read-inst-backward-name)
8382 (looking-at "[a-zA-Z0-9`_$]+")
8383 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
8384 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))
8386 (defun verilog-read-module-name ()
8387 "Return module name when after its ( or ;."
8388 (save-excursion
8389 (re-search-backward "[(;]")
8390 ;; Due to "module x import y (" we must search for declaration begin
8391 (verilog-re-search-backward-quick verilog-defun-re nil nil)
8392 (goto-char (match-end 0))
8393 (verilog-re-search-forward-quick "\\b[a-zA-Z0-9`_$]+" nil nil)
8394 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
8395 (verilog-symbol-detick
8396 (buffer-substring-no-properties (match-beginning 0) (match-end 0)) t)))
8398 (defun verilog-read-inst-param-value ()
8399 "Return list of parameters and values when point is inside instantiation."
8400 (save-excursion
8401 (verilog-read-inst-backward-name)
8402 ;; Skip over instantiation name
8403 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_$]\\|)\\)" nil nil) ; ) isn't word boundary
8404 ;; If there are parameterized instantiations
8405 (when (looking-at ")")
8406 (let ((end-pt (point))
8407 params
8408 param-name paren-beg-pt param-value)
8409 (verilog-backward-open-paren)
8410 (while (verilog-re-search-forward-quick "\\." end-pt t)
8411 (verilog-re-search-forward-quick "\\([a-zA-Z0-9`_$]\\)" nil nil)
8412 (skip-chars-backward "a-zA-Z0-9'_$")
8413 (looking-at "[a-zA-Z0-9`_$]+")
8414 (setq param-name (buffer-substring-no-properties
8415 (match-beginning 0) (match-end 0)))
8416 (verilog-re-search-forward-quick "(" nil nil)
8417 (setq paren-beg-pt (point))
8418 (verilog-forward-close-paren)
8419 (setq param-value (verilog-string-remove-spaces
8420 (buffer-substring-no-properties
8421 paren-beg-pt (1- (point)))))
8422 (setq params (cons (list param-name param-value) params)))
8423 params))))
8425 (defun verilog-read-auto-params (num-param &optional max-param)
8426 "Return parameter list inside auto.
8427 Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters."
8428 (let ((olist))
8429 (save-excursion
8430 ;; /*AUTOPUNT("parameter", "parameter")*/
8431 (backward-sexp 1)
8432 (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?")
8433 (setq olist (cons (match-string 1) olist))
8434 (goto-char (match-end 0))))
8435 (or (eq nil num-param)
8436 (<= num-param (length olist))
8437 (error "%s: Expected %d parameters" (verilog-point-text) num-param))
8438 (if (eq max-param nil) (setq max-param num-param))
8439 (or (eq nil max-param)
8440 (>= max-param (length olist))
8441 (error "%s: Expected <= %d parameters" (verilog-point-text) max-param))
8442 (nreverse olist)))
8444 (defun verilog-read-decls ()
8445 "Compute signal declaration information for the current module at point.
8446 Return an array of [outputs inouts inputs wire reg assign const]."
8447 (let ((end-mod-point (or (verilog-get-end-of-defun) (point-max)))
8448 (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t)
8449 in-modport in-clocking in-ign-to-semi ptype ign-prop
8450 sigs-in sigs-out sigs-inout sigs-var sigs-assign sigs-const
8451 sigs-gparam sigs-intf sigs-modports
8452 vec expect-signal keywd last-keywd newsig rvalue enum io
8453 signed typedefed multidim
8454 modport
8455 varstack tmp)
8456 ;;(if dbg (setq dbg (concat dbg (format "\n\nverilog-read-decls START PT %s END %s\n" (point) end-mod-point))))
8457 (save-excursion
8458 (verilog-beg-of-defun-quick)
8459 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point))
8460 (while (< (point) end-mod-point)
8461 ;;(if dbg (setq dbg (concat dbg (format "Pt %s Vec %s C%c Kwd'%s'\n" (point) vec (following-char) keywd))))
8462 (cond
8463 ((looking-at "//")
8464 (when (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
8465 (setq enum (match-string 2)))
8466 (search-forward "\n"))
8467 ((looking-at "/\\*")
8468 (forward-char 2)
8469 (when (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
8470 (setq enum (match-string 2)))
8471 (or (search-forward "*/")
8472 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8473 ((looking-at "(\\*")
8474 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
8475 (forward-char 1)
8476 (or (search-forward "*)")
8477 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
8478 ((eq ?\" (following-char))
8479 (or (re-search-forward "[^\\]\"" nil t) ; don't forward-char first, since we look for a non backslash first
8480 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
8481 ((eq ?\; (following-char))
8482 (cond (in-ign-to-semi ; Such as inside a "import ...;" in a module header
8483 (setq in-ign-to-semi nil rvalue nil))
8484 ((and in-modport (not (eq in-modport t))) ; end of a modport declaration
8485 (verilog-modport-decls-set
8486 in-modport
8487 (verilog-decls-new sigs-out sigs-inout sigs-in
8488 nil nil nil nil nil nil))
8489 ;; Pop from varstack to restore state to pre-clocking
8490 (setq tmp (car varstack)
8491 varstack (cdr varstack)
8492 sigs-out (aref tmp 0)
8493 sigs-inout (aref tmp 1)
8494 sigs-in (aref tmp 2))
8495 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
8496 v2kargs-ok nil in-modport nil ign-prop nil))
8498 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
8499 v2kargs-ok nil in-modport nil ign-prop nil)))
8500 (forward-char 1))
8501 ((eq ?= (following-char))
8502 (setq rvalue t newsig nil)
8503 (forward-char 1))
8504 ((and (eq ?, (following-char))
8505 (eq paren sig-paren))
8506 (setq rvalue nil)
8507 (forward-char 1))
8508 ;; ,'s can occur inside {} & funcs
8509 ((looking-at "[{(]")
8510 (setq paren (1+ paren))
8511 (forward-char 1))
8512 ((looking-at "[})]")
8513 (setq paren (1- paren))
8514 (forward-char 1)
8515 (when (< paren sig-paren)
8516 (setq expect-signal nil rvalue nil))) ; ) that ends variables inside v2k arg list
8517 ((looking-at "\\s-*\\(\\[[^]]+\\]\\)")
8518 (goto-char (match-end 0))
8519 (cond (newsig ; Memory, not just width. Patch last signal added's memory (nth 3)
8520 (setcar (cdr (cdr (cdr newsig)))
8521 (if (verilog-sig-memory newsig)
8522 (concat (verilog-sig-memory newsig) (match-string 1))
8523 (match-string-no-properties 1))))
8524 (vec ; Multidimensional
8525 (setq multidim (cons vec multidim))
8526 (setq vec (verilog-string-replace-matches
8527 "\\s-+" "" nil nil (match-string-no-properties 1))))
8528 (t ; Bit width
8529 (setq vec (verilog-string-replace-matches
8530 "\\s-+" "" nil nil (match-string-no-properties 1))))))
8531 ;; Normal or escaped identifier -- note we remember the \ if escaped
8532 ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
8533 (goto-char (match-end 0))
8534 (setq last-keywd keywd
8535 keywd (match-string-no-properties 1))
8536 (when (string-match "^\\\\" (match-string 1))
8537 (setq keywd (concat keywd " "))) ; Escaped ID needs space at end
8538 ;; Add any :: package names to same identifier
8539 ;; '*' here is for "import x::*"
8540 (while (looking-at "\\s-*::\\s-*\\(\\*\\|[a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
8541 (goto-char (match-end 0))
8542 (setq keywd (concat keywd "::" (match-string 1)))
8543 (when (string-match "^\\\\" (match-string 1))
8544 (setq keywd (concat keywd " ")))) ; Escaped ID needs space at end
8545 (cond ((equal keywd "input")
8546 (setq vec nil enum nil rvalue nil newsig nil signed nil
8547 typedefed nil multidim nil ptype nil modport nil
8548 expect-signal 'sigs-in io t sig-paren paren))
8549 ((equal keywd "output")
8550 (setq vec nil enum nil rvalue nil newsig nil signed nil
8551 typedefed nil multidim nil ptype nil modport nil
8552 expect-signal 'sigs-out io t sig-paren paren))
8553 ((equal keywd "inout")
8554 (setq vec nil enum nil rvalue nil newsig nil signed nil
8555 typedefed nil multidim nil ptype nil modport nil
8556 expect-signal 'sigs-inout io t sig-paren paren))
8557 ((equal keywd "parameter")
8558 (setq vec nil enum nil rvalue nil signed nil
8559 typedefed nil multidim nil ptype nil modport nil
8560 expect-signal 'sigs-gparam io t sig-paren paren))
8561 ((member keywd '("wire" "reg" ; Fast
8562 ;; net_type
8563 "tri" "tri0" "tri1" "triand" "trior" "trireg"
8564 "uwire" "wand" "wor"
8565 ;; integer_atom_type
8566 "byte" "shortint" "int" "longint" "integer" "time"
8567 "supply0" "supply1"
8568 ;; integer_vector_type - "reg" above
8569 "bit" "logic"
8570 ;; non_integer_type
8571 "shortreal" "real" "realtime"
8572 ;; data_type
8573 "string" "event" "chandle"))
8574 (cond (io
8575 (setq typedefed
8576 (if typedefed (concat typedefed " " keywd) keywd)))
8577 (t (setq vec nil enum nil rvalue nil signed nil
8578 typedefed nil multidim nil sig-paren paren
8579 expect-signal 'sigs-var modport nil))))
8580 ((equal keywd "assign")
8581 (setq vec nil enum nil rvalue nil signed nil
8582 typedefed nil multidim nil ptype nil modport nil
8583 expect-signal 'sigs-assign sig-paren paren))
8584 ((member keywd '("localparam" "genvar"))
8585 (setq vec nil enum nil rvalue nil signed nil
8586 typedefed nil multidim nil ptype nil modport nil
8587 expect-signal 'sigs-const sig-paren paren))
8588 ((member keywd '("signed" "unsigned"))
8589 (setq signed keywd))
8590 ((member keywd '("assert" "assume" "cover" "expect" "restrict"))
8591 (setq ign-prop t))
8592 ((member keywd '("class" "covergroup" "function"
8593 "property" "randsequence" "sequence" "task"))
8594 (unless ign-prop
8595 (setq functask (1+ functask))))
8596 ((member keywd '("endclass" "endgroup" "endfunction"
8597 "endproperty" "endsequence" "endtask"))
8598 (setq functask (1- functask)))
8599 ((equal keywd "modport")
8600 (setq in-modport t))
8601 ((and (equal keywd "clocking")
8602 (not (equal last-keywd "default")))
8603 (setq in-clocking t))
8604 ((equal keywd "import")
8605 (when v2kargs-ok ; import in module header, not a modport import
8606 (setq in-ign-to-semi t rvalue t)))
8607 ((equal keywd "type")
8608 (setq ptype t))
8609 ((equal keywd "var"))
8610 ;; Ifdef? Ignore name of define
8611 ((member keywd '("`ifdef" "`ifndef" "`elsif"))
8612 (setq rvalue t))
8613 ;; Type?
8614 ((unless ptype
8615 (verilog-typedef-name-p keywd))
8616 (cond (io
8617 (setq typedefed
8618 (if typedefed (concat typedefed " " keywd) keywd)))
8619 (t (setq vec nil enum nil rvalue nil signed nil
8620 typedefed keywd ; Have a type
8621 multidim nil sig-paren paren
8622 expect-signal 'sigs-var modport nil))))
8623 ;; Interface with optional modport in v2k arglist?
8624 ;; Skip over parsing modport, and take the interface name as the type
8625 ((and v2kargs-ok
8626 (eq paren 1)
8627 (not rvalue)
8628 (looking-at "\\s-*\\(\\.\\(\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*\\)\\|\\)\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*"))
8629 (when (match-end 2) (goto-char (match-end 2)))
8630 (setq vec nil enum nil rvalue nil signed nil
8631 typedefed keywd multidim nil ptype nil modport (match-string 2)
8632 newsig nil sig-paren paren
8633 expect-signal 'sigs-intf io t ))
8634 ;; Ignore dotted LHS assignments: "assign foo.bar = z;"
8635 ((looking-at "\\s-*\\.")
8636 (goto-char (match-end 0))
8637 (when (not rvalue)
8638 (setq expect-signal nil)))
8639 ;; "modport <keywd>"
8640 ((and (eq in-modport t)
8641 (not (member keywd verilog-keywords)))
8642 (setq in-modport (verilog-modport-new keywd nil nil))
8643 (setq sigs-modports (cons in-modport sigs-modports))
8644 ;; Push old sig values to stack and point to new signal list
8645 (setq varstack (cons (vector sigs-out sigs-inout sigs-in)
8646 varstack))
8647 (setq sigs-in nil sigs-inout nil sigs-out nil))
8648 ;; "modport x (clocking <keywd>)"
8649 ((and in-modport in-clocking)
8650 (verilog-modport-clockings-add in-modport keywd)
8651 (setq in-clocking nil))
8652 ;; endclocking
8653 ((and in-clocking
8654 (equal keywd "endclocking"))
8655 (unless (eq in-clocking t)
8656 (verilog-modport-decls-set
8657 in-clocking
8658 (verilog-decls-new sigs-out sigs-inout sigs-in
8659 nil nil nil nil nil nil))
8660 ;; Pop from varstack to restore state to pre-clocking
8661 (setq tmp (car varstack)
8662 varstack (cdr varstack)
8663 sigs-out (aref tmp 0)
8664 sigs-inout (aref tmp 1)
8665 sigs-in (aref tmp 2)))
8666 (setq in-clocking nil))
8667 ;; "clocking <keywd>"
8668 ((and (eq in-clocking t)
8669 (not (member keywd verilog-keywords)))
8670 (setq in-clocking (verilog-modport-new keywd nil nil))
8671 (setq sigs-modports (cons in-clocking sigs-modports))
8672 ;; Push old sig values to stack and point to new signal list
8673 (setq varstack (cons (vector sigs-out sigs-inout sigs-in)
8674 varstack))
8675 (setq sigs-in nil sigs-inout nil sigs-out nil))
8676 ;; New signal, maybe?
8677 ((and expect-signal
8678 (not rvalue)
8679 (eq functask 0)
8680 (not (member keywd verilog-keywords)))
8681 ;; Add new signal to expect-signal's variable
8682 ;;(if dbg (setq dbg (concat dbg (format "Pt %s New sig %s'\n" (point) keywd))))
8683 (setq newsig (verilog-sig-new keywd vec nil nil enum signed typedefed multidim modport))
8684 (set expect-signal (cons newsig
8685 (symbol-value expect-signal))))))
8687 (forward-char 1)))
8688 (skip-syntax-forward " "))
8689 ;; Return arguments
8690 (setq tmp (verilog-decls-new (nreverse sigs-out)
8691 (nreverse sigs-inout)
8692 (nreverse sigs-in)
8693 (nreverse sigs-var)
8694 (nreverse sigs-modports)
8695 (nreverse sigs-assign)
8696 (nreverse sigs-const)
8697 (nreverse sigs-gparam)
8698 (nreverse sigs-intf)))
8699 ;;(if dbg (verilog-decls-princ tmp))
8700 tmp)))
8702 (defvar verilog-read-sub-decls-in-interfaced nil
8703 "For `verilog-read-sub-decls', process next signal as under interfaced block.")
8705 (defvar verilog-read-sub-decls-gate-ios nil
8706 "For `verilog-read-sub-decls', gate IO pins remaining, nil if non-primitive.")
8708 (eval-when-compile
8709 ;; Prevent compile warnings; these are let's, not globals
8710 ;; Do not remove the eval-when-compile
8711 ;; - we want an error when we are debugging this code if they are refed.
8712 (defvar sigs-in)
8713 (defvar sigs-inout)
8714 (defvar sigs-intf)
8715 (defvar sigs-intfd)
8716 (defvar sigs-out)
8717 (defvar sigs-out-d)
8718 (defvar sigs-out-i)
8719 (defvar sigs-out-unk)
8720 (defvar sigs-temp)
8721 ;; These are known to be from other packages and may not be defined
8722 (defvar diff-command)
8723 ;; There are known to be from newer versions of Emacs
8724 (defvar create-lockfiles)
8725 (defvar which-func-modes))
8727 (defun verilog-read-sub-decls-type (par-values portdata)
8728 "For `verilog-read-sub-decls-line', decode a signal type."
8729 (let* ((type (verilog-sig-type portdata))
8730 (pvassoc (assoc type par-values)))
8731 (cond ((member type '("wire" "reg")) nil)
8732 (pvassoc (nth 1 pvassoc))
8733 (t type))))
8735 (defun verilog-read-sub-decls-sig (submoddecls par-values comment port sig vec multidim mem)
8736 "For `verilog-read-sub-decls-line', add a signal."
8737 ;; sig eq t to indicate .name syntax
8738 ;;(message "vrsds: %s(%S)" port sig)
8739 (let ((dotname (eq sig t))
8740 portdata)
8741 (when sig
8742 (setq port (verilog-symbol-detick-denumber port))
8743 (setq sig (if dotname port (verilog-symbol-detick-denumber sig)))
8744 (if vec (setq vec (verilog-symbol-detick-denumber vec)))
8745 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim)))
8746 (if mem (setq mem (verilog-symbol-detick-denumber mem)))
8747 (unless (or (not sig)
8748 (equal sig "")) ; Ignore .foo(1'b1) assignments
8749 (cond ((or (setq portdata (assoc port (verilog-decls-get-inouts submoddecls)))
8750 (equal "inout" verilog-read-sub-decls-gate-ios))
8751 (setq sigs-inout
8752 (cons (verilog-sig-new
8754 (if dotname (verilog-sig-bits portdata) vec)
8755 (concat "To/From " comment)
8758 (verilog-sig-signed portdata)
8759 (verilog-read-sub-decls-type par-values portdata)
8760 multidim nil)
8761 sigs-inout)))
8762 ((or (setq portdata (assoc port (verilog-decls-get-outputs submoddecls)))
8763 (equal "output" verilog-read-sub-decls-gate-ios))
8764 (setq sigs-out
8765 (cons (verilog-sig-new
8767 (if dotname (verilog-sig-bits portdata) vec)
8768 (concat "From " comment)
8771 (verilog-sig-signed portdata)
8772 ;; Though ok in SV, in V2K code, propagating the
8773 ;; "reg" in "output reg" upwards isn't legal.
8774 ;; Also for backwards compatibility we don't propagate
8775 ;; "input wire" upwards.
8776 ;; See also `verilog-signals-edit-wire-reg'.
8777 (verilog-read-sub-decls-type par-values portdata)
8778 multidim nil)
8779 sigs-out)))
8780 ((or (setq portdata (assoc port (verilog-decls-get-inputs submoddecls)))
8781 (equal "input" verilog-read-sub-decls-gate-ios))
8782 (setq sigs-in
8783 (cons (verilog-sig-new
8785 (if dotname (verilog-sig-bits portdata) vec)
8786 (concat "To " comment)
8789 (verilog-sig-signed portdata)
8790 (verilog-read-sub-decls-type par-values portdata)
8791 multidim nil)
8792 sigs-in)))
8793 ((setq portdata (assoc port (verilog-decls-get-interfaces submoddecls)))
8794 (setq sigs-intf
8795 (cons (verilog-sig-new
8797 (if dotname (verilog-sig-bits portdata) vec)
8798 (concat "To/From " comment)
8801 (verilog-sig-signed portdata)
8802 (verilog-read-sub-decls-type par-values portdata)
8803 multidim nil)
8804 sigs-intf)))
8805 ((setq portdata (and verilog-read-sub-decls-in-interfaced
8806 (assoc port (verilog-decls-get-vars submoddecls))))
8807 (setq sigs-intfd
8808 (cons (verilog-sig-new
8810 (if dotname (verilog-sig-bits portdata) vec)
8811 (concat "To/From " comment)
8814 (verilog-sig-signed portdata)
8815 (verilog-read-sub-decls-type par-values portdata)
8816 multidim nil)
8817 sigs-intf)))
8818 ;; (t -- warning pin isn't defined.) ; Leave for lint tool
8819 )))))
8821 (defun verilog-read-sub-decls-expr (submoddecls par-values comment port expr)
8822 "For `verilog-read-sub-decls-line', parse a subexpression and add signals."
8823 ;;(message "vrsde: `%s'" expr)
8824 ;; Replace special /*[....]*/ comments inserted by verilog-auto-inst-port
8825 (setq expr (verilog-string-replace-matches "/\\*\\(\\.?\\[[^*]+\\]\\)\\*/" "\\1" nil nil expr))
8826 ;; Remove front operators
8827 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
8829 (cond
8830 ;; {..., a, b} requires us to recurse on a,b
8831 ;; To support {#{},{#{a,b}} we'll just split everything on [{},]
8832 ((string-match "^\\s-*{\\(.*\\)}\\s-*$" expr)
8833 (unless verilog-auto-ignore-concat
8834 (let ((mlst (split-string (match-string 1 expr) "[{},]"))
8835 mstr)
8836 (while (setq mstr (pop mlst))
8837 (verilog-read-sub-decls-expr submoddecls par-values comment port mstr)))))
8839 (let (sig vec multidim mem)
8840 ;; Remove leading reduction operators, etc
8841 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
8842 ;;(message "vrsde-ptop: `%s'" expr)
8843 (cond ; Find \signal. Final space is part of escaped signal name
8844 ((string-match "^\\s-*\\(\\\\[^ \t\n\f]+\\s-\\)" expr)
8845 ;;(message "vrsde-s: `%s'" (match-string 1 expr))
8846 (setq sig (match-string 1 expr)
8847 expr (substring expr (match-end 0))))
8848 ;; Find signal
8849 ((string-match "^\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" expr)
8850 ;;(message "vrsde-s: `%s'" (match-string 1 expr))
8851 (setq sig (verilog-string-remove-spaces (match-string 1 expr))
8852 expr (substring expr (match-end 0)))))
8853 ;; Find [vector] or [multi][multi][multi][vector]
8854 (while (string-match "^\\s-*\\(\\[[^]]+\\]\\)" expr)
8855 ;;(message "vrsde-v: `%s'" (match-string 1 expr))
8856 (when vec (setq multidim (cons vec multidim)))
8857 (setq vec (match-string 1 expr)
8858 expr (substring expr (match-end 0))))
8859 ;; Find .[unpacked_memory] or .[unpacked][unpacked]...
8860 (while (string-match "^\\s-*\\.\\(\\(\\[[^]]+\\]\\)+\\)" expr)
8861 ;;(message "vrsde-m: `%s'" (match-string 1 expr))
8862 (setq mem (match-string 1 expr)
8863 expr (substring expr (match-end 0))))
8864 ;; If found signal, and nothing unrecognized, add the signal
8865 ;;(message "vrsde-rem: `%s'" expr)
8866 (when (and sig (string-match "^\\s-*$" expr))
8867 (verilog-read-sub-decls-sig submoddecls par-values comment port sig vec multidim mem))))))
8869 (defun verilog-read-sub-decls-line (submoddecls par-values comment)
8870 "For `verilog-read-sub-decls', read lines of port defs until none match.
8871 Inserts the list of signals found, using submodi to look up each port."
8872 (let (done port)
8873 (save-excursion
8874 (forward-line 1)
8875 (while (not done)
8876 ;; Get port name
8877 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*")
8878 (setq port (match-string-no-properties 1))
8879 (goto-char (match-end 0)))
8880 ;; .\escaped (
8881 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*")
8882 (setq port (concat (match-string-no-properties 1) " ")) ; escaped id's need trailing space
8883 (goto-char (match-end 0)))
8884 ;; .name
8885 ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*[,)/]")
8886 (verilog-read-sub-decls-sig
8887 submoddecls par-values comment (match-string-no-properties 1) t ; sig==t for .name
8888 nil nil nil) ; vec multidim mem
8889 (setq port nil))
8890 ;; .\escaped_name
8891 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*[,)/]")
8892 (verilog-read-sub-decls-sig
8893 submoddecls par-values comment (concat (match-string-no-properties 1) " ") t ; sig==t for .name
8894 nil nil nil) ; vec multidim mem
8895 (setq port nil))
8896 ;; random
8897 ((looking-at "\\s-*\\.[^(]*(")
8898 (setq port nil) ; skip this line
8899 (goto-char (match-end 0)))
8901 (setq port nil done t))) ; Unknown, ignore rest of line
8902 ;; Get signal name. Point is at the first-non-space after (
8903 ;; We intentionally ignore (non-escaped) signals with .s in them
8904 ;; this prevents AUTOWIRE etc from noticing hierarchical sigs.
8905 (when port
8906 (cond ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*)")
8907 (verilog-read-sub-decls-sig
8908 submoddecls par-values comment port
8909 (verilog-string-remove-spaces (match-string-no-properties 1)) ; sig
8910 nil nil nil)) ; vec multidim mem
8912 ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)")
8913 (verilog-read-sub-decls-sig
8914 submoddecls par-values comment port
8915 (verilog-string-remove-spaces (match-string-no-properties 1)) ; sig
8916 (match-string-no-properties 2) nil nil)) ; vec multidim mem
8917 ;; Fastpath was above looking-at's.
8918 ;; For something more complicated invoke a parser
8919 ((looking-at "[^)]+")
8920 (verilog-read-sub-decls-expr
8921 submoddecls par-values comment port
8922 (buffer-substring-no-properties
8923 (point) (1- (progn (search-backward "(") ; start at (
8924 (verilog-forward-sexp-ign-cmt 1)
8925 (point)))))))) ; expr
8927 (forward-line 1)))))
8928 ;;(verilog-read-sub-decls-line (verilog-subdecls-new nil nil nil nil nil) nil "Cmt")
8930 (defun verilog-read-sub-decls-gate (submoddecls par-values comment submod end-inst-point)
8931 "For `verilog-read-sub-decls', read lines of UDP gate decl until none match.
8932 Inserts the list of signals found."
8933 (save-excursion
8934 (let ((iolist (cdr (assoc submod verilog-gate-ios))))
8935 (while (< (point) end-inst-point)
8936 ;; Get primitive's signal name, as will never have port, and no trailing )
8937 (cond ((looking-at "//")
8938 (search-forward "\n"))
8939 ((looking-at "/\\*")
8940 (or (search-forward "*/")
8941 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8942 ((looking-at "(\\*")
8943 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
8944 (forward-char 1)
8945 (or (search-forward "*)")
8946 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
8947 ;; On pins, parse and advance to next pin
8948 ;; Looking at pin, but *not* an // Output comment, or ) to end the inst
8949 ((looking-at "\\s-*[a-zA-Z0-9`_$({}\\\\][^,]*")
8950 (goto-char (match-end 0))
8951 (setq verilog-read-sub-decls-gate-ios (or (car iolist) "input")
8952 iolist (cdr iolist))
8953 (verilog-read-sub-decls-expr
8954 submoddecls par-values comment "primitive_port"
8955 (match-string 0)))
8957 (forward-char 1)
8958 (skip-syntax-forward " ")))))))
8960 (defun verilog-read-sub-decls ()
8961 "Internally parse signals going to modules under this module.
8962 Return an array of [ outputs inouts inputs ] signals for modules that are
8963 instantiated in this module. For example if declare A A (.B(SIG)) and SIG
8964 is an output, then SIG will be included in the list.
8966 This only works on instantiations created with /*AUTOINST*/ converted by
8967 \\[verilog-auto-inst]. Otherwise, it would have to read in the whole
8968 component library to determine connectivity of the design.
8970 One work around for this problem is to manually create // Inputs and //
8971 Outputs comments above subcell signals, for example:
8973 module ModuleName (
8974 // Outputs
8975 .out (out),
8976 // Inputs
8977 .in (in));"
8978 (save-excursion
8979 (let ((end-mod-point (verilog-get-end-of-defun))
8980 st-point end-inst-point par-values
8981 ;; below 3 modified by verilog-read-sub-decls-line
8982 sigs-out sigs-inout sigs-in sigs-intf sigs-intfd)
8983 (verilog-beg-of-defun-quick)
8984 (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t)
8985 (save-excursion
8986 (goto-char (match-beginning 0))
8987 (setq par-values (and verilog-auto-inst-param-value
8988 verilog-auto-inst-param-value-type
8989 (verilog-read-inst-param-value)))
8990 (unless (verilog-inside-comment-or-string-p)
8991 ;; Attempt to snarf a comment
8992 (let* ((submod (verilog-read-inst-module))
8993 (inst (verilog-read-inst-name))
8994 (subprim (member submod verilog-gate-keywords))
8995 (comment (concat inst " of " submod ".v"))
8996 submodi submoddecls)
8997 (cond
8998 (subprim
8999 (setq submodi `primitive
9000 submoddecls (verilog-decls-new nil nil nil nil nil nil nil nil nil)
9001 comment (concat inst " of " submod))
9002 (verilog-backward-open-paren)
9003 (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
9004 (point))
9005 st-point (point))
9006 (forward-char 1)
9007 (verilog-read-sub-decls-gate submoddecls par-values comment submod end-inst-point))
9008 ;; Non-primitive
9010 (when (setq submodi (verilog-modi-lookup submod t))
9011 (setq submoddecls (verilog-modi-get-decls submodi)
9012 verilog-read-sub-decls-gate-ios nil)
9013 (verilog-backward-open-paren)
9014 (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
9015 (point))
9016 st-point (point))
9017 ;; This could have used a list created by verilog-auto-inst
9018 ;; However I want it to be runnable even on user's manually added signals
9019 (let ((verilog-read-sub-decls-in-interfaced t))
9020 (while (re-search-forward "\\s *(?\\s *// Interfaced" end-inst-point t)
9021 (verilog-read-sub-decls-line submoddecls par-values comment))) ; Modifies sigs-ifd
9022 (goto-char st-point)
9023 (while (re-search-forward "\\s *(?\\s *// Interfaces" end-inst-point t)
9024 (verilog-read-sub-decls-line submoddecls par-values comment)) ; Modifies sigs-out
9025 (goto-char st-point)
9026 (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t)
9027 (verilog-read-sub-decls-line submoddecls par-values comment)) ; Modifies sigs-out
9028 (goto-char st-point)
9029 (while (re-search-forward "\\s *(?\\s *// Inouts" end-inst-point t)
9030 (verilog-read-sub-decls-line submoddecls par-values comment)) ; Modifies sigs-inout
9031 (goto-char st-point)
9032 (while (re-search-forward "\\s *(?\\s *// Inputs" end-inst-point t)
9033 (verilog-read-sub-decls-line submoddecls par-values comment)) ; Modifies sigs-in
9034 )))))))
9035 ;; Combine duplicate bits
9036 ;;(setq rr (vector sigs-out sigs-inout sigs-in))
9037 (verilog-subdecls-new
9038 (verilog-signals-combine-bus (nreverse sigs-out))
9039 (verilog-signals-combine-bus (nreverse sigs-inout))
9040 (verilog-signals-combine-bus (nreverse sigs-in))
9041 (verilog-signals-combine-bus (nreverse sigs-intf))
9042 (verilog-signals-combine-bus (nreverse sigs-intfd))))))
9044 (defun verilog-read-inst-pins ()
9045 "Return an array of [ pins ] for the current instantiation at point.
9046 For example if declare A A (.B(SIG)) then B will be included in the list."
9047 (save-excursion
9048 (let ((end-mod-point (point)) ; presume at /*AUTOINST*/ point
9049 pins pin)
9050 (verilog-backward-open-paren)
9051 (while (re-search-forward "\\.\\([^(,) \t\n\f]*\\)\\s-*" end-mod-point t)
9052 (setq pin (match-string 1))
9053 (unless (verilog-inside-comment-or-string-p)
9054 (setq pins (cons (list pin) pins))
9055 (when (looking-at "(")
9056 (verilog-forward-sexp-ign-cmt 1))))
9057 (vector pins))))
9059 (defun verilog-read-arg-pins ()
9060 "Return an array of [ pins ] for the current argument declaration at point."
9061 (save-excursion
9062 (let ((end-mod-point (point)) ; presume at /*AUTOARG*/ point
9063 pins pin)
9064 (verilog-backward-open-paren)
9065 (while (re-search-forward "\\([a-zA-Z0-9$_.%`]+\\)" end-mod-point t)
9066 (setq pin (match-string 1))
9067 (unless (verilog-inside-comment-or-string-p)
9068 (setq pins (cons (list pin) pins))))
9069 (vector pins))))
9071 (defun verilog-read-auto-constants (beg end-mod-point)
9072 "Return a list of AUTO_CONSTANTs used in the region from BEG to END-MOD-POINT."
9073 ;; Insert new
9074 (save-excursion
9075 (let (sig-list tpl-end-pt)
9076 (goto-char beg)
9077 (while (re-search-forward "\\<AUTO_CONSTANT" end-mod-point t)
9078 (if (not (looking-at "\\s *("))
9079 (error "%s: Missing () after AUTO_CONSTANT" (verilog-point-text)))
9080 (search-forward "(" end-mod-point)
9081 (setq tpl-end-pt (save-excursion
9082 (backward-char 1)
9083 (verilog-forward-sexp-cmt 1) ; Moves to paren that closes argdecl's
9084 (backward-char 1)
9085 (point)))
9086 (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t)
9087 (setq sig-list (cons (list (match-string 1) nil nil) sig-list))))
9088 sig-list)))
9090 (defvar verilog-cache-has-lisp nil "True if any AUTO_LISP in buffer.")
9091 (make-variable-buffer-local 'verilog-cache-has-lisp)
9093 (defun verilog-read-auto-lisp-present ()
9094 "Set `verilog-cache-has-lisp' if any AUTO_LISP in this buffer."
9095 (save-excursion
9096 (goto-char (point-min))
9097 (setq verilog-cache-has-lisp (re-search-forward "\\<AUTO_LISP(" nil t))))
9099 (defun verilog-read-auto-lisp (start end)
9100 "Look for and evaluate an AUTO_LISP between START and END.
9101 Must call `verilog-read-auto-lisp-present' before this function."
9102 ;; This function is expensive for large buffers, so we cache if any AUTO_LISP exists
9103 (when verilog-cache-has-lisp
9104 (save-excursion
9105 (goto-char start)
9106 (while (re-search-forward "\\<AUTO_LISP(" end t)
9107 (backward-char)
9108 (let* ((beg-pt (prog1 (point)
9109 (verilog-forward-sexp-cmt 1))) ; Closing paren
9110 (end-pt (point))
9111 (verilog-in-hooks t))
9112 (eval-region beg-pt end-pt nil))))))
9114 (defun verilog-read-always-signals-recurse
9115 (exit-keywd rvalue temp-next)
9116 "Recursive routine for parentheses/bracket matching.
9117 EXIT-KEYWD is expression to stop at, nil if top level.
9118 RVALUE is true if at right hand side of equal.
9119 IGNORE-NEXT is true to ignore next token, fake from inside case statement."
9120 (let* ((semi-rvalue (equal "endcase" exit-keywd)) ; true if after a ; we are looking for rvalue
9121 keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-list end-else-check
9122 ignore-next)
9123 ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue temp-next))))
9124 (while (not (or (eobp) gotend))
9125 (cond
9126 ((looking-at "//")
9127 (search-forward "\n"))
9128 ((looking-at "/\\*")
9129 (or (search-forward "*/")
9130 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
9131 ((looking-at "(\\*")
9132 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
9133 (forward-char 1)
9134 (or (search-forward "*)")
9135 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
9136 (t (setq keywd (buffer-substring-no-properties
9137 (point)
9138 (save-excursion (when (eq 0 (skip-chars-forward "a-zA-Z0-9$_.%`"))
9139 (forward-char 1))
9140 (point)))
9141 sig-last-tolk sig-tolk
9142 sig-tolk nil)
9143 ;;(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))))
9144 (cond
9145 ((equal keywd "\"")
9146 (or (re-search-forward "[^\\]\"" nil t)
9147 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
9148 ;; else at top level loop, keep parsing
9149 ((and end-else-check (equal keywd "else"))
9150 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else %s\n" keywd))))
9151 ;; no forward movement, want to see else in lower loop
9152 (setq end-else-check nil))
9153 ;; End at top level loop
9154 ((and end-else-check (looking-at "[^ \t\n\f]"))
9155 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else-other %s\n" keywd))))
9156 (setq gotend t))
9157 ;; Final statement?
9158 ((and exit-keywd (and (equal keywd exit-keywd)
9159 (not (looking-at "::"))))
9160 (setq gotend t)
9161 (forward-char (length keywd)))
9162 ;; Standard tokens...
9163 ((equal keywd ";")
9164 (setq ignore-next nil rvalue semi-rvalue)
9165 ;; Final statement at top level loop?
9166 (when (not exit-keywd)
9167 ;;(if dbg (setq dbg (concat dbg (format "\ttop-end-check %s\n" keywd))))
9168 (setq end-else-check t))
9169 (forward-char 1))
9170 ((equal keywd "'")
9171 (if (looking-at "'[sS]?[hdxboHDXBO]?[ \t]*[0-9a-fA-F_xzXZ?]+")
9172 (goto-char (match-end 0))
9173 (forward-char 1)))
9174 ((equal keywd ":") ; Case statement, begin/end label, x?y:z
9175 (cond ((looking-at "::")
9176 (forward-char 1)) ; Another forward-char below
9177 ((equal "endcase" exit-keywd) ; case x: y=z; statement next
9178 (setq ignore-next nil rvalue nil))
9179 ((equal "?" exit-keywd) ; x?y:z rvalue
9180 ) ; NOP
9181 ((equal "]" exit-keywd) ; [x:y] rvalue
9182 ) ; NOP
9183 (got-sig ; label: statement
9184 (setq ignore-next nil rvalue semi-rvalue got-sig nil))
9185 ((not rvalue) ; begin label
9186 (setq ignore-next t rvalue nil)))
9187 (forward-char 1))
9188 ((equal keywd "=")
9189 (when got-sig
9190 ;;(if dbg (setq dbg (concat dbg (format "\t\tequal got-sig=%S got-list=%s\n" got-sig got-list))))
9191 (set got-list (cons got-sig (symbol-value got-list)))
9192 (setq got-sig nil))
9193 (when (not rvalue)
9194 (if (eq (char-before) ?< )
9195 (setq sigs-out-d (append sigs-out-d sigs-out-unk)
9196 sigs-out-unk nil)
9197 (setq sigs-out-i (append sigs-out-i sigs-out-unk)
9198 sigs-out-unk nil)))
9199 (setq ignore-next nil rvalue t)
9200 (forward-char 1))
9201 ((equal keywd "?")
9202 (forward-char 1)
9203 (verilog-read-always-signals-recurse ":" rvalue nil))
9204 ((equal keywd "[")
9205 (forward-char 1)
9206 (verilog-read-always-signals-recurse "]" t nil))
9207 ((equal keywd "(")
9208 (forward-char 1)
9209 (cond (sig-last-tolk ; Function call; zap last signal
9210 (setq got-sig nil)))
9211 (cond ((equal last-keywd "for")
9212 ;; temp-next: Variables on LHS are lvalues, but generally we want
9213 ;; to ignore them, assuming they are loop increments
9214 (verilog-read-always-signals-recurse ";" nil t)
9215 (verilog-read-always-signals-recurse ";" t nil)
9216 (verilog-read-always-signals-recurse ")" nil nil))
9217 (t (verilog-read-always-signals-recurse ")" t nil))))
9218 ((equal keywd "begin")
9219 (skip-syntax-forward "w_")
9220 (verilog-read-always-signals-recurse "end" nil nil)
9221 ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd))))
9222 (setq ignore-next nil rvalue semi-rvalue)
9223 (if (not exit-keywd) (setq end-else-check t)))
9224 ((member keywd '("case" "casex" "casez" "randcase"))
9225 (skip-syntax-forward "w_")
9226 (verilog-read-always-signals-recurse "endcase" t nil)
9227 (setq ignore-next nil rvalue semi-rvalue)
9228 (if (not exit-keywd) (setq gotend t))) ; top level begin/end
9229 ((string-match "^[$`a-zA-Z_]" keywd) ; not exactly word constituent
9230 (cond ((member keywd '("`ifdef" "`ifndef" "`elsif"))
9231 (setq ignore-next t))
9232 ((or ignore-next
9233 (member keywd verilog-keywords)
9234 (string-match "^\\$" keywd)) ; PLI task
9235 (setq ignore-next nil))
9237 (setq keywd (verilog-symbol-detick-denumber keywd))
9238 (when got-sig
9239 (set got-list (cons got-sig (symbol-value got-list)))
9240 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S got-list=%S\n" got-sig got-list))))
9242 (setq got-list (cond (temp-next 'sigs-temp)
9243 (rvalue 'sigs-in)
9244 (t 'sigs-out-unk))
9245 got-sig (if (or (not keywd)
9246 (assoc keywd (symbol-value got-list)))
9247 nil (list keywd nil nil))
9248 temp-next nil
9249 sig-tolk t)))
9250 (skip-chars-forward "a-zA-Z0-9$_.%`"))
9252 (forward-char 1)))
9253 ;; End of non-comment token
9254 (setq last-keywd keywd)))
9255 (skip-syntax-forward " "))
9256 ;; Append the final pending signal
9257 (when got-sig
9258 ;;(if dbg (setq dbg (concat dbg (format "\t\tfinal got-sig=%S got-list=%s\n" got-sig got-list))))
9259 (set got-list (cons got-sig (symbol-value got-list)))
9260 (setq got-sig nil))
9261 ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd))))
9264 (defun verilog-read-always-signals ()
9265 "Parse always block at point and return list of (outputs inout inputs)."
9266 (save-excursion
9267 (let* (;(dbg "")
9268 sigs-out-d sigs-out-i sigs-out-unk sigs-temp sigs-in)
9269 (verilog-read-always-signals-recurse nil nil nil)
9270 (setq sigs-out-i (append sigs-out-i sigs-out-unk)
9271 sigs-out-unk nil)
9272 ;;(if dbg (with-current-buffer (get-buffer-create "*vl-dbg*") (delete-region (point-min) (point-max)) (insert dbg) (setq dbg "")))
9273 ;; Return what was found
9274 (verilog-alw-new sigs-out-d sigs-out-i sigs-temp sigs-in))))
9276 (defun verilog-read-instants ()
9277 "Parse module at point and return list of ( ( file instance ) ... )."
9278 (verilog-beg-of-defun-quick)
9279 (let* ((end-mod-point (verilog-get-end-of-defun))
9280 (state nil)
9281 (instants-list nil))
9282 (save-excursion
9283 (while (< (point) end-mod-point)
9284 ;; Stay at level 0, no comments
9285 (while (progn
9286 (setq state (parse-partial-sexp (point) end-mod-point 0 t nil))
9287 (or (> (car state) 0) ; in parens
9288 (nth 5 state) ; comment
9290 (forward-line 1))
9291 (beginning-of-line)
9292 (if (looking-at "^\\s-*\\([a-zA-Z0-9`_$]+\\)\\s-+\\([a-zA-Z0-9`_$]+\\)\\s-*(")
9293 ;;(if (looking-at "^\\(.+\\)$")
9294 (let ((module (match-string 1))
9295 (instant (match-string 2)))
9296 (if (not (member module verilog-keywords))
9297 (setq instants-list (cons (list module instant) instants-list)))))
9298 (forward-line 1)))
9299 instants-list))
9302 (defun verilog-read-auto-template-middle ()
9303 "With point in middle of an AUTO_TEMPLATE, parse it.
9304 Returns REGEXP and list of ( (signal_name connection_name)... )."
9305 (save-excursion
9306 ;; Find beginning
9307 (let ((tpl-regexp "\\([0-9]+\\)")
9308 (lineno -1) ; -1 to offset for the AUTO_TEMPLATE's newline
9309 (templateno 0)
9310 tpl-sig-list tpl-wild-list tpl-end-pt rep)
9311 ;; Parse "REGEXP"
9312 ;; We reserve @"..." for future lisp expressions that evaluate
9313 ;; once-per-AUTOINST
9314 (when (looking-at "\\s-*\"\\([^\"]*\\)\"")
9315 (setq tpl-regexp (match-string 1))
9316 (goto-char (match-end 0)))
9317 (search-forward "(")
9318 ;; Parse lines in the template
9319 (when (or verilog-auto-inst-template-numbers
9320 verilog-auto-template-warn-unused)
9321 (save-excursion
9322 (let ((pre-pt (point)))
9323 (goto-char (point-min))
9324 (while (search-forward "AUTO_TEMPLATE" pre-pt t)
9325 (setq templateno (1+ templateno)))
9326 (while (< (point) pre-pt)
9327 (forward-line 1)
9328 (setq lineno (1+ lineno))))))
9329 (setq tpl-end-pt (save-excursion
9330 (backward-char 1)
9331 (verilog-forward-sexp-cmt 1) ; Moves to paren that closes argdecl's
9332 (backward-char 1)
9333 (point)))
9335 (while (< (point) tpl-end-pt)
9336 (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
9337 (setq tpl-sig-list
9338 (cons (list
9339 (match-string-no-properties 1)
9340 (match-string-no-properties 2)
9341 templateno lineno)
9342 tpl-sig-list))
9343 (goto-char (match-end 0)))
9344 ;; Regexp form??
9345 ((looking-at
9346 ;; Regexp bug in XEmacs disallows ][ inside [], and wants + last
9347 "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]+\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
9348 (setq rep (match-string-no-properties 3))
9349 (goto-char (match-end 0))
9350 (setq tpl-wild-list
9351 (cons (list
9352 (concat "^"
9353 (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil
9354 (match-string 1))
9355 "$")
9357 templateno lineno)
9358 tpl-wild-list)))
9359 ((looking-at "[ \t\f]+")
9360 (goto-char (match-end 0)))
9361 ((looking-at "\n")
9362 (setq lineno (1+ lineno))
9363 (goto-char (match-end 0)))
9364 ((looking-at "//")
9365 (search-forward "\n")
9366 (setq lineno (1+ lineno)))
9367 ((looking-at "/\\*")
9368 (forward-char 2)
9369 (or (search-forward "*/")
9370 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
9372 (error "%s: AUTO_TEMPLATE parsing error: %s"
9373 (verilog-point-text)
9374 (progn (looking-at ".*$") (match-string 0))))))
9375 ;; Return
9376 (vector tpl-regexp
9377 (list tpl-sig-list tpl-wild-list)))))
9379 (defun verilog-read-auto-template (module)
9380 "Look for an auto_template for the instantiation of the given MODULE.
9381 If found returns `verilog-read-auto-template-inside' structure."
9382 (save-excursion
9383 ;; Find beginning
9384 (let ((pt (point)))
9385 ;; Note this search is expensive, as we hunt from mod-begin to point
9386 ;; for every instantiation. Likewise in verilog-read-auto-lisp.
9387 ;; So, we look first for an exact string rather than a slow regexp.
9388 ;; Someday we may keep a cache of every template, but this would also
9389 ;; need to record the relative position of each AUTOINST, as multiple
9390 ;; templates exist for each module, and we're inserting lines.
9391 (cond ((or
9392 ;; See also regexp in `verilog-auto-template-lint'
9393 (verilog-re-search-backward-substr
9394 "AUTO_TEMPLATE"
9395 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)
9396 ;; Also try forward of this AUTOINST
9397 ;; This is for historical support; this isn't speced as working
9398 (progn
9399 (goto-char pt)
9400 (verilog-re-search-forward-substr
9401 "AUTO_TEMPLATE"
9402 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)))
9403 (goto-char (match-end 0))
9404 (verilog-read-auto-template-middle))
9405 ;; If no template found
9406 (t (vector "" nil))))))
9407 ;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry"))
9409 (defvar verilog-auto-template-hits nil "Successful lookups with `verilog-read-auto-template-hit'.")
9410 (make-variable-buffer-local 'verilog-auto-template-hits)
9412 (defun verilog-read-auto-template-init ()
9413 "Initialize `verilog-read-auto-template'."
9414 (when (eval-when-compile (fboundp 'make-hash-table)) ; else feature not allowed
9415 (when verilog-auto-template-warn-unused
9416 (setq verilog-auto-template-hits
9417 (make-hash-table :test 'equal :rehash-size 4.0)))))
9419 (defun verilog-read-auto-template-hit (tpl-ass)
9420 "Record that TPL-ASS template from `verilog-read-auto-template' was used."
9421 (when (eval-when-compile (fboundp 'make-hash-table)) ; else feature not allowed
9422 (when verilog-auto-template-warn-unused
9423 (unless verilog-auto-template-hits
9424 (verilog-read-auto-template-init))
9425 (puthash (vector (nth 2 tpl-ass) (nth 3 tpl-ass)) t
9426 verilog-auto-template-hits))))
9428 (defun verilog-set-define (defname defvalue &optional buffer enumname)
9429 "Set the definition DEFNAME to the DEFVALUE in the given BUFFER.
9430 Optionally associate it with the specified enumeration ENUMNAME."
9431 (with-current-buffer (or buffer (current-buffer))
9432 ;; Namespace intentionally short for AUTOs and compatibility
9433 (let ((mac (intern (concat "vh-" defname))))
9434 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
9435 ;; Need to define to a constant if no value given
9436 (set (make-local-variable mac)
9437 (if (equal defvalue "") "1" defvalue)))
9438 (if enumname
9439 ;; Namespace intentionally short for AUTOs and compatibility
9440 (let ((enumvar (intern (concat "venum-" enumname))))
9441 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
9442 (unless (boundp enumvar) (set enumvar nil))
9443 (add-to-list (make-local-variable enumvar) defname)))))
9445 (defun verilog-read-defines (&optional filename recurse subcall)
9446 "Read \\=`defines and parameters for the current file, or optional FILENAME.
9447 If the filename is provided, `verilog-library-flags' will be used to
9448 resolve it. If optional RECURSE is non-nil, recurse through \\=`includes.
9450 Localparams must be simple assignments to constants, or have their own
9451 \"localparam\" label rather than a list of localparams. Thus:
9453 localparam X = 5, Y = 10; // Ok
9454 localparam X = {1\\='b1, 2\\='h2}; // Ok
9455 localparam X = {1\\='b1, 2\\='h2}, Y = 10; // Bad, make into 2 localparam lines
9457 Defines must be simple text substitutions, one on a line, starting
9458 at the beginning of the line. Any ifdefs or multiline comments around the
9459 define are ignored.
9461 Defines are stored inside Emacs variables using the name
9462 vh-{definename}.
9464 Localparams define what symbols are constants so that AUTOSENSE
9465 will not include them in sensitivity lists. However any
9466 parameters in the include file are not considered ports in the
9467 including file, thus will not appear in AUTOINSTPARAM lists for a
9468 parent module..
9470 The file variables feature can be used to set defines that
9471 `verilog-mode' can see; put at the *END* of your file something
9472 like:
9474 // Local Variables:
9475 // vh-macro:\"macro_definition\"
9476 // End:
9478 If macros are defined earlier in the same file and you want their values,
9479 you can read them automatically with:
9481 // Local Variables:
9482 // verilog-auto-read-includes:t
9483 // End:
9485 Or a more specific alternative example, which requires having
9486 `enable-local-eval' non-nil:
9488 // Local Variables:
9489 // eval:(verilog-read-defines)
9490 // eval:(verilog-read-defines \"group_standard_includes.v\")
9491 // End:
9493 Note these are only read when the file is first visited, you must use
9494 \\[find-alternate-file] RET to have these take effect after editing them!
9496 If you want to disable the \"Process `eval' or hook local variables\"
9497 warning message, you need to add to your init file:
9499 (setq enable-local-eval t)"
9500 (let ((origbuf (current-buffer)))
9501 (save-excursion
9502 (unless subcall (verilog-getopt-flags))
9503 (when filename
9504 (let ((fns (verilog-library-filenames filename (buffer-file-name))))
9505 (if fns
9506 (set-buffer (find-file-noselect (car fns)))
9507 (error "%s: Can't find verilog-read-defines file: %s"
9508 (verilog-point-text) filename))))
9509 (when recurse
9510 (goto-char (point-min))
9511 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
9512 (let ((inc (verilog-string-replace-matches
9513 "\"" "" nil nil (match-string-no-properties 1))))
9514 (unless (verilog-inside-comment-or-string-p)
9515 (verilog-read-defines inc recurse t)))))
9516 ;; Read `defines
9517 ;; note we don't use verilog-re... it's faster this way, and that
9518 ;; function has problems when comments are at the end of the define
9519 (goto-char (point-min))
9520 (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t)
9521 (let ((defname (match-string-no-properties 1))
9522 (defvalue (match-string-no-properties 2)))
9523 (unless (verilog-inside-comment-or-string-p (match-beginning 0))
9524 (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue))
9525 (verilog-set-define defname defvalue origbuf))))
9526 ;; Hack: Read parameters
9527 (goto-char (point-min))
9528 (while (re-search-forward
9529 "^\\s-*\\(parameter\\|localparam\\)\\(\\s-*\\[[^]]*\\]\\)?\\s-*" nil t)
9530 (let (enumname)
9531 ;; The primary way of getting defines is verilog-read-decls
9532 ;; However, that isn't called yet for included files, so we'll add another scheme
9533 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
9534 (setq enumname (match-string-no-properties 2)))
9535 (forward-comment 99999)
9536 (while (looking-at (concat "\\s-*,?\\s-*\\(?:/[/*].*?$\\)?\\s-*\\([a-zA-Z0-9_$]+\\)"
9537 "\\s-*=\\s-*\\([^;,]*\\),?\\s-*\\(/[/*].*?$\\)?\\s-*"))
9538 (unless (verilog-inside-comment-or-string-p (match-beginning 0))
9539 (verilog-set-define (match-string-no-properties 1)
9540 (match-string-no-properties 2) origbuf enumname))
9541 (goto-char (match-end 0))
9542 (forward-comment 99999)))))))
9544 (defun verilog-read-includes ()
9545 "Read \\=`includes for the current file.
9546 This will find all of the \\=`includes which are at the beginning of lines,
9547 ignoring any ifdefs or multiline comments around them.
9548 `verilog-read-defines' is then performed on the current and each included
9549 file.
9551 It is often useful put at the *END* of your file something like:
9553 // Local Variables:
9554 // verilog-auto-read-includes:t
9555 // End:
9557 Or the equivalent longer version, which requires having
9558 `enable-local-eval' non-nil:
9560 // Local Variables:
9561 // eval:(verilog-read-defines)
9562 // eval:(verilog-read-includes)
9563 // End:
9565 Note includes are only read when the file is first visited, you must use
9566 \\[find-alternate-file] RET to have these take effect after editing them!
9568 It is good to get in the habit of including all needed files in each .v
9569 file that needs it, rather than waiting for compile time. This will aid
9570 this process, Verilint, and readability. To prevent defining the same
9571 variable over and over when many modules are compiled together, put a test
9572 around the inside each include file:
9574 foo.v (an include file):
9575 \\=`ifdef _FOO_V // include if not already included
9576 \\=`else
9577 \\=`define _FOO_V
9578 ... contents of file
9579 \\=`endif // _FOO_V"
9580 ;;slow: (verilog-read-defines nil t)
9581 (save-excursion
9582 (verilog-getopt-flags)
9583 (goto-char (point-min))
9584 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
9585 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string 1))))
9586 (verilog-read-defines inc nil t)))))
9588 (defun verilog-read-signals (&optional start end)
9589 "Return a simple list of all possible signals in the file.
9590 Bounded by optional region from START to END. Overly aggressive but fast.
9591 Some macros and such are also found and included. For dinotrace.el."
9592 (let (sigs-all keywd)
9593 (progn;save-excursion
9594 (goto-char (or start (point-min)))
9595 (setq end (or end (point-max)))
9596 (while (re-search-forward "[\"/a-zA-Z_.%`]" end t)
9597 (forward-char -1)
9598 (cond
9599 ((looking-at "//")
9600 (search-forward "\n"))
9601 ((looking-at "/\\*")
9602 (search-forward "*/"))
9603 ((looking-at "(\\*")
9604 (or (looking-at "(\\*\\s-*)") ; It's an "always @ (*)"
9605 (search-forward "*)")))
9606 ((eq ?\" (following-char))
9607 (re-search-forward "[^\\]\"")) ; don't forward-char first, since we look for a non backslash first
9608 ((looking-at "\\s-*\\([a-zA-Z0-9$_.%`]+\\)")
9609 (goto-char (match-end 0))
9610 (setq keywd (match-string-no-properties 1))
9611 (or (member keywd verilog-keywords)
9612 (member keywd sigs-all)
9613 (setq sigs-all (cons keywd sigs-all))))
9614 (t (forward-char 1))))
9615 ;; Return list
9616 sigs-all)))
9619 ;; Argument file parsing
9622 (defun verilog-getopt (arglist)
9623 "Parse -f, -v etc arguments in ARGLIST list or string."
9624 (unless (listp arglist) (setq arglist (list arglist)))
9625 (let ((space-args '())
9626 arg next-param)
9627 ;; Split on spaces, so users can pass whole command lines
9628 (while arglist
9629 (setq arg (car arglist)
9630 arglist (cdr arglist))
9631 (while (string-match "^\\([^ \t\n\f]+\\)[ \t\n\f]*\\(.*$\\)" arg)
9632 (setq space-args (append space-args
9633 (list (match-string-no-properties 1 arg))))
9634 (setq arg (match-string 2 arg))))
9635 ;; Parse arguments
9636 (while space-args
9637 (setq arg (car space-args)
9638 space-args (cdr space-args))
9639 (cond
9640 ;; Need another arg
9641 ((equal arg "-f")
9642 (setq next-param arg))
9643 ((equal arg "-v")
9644 (setq next-param arg))
9645 ((equal arg "-y")
9646 (setq next-param arg))
9647 ;; +libext+(ext1)+(ext2)...
9648 ((string-match "^\\+libext\\+\\(.*\\)" arg)
9649 (setq arg (match-string 1 arg))
9650 (while (string-match "\\([^+]+\\)\\+?\\(.*\\)" arg)
9651 (verilog-add-list-unique `verilog-library-extensions
9652 (match-string 1 arg))
9653 (setq arg (match-string 2 arg))))
9655 ((or (string-match "^-D\\([^+=]*\\)[+=]\\(.*\\)" arg) ; -Ddefine=val
9656 (string-match "^-D\\([^+=]*\\)\\(\\)" arg) ; -Ddefine
9657 (string-match "^\\+define\\([^+=]*\\)[+=]\\(.*\\)" arg) ; +define+val
9658 (string-match "^\\+define\\([^+=]*\\)\\(\\)" arg)) ; +define+define
9659 (verilog-set-define (match-string 1 arg) (match-string 2 arg)))
9661 ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ; +incdir+dir
9662 (string-match "^-I\\(.*\\)" arg)) ; -Idir
9663 (verilog-add-list-unique `verilog-library-directories
9664 (match-string 1 (substitute-in-file-name arg))))
9665 ;; Ignore
9666 ((equal "+librescan" arg))
9667 ((string-match "^-U\\(.*\\)" arg)) ; -Udefine
9668 ;; Second parameters
9669 ((equal next-param "-f")
9670 (setq next-param nil)
9671 (verilog-getopt-file (substitute-in-file-name arg)))
9672 ((equal next-param "-v")
9673 (setq next-param nil)
9674 (verilog-add-list-unique `verilog-library-files
9675 (substitute-in-file-name arg)))
9676 ((equal next-param "-y")
9677 (setq next-param nil)
9678 (verilog-add-list-unique `verilog-library-directories
9679 (substitute-in-file-name arg)))
9680 ;; Filename
9681 ((string-match "^[^-+]" arg)
9682 (verilog-add-list-unique `verilog-library-files
9683 (substitute-in-file-name arg)))
9684 ;; Default - ignore; no warning
9685 ))))
9686 ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir"))
9688 (defun verilog-getopt-file (filename)
9689 "Read Verilog options from the specified FILENAME."
9690 (save-excursion
9691 (let ((fns (verilog-library-filenames filename (buffer-file-name)))
9692 (orig-buffer (current-buffer))
9693 line)
9694 (if fns
9695 (set-buffer (find-file-noselect (car fns)))
9696 (error "%s: Can't find verilog-getopt-file -f file: %s"
9697 (verilog-point-text) filename))
9698 (goto-char (point-min))
9699 (while (not (eobp))
9700 (setq line (buffer-substring (point) (point-at-eol)))
9701 (forward-line 1)
9702 (when (string-match "//" line)
9703 (setq line (substring line 0 (match-beginning 0))))
9704 (with-current-buffer orig-buffer ; Variables are buffer-local, so need right context.
9705 (verilog-getopt line))))))
9707 (defun verilog-getopt-flags ()
9708 "Convert `verilog-library-flags' into standard library variables."
9709 ;; If the flags are local, then all the outputs should be local also
9710 (when (local-variable-p `verilog-library-flags (current-buffer))
9711 (mapc 'make-local-variable '(verilog-library-extensions
9712 verilog-library-directories
9713 verilog-library-files
9714 verilog-library-flags)))
9715 ;; Allow user to customize
9716 (verilog-run-hooks 'verilog-before-getopt-flags-hook)
9717 ;; Process arguments
9718 (verilog-getopt verilog-library-flags)
9719 ;; Allow user to customize
9720 (verilog-run-hooks 'verilog-getopt-flags-hook))
9722 (defun verilog-add-list-unique (varref object)
9723 "Append to VARREF list the given OBJECT,
9724 unless it is already a member of the variable's list."
9725 (unless (member object (symbol-value varref))
9726 (set varref (append (symbol-value varref) (list object))))
9727 varref)
9728 ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l)
9730 (defun verilog-current-flags ()
9731 "Convert `verilog-library-flags' and similar variables to command line.
9732 Used for __FLAGS__ in `verilog-expand-command'."
9733 (let ((cmd (mapconcat `concat verilog-library-flags " ")))
9734 (when (equal cmd "")
9735 (setq cmd (concat
9736 "+libext+" (mapconcat `concat verilog-library-extensions "+")
9737 (mapconcat (lambda (i) (concat " -y " i " +incdir+" i))
9738 verilog-library-directories "")
9739 (mapconcat (lambda (i) (concat " -v " i))
9740 verilog-library-files ""))))
9741 cmd))
9742 ;;(verilog-current-flags)
9745 ;;; Cached directory support:
9748 (defvar verilog-dir-cache-preserving nil
9749 "If true, the directory cache is enabled, and file system changes are ignored.
9750 See `verilog-dir-exists-p' and `verilog-dir-files'.")
9752 ;; If adding new cached variable, add also to verilog-preserve-dir-cache
9753 (defvar verilog-dir-cache-list nil
9754 "Alist of (((Cwd Dirname) Results)...) for caching `verilog-dir-files'.")
9755 (defvar verilog-dir-cache-lib-filenames nil
9756 "Cached data for `verilog-library-filenames'.")
9758 (defmacro verilog-preserve-dir-cache (&rest body)
9759 "Execute the BODY forms, allowing directory cache preservation within BODY.
9760 This means that changes inside BODY made to the file system will not be
9761 seen by the `verilog-dir-files' and related functions."
9762 `(let ((verilog-dir-cache-preserving (current-buffer))
9763 verilog-dir-cache-list
9764 verilog-dir-cache-lib-filenames)
9765 (progn ,@body)))
9767 (defun verilog-dir-files (dirname)
9768 "Return all filenames in the DIRNAME directory.
9769 Relative paths depend on the `default-directory'.
9770 Results are cached if inside `verilog-preserve-dir-cache'."
9771 (unless verilog-dir-cache-preserving
9772 (setq verilog-dir-cache-list nil)) ; Cache disabled
9773 ;; We don't use expand-file-name on the dirname to make key, as it's slow
9774 (let* ((cache-key (list dirname default-directory))
9775 (fass (assoc cache-key verilog-dir-cache-list))
9776 exp-dirname data)
9777 (cond (fass ; Return data from cache hit
9778 (nth 1 fass))
9780 (setq exp-dirname (expand-file-name dirname)
9781 data (and (file-directory-p exp-dirname)
9782 (directory-files exp-dirname nil nil nil)))
9783 ;; Note we also encache nil for non-existing dirs.
9784 (setq verilog-dir-cache-list (cons (list cache-key data)
9785 verilog-dir-cache-list))
9786 data))))
9787 ;; Miss-and-hit test:
9788 ;;(verilog-preserve-dir-cache (prin1 (verilog-dir-files "."))
9789 ;; (prin1 (verilog-dir-files ".")) nil)
9791 (defun verilog-dir-file-exists-p (filename)
9792 "Return true if FILENAME exists.
9793 Like `file-exists-p' but results are cached if inside
9794 `verilog-preserve-dir-cache'."
9795 (let* ((dirname (file-name-directory filename))
9796 ;; Correct for file-name-nondirectory returning same if no slash.
9797 (dirnamed (if (or (not dirname) (equal dirname filename))
9798 default-directory dirname))
9799 (flist (verilog-dir-files dirnamed)))
9800 (and flist
9801 (member (file-name-nondirectory filename) flist)
9802 t)))
9803 ;;(verilog-dir-file-exists-p "verilog-mode.el")
9804 ;;(verilog-dir-file-exists-p "../verilog-mode/verilog-mode.el")
9807 ;;; Module name lookup:
9810 (defun verilog-module-inside-filename-p (module filename)
9811 "Return modi if MODULE is specified inside FILENAME, else nil.
9812 Allows version control to check out the file if need be."
9813 (and (or (file-exists-p filename)
9814 (and (fboundp 'vc-backend)
9815 (vc-backend filename)))
9816 (let (modi type)
9817 (with-current-buffer (find-file-noselect filename)
9818 (save-excursion
9819 (goto-char (point-min))
9820 (while (and
9821 ;; It may be tempting to look for verilog-defun-re,
9822 ;; don't, it slows things down a lot!
9823 (verilog-re-search-forward-quick "\\<\\(module\\|interface\\|program\\)\\>" nil t)
9824 (setq type (match-string-no-properties 0))
9825 (verilog-re-search-forward-quick "[(;]" nil t))
9826 (if (equal module (verilog-read-module-name))
9827 (setq modi (verilog-modi-new module filename (point) type))))
9828 modi)))))
9830 (defun verilog-is-number (symbol)
9831 "Return true if SYMBOL is number-like."
9832 (or (string-match "^[0-9 \t:]+$" symbol)
9833 (string-match "^[---]*[0-9]+$" symbol)
9834 (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol)))
9836 (defun verilog-symbol-detick (symbol wing-it)
9837 "Return an expanded SYMBOL name without any defines.
9838 If the variable vh-{symbol} is defined, return that value.
9839 If undefined, and WING-IT, return just SYMBOL without the tick, else nil."
9840 (while (and symbol (string-match "^`" symbol))
9841 (setq symbol (substring symbol 1))
9842 (setq symbol
9843 ;; Namespace intentionally short for AUTOs and compatibility
9844 (if (boundp (intern (concat "vh-" symbol)))
9845 ;; Emacs has a bug where boundp on a buffer-local
9846 ;; variable in only one buffer returns t in another.
9847 ;; This can confuse, so check for nil.
9848 ;; Namespace intentionally short for AUTOs and compatibility
9849 (let ((val (eval (intern (concat "vh-" symbol)))))
9850 (if (eq val nil)
9851 (if wing-it symbol nil)
9852 val))
9853 (if wing-it symbol nil))))
9854 symbol)
9855 ;;(verilog-symbol-detick "`mod" nil)
9857 (defun verilog-symbol-detick-denumber (symbol)
9858 "Return SYMBOL with defines converted and any numbers dropped to nil."
9859 (when (string-match "^`" symbol)
9860 ;; This only will work if the define is a simple signal, not
9861 ;; something like a[b]. Sorry, it should be substituted into the parser
9862 (setq symbol
9863 (verilog-string-replace-matches
9864 "\\[[^0-9: \t]+\\]" "" nil nil
9865 (or (verilog-symbol-detick symbol nil)
9866 (if verilog-auto-sense-defines-constant
9868 symbol)))))
9869 (if (verilog-is-number symbol)
9871 symbol))
9873 (defun verilog-symbol-detick-text (text)
9874 "Return TEXT without any known defines.
9875 If the variable vh-{symbol} is defined, substitute that value."
9876 (let ((ok t) symbol val)
9877 (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text))
9878 (setq symbol (match-string 1 text))
9879 ;;(message symbol)
9880 (cond ((and
9881 ;; Namespace intentionally short for AUTOs and compatibility
9882 (boundp (intern (concat "vh-" symbol)))
9883 ;; Emacs has a bug where boundp on a buffer-local
9884 ;; variable in only one buffer returns t in another.
9885 ;; This can confuse, so check for nil.
9886 ;; Namespace intentionally short for AUTOs and compatibility
9887 (setq val (eval (intern (concat "vh-" symbol)))))
9888 (setq text (replace-match val nil nil text)))
9889 (t (setq ok nil)))))
9890 text)
9891 ;;(progn (setq vh-mod "`foo" vh-foo "bar") (verilog-symbol-detick-text "bar `mod `undefed"))
9893 (defun verilog-expand-dirnames (&optional dirnames)
9894 "Return a list of existing directories given a list of wildcarded DIRNAMES.
9895 Or, just the existing dirnames themselves if there are no wildcards."
9896 ;; Note this function is performance critical.
9897 ;; Do not call anything that requires disk access that cannot be cached.
9898 (interactive)
9899 (unless dirnames
9900 (error "`verilog-library-directories' should include at least `.'"))
9901 (setq dirnames (reverse dirnames)) ; not nreverse
9902 (let ((dirlist nil)
9903 pattern dirfile dirfiles dirname root filename rest basefile)
9904 (while dirnames
9905 (setq dirname (substitute-in-file-name (car dirnames))
9906 dirnames (cdr dirnames))
9907 (cond ((string-match (concat "^\\(\\|[/\\]*[^*?]*[/\\]\\)" ; root
9908 "\\([^/\\]*[*?][^/\\]*\\)" ; filename with *?
9909 "\\(.*\\)") ; rest
9910 dirname)
9911 (setq root (match-string 1 dirname)
9912 filename (match-string 2 dirname)
9913 rest (match-string 3 dirname)
9914 pattern filename)
9915 ;; now replace those * and ? with .+ and .
9916 ;; use ^ and /> to get only whole file names
9917 (setq pattern (verilog-string-replace-matches "[*]" ".+" nil nil pattern)
9918 pattern (verilog-string-replace-matches "[?]" "." nil nil pattern)
9919 pattern (concat "^" pattern "$")
9920 dirfiles (verilog-dir-files root))
9921 (while dirfiles
9922 (setq basefile (car dirfiles)
9923 dirfile (expand-file-name (concat root basefile rest))
9924 dirfiles (cdr dirfiles))
9925 (if (and (string-match pattern basefile)
9926 ;; Don't allow abc/*/rtl to match abc/rtl via ..
9927 (not (equal basefile "."))
9928 (not (equal basefile ".."))
9929 (file-directory-p dirfile))
9930 (setq dirlist (cons dirfile dirlist)))))
9931 ;; Defaults
9933 (if (file-directory-p dirname)
9934 (setq dirlist (cons dirname dirlist))))))
9935 dirlist))
9936 ;;(verilog-expand-dirnames (list "." ".." "nonexist" "../*" "/home/wsnyder/*/v"))
9938 (defun verilog-library-filenames (filename &optional current check-ext)
9939 "Return a search path to find the given FILENAME or module name.
9940 Uses the optional CURRENT filename or variable `buffer-file-name', plus
9941 `verilog-library-directories' and `verilog-library-extensions'
9942 variables to build the path. With optional CHECK-EXT also check
9943 `verilog-library-extensions'."
9944 (unless current (setq current (buffer-file-name)))
9945 (unless verilog-dir-cache-preserving
9946 (setq verilog-dir-cache-lib-filenames nil))
9947 (let* ((cache-key (list filename current check-ext))
9948 (fass (assoc cache-key verilog-dir-cache-lib-filenames))
9949 chkdirs chkdir chkexts fn outlist)
9950 (cond (fass ; Return data from cache hit
9951 (nth 1 fass))
9953 ;; Note this expand can't be easily cached, as we need to
9954 ;; pick up buffer-local variables for newly read sub-module files
9955 (setq chkdirs (verilog-expand-dirnames verilog-library-directories))
9956 (while chkdirs
9957 (setq chkdir (expand-file-name (car chkdirs)
9958 (file-name-directory current))
9959 chkexts (if check-ext verilog-library-extensions `("")))
9960 (while chkexts
9961 (setq fn (expand-file-name (concat filename (car chkexts))
9962 chkdir))
9963 ;;(message "Check for %s" fn)
9964 (if (verilog-dir-file-exists-p fn)
9965 (setq outlist (cons (expand-file-name
9966 fn (file-name-directory current))
9967 outlist)))
9968 (setq chkexts (cdr chkexts)))
9969 (setq chkdirs (cdr chkdirs)))
9970 (setq outlist (nreverse outlist))
9971 (setq verilog-dir-cache-lib-filenames
9972 (cons (list cache-key outlist)
9973 verilog-dir-cache-lib-filenames))
9974 outlist))))
9976 (defun verilog-module-filenames (module current)
9977 "Return a search path to find the given MODULE name.
9978 Uses the CURRENT filename, `verilog-library-extensions',
9979 `verilog-library-directories' and `verilog-library-files'
9980 variables to build the path."
9981 ;; Return search locations for it
9982 (append (list current) ; first, current buffer
9983 (verilog-library-filenames module current t)
9984 ;; Finally any libraries; fixed up if using e.g. tramp
9985 (mapcar (lambda (fname)
9986 (if (file-name-absolute-p fname)
9987 (concat (file-remote-p current) fname)
9988 fname))
9989 verilog-library-files)))
9992 ;; Module Information
9994 ;; Many of these functions work on "modi" a module information structure
9995 ;; A modi is: [module-name-string file-name begin-point]
9997 (defvar verilog-cache-enabled t
9998 "Non-nil enables caching of signals, etc. Set to nil for debugging to make things SLOW!")
10000 (defvar verilog-modi-cache-list nil
10001 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)...
10002 For speeding up verilog-modi-get-* commands.
10003 Buffer-local.")
10004 (make-variable-buffer-local 'verilog-modi-cache-list)
10006 (defvar verilog-modi-cache-preserve-tick nil
10007 "Modification tick after which the cache is still considered valid.
10008 Use `verilog-preserve-modi-cache' to set it.")
10009 (defvar verilog-modi-cache-preserve-buffer nil
10010 "Modification tick after which the cache is still considered valid.
10011 Use `verilog-preserve-modi-cache' to set it.")
10012 (defvar verilog-modi-cache-current-enable nil
10013 "Non-nil means allow caching `verilog-modi-current', set by let().")
10014 (defvar verilog-modi-cache-current nil
10015 "Currently active `verilog-modi-current', if any, set by let().")
10016 (defvar verilog-modi-cache-current-max nil
10017 "Current endmodule point for `verilog-modi-cache-current', if any.")
10019 (defun verilog-modi-current ()
10020 "Return the modi structure for the module currently at point, possibly cached."
10021 (cond ((and verilog-modi-cache-current
10022 (>= (point) (verilog-modi-get-point verilog-modi-cache-current))
10023 (<= (point) verilog-modi-cache-current-max))
10024 ;; Slow assertion, for debugging the cache:
10025 ;;(or (equal verilog-modi-cache-current (verilog-modi-current-get)) (debug))
10026 verilog-modi-cache-current)
10027 (verilog-modi-cache-current-enable
10028 (setq verilog-modi-cache-current (verilog-modi-current-get)
10029 verilog-modi-cache-current-max
10030 ;; The cache expires when we pass "endmodule" as then the
10031 ;; current modi may change to the next module
10032 ;; This relies on the AUTOs generally inserting, not deleting text
10033 (save-excursion
10034 (verilog-re-search-forward-quick verilog-end-defun-re nil nil)))
10035 verilog-modi-cache-current)
10037 (verilog-modi-current-get))))
10039 (defun verilog-modi-current-get ()
10040 "Return the modi structure for the module currently at point."
10041 (let* (name type pt)
10042 ;; read current module's name
10043 (save-excursion
10044 (verilog-re-search-backward-quick verilog-defun-re nil nil)
10045 (setq type (match-string-no-properties 0))
10046 (verilog-re-search-forward-quick "(" nil nil)
10047 (setq name (verilog-read-module-name))
10048 (setq pt (point)))
10049 ;; return modi - note this vector built two places
10050 (verilog-modi-new name (or (buffer-file-name) (current-buffer)) pt type)))
10052 (defvar verilog-modi-lookup-cache nil "Hash of (modulename modi).")
10053 (make-variable-buffer-local 'verilog-modi-lookup-cache)
10054 (defvar verilog-modi-lookup-last-current nil "Cache of `current-buffer' at last lookup.")
10055 (defvar verilog-modi-lookup-last-tick nil "Cache of `buffer-chars-modified-tick' at last lookup.")
10057 (defun verilog-modi-lookup (module allow-cache &optional ignore-error)
10058 "Find the file and point at which MODULE is defined.
10059 If ALLOW-CACHE is set, check and remember cache of previous lookups.
10060 Return modi if successful, else print message unless IGNORE-ERROR is true."
10061 (let* ((current (or (buffer-file-name) (current-buffer)))
10062 modi)
10063 ;; Check cache
10064 ;;(message "verilog-modi-lookup: %s" module)
10065 (cond ((and verilog-modi-lookup-cache
10066 verilog-cache-enabled
10067 allow-cache
10068 (setq modi (gethash module verilog-modi-lookup-cache))
10069 (equal verilog-modi-lookup-last-current current)
10070 ;; If hit is in current buffer, then tick must match
10071 (or (equal verilog-modi-lookup-last-tick (buffer-chars-modified-tick))
10072 (not (equal current (verilog-modi-file-or-buffer modi)))))
10073 ;;(message "verilog-modi-lookup: HIT %S" modi)
10074 modi)
10075 ;; Miss
10076 (t (let* ((realname (verilog-symbol-detick module t))
10077 (orig-filenames (verilog-module-filenames realname current))
10078 (filenames orig-filenames)
10079 mif)
10080 (while (and filenames (not mif))
10081 (if (not (setq mif (verilog-module-inside-filename-p realname (car filenames))))
10082 (setq filenames (cdr filenames))))
10083 ;; mif has correct form to become later elements of modi
10084 (setq modi mif)
10085 (or mif ignore-error
10086 (error
10087 (concat
10088 "%s: Can't locate `%s' module definition%s"
10089 "\n Check the verilog-library-directories variable."
10090 "\n I looked in (if not listed, doesn't exist):\n\t%s")
10091 (verilog-point-text) module
10092 (if (not (equal module realname))
10093 (concat " (Expanded macro to " realname ")")
10095 (mapconcat 'concat orig-filenames "\n\t")))
10096 (when (eval-when-compile (fboundp 'make-hash-table))
10097 (unless verilog-modi-lookup-cache
10098 (setq verilog-modi-lookup-cache
10099 (make-hash-table :test 'equal :rehash-size 4.0)))
10100 (puthash module modi verilog-modi-lookup-cache))
10101 (setq verilog-modi-lookup-last-current current
10102 verilog-modi-lookup-last-tick (buffer-chars-modified-tick)))))
10103 modi))
10105 (defun verilog-modi-filename (modi)
10106 "Filename of MODI, or name of buffer if it's never been saved."
10107 (if (bufferp (verilog-modi-file-or-buffer modi))
10108 (or (buffer-file-name (verilog-modi-file-or-buffer modi))
10109 (buffer-name (verilog-modi-file-or-buffer modi)))
10110 (verilog-modi-file-or-buffer modi)))
10112 (defun verilog-modi-goto (modi)
10113 "Move point/buffer to specified MODI."
10114 (or modi (error "Passed unfound modi to goto, check earlier"))
10115 (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi))
10116 (verilog-modi-file-or-buffer modi)
10117 (find-file-noselect (verilog-modi-file-or-buffer modi))))
10118 (or (equal major-mode `verilog-mode) ; Put into Verilog mode to get syntax
10119 (verilog-mode))
10120 (goto-char (verilog-modi-get-point modi)))
10122 (defun verilog-goto-defun-file (module)
10123 "Move point to the file at which a given MODULE is defined."
10124 (interactive "sGoto File for Module: ")
10125 (let* ((modi (verilog-modi-lookup module nil)))
10126 (when modi
10127 (verilog-modi-goto modi)
10128 (switch-to-buffer (current-buffer)))))
10130 (defun verilog-modi-cache-results (modi function)
10131 "Run on MODI the given FUNCTION. Locate the module in a file.
10132 Cache the output of function so next call may have faster access."
10133 (let (fass)
10134 (save-excursion ; Cache is buffer-local so can't avoid this.
10135 (verilog-modi-goto modi)
10136 (if (and (setq fass (assoc (list modi function)
10137 verilog-modi-cache-list))
10138 ;; Destroy caching when incorrect; Modified or file changed
10139 (not (and verilog-cache-enabled
10140 (or (equal (buffer-chars-modified-tick) (nth 1 fass))
10141 (and verilog-modi-cache-preserve-tick
10142 (<= verilog-modi-cache-preserve-tick (nth 1 fass))
10143 (equal verilog-modi-cache-preserve-buffer (current-buffer))))
10144 (equal (visited-file-modtime) (nth 2 fass)))))
10145 (setq verilog-modi-cache-list nil
10146 fass nil))
10147 (cond (fass
10148 ;; Return data from cache hit
10149 (nth 3 fass))
10151 ;; Read from file
10152 ;; Clear then restore any highlighting to make emacs19 happy
10153 (let ((func-returns
10154 (verilog-save-font-no-change-functions
10155 (funcall function))))
10156 ;; Cache for next time
10157 (setq verilog-modi-cache-list
10158 (cons (list (list modi function)
10159 (buffer-chars-modified-tick)
10160 (visited-file-modtime)
10161 func-returns)
10162 verilog-modi-cache-list))
10163 func-returns))))))
10165 (defun verilog-modi-cache-add (modi function element sig-list)
10166 "Add function return results to the module cache.
10167 Update MODI's cache for given FUNCTION so that the return ELEMENT of that
10168 function now contains the additional SIG-LIST parameters."
10169 (let (fass)
10170 (save-excursion
10171 (verilog-modi-goto modi)
10172 (if (setq fass (assoc (list modi function)
10173 verilog-modi-cache-list))
10174 (let ((func-returns (nth 3 fass)))
10175 (aset func-returns element
10176 (append sig-list (aref func-returns element))))))))
10178 (defmacro verilog-preserve-modi-cache (&rest body)
10179 "Execute the BODY forms, allowing cache preservation within BODY.
10180 This means that changes to the buffer will not result in the cache being
10181 flushed. If the changes affect the modsig state, they must call the
10182 modsig-cache-add-* function, else the results of later calls may be
10183 incorrect. Without this, changes are assumed to be adding/removing signals
10184 and invalidating the cache."
10185 `(let ((verilog-modi-cache-preserve-tick (buffer-chars-modified-tick))
10186 (verilog-modi-cache-preserve-buffer (current-buffer)))
10187 (progn ,@body)))
10190 (defun verilog-modi-modport-lookup-one (modi name &optional ignore-error)
10191 "Given a MODI, return the declarations related to the given modport NAME.
10192 Report errors unless optional IGNORE-ERROR."
10193 ;; Recursive routine - see below
10194 (let* ((realname (verilog-symbol-detick name t))
10195 (modport (assoc name (verilog-decls-get-modports (verilog-modi-get-decls modi)))))
10196 (or modport ignore-error
10197 (error "%s: Can't locate `%s' modport definition%s"
10198 (verilog-point-text) name
10199 (if (not (equal name realname))
10200 (concat " (Expanded macro to " realname ")")
10201 "")))
10202 (let* ((decls (verilog-modport-decls modport))
10203 (clks (verilog-modport-clockings modport)))
10204 ;; Now expand any clocking's
10205 (while clks
10206 (setq decls (verilog-decls-append
10207 decls
10208 (verilog-modi-modport-lookup-one modi (car clks) ignore-error)))
10209 (setq clks (cdr clks)))
10210 decls)))
10212 (defun verilog-modi-modport-lookup (modi name-re &optional ignore-error)
10213 "Given a MODI, return the declarations related to the given modport NAME-RE.
10214 If the modport points to any clocking blocks, expand the signals to include
10215 those clocking block's signals."
10216 ;; Recursive routine - see below
10217 (let* ((mod-decls (verilog-modi-get-decls modi))
10218 (clks (verilog-decls-get-modports mod-decls))
10219 (name-re (concat "^" name-re "$"))
10220 (decls (verilog-decls-new nil nil nil nil nil nil nil nil nil)))
10221 ;; Pull in all modports
10222 (while clks
10223 (when (string-match name-re (verilog-modport-name (car clks)))
10224 (setq decls (verilog-decls-append
10225 decls
10226 (verilog-modi-modport-lookup-one modi (verilog-modport-name (car clks)) ignore-error))))
10227 (setq clks (cdr clks)))
10228 decls))
10230 (defun verilog-signals-matching-enum (in-list enum)
10231 "Return all signals in IN-LIST matching the given ENUM."
10232 (let (out-list)
10233 (while in-list
10234 (if (equal (verilog-sig-enum (car in-list)) enum)
10235 (setq out-list (cons (car in-list) out-list)))
10236 (setq in-list (cdr in-list)))
10237 ;; New scheme
10238 ;; Namespace intentionally short for AUTOs and compatibility
10239 (let* ((enumvar (intern (concat "venum-" enum)))
10240 (enumlist (and (boundp enumvar) (eval enumvar))))
10241 (while enumlist
10242 (add-to-list 'out-list (list (car enumlist)))
10243 (setq enumlist (cdr enumlist))))
10244 (nreverse out-list)))
10246 (defun verilog-signals-matching-regexp (in-list regexp)
10247 "Return all signals in IN-LIST matching the given REGEXP, if non-nil."
10248 (if (or (not regexp) (equal regexp ""))
10249 in-list
10250 (let ((case-fold-search verilog-case-fold)
10251 out-list)
10252 (while in-list
10253 (if (string-match regexp (verilog-sig-name (car in-list)))
10254 (setq out-list (cons (car in-list) out-list)))
10255 (setq in-list (cdr in-list)))
10256 (nreverse out-list))))
10258 (defun verilog-signals-not-matching-regexp (in-list regexp)
10259 "Return all signals in IN-LIST not matching the given REGEXP, if non-nil."
10260 (if (or (not regexp) (equal regexp ""))
10261 in-list
10262 (let ((case-fold-search verilog-case-fold)
10263 out-list)
10264 (while in-list
10265 (if (not (string-match regexp (verilog-sig-name (car in-list))))
10266 (setq out-list (cons (car in-list) out-list)))
10267 (setq in-list (cdr in-list)))
10268 (nreverse out-list))))
10270 (defun verilog-signals-matching-dir-re (in-list decl-type regexp)
10271 "Return all signals in IN-LIST matching the given DECL-TYPE and REGEXP,
10272 if non-nil."
10273 (if (or (not regexp) (equal regexp ""))
10274 in-list
10275 (let (out-list to-match)
10276 (while in-list
10277 ;; Note verilog-insert-one-definition matches on this order
10278 (setq to-match (concat
10279 decl-type
10280 " " (verilog-sig-signed (car in-list))
10281 " " (verilog-sig-multidim (car in-list))
10282 (verilog-sig-bits (car in-list))))
10283 (if (string-match regexp to-match)
10284 (setq out-list (cons (car in-list) out-list)))
10285 (setq in-list (cdr in-list)))
10286 (nreverse out-list))))
10288 (defun verilog-signals-edit-wire-reg (in-list)
10289 "Return all signals in IN-LIST with wire/reg data types made blank."
10290 (mapcar (lambda (sig)
10291 (when (member (verilog-sig-type sig) '("wire" "reg"))
10292 (verilog-sig-type-set sig nil))
10293 sig) in-list))
10295 ;; Combined
10296 (defun verilog-decls-get-signals (decls)
10297 "Return all declared signals in DECLS, excluding `assign' statements."
10298 (append
10299 (verilog-decls-get-outputs decls)
10300 (verilog-decls-get-inouts decls)
10301 (verilog-decls-get-inputs decls)
10302 (verilog-decls-get-vars decls)
10303 (verilog-decls-get-consts decls)
10304 (verilog-decls-get-gparams decls)))
10306 (defun verilog-decls-get-ports (decls)
10307 (append
10308 (verilog-decls-get-outputs decls)
10309 (verilog-decls-get-inouts decls)
10310 (verilog-decls-get-inputs decls)))
10312 (defun verilog-decls-get-iovars (decls)
10313 (append
10314 (verilog-decls-get-vars decls)
10315 (verilog-decls-get-outputs decls)
10316 (verilog-decls-get-inouts decls)
10317 (verilog-decls-get-inputs decls)))
10319 (defsubst verilog-modi-cache-add-outputs (modi sig-list)
10320 (verilog-modi-cache-add modi 'verilog-read-decls 0 sig-list))
10321 (defsubst verilog-modi-cache-add-inouts (modi sig-list)
10322 (verilog-modi-cache-add modi 'verilog-read-decls 1 sig-list))
10323 (defsubst verilog-modi-cache-add-inputs (modi sig-list)
10324 (verilog-modi-cache-add modi 'verilog-read-decls 2 sig-list))
10325 (defsubst verilog-modi-cache-add-vars (modi sig-list)
10326 (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list))
10327 (defsubst verilog-modi-cache-add-gparams (modi sig-list)
10328 (verilog-modi-cache-add modi 'verilog-read-decls 7 sig-list))
10331 ;;; Auto creation utilities:
10334 (defun verilog-auto-re-search-do (search-for func)
10335 "Search for the given auto text regexp SEARCH-FOR, and perform FUNC where it occurs."
10336 (goto-char (point-min))
10337 (while (verilog-re-search-forward-quick search-for nil t)
10338 (funcall func)))
10340 (defun verilog-insert-one-definition (sig type indent-pt)
10341 "Print out a definition for SIG of the given TYPE,
10342 with appropriate INDENT-PT indentation."
10343 (indent-to indent-pt)
10344 ;; Note verilog-signals-matching-dir-re matches on this order
10345 (insert type)
10346 (when (verilog-sig-modport sig)
10347 (insert "." (verilog-sig-modport sig)))
10348 (when (verilog-sig-signed sig)
10349 (insert " " (verilog-sig-signed sig)))
10350 (when (verilog-sig-multidim sig)
10351 (insert " " (verilog-sig-multidim-string sig)))
10352 (when (verilog-sig-bits sig)
10353 (insert " " (verilog-sig-bits sig)))
10354 (indent-to (max 24 (+ indent-pt 16)))
10355 (unless (= (char-syntax (preceding-char)) ?\ )
10356 (insert " ")) ; Need space between "]name" if indent-to did nothing
10357 (insert (verilog-sig-name sig))
10358 (when (verilog-sig-memory sig)
10359 (insert " " (verilog-sig-memory sig))))
10361 (defun verilog-insert-definition (modi sigs direction indent-pt v2k &optional dont-sort)
10362 "Print out a definition for MODI's list of SIGS of the given DIRECTION,
10363 with appropriate INDENT-PT indentation. If V2K, use Verilog 2001 I/O
10364 format. Sort unless DONT-SORT. DIRECTION is normally wire/reg/output.
10365 When MODI is non-null, also add to modi-cache, for tracking."
10366 (when modi
10367 (cond ((equal direction "wire")
10368 (verilog-modi-cache-add-vars modi sigs))
10369 ((equal direction "reg")
10370 (verilog-modi-cache-add-vars modi sigs))
10371 ((equal direction "output")
10372 (verilog-modi-cache-add-outputs modi sigs)
10373 (when verilog-auto-declare-nettype
10374 (verilog-modi-cache-add-vars modi sigs)))
10375 ((equal direction "input")
10376 (verilog-modi-cache-add-inputs modi sigs)
10377 (when verilog-auto-declare-nettype
10378 (verilog-modi-cache-add-vars modi sigs)))
10379 ((equal direction "inout")
10380 (verilog-modi-cache-add-inouts modi sigs)
10381 (when verilog-auto-declare-nettype
10382 (verilog-modi-cache-add-vars modi sigs)))
10383 ((equal direction "interface"))
10384 ((equal direction "parameter")
10385 (verilog-modi-cache-add-gparams modi sigs))
10387 (error "Unsupported verilog-insert-definition direction: `%s'" direction))))
10388 (or dont-sort
10389 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
10390 (while sigs
10391 (let ((sig (car sigs)))
10392 (verilog-insert-one-definition
10394 ;; Want "type x" or "output type x", not "wire type x"
10395 (cond ((and (equal "wire" verilog-auto-wire-type)
10396 (or (not (verilog-sig-type sig))
10397 (equal "logic" (verilog-sig-type sig))))
10398 (if (member direction '("input" "output" "inout"))
10399 direction
10400 "wire"))
10402 ((or (verilog-sig-type sig)
10403 verilog-auto-wire-type)
10404 (concat
10405 (when (member direction '("input" "output" "inout"))
10406 (concat direction " "))
10407 (or (verilog-sig-type sig)
10408 verilog-auto-wire-type)))
10410 ((and verilog-auto-declare-nettype
10411 (member direction '("input" "output" "inout")))
10412 (concat direction " " verilog-auto-declare-nettype))
10414 direction))
10415 indent-pt)
10416 (insert (if v2k "," ";"))
10417 (if (or (not verilog-auto-wire-comment)
10418 (not (verilog-sig-comment sig))
10419 (equal "" (verilog-sig-comment sig)))
10420 (insert "\n")
10421 (indent-to (max 48 (+ indent-pt 40)))
10422 (verilog-insert "// " (verilog-sig-comment sig) "\n"))
10423 (setq sigs (cdr sigs)))))
10425 (eval-when-compile
10426 (if (not (boundp 'indent-pt))
10427 (defvar indent-pt nil "Local used by `verilog-insert-indent'.")))
10429 (defun verilog-insert-indent (&rest stuff)
10430 "Indent to position stored in local `indent-pt' variable, then insert STUFF.
10431 Presumes that any newlines end a list element."
10432 (let ((need-indent t))
10433 (while stuff
10434 (if need-indent (indent-to indent-pt))
10435 (setq need-indent nil)
10436 (verilog-insert (car stuff))
10437 (setq need-indent (string-match "\n$" (car stuff))
10438 stuff (cdr stuff)))))
10439 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n"))
10441 (defun verilog-forward-or-insert-line ()
10442 "Move forward a line, unless at EOB, then insert a newline."
10443 (if (eobp) (insert "\n")
10444 (forward-line)))
10446 (defun verilog-repair-open-comma ()
10447 "Insert comma if previous argument is other than an open parenthesis or endif."
10448 ;; We can't just search backward for ) as it might be inside another expression.
10449 ;; Also want "`ifdef X input foo `endif" to just leave things to the human to deal with
10450 (save-excursion
10451 (verilog-backward-syntactic-ws-quick)
10452 (when (and (not (save-excursion ; Not beginning (, or existing ,
10453 (backward-char 1)
10454 (looking-at "[(,]")))
10455 (not (save-excursion ; Not `endif, or user define
10456 (backward-char 1)
10457 (skip-chars-backward "[a-zA-Z0-9_`]")
10458 (looking-at "`"))))
10459 (insert ","))))
10461 (defun verilog-repair-close-comma ()
10462 "If point is at a comma followed by a close parenthesis, fix it.
10463 This repairs those mis-inserted by an AUTOARG."
10464 ;; It would be much nicer if Verilog allowed extra commas like Perl does!
10465 (save-excursion
10466 (verilog-forward-close-paren)
10467 (backward-char 1)
10468 (verilog-backward-syntactic-ws-quick)
10469 (backward-char 1)
10470 (when (looking-at ",")
10471 (delete-char 1))))
10473 (defun verilog-make-width-expression (range-exp)
10474 "Return an expression calculating the length of a range [x:y] in RANGE-EXP."
10475 ;; strip off the []
10476 (cond ((not range-exp)
10477 "1")
10479 (if (string-match "^\\[\\(.*\\)\\]$" range-exp)
10480 (setq range-exp (match-string 1 range-exp)))
10481 (cond ((not range-exp)
10482 "1")
10483 ;; [#:#] We can compute a numeric result
10484 ((string-match "^\\s *\\([0-9]+\\)\\s *:\\s *\\([0-9]+\\)\\s *$"
10485 range-exp)
10486 (int-to-string
10487 (1+ (abs (- (string-to-number (match-string 1 range-exp))
10488 (string-to-number (match-string 2 range-exp)))))))
10489 ;; [PARAM-1:0] can just return PARAM
10490 ((string-match "^\\s *\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s *-\\s *1\\s *:\\s *0\\s *$" range-exp)
10491 (match-string 1 range-exp))
10492 ;; [arbitrary] need math
10493 ((string-match "^\\(.*\\)\\s *:\\s *\\(.*\\)\\s *$" range-exp)
10494 (concat "(1+(" (match-string 1 range-exp) ")"
10495 (if (equal "0" (match-string 2 range-exp))
10496 "" ; Don't bother with -(0)
10497 (concat "-(" (match-string 2 range-exp) ")"))
10498 ")"))
10499 (t nil)))))
10500 ;;(verilog-make-width-expression "`A:`B")
10502 (defun verilog-simplify-range-expression (expr)
10503 "Return a simplified range expression with constants eliminated from EXPR."
10504 ;; Note this is always called with brackets; ie [z] or [z:z]
10505 (if (not (string-match "[---+*()]" expr))
10506 expr ; short-circuit
10507 (let ((out expr)
10508 (last-pass ""))
10509 (while (not (equal last-pass out))
10510 (setq last-pass out)
10511 ;; Prefix regexp needs beginning of match, or some symbol of
10512 ;; lesser or equal precedence. We assume the [:]'s exist in expr.
10513 ;; Ditto the end.
10514 (while (string-match
10515 (concat "\\([[({:*+-]\\)" ; - must be last
10516 "(\\<\\([0-9A-Za-z_]+\\))"
10517 "\\([])}:*+-]\\)")
10518 out)
10519 (setq out (replace-match "\\1\\2\\3" nil nil out)))
10520 (while (string-match
10521 (concat "\\([[({:*+-]\\)" ; - must be last
10522 "\\$clog2\\s *(\\<\\([0-9]+\\))"
10523 "\\([])}:*+-]\\)")
10524 out)
10525 (setq out (replace-match
10526 (concat
10527 (match-string 1 out)
10528 (int-to-string (verilog-clog2 (string-to-number (match-string 2 out))))
10529 (match-string 3 out))
10530 nil nil out)))
10531 ;; For precedence do * before +/-
10532 (while (string-match
10533 (concat "\\([[({:*+-]\\)"
10534 "\\([0-9]+\\)\\s *\\([*]\\)\\s *\\([0-9]+\\)"
10535 "\\([])}:*+-]\\)")
10536 out)
10537 (setq out (replace-match
10538 (concat (match-string 1 out)
10539 (int-to-string (* (string-to-number (match-string 2 out))
10540 (string-to-number (match-string 4 out))))
10541 (match-string 5 out))
10542 nil nil out)))
10543 (while (string-match
10544 (concat "\\([[({:+-]\\)" ; No * here as higher prec
10545 "\\([0-9]+\\)\\s *\\([---+]\\)\\s *\\([0-9]+\\)"
10546 "\\([])}:+-]\\)")
10547 out)
10548 (let ((pre (match-string 1 out))
10549 (lhs (string-to-number (match-string 2 out)))
10550 (rhs (string-to-number (match-string 4 out)))
10551 (post (match-string 5 out))
10552 val)
10553 (when (equal pre "-")
10554 (setq lhs (- lhs)))
10555 (setq val (if (equal (match-string 3 out) "-")
10556 (- lhs rhs)
10557 (+ lhs rhs))
10558 out (replace-match
10559 (concat (if (and (equal pre "-")
10560 (< val 0))
10561 "" ; Not "--20" but just "-20"
10562 pre)
10563 (int-to-string val)
10564 post)
10565 nil nil out)) )))
10566 out)))
10568 ;;(verilog-simplify-range-expression "[1:3]") ; 1
10569 ;;(verilog-simplify-range-expression "[(1):3]") ; 1
10570 ;;(verilog-simplify-range-expression "[(((16)+1)+1+(1+1))]") ; 20
10571 ;;(verilog-simplify-range-expression "[(2*3+6*7)]") ; 48
10572 ;;(verilog-simplify-range-expression "[(FOO*4-1*2)]") ; FOO*4-2
10573 ;;(verilog-simplify-range-expression "[(FOO*4+1-1)]") ; FOO*4+0
10574 ;;(verilog-simplify-range-expression "[(func(BAR))]") ; func(BAR)
10575 ;;(verilog-simplify-range-expression "[FOO-1+1-1+1]") ; FOO-0
10576 ;;(verilog-simplify-range-expression "[$clog2(2)]") ; 1
10577 ;;(verilog-simplify-range-expression "[$clog2(7)]") ; 3
10579 (defun verilog-clog2 (value)
10580 "Compute $clog2 - ceiling log2 of VALUE."
10581 (if (< value 1)
10583 (ceiling (/ (log value) (log 2)))))
10585 (defun verilog-typedef-name-p (variable-name)
10586 "Return true if the VARIABLE-NAME is a type definition."
10587 (when verilog-typedef-regexp
10588 (verilog-string-match-fold verilog-typedef-regexp variable-name)))
10590 ;;; Auto deletion:
10593 (defun verilog-delete-autos-lined ()
10594 "Delete autos that occupy multiple lines, between begin and end comments."
10595 ;; The newline must not have a comment property, so we must
10596 ;; delete the end auto's newline, not the first newline
10597 (forward-line 1)
10598 (let ((pt (point)))
10599 (when (and
10600 (looking-at "\\s-*// Beginning")
10601 (search-forward "// End of automatic" nil t))
10602 ;; End exists
10603 (end-of-line)
10604 (forward-line 1)
10605 (delete-region pt (point)))))
10607 (defun verilog-delete-empty-auto-pair ()
10608 "Delete begin/end auto pair at point, if empty."
10609 (forward-line 0)
10610 (when (looking-at (concat "\\s-*// Beginning of automatic.*\n"
10611 "\\s-*// End of automatics\n"))
10612 (delete-region (point) (save-excursion (forward-line 2) (point)))))
10614 (defun verilog-forward-close-paren ()
10615 "Find the close parenthesis that match the current point.
10616 Ignore other close parenthesis with matching open parens."
10617 (let ((parens 1))
10618 (while (> parens 0)
10619 (unless (verilog-re-search-forward-quick "[()]" nil t)
10620 (error "%s: Mismatching ()" (verilog-point-text)))
10621 (cond ((= (preceding-char) ?\( )
10622 (setq parens (1+ parens)))
10623 ((= (preceding-char) ?\) )
10624 (setq parens (1- parens)))))))
10626 (defun verilog-backward-open-paren ()
10627 "Find the open parenthesis that match the current point.
10628 Ignore other open parenthesis with matching close parens."
10629 (let ((parens 1))
10630 (while (> parens 0)
10631 (unless (verilog-re-search-backward-quick "[()]" nil t)
10632 (error "%s: Mismatching ()" (verilog-point-text)))
10633 (cond ((= (following-char) ?\) )
10634 (setq parens (1+ parens)))
10635 ((= (following-char) ?\( )
10636 (setq parens (1- parens)))))))
10638 (defun verilog-backward-open-bracket ()
10639 "Find the open bracket that match the current point.
10640 Ignore other open bracket with matching close bracket."
10641 (let ((parens 1))
10642 (while (> parens 0)
10643 (unless (verilog-re-search-backward-quick "[][]" nil t)
10644 (error "%s: Mismatching []" (verilog-point-text)))
10645 (cond ((= (following-char) ?\] )
10646 (setq parens (1+ parens)))
10647 ((= (following-char) ?\[ )
10648 (setq parens (1- parens)))))))
10650 (defun verilog-delete-to-paren ()
10651 "Delete the automatic inst/sense/arg created by autos.
10652 Deletion stops at the matching end parenthesis, outside comments."
10653 (delete-region (point)
10654 (save-excursion
10655 (verilog-backward-open-paren)
10656 (verilog-forward-sexp-ign-cmt 1) ; Moves to paren that closes argdecl's
10657 (backward-char 1)
10658 (point))))
10660 (defun verilog-auto-star-safe ()
10661 "Return if a .* AUTOINST is safe to delete or expand.
10662 It was created by the AUTOS themselves, or by the user."
10663 (and verilog-auto-star-expand
10664 (looking-at
10665 (concat "[ \t\n\f,]*\\([)]\\|// " verilog-inst-comment-re "\\)"))))
10667 (defun verilog-delete-auto-star-all ()
10668 "Delete a .* AUTOINST, if it is safe."
10669 (when (verilog-auto-star-safe)
10670 (verilog-delete-to-paren)))
10672 (defun verilog-delete-auto-star-implicit ()
10673 "Delete all .* implicit connections created by `verilog-auto-star'.
10674 This function will be called automatically at save unless
10675 `verilog-auto-star-save' is set, any non-templated expanded pins will be
10676 removed."
10677 (interactive)
10678 (let (paren-pt indent have-close-paren)
10679 (save-excursion
10680 (goto-char (point-min))
10681 ;; We need to match these even outside of comments.
10682 ;; For reasonable performance, we don't check if inside comments, sorry.
10683 (while (re-search-forward "// Implicit \\.\\*" nil t)
10684 (setq paren-pt (point))
10685 (beginning-of-line)
10686 (setq have-close-paren
10687 (save-excursion
10688 (when (search-forward ");" paren-pt t)
10689 (setq indent (current-indentation))
10690 t)))
10691 (delete-region (point) (+ 1 paren-pt)) ; Nuke line incl CR
10692 (when have-close-paren
10693 ;; Delete extra commentary
10694 (save-excursion
10695 (while (progn
10696 (forward-line -1)
10697 (looking-at (concat "\\s *//\\s *" verilog-inst-comment-re "\n")))
10698 (delete-region (match-beginning 0) (match-end 0))))
10699 ;; If it is simple, we can put the ); on the same line as the last text
10700 (let ((rtn-pt (point)))
10701 (save-excursion
10702 (while (progn (backward-char 1)
10703 (looking-at "[ \t\n\f]")))
10704 (when (looking-at ",")
10705 (delete-region (+ 1 (point)) rtn-pt))))
10706 (when (bolp)
10707 (indent-to indent))
10708 (insert ");\n")
10709 ;; Still need to kill final comma - always is one as we put one after the .*
10710 (re-search-backward ",")
10711 (delete-char 1))))))
10713 (defun verilog-delete-auto-buffer ()
10714 "Perform `verilog-delete-auto' on the current buffer.
10715 Intended for internal use inside a `verilog-save-font-no-change-functions' block."
10716 ;; Allow user to customize
10717 (verilog-run-hooks 'verilog-before-delete-auto-hook)
10719 ;; Remove those that have multi-line insertions, possibly with parameters
10720 ;; We allow anything beginning with AUTO, so that users can add their own
10721 ;; patterns
10722 (verilog-auto-re-search-do
10723 (concat "/\\*AUTO[A-Za-z0-9_]+"
10724 ;; Optional parens or quoted parameter or .* for (((...)))
10725 "\\(\\|([^)]*)\\|(\"[^\"]*\")\\).*?"
10726 "\\*/")
10727 'verilog-delete-autos-lined)
10728 ;; Remove those that are in parenthesis
10729 (verilog-auto-re-search-do
10730 (concat "/\\*"
10731 (eval-when-compile
10732 (verilog-regexp-words
10733 `("AS" "AUTOARG" "AUTOCONCATWIDTH" "AUTOINST" "AUTOINSTPARAM"
10734 "AUTOSENSE")))
10735 "\\*/")
10736 'verilog-delete-to-paren)
10737 ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments
10738 (verilog-auto-re-search-do "\\.\\*"
10739 'verilog-delete-auto-star-all)
10740 ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed
10741 (goto-char (point-min))
10742 (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)\\([ \tLT0-9]*\\| LHS: .*\\)?$" nil t)
10743 (replace-match ""))
10745 ;; Final customize
10746 (verilog-run-hooks 'verilog-delete-auto-hook))
10748 (defun verilog-delete-auto ()
10749 "Delete the automatic outputs, regs, and wires created by \\[verilog-auto].
10750 Use \\[verilog-auto] to re-insert the updated AUTOs.
10752 The hooks `verilog-before-delete-auto-hook' and `verilog-delete-auto-hook' are
10753 called before and after this function, respectively."
10754 (interactive)
10755 (save-excursion
10756 (if (buffer-file-name)
10757 (find-file-noselect (buffer-file-name))) ; To check we have latest version
10758 (verilog-save-font-no-change-functions
10759 (verilog-save-scan-cache
10760 (verilog-delete-auto-buffer)))))
10763 ;;; Auto inject:
10766 (defun verilog-inject-auto ()
10767 "Examine legacy non-AUTO code and insert AUTOs in appropriate places.
10769 Any always @ blocks with sensitivity lists that match computed lists will
10770 be replaced with /*AS*/ comments.
10772 Any cells will get /*AUTOINST*/ added to the end of the pin list.
10773 Pins with have identical names will be deleted.
10775 Argument lists will not be deleted, /*AUTOARG*/ will only be inserted to
10776 support adding new ports. You may wish to delete older ports yourself.
10778 For example:
10780 module ExampInject (i, o);
10781 input i;
10782 input j;
10783 output o;
10784 always @ (i or j)
10785 o = i | j;
10786 InstModule instName
10787 (.foobar(baz),
10788 j(j));
10789 endmodule
10791 Typing \\[verilog-inject-auto] will make this into:
10793 module ExampInject (i, o/*AUTOARG*/
10794 // Inputs
10796 input i;
10797 output o;
10798 always @ (/*AS*/i or j)
10799 o = i | j;
10800 InstModule instName
10801 (.foobar(baz),
10802 /*AUTOINST*/
10803 // Outputs
10804 j(j));
10805 endmodule"
10806 (interactive)
10807 (verilog-auto t))
10809 (defun verilog-inject-arg ()
10810 "Inject AUTOARG into new code. See `verilog-inject-auto'."
10811 ;; Presume one module per file.
10812 (save-excursion
10813 (goto-char (point-min))
10814 (while (verilog-re-search-forward-quick "\\<module\\>" nil t)
10815 (let ((endmodp (save-excursion
10816 (verilog-re-search-forward-quick "\\<endmodule\\>" nil t)
10817 (point))))
10818 ;; See if there's already a comment .. inside a comment so not verilog-re-search
10819 (when (not (re-search-forward "/\\*AUTOARG\\*/" endmodp t))
10820 (verilog-re-search-forward-quick ";" nil t)
10821 (backward-char 1)
10822 (verilog-backward-syntactic-ws-quick)
10823 (backward-char 1) ; Moves to paren that closes argdecl's
10824 (when (looking-at ")")
10825 (verilog-insert "/*AUTOARG*/")))))))
10827 (defun verilog-inject-sense ()
10828 "Inject AUTOSENSE into new code. See `verilog-inject-auto'."
10829 (save-excursion
10830 (goto-char (point-min))
10831 (while (verilog-re-search-forward-quick "\\<always\\s *@\\s *(" nil t)
10832 (let* ((start-pt (point))
10833 (modi (verilog-modi-current))
10834 (moddecls (verilog-modi-get-decls modi))
10835 pre-sigs
10836 got-sigs)
10837 (backward-char 1)
10838 (verilog-forward-sexp-ign-cmt 1)
10839 (backward-char 1) ; End )
10840 (when (not (verilog-re-search-backward-quick "/\\*\\(AUTOSENSE\\|AS\\)\\*/" start-pt t))
10841 (setq pre-sigs (verilog-signals-from-signame
10842 (verilog-read-signals start-pt (point)))
10843 got-sigs (verilog-auto-sense-sigs moddecls nil))
10844 (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal?
10845 (verilog-signals-not-in got-sigs pre-sigs)))
10846 (delete-region start-pt (point))
10847 (verilog-insert "/*AS*/")))))))
10849 (defun verilog-inject-inst ()
10850 "Inject AUTOINST into new code. See `verilog-inject-auto'."
10851 (save-excursion
10852 (goto-char (point-min))
10853 ;; It's hard to distinguish modules; we'll instead search for pins.
10854 (while (verilog-re-search-forward-quick "\\.\\s *[a-zA-Z0-9`_$]+\\s *(\\s *[a-zA-Z0-9`_$]+\\s *)" nil t)
10855 (verilog-backward-open-paren) ; Inst start
10856 (cond
10857 ((= (preceding-char) ?\#) ; #(...) parameter section, not pin. Skip.
10858 (forward-char 1)
10859 (verilog-forward-close-paren)) ; Parameters done
10861 (forward-char 1)
10862 (let ((indent-pt (+ (current-column)))
10863 (end-pt (save-excursion (verilog-forward-close-paren) (point))))
10864 (cond ((verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-pt t)
10865 (goto-char end-pt)) ; Already there, continue search with next instance
10867 ;; Delete identical interconnect
10868 (let ((case-fold-search nil)) ; So we don't convert upper-to-lower, etc
10869 (while (verilog-re-search-forward-quick "\\.\\s *\\([a-zA-Z0-9`_$]+\\)*\\s *(\\s *\\1\\s *)\\s *" end-pt t)
10870 (delete-region (match-beginning 0) (match-end 0))
10871 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))) ; Keep it correct
10872 (while (or (looking-at "[ \t\n\f,]+")
10873 (looking-at "//[^\n]*"))
10874 (delete-region (match-beginning 0) (match-end 0))
10875 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))))))
10876 (verilog-forward-close-paren)
10877 (backward-char 1)
10878 ;; Not verilog-re-search, as we don't want to strip comments
10879 (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t)
10880 (delete-region (match-beginning 0) (match-end 0)))
10881 (verilog-insert "\n")
10882 (verilog-insert-indent "/*AUTOINST*/")))))))))
10885 ;; Auto diff:
10888 (defun verilog-diff-buffers-p (b1 b2 &optional whitespace regexp)
10889 "Return nil if buffers B1 and B2 have same contents.
10890 Else, return point in B1 that first mismatches.
10891 If optional WHITESPACE true, ignore whitespace.
10892 If optional REGEXP, ignore differences matching it."
10893 (save-excursion
10894 (let* ((case-fold-search nil) ; compare-buffer-substrings cares
10895 (p1 (with-current-buffer b1 (goto-char (point-min))))
10896 (p2 (with-current-buffer b2 (goto-char (point-min))))
10897 (maxp1 (with-current-buffer b1 (point-max)))
10898 (maxp2 (with-current-buffer b2 (point-max)))
10899 (op1 -1) (op2 -1)
10900 progress size)
10901 (while (not (and (eq p1 op1) (eq p2 op2)))
10902 ;; If both windows have whitespace optionally skip over it.
10903 (when whitespace
10904 ;; skip-syntax-* doesn't count \n
10905 (with-current-buffer b1
10906 (goto-char p1)
10907 (skip-chars-forward " \t\n\r\f\v")
10908 (setq p1 (point)))
10909 (with-current-buffer b2
10910 (goto-char p2)
10911 (skip-chars-forward " \t\n\r\f\v")
10912 (setq p2 (point))))
10913 (when regexp
10914 (with-current-buffer b1
10915 (goto-char p1)
10916 (when (looking-at regexp)
10917 (setq p1 (match-end 0))))
10918 (with-current-buffer b2
10919 (goto-char p2)
10920 (when (looking-at regexp)
10921 (setq p2 (match-end 0)))))
10922 (setq size (min (- maxp1 p1) (- maxp2 p2)))
10923 (setq progress (compare-buffer-substrings b2 p2 (+ size p2)
10924 b1 p1 (+ size p1)))
10925 (setq progress (if (zerop progress) size (1- (abs progress))))
10926 (setq op1 p1 op2 p2
10927 p1 (+ p1 progress)
10928 p2 (+ p2 progress)))
10929 ;; Return value
10930 (if (and (eq p1 maxp1) (eq p2 maxp2))
10931 nil p1))))
10933 (defun verilog-diff-file-with-buffer (f1 b2 &optional whitespace show)
10934 "View the differences between file F1 and buffer B2.
10935 This requires the external program `diff-command' to be in your `exec-path',
10936 and uses `diff-switches' in which you may want to have \"-u\" flag.
10937 Ignores WHITESPACE if t, and writes output to stdout if SHOW."
10938 ;; Similar to `diff-buffer-with-file' but works on XEmacs, and doesn't
10939 ;; call `diff' as `diff' has different calling semantics on different
10940 ;; versions of Emacs.
10941 (if (not (file-exists-p f1))
10942 (message "Buffer `%s' has no associated file on disk" (buffer-name b2))
10943 (with-temp-buffer "*Verilog-Diff*"
10944 (let ((outbuf (current-buffer))
10945 (f2 (make-temp-file "vm-diff-auto-")))
10946 (unwind-protect
10947 (progn
10948 (with-current-buffer b2
10949 (save-restriction
10950 (widen)
10951 (write-region (point-min) (point-max) f2 nil 'nomessage)))
10952 (call-process diff-command nil outbuf t
10953 diff-switches ; User may want -u in diff-switches
10954 (if whitespace "-b" "")
10955 f1 f2)
10956 ;; Print out results. Alternatively we could have call-processed
10957 ;; ourself, but this way we can reuse diff switches
10958 (when show
10959 (with-current-buffer outbuf (message "%s" (buffer-string))))))
10960 (sit-for 0)
10961 (when (file-exists-p f2)
10962 (delete-file f2))))))
10964 (defun verilog-diff-report (b1 b2 diffpt)
10965 "Report differences detected with `verilog-diff-auto'.
10966 Differences are between buffers B1 and B2, starting at point
10967 DIFFPT. This function is called via `verilog-diff-function'."
10968 (let ((name1 (with-current-buffer b1 (buffer-file-name))))
10969 (verilog-warn-error "%s:%d: Difference in AUTO expansion found"
10970 name1 (with-current-buffer b1
10971 (count-lines (point-min) diffpt)))
10972 (cond (noninteractive
10973 (verilog-diff-file-with-buffer name1 b2 t t))
10975 (ediff-buffers b1 b2)))))
10977 (defun verilog-diff-auto ()
10978 "Expand AUTOs in a temporary buffer and indicate any change.
10979 Whitespace is ignored when detecting differences, but once a
10980 difference is detected, whitespace differences may be shown.
10982 To call this from the command line, see \\[verilog-batch-diff-auto].
10984 The action on differences is selected with
10985 `verilog-diff-function'. The default is `verilog-diff-report'
10986 which will report an error and run `ediff' in interactive mode,
10987 or `diff' in batch mode."
10988 (interactive)
10989 (let ((b1 (current-buffer)) b2 diffpt
10990 (name1 (buffer-file-name))
10991 (newname "*Verilog-Diff*"))
10992 (save-excursion
10993 (when (get-buffer newname)
10994 (kill-buffer newname))
10995 (setq b2 (let (buffer-file-name) ; Else clone is upset
10996 (clone-buffer newname)))
10997 (with-current-buffer b2
10998 ;; auto requires the filename, but can't have same filename in two
10999 ;; buffers; so override both b1 and b2's names
11000 (let ((buffer-file-name name1))
11001 (unwind-protect
11002 (progn
11003 (with-current-buffer b1 (setq buffer-file-name nil))
11004 (verilog-auto)
11005 (when (not verilog-auto-star-save)
11006 (verilog-delete-auto-star-implicit)))
11007 ;; Restore name if unwind
11008 (with-current-buffer b1 (setq buffer-file-name name1)))))
11010 (setq diffpt (verilog-diff-buffers-p b1 b2 t verilog-diff-ignore-regexp))
11011 (cond ((not diffpt)
11012 (unless noninteractive (message "AUTO expansion identical"))
11013 (kill-buffer newname)) ; Nice to cleanup after oneself
11015 (funcall verilog-diff-function b1 b2 diffpt)))
11016 ;; Return result of compare
11017 diffpt)))
11020 ;; Auto save
11023 (defun verilog-auto-save-check ()
11024 "On saving see if we need auto update."
11025 (cond ((not verilog-auto-save-policy)) ; disabled
11026 ((not (save-excursion
11027 (save-match-data
11028 (let ((case-fold-search nil))
11029 (goto-char (point-min))
11030 (re-search-forward "AUTO" nil t))))))
11031 ((eq verilog-auto-save-policy 'force)
11032 (verilog-auto))
11033 ((not (buffer-modified-p)))
11034 ((eq verilog-auto-update-tick (buffer-chars-modified-tick))) ; up-to-date
11035 ((eq verilog-auto-save-policy 'detect)
11036 (verilog-auto))
11038 (when (yes-or-no-p "AUTO statements not recomputed, do it now? ")
11039 (verilog-auto))
11040 ;; Don't ask again if didn't update
11041 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))))
11042 (when (not verilog-auto-star-save)
11043 (verilog-delete-auto-star-implicit))
11044 nil) ; Always return nil -- we don't write the file ourselves
11046 (defun verilog-auto-read-locals ()
11047 "Return file local variable segment at bottom of file."
11048 (save-excursion
11049 (goto-char (point-max))
11050 (if (re-search-backward "Local Variables:" nil t)
11051 (buffer-substring-no-properties (point) (point-max))
11052 "")))
11054 (defun verilog-auto-reeval-locals (&optional force)
11055 "Read file local variable segment at bottom of file if it has changed.
11056 If FORCE, always reread it."
11057 (let ((curlocal (verilog-auto-read-locals)))
11058 (when (or force (not (equal verilog-auto-last-file-locals curlocal)))
11059 (set (make-local-variable 'verilog-auto-last-file-locals) curlocal)
11060 ;; Note this may cause this function to be recursively invoked,
11061 ;; because hack-local-variables may call (verilog-mode)
11062 ;; The above when statement will prevent it from recursing forever.
11063 (hack-local-variables)
11064 t)))
11066 ;;; Auto creation:
11069 (defun verilog-auto-arg-ports (sigs message indent-pt)
11070 "Print a list of ports for AUTOARG.
11071 Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT."
11072 (when sigs
11073 (when verilog-auto-arg-sort
11074 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
11075 (insert "\n")
11076 (indent-to indent-pt)
11077 (insert message)
11078 (insert "\n")
11079 (let ((space ""))
11080 (indent-to indent-pt)
11081 (while sigs
11082 (cond ((equal verilog-auto-arg-format 'single)
11083 (insert space)
11084 (indent-to indent-pt)
11085 (setq space "\n"))
11086 ;; verilog-auto-arg-format 'packed
11087 ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column)
11088 (insert "\n")
11089 (indent-to indent-pt)
11090 (setq space " "))
11092 (insert space)
11093 (setq space " ")))
11094 (insert (verilog-sig-name (car sigs)) ",")
11095 (setq sigs (cdr sigs))))))
11097 (defun verilog-auto-arg ()
11098 "Expand AUTOARG statements.
11099 Replace the argument declarations at the beginning of the
11100 module with ones automatically derived from input and output
11101 statements. This can be dangerous if the module is instantiated
11102 using position-based connections, so use only name-based when
11103 instantiating the resulting module. Long lines are split based
11104 on the `fill-column', see \\[set-fill-column].
11106 Limitations:
11107 Concatenation and outputting partial buses is not supported.
11109 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11111 For example:
11113 module ExampArg (/*AUTOARG*/);
11114 input i;
11115 output o;
11116 endmodule
11118 Typing \\[verilog-auto] will make this into:
11120 module ExampArg (/*AUTOARG*/
11121 // Outputs
11123 // Inputs
11126 input i;
11127 output o;
11128 endmodule
11130 The argument declarations may be printed in declaration order to
11131 best suit order based instantiations, or alphabetically, based on
11132 the `verilog-auto-arg-sort' variable.
11134 Formatting is controlled with `verilog-auto-arg-format' variable.
11136 Any ports declared between the ( and /*AUTOARG*/ are presumed to be
11137 predeclared and are not redeclared by AUTOARG. AUTOARG will make a
11138 conservative guess on adding a comma for the first signal, if you have
11139 any ifdefs or complicated expressions before the AUTOARG you will need
11140 to choose the comma yourself.
11142 Avoid declaring ports manually, as it makes code harder to maintain."
11143 (save-excursion
11144 (let* ((modi (verilog-modi-current))
11145 (moddecls (verilog-modi-get-decls modi))
11146 (skip-pins (aref (verilog-read-arg-pins) 0)))
11147 (verilog-repair-open-comma)
11148 (verilog-auto-arg-ports (verilog-signals-not-in
11149 (verilog-decls-get-outputs moddecls)
11150 skip-pins)
11151 "// Outputs"
11152 verilog-indent-level-declaration)
11153 (verilog-auto-arg-ports (verilog-signals-not-in
11154 (verilog-decls-get-inouts moddecls)
11155 skip-pins)
11156 "// Inouts"
11157 verilog-indent-level-declaration)
11158 (verilog-auto-arg-ports (verilog-signals-not-in
11159 (verilog-decls-get-inputs moddecls)
11160 skip-pins)
11161 "// Inputs"
11162 verilog-indent-level-declaration)
11163 (verilog-repair-close-comma)
11164 (unless (eq (char-before) ?/ )
11165 (insert "\n"))
11166 (indent-to verilog-indent-level-declaration))))
11168 (defun verilog-auto-assign-modport ()
11169 "Expand AUTOASSIGNMODPORT statements, as part of \\[verilog-auto].
11170 Take input/output/inout statements from the specified interface
11171 and modport and use to build assignments into the modport, for
11172 making verification modules that connect to UVM interfaces.
11174 The first parameter is the name of an interface.
11176 The second parameter is a regexp of modports to read from in
11177 that interface.
11179 The third parameter is the instance name to use to dot reference into.
11181 The optional fourth parameter is a regular expression, and only
11182 signals matching the regular expression will be included.
11184 Limitations:
11186 Interface names must be resolvable to filenames. See `verilog-auto-inst'.
11188 Inouts are not supported, as assignments must be unidirectional.
11190 If a signal is part of the interface header and in both a
11191 modport and the interface itself, it will not be listed. (As
11192 this would result in a syntax error when the connections are
11193 made.)
11195 See the example in `verilog-auto-inout-modport'."
11196 (save-excursion
11197 (let* ((params (verilog-read-auto-params 3 4))
11198 (submod (nth 0 params))
11199 (modport-re (nth 1 params))
11200 (inst-name (nth 2 params))
11201 (regexp (nth 3 params))
11202 direction-re submodi) ; direction argument not supported until requested
11203 ;; Lookup position, etc of co-module
11204 ;; Note this may raise an error
11205 (when (setq submodi (verilog-modi-lookup submod t))
11206 (let* ((indent-pt (current-indentation))
11207 (submoddecls (verilog-modi-get-decls submodi))
11208 (submodportdecls (verilog-modi-modport-lookup submodi modport-re))
11209 (sig-list-i (verilog-signals-in ; Decls doesn't have data types, must resolve
11210 (verilog-decls-get-vars submoddecls)
11211 (verilog-signals-not-in
11212 (verilog-decls-get-inputs submodportdecls)
11213 (verilog-decls-get-ports submoddecls))))
11214 (sig-list-o (verilog-signals-in ; Decls doesn't have data types, must resolve
11215 (verilog-decls-get-vars submoddecls)
11216 (verilog-signals-not-in
11217 (verilog-decls-get-outputs submodportdecls)
11218 (verilog-decls-get-ports submoddecls)))))
11219 (forward-line 1)
11220 (setq sig-list-i (verilog-signals-edit-wire-reg
11221 (verilog-signals-matching-dir-re
11222 (verilog-signals-matching-regexp sig-list-i regexp)
11223 "input" direction-re))
11224 sig-list-o (verilog-signals-edit-wire-reg
11225 (verilog-signals-matching-dir-re
11226 (verilog-signals-matching-regexp sig-list-o regexp)
11227 "output" direction-re)))
11228 (setq sig-list-i (sort (copy-alist sig-list-i) `verilog-signals-sort-compare))
11229 (setq sig-list-o (sort (copy-alist sig-list-o) `verilog-signals-sort-compare))
11230 (when (or sig-list-i sig-list-o)
11231 (verilog-insert-indent "// Beginning of automatic assignments from modport\n")
11232 ;; Don't sort them so an upper AUTOINST will match the main module
11233 (let ((sigs sig-list-o))
11234 (while sigs
11235 (verilog-insert-indent "assign " (verilog-sig-name (car sigs))
11236 " = " inst-name
11237 "." (verilog-sig-name (car sigs)) ";\n")
11238 (setq sigs (cdr sigs))))
11239 (let ((sigs sig-list-i))
11240 (while sigs
11241 (verilog-insert-indent "assign " inst-name
11242 "." (verilog-sig-name (car sigs))
11243 " = " (verilog-sig-name (car sigs)) ";\n")
11244 (setq sigs (cdr sigs))))
11245 (verilog-insert-indent "// End of automatics\n")))))))
11247 (defun verilog-auto-inst-port-map (_port-st)
11248 nil)
11250 (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning
11251 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
11252 (defvar vl-modport nil "See `verilog-auto-inst'.") ; Prevent compile warning
11253 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
11254 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning
11255 (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning
11256 (defvar vl-bits nil "See `verilog-auto-inst'.") ; Prevent compile warning
11257 (defvar vl-mbits nil "See `verilog-auto-inst'.") ; Prevent compile warning
11259 (defun verilog-auto-inst-port (port-st indent-pt moddecls tpl-list tpl-num for-star par-values)
11260 "Print out an instantiation connection for this PORT-ST.
11261 Insert to INDENT-PT, use template TPL-LIST.
11262 @ are instantiation numbers, replaced with TPL-NUM.
11263 @\"(expression @)\" are evaluated, with @ as a variable.
11264 If FOR-STAR add comment it is a .* expansion.
11265 If PAR-VALUES replace final strings with these parameter values."
11266 (let* ((port (verilog-sig-name port-st))
11267 (tpl-ass (or (assoc port (car tpl-list))
11268 (verilog-auto-inst-port-map port-st)))
11269 ;; vl-* are documented for user use
11270 (vl-name (verilog-sig-name port-st))
11271 (vl-width (verilog-sig-width port-st))
11272 (vl-modport (verilog-sig-modport port-st))
11273 (vl-memory (verilog-sig-memory port-st))
11274 (vl-mbits (if (verilog-sig-multidim port-st)
11275 (verilog-sig-multidim-string port-st) ""))
11276 (vl-bits (if (or verilog-auto-inst-vector
11277 (not (assoc port (verilog-decls-get-signals moddecls)))
11278 (not (equal (verilog-sig-bits port-st)
11279 (verilog-sig-bits
11280 (assoc port (verilog-decls-get-signals moddecls))))))
11281 (or (verilog-sig-bits port-st) "")
11282 ""))
11283 (case-fold-search nil)
11284 (check-values par-values)
11285 tpl-net dflt-bits)
11286 ;; Replace parameters in bit-width
11287 (when (and check-values
11288 (not (equal vl-bits "")))
11289 (while check-values
11290 (setq vl-bits (verilog-string-replace-matches
11291 (concat "\\<" (nth 0 (car check-values)) "\\>")
11292 (concat "(" (nth 1 (car check-values)) ")")
11293 t t vl-bits)
11294 vl-mbits (verilog-string-replace-matches
11295 (concat "\\<" (nth 0 (car check-values)) "\\>")
11296 (concat "(" (nth 1 (car check-values)) ")")
11297 t t vl-mbits)
11298 vl-memory (when vl-memory
11299 (verilog-string-replace-matches
11300 (concat "\\<" (nth 0 (car check-values)) "\\>")
11301 (concat "(" (nth 1 (car check-values)) ")")
11302 t t vl-memory))
11303 check-values (cdr check-values)))
11304 (setq vl-bits (verilog-simplify-range-expression vl-bits)
11305 vl-mbits (verilog-simplify-range-expression vl-mbits)
11306 vl-memory (when vl-memory (verilog-simplify-range-expression vl-memory))
11307 vl-width (verilog-make-width-expression vl-bits))) ; Not in the loop for speed
11308 ;; Default net value if not found
11309 (setq dflt-bits (if (or (and (verilog-sig-bits port-st)
11310 (verilog-sig-multidim port-st))
11311 (verilog-sig-memory port-st))
11312 (concat "/*" vl-mbits vl-bits
11313 ;; .[ used to separate packed from unpacked
11314 (if vl-memory "." "")
11315 (if vl-memory vl-memory "")
11316 "*/")
11317 (concat vl-bits))
11318 tpl-net (concat port
11319 (if (and vl-modport
11320 ;; .modport cannot be added if attachment is
11321 ;; already declared as modport, VCS croaks
11322 (let ((sig (assoc port (verilog-decls-get-interfaces moddecls))))
11323 (not (and sig (verilog-sig-modport sig)))))
11324 (concat "." vl-modport) "")
11325 dflt-bits))
11326 ;; Find template
11327 (cond (tpl-ass ; Template of exact port name
11328 (setq tpl-net (nth 1 tpl-ass)))
11329 ((nth 1 tpl-list) ; Wildcards in template, search them
11330 (let ((wildcards (nth 1 tpl-list)))
11331 (while wildcards
11332 (when (string-match (nth 0 (car wildcards)) port)
11333 (setq tpl-ass (car wildcards) ; so allow @ parsing
11334 tpl-net (replace-match (nth 1 (car wildcards))
11335 t nil port)))
11336 (setq wildcards (cdr wildcards))))))
11337 ;; Parse Templated variable
11338 (when tpl-ass
11339 ;; Evaluate @"(lispcode)"
11340 (when (string-match "@\".*[^\\]\"" tpl-net)
11341 (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net)
11342 (setq tpl-net
11343 (concat
11344 (substring tpl-net 0 (match-beginning 0))
11345 (save-match-data
11346 (let* ((expr (match-string 1 tpl-net))
11347 (value
11348 (progn
11349 (setq expr (verilog-string-replace-matches "\\\\\"" "\"" nil nil expr))
11350 (setq expr (verilog-string-replace-matches "@" tpl-num nil nil expr))
11351 (prin1 (eval (car (read-from-string expr)))
11352 (lambda (_ch) ())))))
11353 (if (numberp value) (setq value (number-to-string value)))
11354 value))
11355 (substring tpl-net (match-end 0))))))
11356 ;; Replace @ and [] magic variables in final output
11357 (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net))
11358 (setq tpl-net (verilog-string-replace-matches "\\[\\]\\[\\]" dflt-bits nil nil tpl-net))
11359 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)))
11360 ;; Insert it
11361 (indent-to indent-pt)
11362 (insert "." port)
11363 (unless (and verilog-auto-inst-dot-name
11364 (equal port tpl-net))
11365 (indent-to verilog-auto-inst-column)
11366 (insert "(" tpl-net ")"))
11367 (insert ",")
11368 (cond (tpl-ass
11369 (verilog-read-auto-template-hit tpl-ass)
11370 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
11371 verilog-auto-inst-column))
11372 ;; verilog-insert requires the complete comment in one call - including the newline
11373 (cond ((equal verilog-auto-inst-template-numbers `lhs)
11374 (verilog-insert " // Templated"
11375 " LHS: " (nth 0 tpl-ass)
11376 "\n"))
11377 (verilog-auto-inst-template-numbers
11378 (verilog-insert " // Templated"
11379 " T" (int-to-string (nth 2 tpl-ass))
11380 " L" (int-to-string (nth 3 tpl-ass))
11381 "\n"))
11383 (verilog-insert " // Templated\n"))))
11384 (for-star
11385 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
11386 verilog-auto-inst-column))
11387 (verilog-insert " // Implicit .*\n"))
11389 (insert "\n")))))
11390 ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3")
11391 ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]")
11392 ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));")
11394 (defun verilog-auto-inst-port-list (sig-list indent-pt moddecls tpl-list tpl-num for-star par-values)
11395 "For `verilog-auto-inst' print a list of ports using `verilog-auto-inst-port'."
11396 (when verilog-auto-inst-sort
11397 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)))
11398 (mapc (lambda (port)
11399 (verilog-auto-inst-port port indent-pt moddecls
11400 tpl-list tpl-num for-star par-values))
11401 sig-list))
11403 (defun verilog-auto-inst-first ()
11404 "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]."
11405 ;; Do we need a trailing comma?
11406 ;; There maybe an ifdef or something similar before us. What a mess. Thus
11407 ;; to avoid trouble we only insert on preceding ) or *.
11408 ;; Insert first port on new line
11409 (insert "\n") ; Must insert before search, so point will move forward if insert comma
11410 (save-excursion
11411 (verilog-re-search-backward-quick "[^ \t\n\f]" nil nil)
11412 (when (looking-at ")\\|\\*") ; Generally don't insert, unless we are fairly sure
11413 (forward-char 1)
11414 (insert ","))))
11416 (defun verilog-auto-star ()
11417 "Expand SystemVerilog .* pins, as part of \\[verilog-auto].
11419 If `verilog-auto-star-expand' is set, .* pins are treated if they were
11420 AUTOINST statements, otherwise they are ignored. For safety, Verilog mode
11421 will also ignore any .* that are not last in your pin list (this prevents
11422 it from deleting pins following the .* when it expands the AUTOINST.)
11424 On writing your file, unless `verilog-auto-star-save' is set, any
11425 non-templated expanded pins will be removed. You may do this at any time
11426 with \\[verilog-delete-auto-star-implicit].
11428 If you are converting a module to use .* for the first time, you may wish
11429 to use \\[verilog-inject-auto] and then replace the created AUTOINST with .*.
11431 See `verilog-auto-inst' for examples, templates, and more information."
11432 (when (verilog-auto-star-safe)
11433 (verilog-auto-inst)))
11435 (defun verilog-auto-inst ()
11436 "Expand AUTOINST statements, as part of \\[verilog-auto].
11437 Replace the pin connections to an instantiation or interface
11438 declaration with ones automatically derived from the module or
11439 interface header of the instantiated item.
11441 If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports,
11442 and delete them before saving unless `verilog-auto-star-save' is set.
11443 See `verilog-auto-star' for more information.
11445 The pins are printed in declaration order or alphabetically,
11446 based on the `verilog-auto-inst-sort' variable.
11448 Limitations:
11449 Module names must be resolvable to filenames by adding a
11450 `verilog-library-extensions', and being found in the same directory, or
11451 by changing the variable `verilog-library-flags' or
11452 `verilog-library-directories'. Macros `modname are translated through the
11453 vh-{name} Emacs variable, if that is not found, it just ignores the \\=`.
11455 In templates you must have one signal per line, ending in a ), or ));,
11456 and have proper () nesting, including a final ); to end the template.
11458 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11460 SystemVerilog multidimensional input/output has only experimental support.
11462 SystemVerilog .name syntax is used if `verilog-auto-inst-dot-name' is set.
11464 Parameters referenced by the instantiation will remain symbolic, unless
11465 `verilog-auto-inst-param-value' is set.
11467 Gate primitives (and/or) may have AUTOINST for the purpose of
11468 AUTOWIRE declarations, etc. Gates are the only case when
11469 position based connections are passed.
11471 The array part of arrayed instances are ignored; this may
11472 result in undesirable default AUTOINST connections; use a
11473 template instead.
11475 For example, first take the submodule InstModule.v:
11477 module InstModule (o,i);
11478 output [31:0] o;
11479 input i;
11480 wire [31:0] o = {32{i}};
11481 endmodule
11483 This is then used in an upper level module:
11485 module ExampInst (o,i);
11486 output o;
11487 input i;
11488 InstModule instName
11489 (/*AUTOINST*/);
11490 endmodule
11492 Typing \\[verilog-auto] will make this into:
11494 module ExampInst (o,i);
11495 output o;
11496 input i;
11497 InstModule instName
11498 (/*AUTOINST*/
11499 // Outputs
11500 .ov (ov[31:0]),
11501 // Inputs
11502 .i (i));
11503 endmodule
11505 Where the list of inputs and outputs came from the inst module.
11507 Exceptions:
11509 Unless you are instantiating a module multiple times, or the module is
11510 something trivial like an adder, DO NOT CHANGE SIGNAL NAMES ACROSS HIERARCHY.
11511 It just makes for unmaintainable code. To sanitize signal names, try
11512 vrename from URL `http://www.veripool.org'.
11514 When you need to violate this suggestion there are two ways to list
11515 exceptions, placing them before the AUTOINST, or using templates.
11517 Any ports defined before the /*AUTOINST*/ are not included in the list of
11518 automatics. This is similar to making a template as described below, but
11519 is restricted to simple connections just like you normally make. Also note
11520 that any signals before the AUTOINST will only be picked up by AUTOWIRE if
11521 you have the appropriate // Input or // Output comment, and exactly the
11522 same line formatting as AUTOINST itself uses.
11524 InstModule instName
11525 (// Inputs
11526 .i (my_i_dont_mess_with_it),
11527 /*AUTOINST*/
11528 // Outputs
11529 .ov (ov[31:0]));
11532 Templates:
11534 For multiple instantiations based upon a single template, create a
11535 commented out template:
11537 /* InstModule AUTO_TEMPLATE (
11538 .sig3 (sigz[]),
11542 Templates go ABOVE the instantiation(s). When an instantiation is
11543 expanded `verilog-mode' simply searches up for the closest template.
11544 Thus you can have multiple templates for the same module, just alternate
11545 between the template for an instantiation and the instantiation itself.
11546 (For backward compatibility if no template is found above, it
11547 will also look below, but do not use this behavior in new designs.)
11549 The module name must be the same as the name of the module in the
11550 instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact
11551 words and capitalized. Only signals that must be different for each
11552 instantiation need to be listed.
11554 Inside a template, a [] in a connection name (with nothing else
11555 inside the brackets) will be replaced by the same bus subscript
11556 as it is being connected to, or the [] will be removed if it is
11557 a single bit signal.
11559 Inside a template, a [][] in a connection name will behave
11560 similarly to a [] for scalar or single-dimensional connection;
11561 for a multidimensional connection it will print a comment
11562 similar to that printed when a template is not used. Generally
11563 it is a good idea to do this for all connections in a template,
11564 as then they will work for any width signal, and with AUTOWIRE.
11565 See PTL_BUS becoming PTL_BUSNEW below.
11567 Inside a template, a [] in a connection name (with nothing else inside
11568 the brackets) will be replaced by the same bus subscript as it is being
11569 connected to, or the [] will be removed if it is a single bit signal.
11570 Generally it is a good idea to do this for all connections in a template,
11571 as then they will work for any width signal, and with AUTOWIRE. See
11572 PTL_BUS becoming PTL_BUSNEW below.
11574 If you have a complicated template, set `verilog-auto-inst-template-numbers'
11575 to see which regexps are matching. Don't leave that mode set after
11576 debugging is completed though, it will result in lots of extra differences
11577 and merge conflicts.
11579 Setting `verilog-auto-template-warn-unused' will report errors
11580 if any template lines are unused.
11582 For example:
11584 /* InstModule AUTO_TEMPLATE (
11585 .ptl_bus (ptl_busnew[]),
11588 InstModule ms2m (/*AUTOINST*/);
11590 Typing \\[verilog-auto] will make this into:
11592 InstModule ms2m (/*AUTOINST*/
11593 // Outputs
11594 .NotInTemplate (NotInTemplate),
11595 .ptl_bus (ptl_busnew[3:0]), // Templated
11596 ....
11599 Multiple Module Templates:
11601 The same template lines can be applied to multiple modules with
11602 the syntax as follows:
11604 /* InstModuleA AUTO_TEMPLATE
11605 InstModuleB AUTO_TEMPLATE
11606 InstModuleC AUTO_TEMPLATE
11607 InstModuleD AUTO_TEMPLATE (
11608 .ptl_bus (ptl_busnew[]),
11612 Note there is only one AUTO_TEMPLATE opening parenthesis.
11614 @ Templates:
11616 It is common to instantiate a cell multiple times, so templates make it
11617 trivial to substitute part of the cell name into the connection name.
11619 /* InstName AUTO_TEMPLATE <optional \"REGEXP\"> (
11620 .sig1 (sigx[@]),
11621 .sig2 (sigy[@\"(% (+ 1 @) 4)\"]),
11625 If no regular expression is provided immediately after the AUTO_TEMPLATE
11626 keyword, then the @ character in any connection names will be replaced
11627 with the instantiation number; the first digits found in the cell's
11628 instantiation name.
11630 If a regular expression is provided, the @ character will be replaced
11631 with the first () grouping that matches against the cell name. Using a
11632 regexp of `\\([0-9]+\\)' provides identical values for @ as when no
11633 regexp is provided. If you use multiple layers of parenthesis,
11634 `test\\([^0-9]+\\)_\\([0-9]+\\)' would replace @ with non-number
11635 characters after test and before _, whereas
11636 `\\(test\\([a-z]+\\)_\\([0-9]+\\)\\)' would replace @ with the entire
11637 match.
11639 For example:
11641 /* InstModule AUTO_TEMPLATE (
11642 .ptl_mapvalidx (ptl_mapvalid[@]),
11643 .ptl_mapvalidp1x (ptl_mapvalid[@\"(% (+ 1 @) 4)\"]),
11646 InstModule ms2m (/*AUTOINST*/);
11648 Typing \\[verilog-auto] will make this into:
11650 InstModule ms2m (/*AUTOINST*/
11651 // Outputs
11652 .ptl_mapvalidx (ptl_mapvalid[2]),
11653 .ptl_mapvalidp1x (ptl_mapvalid[3]));
11655 Note the @ character was replaced with the 2 from \"ms2m\".
11657 Alternatively, using a regular expression for @:
11659 /* InstModule AUTO_TEMPLATE \"_\\([a-z]+\\)\" (
11660 .ptl_mapvalidx (@_ptl_mapvalid),
11661 .ptl_mapvalidp1x (ptl_mapvalid_@),
11664 InstModule ms2_FOO (/*AUTOINST*/);
11665 InstModule ms2_BAR (/*AUTOINST*/);
11667 Typing \\[verilog-auto] will make this into:
11669 InstModule ms2_FOO (/*AUTOINST*/
11670 // Outputs
11671 .ptl_mapvalidx (FOO_ptl_mapvalid),
11672 .ptl_mapvalidp1x (ptl_mapvalid_FOO));
11673 InstModule ms2_BAR (/*AUTOINST*/
11674 // Outputs
11675 .ptl_mapvalidx (BAR_ptl_mapvalid),
11676 .ptl_mapvalidp1x (ptl_mapvalid_BAR));
11679 Regexp Templates:
11681 A template entry of the form
11683 .pci_req\\([0-9]+\\)_l (pci_req_jtag_[\\1]),
11685 will apply an Emacs style regular expression search for any port beginning
11686 in pci_req followed by numbers and ending in _l and connecting that to
11687 the pci_req_jtag_[] net, with the bus subscript coming from what matches
11688 inside the first set of \\( \\). Thus pci_req2_l becomes pci_req_jtag_[2].
11690 Since \\([0-9]+\\) is so common and ugly to read, a @ in the port name
11691 does the same thing. (Note a @ in the connection/replacement text is
11692 completely different -- still use \\1 there!) Thus this is the same as
11693 the above template:
11695 .pci_req@_l (pci_req_jtag_[\\1]),
11697 Here's another example to remove the _l, useful when naming conventions
11698 specify _ alone to mean active low. Note the use of [] to keep the bus
11699 subscript:
11701 .\\(.*\\)_l (\\1_[]),
11703 Lisp Templates:
11705 First any regular expression template is expanded.
11707 If the syntax @\"( ... )\" is found in a connection, the expression in
11708 quotes will be evaluated as a Lisp expression, with @ replaced by the
11709 instantiation number. The MAPVALIDP1X example above would put @+1 modulo
11710 4 into the brackets. Quote all double-quotes inside the expression with
11711 a leading backslash (\\\"...\\\"); or if the Lisp template is also a
11712 regexp template backslash the backslash quote (\\\\\"...\\\\\").
11714 There are special variables defined that are useful in these
11715 Lisp functions:
11717 vl-name Name portion of the input/output port.
11718 vl-bits Bus bits portion of the input/output port (`[2:0]').
11719 vl-mbits Multidimensional array bits for port (`[2:0][3:0]').
11720 vl-width Width of the input/output port (`3' for [2:0]).
11721 May be a (...) expression if bits isn't a constant.
11722 vl-dir Direction of the pin input/output/inout/interface.
11723 vl-modport The modport, if an interface with a modport.
11724 vl-cell-type Module name/type of the cell (`InstModule').
11725 vl-cell-name Instance name of the cell (`instName').
11727 Normal Lisp variables may be used in expressions. See
11728 `verilog-read-defines' which can set vh-{definename} variables for use
11729 here. Also, any comments of the form:
11731 /*AUTO_LISP(setq foo 1)*/
11733 will evaluate any Lisp expression inside the parenthesis between the
11734 beginning of the buffer and the point of the AUTOINST. This allows
11735 functions to be defined or variables to be changed between instantiations.
11736 (See also `verilog-auto-insert-lisp' if you want the output from your
11737 lisp function to be inserted.)
11739 Note that when using lisp expressions errors may occur when @ is not a
11740 number; you may need to use the standard Emacs Lisp functions
11741 `number-to-string' and `string-to-number'.
11743 After the evaluation is completed, @ substitution and [] substitution
11744 occur.
11746 For more information see the \\[verilog-faq] and forums at URL
11747 `http://www.veripool.org'."
11748 (save-excursion
11749 ;; Find beginning
11750 (let* ((pt (point))
11751 (for-star (save-excursion (backward-char 2) (looking-at "\\.\\*")))
11752 (indent-pt (save-excursion (verilog-backward-open-paren)
11753 (1+ (current-column))))
11754 (verilog-auto-inst-column (max verilog-auto-inst-column
11755 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
11756 (modi (verilog-modi-current))
11757 (moddecls (verilog-modi-get-decls modi))
11758 submod submodi submoddecls
11759 inst skip-pins tpl-list tpl-num did-first par-values)
11761 ;; Find module name that is instantiated
11762 (setq submod (verilog-read-inst-module)
11763 inst (verilog-read-inst-name)
11764 vl-cell-type submod
11765 vl-cell-name inst
11766 skip-pins (aref (verilog-read-inst-pins) 0))
11768 ;; Parse any AUTO_LISP() before here
11769 (verilog-read-auto-lisp (point-min) pt)
11771 ;; Read parameters (after AUTO_LISP)
11772 (setq par-values (and verilog-auto-inst-param-value
11773 (verilog-read-inst-param-value)))
11775 ;; Lookup position, etc of submodule
11776 ;; Note this may raise an error
11777 (when (and (not (member submod verilog-gate-keywords))
11778 (setq submodi (verilog-modi-lookup submod t)))
11779 (setq submoddecls (verilog-modi-get-decls submodi))
11780 ;; If there's a number in the instantiation, it may be an argument to the
11781 ;; automatic variable instantiation program.
11782 (let* ((tpl-info (verilog-read-auto-template submod))
11783 (tpl-regexp (aref tpl-info 0)))
11784 (setq tpl-num (if (verilog-string-match-fold tpl-regexp inst)
11785 (match-string 1 inst)
11787 tpl-list (aref tpl-info 1)))
11788 ;; Find submodule's signals and dump
11789 (let ((sig-list (and (equal (verilog-modi-get-type submodi) "interface")
11790 (verilog-signals-not-in
11791 (verilog-decls-get-vars submoddecls)
11792 skip-pins)))
11793 (vl-dir "interfaced"))
11794 (when (and sig-list
11795 verilog-auto-inst-interfaced-ports)
11796 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11797 ;; Note these are searched for in verilog-read-sub-decls.
11798 (verilog-insert-indent "// Interfaced\n")
11799 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11800 tpl-list tpl-num for-star par-values)))
11801 (let ((sig-list (verilog-signals-not-in
11802 (verilog-decls-get-interfaces submoddecls)
11803 skip-pins))
11804 (vl-dir "interface"))
11805 (when sig-list
11806 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11807 ;; Note these are searched for in verilog-read-sub-decls.
11808 (verilog-insert-indent "// Interfaces\n")
11809 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11810 tpl-list tpl-num for-star par-values)))
11811 (let ((sig-list (verilog-signals-not-in
11812 (verilog-decls-get-outputs submoddecls)
11813 skip-pins))
11814 (vl-dir "output"))
11815 (when sig-list
11816 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11817 (verilog-insert-indent "// Outputs\n")
11818 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11819 tpl-list tpl-num for-star par-values)))
11820 (let ((sig-list (verilog-signals-not-in
11821 (verilog-decls-get-inouts submoddecls)
11822 skip-pins))
11823 (vl-dir "inout"))
11824 (when sig-list
11825 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11826 (verilog-insert-indent "// Inouts\n")
11827 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11828 tpl-list tpl-num for-star par-values)))
11829 (let ((sig-list (verilog-signals-not-in
11830 (verilog-decls-get-inputs submoddecls)
11831 skip-pins))
11832 (vl-dir "input"))
11833 (when sig-list
11834 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11835 (verilog-insert-indent "// Inputs\n")
11836 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11837 tpl-list tpl-num for-star par-values)))
11838 ;; Kill extra semi
11839 (save-excursion
11840 (cond (did-first
11841 (re-search-backward "," pt t)
11842 (delete-char 1)
11843 (insert ");")
11844 (search-forward "\n") ; Added by inst-port
11845 (delete-char -1)
11846 (if (search-forward ")" nil t) ; From user, moved up a line
11847 (delete-char -1))
11848 (if (search-forward ";" nil t) ; Don't error if user had syntax error and forgot it
11849 (delete-char -1)))))))))
11851 (defun verilog-auto-inst-param ()
11852 "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto].
11853 Replace the parameter connections to an instantiation with ones
11854 automatically derived from the module header of the instantiated netlist.
11856 See \\[verilog-auto-inst] for limitations, and templates to customize the
11857 output.
11859 For example, first take the submodule InstModule.v:
11861 module InstModule (o,i);
11862 parameter PAR;
11863 endmodule
11865 This is then used in an upper level module:
11867 module ExampInst (o,i);
11868 parameter PAR;
11869 InstModule #(/*AUTOINSTPARAM*/)
11870 instName (/*AUTOINST*/);
11871 endmodule
11873 Typing \\[verilog-auto] will make this into:
11875 module ExampInst (o,i);
11876 output o;
11877 input i;
11878 InstModule #(/*AUTOINSTPARAM*/
11879 // Parameters
11880 .PAR (PAR));
11881 instName (/*AUTOINST*/);
11882 endmodule
11884 Where the list of parameter connections come from the inst module.
11886 Templates:
11888 You can customize the parameter connections using AUTO_TEMPLATEs,
11889 just as you would with \\[verilog-auto-inst]."
11890 (save-excursion
11891 ;; Find beginning
11892 (let* ((pt (point))
11893 (indent-pt (save-excursion (verilog-backward-open-paren)
11894 (1+ (current-column))))
11895 (verilog-auto-inst-column (max verilog-auto-inst-column
11896 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
11897 (modi (verilog-modi-current))
11898 (moddecls (verilog-modi-get-decls modi))
11899 submod submodi submoddecls
11900 inst skip-pins tpl-list tpl-num did-first)
11901 ;; Find module name that is instantiated
11902 (setq submod (save-excursion
11903 ;; Get to the point where AUTOINST normally is to read the module
11904 (verilog-re-search-forward-quick "[(;]" nil nil)
11905 (verilog-read-inst-module))
11906 inst (save-excursion
11907 ;; Get to the point where AUTOINST normally is to read the module
11908 (verilog-re-search-forward-quick "[(;]" nil nil)
11909 (verilog-read-inst-name))
11910 vl-cell-type submod
11911 vl-cell-name inst
11912 skip-pins (aref (verilog-read-inst-pins) 0))
11914 ;; Parse any AUTO_LISP() before here
11915 (verilog-read-auto-lisp (point-min) pt)
11917 ;; Lookup position, etc of submodule
11918 ;; Note this may raise an error
11919 (when (setq submodi (verilog-modi-lookup submod t))
11920 (setq submoddecls (verilog-modi-get-decls submodi))
11921 ;; If there's a number in the instantiation, it may be an argument to the
11922 ;; automatic variable instantiation program.
11923 (let* ((tpl-info (verilog-read-auto-template submod))
11924 (tpl-regexp (aref tpl-info 0)))
11925 (setq tpl-num (if (verilog-string-match-fold tpl-regexp inst)
11926 (match-string 1 inst)
11928 tpl-list (aref tpl-info 1)))
11929 ;; Find submodule's signals and dump
11930 (let ((sig-list (verilog-signals-not-in
11931 (verilog-decls-get-gparams submoddecls)
11932 skip-pins))
11933 (vl-dir "parameter"))
11934 (when sig-list
11935 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11936 ;; Note these are searched for in verilog-read-sub-decls.
11937 (verilog-insert-indent "// Parameters\n")
11938 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11939 tpl-list tpl-num nil nil)))
11940 ;; Kill extra semi
11941 (save-excursion
11942 (cond (did-first
11943 (re-search-backward "," pt t)
11944 (delete-char 1)
11945 (insert ")")
11946 (search-forward "\n") ; Added by inst-port
11947 (delete-char -1)
11948 (if (search-forward ")" nil t) ; From user, moved up a line
11949 (delete-char -1)))))))))
11951 (defun verilog-auto-reg ()
11952 "Expand AUTOREG statements, as part of \\[verilog-auto].
11953 Make reg statements for any output that isn't already declared,
11954 and isn't a wire output from a block. `verilog-auto-wire-type'
11955 may be used to change the datatype of the declarations.
11957 Limitations:
11958 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11960 This does NOT work on memories, declare those yourself.
11962 An example:
11964 module ExampReg (o,i);
11965 output o;
11966 input i;
11967 /*AUTOREG*/
11968 always o = i;
11969 endmodule
11971 Typing \\[verilog-auto] will make this into:
11973 module ExampReg (o,i);
11974 output o;
11975 input i;
11976 /*AUTOREG*/
11977 // Beginning of automatic regs (for this module's undeclared outputs)
11978 reg o;
11979 // End of automatics
11980 always o = i;
11981 endmodule"
11982 (save-excursion
11983 ;; Point must be at insertion point.
11984 (let* ((indent-pt (current-indentation))
11985 (modi (verilog-modi-current))
11986 (moddecls (verilog-modi-get-decls modi))
11987 (modsubdecls (verilog-modi-get-sub-decls modi))
11988 (sig-list (verilog-signals-not-in
11989 (verilog-decls-get-outputs moddecls)
11990 (append (verilog-signals-with ; ignore typed signals
11991 'verilog-sig-type
11992 (verilog-decls-get-outputs moddecls))
11993 (verilog-decls-get-vars moddecls)
11994 (verilog-decls-get-assigns moddecls)
11995 (verilog-decls-get-consts moddecls)
11996 (verilog-decls-get-gparams moddecls)
11997 (verilog-subdecls-get-interfaced modsubdecls)
11998 (verilog-subdecls-get-outputs modsubdecls)
11999 (verilog-subdecls-get-inouts modsubdecls)))))
12000 (when sig-list
12001 (verilog-forward-or-insert-line)
12002 (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n")
12003 (verilog-insert-definition modi sig-list "reg" indent-pt nil)
12004 (verilog-insert-indent "// End of automatics\n")))))
12006 (defun verilog-auto-reg-input ()
12007 "Expand AUTOREGINPUT statements, as part of \\[verilog-auto].
12008 Make reg statements instantiation inputs that aren't already declared.
12009 This is useful for making a top level shell for testing the module that is
12010 to be instantiated.
12012 Limitations:
12013 This ONLY detects inputs of AUTOINSTants (see `verilog-read-sub-decls').
12015 This does NOT work on memories, declare those yourself.
12017 An example (see `verilog-auto-inst' for what else is going on here):
12019 module ExampRegInput (o,i);
12020 output o;
12021 input i;
12022 /*AUTOREGINPUT*/
12023 InstModule instName
12024 (/*AUTOINST*/);
12025 endmodule
12027 Typing \\[verilog-auto] will make this into:
12029 module ExampRegInput (o,i);
12030 output o;
12031 input i;
12032 /*AUTOREGINPUT*/
12033 // Beginning of automatic reg inputs (for undeclared ...
12034 reg [31:0] iv; // From inst of inst.v
12035 // End of automatics
12036 InstModule instName
12037 (/*AUTOINST*/
12038 // Outputs
12039 .o (o[31:0]),
12040 // Inputs
12041 .iv (iv));
12042 endmodule"
12043 (save-excursion
12044 ;; Point must be at insertion point.
12045 (let* ((indent-pt (current-indentation))
12046 (modi (verilog-modi-current))
12047 (moddecls (verilog-modi-get-decls modi))
12048 (modsubdecls (verilog-modi-get-sub-decls modi))
12049 (sig-list (verilog-signals-combine-bus
12050 (verilog-signals-not-in
12051 (append (verilog-subdecls-get-inputs modsubdecls)
12052 (verilog-subdecls-get-inouts modsubdecls))
12053 (append (verilog-decls-get-signals moddecls)
12054 (verilog-decls-get-assigns moddecls))))))
12055 (when sig-list
12056 (verilog-forward-or-insert-line)
12057 (verilog-insert-indent "// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)\n")
12058 (verilog-insert-definition modi sig-list "reg" indent-pt nil)
12059 (verilog-insert-indent "// End of automatics\n")))))
12061 (defun verilog-auto-logic-setup ()
12062 "Prepare variables due to AUTOLOGIC."
12063 (unless verilog-auto-wire-type
12064 (set (make-local-variable 'verilog-auto-wire-type)
12065 "logic")))
12067 (defun verilog-auto-logic ()
12068 "Expand AUTOLOGIC statements, as part of \\[verilog-auto].
12069 Make wire statements using the SystemVerilog logic keyword.
12070 This is currently equivalent to:
12072 /*AUTOWIRE*/
12074 with the below at the bottom of the file
12076 // Local Variables:
12077 // verilog-auto-logic-type:\"logic\"
12078 // End:
12080 In the future AUTOLOGIC may declare additional identifiers,
12081 while AUTOWIRE will not."
12082 (save-excursion
12083 (verilog-auto-logic-setup)
12084 (verilog-auto-wire)))
12086 (defun verilog-auto-wire ()
12087 "Expand AUTOWIRE statements, as part of \\[verilog-auto].
12088 Make wire statements for instantiations outputs that aren't
12089 already declared. `verilog-auto-wire-type' may be used to change
12090 the datatype of the declarations.
12092 Limitations:
12093 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'),
12094 and all buses must have widths, such as those from AUTOINST, or using []
12095 in AUTO_TEMPLATEs.
12097 This does NOT work on memories or SystemVerilog .name connections,
12098 declare those yourself.
12100 Verilog mode will add \"Couldn't Merge\" comments to signals it cannot
12101 determine how to bus together. This occurs when you have ports with
12102 non-numeric or non-sequential bus subscripts. If Verilog mode
12103 mis-guessed, you'll have to declare them yourself.
12105 An example (see `verilog-auto-inst' for what else is going on here):
12107 module ExampWire (o,i);
12108 output o;
12109 input i;
12110 /*AUTOWIRE*/
12111 InstModule instName
12112 (/*AUTOINST*/);
12113 endmodule
12115 Typing \\[verilog-auto] will make this into:
12117 module ExampWire (o,i);
12118 output o;
12119 input i;
12120 /*AUTOWIRE*/
12121 // Beginning of automatic wires
12122 wire [31:0] ov; // From inst of inst.v
12123 // End of automatics
12124 InstModule instName
12125 (/*AUTOINST*/
12126 // Outputs
12127 .ov (ov[31:0]),
12128 // Inputs
12129 .i (i));
12130 wire o = | ov;
12131 endmodule"
12132 (save-excursion
12133 ;; Point must be at insertion point.
12134 (let* ((indent-pt (current-indentation))
12135 (modi (verilog-modi-current))
12136 (moddecls (verilog-modi-get-decls modi))
12137 (modsubdecls (verilog-modi-get-sub-decls modi))
12138 (sig-list (verilog-signals-combine-bus
12139 (verilog-signals-not-in
12140 (append (verilog-subdecls-get-outputs modsubdecls)
12141 (verilog-subdecls-get-inouts modsubdecls))
12142 (verilog-decls-get-signals moddecls)))))
12143 (when sig-list
12144 (verilog-forward-or-insert-line)
12145 (verilog-insert-indent "// Beginning of automatic wires (for undeclared instantiated-module outputs)\n")
12146 (verilog-insert-definition modi sig-list "wire" indent-pt nil)
12147 (verilog-insert-indent "// End of automatics\n")
12148 ;; We used to optionally call verilog-pretty-declarations and
12149 ;; verilog-pretty-expr here, but it's too slow on huge modules,
12150 ;; plus makes everyone's module change. Finally those call
12151 ;; syntax-ppss which is broken when change hooks are disabled.
12152 ))))
12154 (defun verilog-auto-output ()
12155 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto].
12156 Make output statements for any output signal from an /*AUTOINST*/ that
12157 isn't an input to another AUTOINST. This is useful for modules which
12158 only instantiate other modules.
12160 Limitations:
12161 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
12163 If placed inside the parenthesis of a module declaration, it creates
12164 Verilog 2001 style, else uses Verilog 1995 style.
12166 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
12167 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
12169 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
12171 Types are added to declarations if an AUTOLOGIC or
12172 `verilog-auto-wire-type' is set to logic.
12174 Signals matching `verilog-auto-output-ignore-regexp' are not included.
12176 An example (see `verilog-auto-inst' for what else is going on here):
12178 module ExampOutput (ov,i);
12179 input i;
12180 /*AUTOOUTPUT*/
12181 InstModule instName
12182 (/*AUTOINST*/);
12183 endmodule
12185 Typing \\[verilog-auto] will make this into:
12187 module ExampOutput (ov,i);
12188 input i;
12189 /*AUTOOUTPUT*/
12190 // Beginning of automatic outputs (from unused autoinst outputs)
12191 output [31:0] ov; // From inst of inst.v
12192 // End of automatics
12193 InstModule instName
12194 (/*AUTOINST*/
12195 // Outputs
12196 .ov (ov[31:0]),
12197 // Inputs
12198 .i (i));
12199 endmodule
12201 You may also provide an optional regular expression, in which case only
12202 signals matching the regular expression will be included. For example the
12203 same expansion will result from only extracting outputs starting with ov:
12205 /*AUTOOUTPUT(\"^ov\")*/"
12206 (save-excursion
12207 ;; Point must be at insertion point.
12208 (let* ((indent-pt (current-indentation))
12209 (params (verilog-read-auto-params 0 1))
12210 (regexp (nth 0 params))
12211 (v2k (verilog-in-paren-quick))
12212 (modi (verilog-modi-current))
12213 (moddecls (verilog-modi-get-decls modi))
12214 (modsubdecls (verilog-modi-get-sub-decls modi))
12215 (sig-list (verilog-signals-not-in
12216 (verilog-subdecls-get-outputs modsubdecls)
12217 (append (verilog-decls-get-outputs moddecls)
12218 (verilog-decls-get-inouts moddecls)
12219 (verilog-decls-get-inputs moddecls)
12220 (verilog-subdecls-get-inputs modsubdecls)
12221 (verilog-subdecls-get-inouts modsubdecls)))))
12222 (when regexp
12223 (setq sig-list (verilog-signals-matching-regexp
12224 sig-list regexp)))
12225 (setq sig-list (verilog-signals-not-matching-regexp
12226 sig-list verilog-auto-output-ignore-regexp))
12227 (verilog-forward-or-insert-line)
12228 (when v2k (verilog-repair-open-comma))
12229 (when sig-list
12230 (verilog-insert-indent "// Beginning of automatic outputs (from unused autoinst outputs)\n")
12231 (verilog-insert-definition modi sig-list "output" indent-pt v2k)
12232 (verilog-insert-indent "// End of automatics\n"))
12233 (when v2k (verilog-repair-close-comma)))))
12235 (defun verilog-auto-output-every ()
12236 "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto].
12237 Make output statements for any signals that aren't primary inputs or
12238 outputs already. This makes every signal in the design an output. This is
12239 useful to get Synopsys to preserve every signal in the design, since it
12240 won't optimize away the outputs.
12242 An example:
12244 module ExampOutputEvery (o,i,tempa,tempb);
12245 output o;
12246 input i;
12247 /*AUTOOUTPUTEVERY*/
12248 wire tempa = i;
12249 wire tempb = tempa;
12250 wire o = tempb;
12251 endmodule
12253 Typing \\[verilog-auto] will make this into:
12255 module ExampOutputEvery (o,i,tempa,tempb);
12256 output o;
12257 input i;
12258 /*AUTOOUTPUTEVERY*/
12259 // Beginning of automatic outputs (every signal)
12260 output tempb;
12261 output tempa;
12262 // End of automatics
12263 wire tempa = i;
12264 wire tempb = tempa;
12265 wire o = tempb;
12266 endmodule
12268 You may also provide an optional regular expression, in which case only
12269 signals matching the regular expression will be included. For example the
12270 same expansion will result from only extracting outputs starting with ov:
12272 /*AUTOOUTPUTEVERY(\"^ov\")*/"
12273 (save-excursion
12274 ;;Point must be at insertion point
12275 (let* ((indent-pt (current-indentation))
12276 (params (verilog-read-auto-params 0 1))
12277 (regexp (nth 0 params))
12278 (v2k (verilog-in-paren-quick))
12279 (modi (verilog-modi-current))
12280 (moddecls (verilog-modi-get-decls modi))
12281 (sig-list (verilog-signals-combine-bus
12282 (verilog-signals-not-in
12283 (verilog-decls-get-signals moddecls)
12284 (verilog-decls-get-ports moddecls)))))
12285 (when regexp
12286 (setq sig-list (verilog-signals-matching-regexp
12287 sig-list regexp)))
12288 (setq sig-list (verilog-signals-not-matching-regexp
12289 sig-list verilog-auto-output-ignore-regexp))
12290 (verilog-forward-or-insert-line)
12291 (when v2k (verilog-repair-open-comma))
12292 (when sig-list
12293 (verilog-insert-indent "// Beginning of automatic outputs (every signal)\n")
12294 (verilog-insert-definition modi sig-list "output" indent-pt v2k)
12295 (verilog-insert-indent "// End of automatics\n"))
12296 (when v2k (verilog-repair-close-comma)))))
12298 (defun verilog-auto-input ()
12299 "Expand AUTOINPUT statements, as part of \\[verilog-auto].
12300 Make input statements for any input signal into an /*AUTOINST*/ that
12301 isn't declared elsewhere inside the module. This is useful for modules which
12302 only instantiate other modules.
12304 Limitations:
12305 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
12307 If placed inside the parenthesis of a module declaration, it creates
12308 Verilog 2001 style, else uses Verilog 1995 style.
12310 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
12311 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
12313 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
12315 Types are added to declarations if an AUTOLOGIC or
12316 `verilog-auto-wire-type' is set to logic.
12318 Signals matching `verilog-auto-input-ignore-regexp' are not included.
12320 An example (see `verilog-auto-inst' for what else is going on here):
12322 module ExampInput (ov,i);
12323 output [31:0] ov;
12324 /*AUTOINPUT*/
12325 InstModule instName
12326 (/*AUTOINST*/);
12327 endmodule
12329 Typing \\[verilog-auto] will make this into:
12331 module ExampInput (ov,i);
12332 output [31:0] ov;
12333 /*AUTOINPUT*/
12334 // Beginning of automatic inputs (from unused autoinst inputs)
12335 input i; // From inst of inst.v
12336 // End of automatics
12337 InstModule instName
12338 (/*AUTOINST*/
12339 // Outputs
12340 .ov (ov[31:0]),
12341 // Inputs
12342 .i (i));
12343 endmodule
12345 You may also provide an optional regular expression, in which case only
12346 signals matching the regular expression will be included. For example the
12347 same expansion will result from only extracting inputs starting with i:
12349 /*AUTOINPUT(\"^i\")*/"
12350 (save-excursion
12351 (let* ((indent-pt (current-indentation))
12352 (params (verilog-read-auto-params 0 1))
12353 (regexp (nth 0 params))
12354 (v2k (verilog-in-paren-quick))
12355 (modi (verilog-modi-current))
12356 (moddecls (verilog-modi-get-decls modi))
12357 (modsubdecls (verilog-modi-get-sub-decls modi))
12358 (sig-list (verilog-signals-not-in
12359 (verilog-subdecls-get-inputs modsubdecls)
12360 (append (verilog-decls-get-inputs moddecls)
12361 (verilog-decls-get-inouts moddecls)
12362 (verilog-decls-get-outputs moddecls)
12363 (verilog-decls-get-vars moddecls)
12364 (verilog-decls-get-consts moddecls)
12365 (verilog-decls-get-gparams moddecls)
12366 (verilog-subdecls-get-interfaced modsubdecls)
12367 (verilog-subdecls-get-outputs modsubdecls)
12368 (verilog-subdecls-get-inouts modsubdecls)))))
12369 (when regexp
12370 (setq sig-list (verilog-signals-matching-regexp
12371 sig-list regexp)))
12372 (setq sig-list (verilog-signals-not-matching-regexp
12373 sig-list verilog-auto-input-ignore-regexp))
12374 (verilog-forward-or-insert-line)
12375 (when v2k (verilog-repair-open-comma))
12376 (when sig-list
12377 (verilog-insert-indent "// Beginning of automatic inputs (from unused autoinst inputs)\n")
12378 (verilog-insert-definition modi sig-list "input" indent-pt v2k)
12379 (verilog-insert-indent "// End of automatics\n"))
12380 (when v2k (verilog-repair-close-comma)))))
12382 (defun verilog-auto-inout ()
12383 "Expand AUTOINOUT statements, as part of \\[verilog-auto].
12384 Make inout statements for any inout signal in an /*AUTOINST*/ that
12385 isn't declared elsewhere inside the module.
12387 Limitations:
12388 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
12390 If placed inside the parenthesis of a module declaration, it creates
12391 Verilog 2001 style, else uses Verilog 1995 style.
12393 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
12394 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
12396 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
12398 Types are added to declarations if an AUTOLOGIC or
12399 `verilog-auto-wire-type' is set to logic.
12401 Signals matching `verilog-auto-inout-ignore-regexp' are not included.
12403 An example (see `verilog-auto-inst' for what else is going on here):
12405 module ExampInout (ov,i);
12406 input i;
12407 /*AUTOINOUT*/
12408 InstModule instName
12409 (/*AUTOINST*/);
12410 endmodule
12412 Typing \\[verilog-auto] will make this into:
12414 module ExampInout (ov,i);
12415 input i;
12416 /*AUTOINOUT*/
12417 // Beginning of automatic inouts (from unused autoinst inouts)
12418 inout [31:0] ov; // From inst of inst.v
12419 // End of automatics
12420 InstModule instName
12421 (/*AUTOINST*/
12422 // Inouts
12423 .ov (ov[31:0]),
12424 // Inputs
12425 .i (i));
12426 endmodule
12428 You may also provide an optional regular expression, in which case only
12429 signals matching the regular expression will be included. For example the
12430 same expansion will result from only extracting inouts starting with i:
12432 /*AUTOINOUT(\"^i\")*/"
12433 (save-excursion
12434 ;; Point must be at insertion point.
12435 (let* ((indent-pt (current-indentation))
12436 (params (verilog-read-auto-params 0 1))
12437 (regexp (nth 0 params))
12438 (v2k (verilog-in-paren-quick))
12439 (modi (verilog-modi-current))
12440 (moddecls (verilog-modi-get-decls modi))
12441 (modsubdecls (verilog-modi-get-sub-decls modi))
12442 (sig-list (verilog-signals-not-in
12443 (verilog-subdecls-get-inouts modsubdecls)
12444 (append (verilog-decls-get-outputs moddecls)
12445 (verilog-decls-get-inouts moddecls)
12446 (verilog-decls-get-inputs moddecls)
12447 (verilog-subdecls-get-inputs modsubdecls)
12448 (verilog-subdecls-get-outputs modsubdecls)))))
12449 (when regexp
12450 (setq sig-list (verilog-signals-matching-regexp
12451 sig-list regexp)))
12452 (setq sig-list (verilog-signals-not-matching-regexp
12453 sig-list verilog-auto-inout-ignore-regexp))
12454 (verilog-forward-or-insert-line)
12455 (when v2k (verilog-repair-open-comma))
12456 (when sig-list
12457 (verilog-insert-indent "// Beginning of automatic inouts (from unused autoinst inouts)\n")
12458 (verilog-insert-definition modi sig-list "inout" indent-pt v2k)
12459 (verilog-insert-indent "// End of automatics\n"))
12460 (when v2k (verilog-repair-close-comma)))))
12462 (defun verilog-auto-inout-module (&optional complement all-in)
12463 "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto].
12464 Take input/output/inout statements from the specified module and insert
12465 into the current module. This is useful for making null templates and
12466 shell modules which need to have identical I/O with another module.
12467 Any I/O which are already defined in this module will not be redefined.
12468 For the complement of this function, see `verilog-auto-inout-comp',
12469 and to make monitors with all inputs, see `verilog-auto-inout-in'.
12471 Limitations:
12472 If placed inside the parenthesis of a module declaration, it creates
12473 Verilog 2001 style, else uses Verilog 1995 style.
12475 Concatenation and outputting partial buses is not supported.
12477 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12479 Signals are not inserted in the same order as in the original module,
12480 though they will appear to be in the same order to an AUTOINST
12481 instantiating either module.
12483 Signals declared as \"output reg\" or \"output wire\" etc will
12484 lose the wire/reg declaration so that shell modules may
12485 generate those outputs differently. However, \"output logic\"
12486 is propagated.
12488 An example:
12490 module ExampShell (/*AUTOARG*/);
12491 /*AUTOINOUTMODULE(\"ExampMain\")*/
12492 endmodule
12494 module ExampMain (i,o,io);
12495 input i;
12496 output o;
12497 inout io;
12498 endmodule
12500 Typing \\[verilog-auto] will make this into:
12502 module ExampShell (/*AUTOARG*/i,o,io);
12503 /*AUTOINOUTMODULE(\"ExampMain\")*/
12504 // Beginning of automatic in/out/inouts (from specific module)
12505 output o;
12506 inout io;
12507 input i;
12508 // End of automatics
12509 endmodule
12511 You may also provide an optional regular expression, in which case only
12512 signals matching the regular expression will be included. For example the
12513 same expansion will result from only extracting signals starting with i:
12515 /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/
12517 You may also provide an optional third argument regular
12518 expression, in which case only signals which have that pin
12519 direction and data type matching that regular expression will be
12520 included. This matches against everything before the signal name
12521 in the declaration, for example against \"input\" (single
12522 bit), \"output logic\" (direction and type) or
12523 \"output [1:0]\" (direction and implicit type). You also
12524 probably want to skip spaces in your regexp.
12526 For example, the below will result in matching the output \"o\"
12527 against the previous example's module:
12529 /*AUTOINOUTMODULE(\"ExampMain\",\"\",\"^output.*\")*/
12531 You may also provide an optional fourth argument regular
12532 expression, which if not \"\" only signals which do NOT match
12533 that expression are included."
12534 ;; Beware spacing of quotes in above as can mess up Emacs indenter
12535 (save-excursion
12536 (let* ((params (verilog-read-auto-params 1 4))
12537 (submod (nth 0 params))
12538 (regexp (nth 1 params))
12539 (direction-re (nth 2 params))
12540 (not-re (nth 3 params))
12541 submodi)
12542 ;; Lookup position, etc of co-module
12543 ;; Note this may raise an error
12544 (when (setq submodi (verilog-modi-lookup submod t))
12545 (let* ((indent-pt (current-indentation))
12546 (v2k (verilog-in-paren-quick))
12547 (modi (verilog-modi-current))
12548 (moddecls (verilog-modi-get-decls modi))
12549 (submoddecls (verilog-modi-get-decls submodi))
12550 (sig-list-i (verilog-signals-not-in
12551 (cond (all-in
12552 (append
12553 (verilog-decls-get-inputs submoddecls)
12554 (verilog-decls-get-inouts submoddecls)
12555 (verilog-decls-get-outputs submoddecls)))
12556 (complement
12557 (verilog-decls-get-outputs submoddecls))
12558 (t (verilog-decls-get-inputs submoddecls)))
12559 (append (verilog-decls-get-inputs moddecls))))
12560 (sig-list-o (verilog-signals-not-in
12561 (cond (all-in nil)
12562 (complement
12563 (verilog-decls-get-inputs submoddecls))
12564 (t (verilog-decls-get-outputs submoddecls)))
12565 (append (verilog-decls-get-outputs moddecls))))
12566 (sig-list-io (verilog-signals-not-in
12567 (cond (all-in nil)
12568 (t (verilog-decls-get-inouts submoddecls)))
12569 (append (verilog-decls-get-inouts moddecls))))
12570 (sig-list-if (verilog-signals-not-in
12571 (verilog-decls-get-interfaces submoddecls)
12572 (append (verilog-decls-get-interfaces moddecls)))))
12573 (forward-line 1)
12574 (setq sig-list-i (verilog-signals-edit-wire-reg
12575 (verilog-signals-not-matching-regexp
12576 (verilog-signals-matching-dir-re
12577 (verilog-signals-matching-regexp sig-list-i regexp)
12578 "input" direction-re) not-re))
12579 sig-list-o (verilog-signals-edit-wire-reg
12580 (verilog-signals-not-matching-regexp
12581 (verilog-signals-matching-dir-re
12582 (verilog-signals-matching-regexp sig-list-o regexp)
12583 "output" direction-re) not-re))
12584 sig-list-io (verilog-signals-edit-wire-reg
12585 (verilog-signals-not-matching-regexp
12586 (verilog-signals-matching-dir-re
12587 (verilog-signals-matching-regexp sig-list-io regexp)
12588 "inout" direction-re) not-re))
12589 sig-list-if (verilog-signals-not-matching-regexp
12590 (verilog-signals-matching-dir-re
12591 (verilog-signals-matching-regexp sig-list-if regexp)
12592 "interface" direction-re) not-re))
12593 (when v2k (verilog-repair-open-comma))
12594 (when (or sig-list-i sig-list-o sig-list-io sig-list-if)
12595 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n")
12596 ;; Don't sort them so an upper AUTOINST will match the main module
12597 (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
12598 (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
12599 (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
12600 (verilog-insert-definition modi sig-list-if "interface" indent-pt v2k t)
12601 (verilog-insert-indent "// End of automatics\n"))
12602 (when v2k (verilog-repair-close-comma)))))))
12604 (defun verilog-auto-inout-comp ()
12605 "Expand AUTOINOUTCOMP statements, as part of \\[verilog-auto].
12606 Take input/output/inout statements from the specified module and
12607 insert the inverse into the current module (inputs become outputs
12608 and vice-versa.) This is useful for making test and stimulus
12609 modules which need to have complementing I/O with another module.
12610 Any I/O which are already defined in this module will not be
12611 redefined. For the complement of this function, see
12612 `verilog-auto-inout-module'.
12614 Limitations:
12615 If placed inside the parenthesis of a module declaration, it creates
12616 Verilog 2001 style, else uses Verilog 1995 style.
12618 Concatenation and outputting partial buses is not supported.
12620 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12622 Signals are not inserted in the same order as in the original module,
12623 though they will appear to be in the same order to an AUTOINST
12624 instantiating either module.
12626 An example:
12628 module ExampShell (/*AUTOARG*/);
12629 /*AUTOINOUTCOMP(\"ExampMain\")*/
12630 endmodule
12632 module ExampMain (i,o,io);
12633 input i;
12634 output o;
12635 inout io;
12636 endmodule
12638 Typing \\[verilog-auto] will make this into:
12640 module ExampShell (/*AUTOARG*/i,o,io);
12641 /*AUTOINOUTCOMP(\"ExampMain\")*/
12642 // Beginning of automatic in/out/inouts (from specific module)
12643 output i;
12644 inout io;
12645 input o;
12646 // End of automatics
12647 endmodule
12649 You may also provide an optional regular expression, in which case only
12650 signals matching the regular expression will be included. For example the
12651 same expansion will result from only extracting signals starting with i:
12653 /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/
12655 You may also provide an optional third argument regular
12656 expression, in which case only signals which have that pin
12657 direction and data type matching that regular expression will be
12658 included. This matches against everything before the signal name
12659 in the declaration, for example against \"input\" (single
12660 bit), \"output logic\" (direction and type)
12661 or \"output [1:0]\" (direction and implicit type). You also
12662 probably want to skip spaces in your regexp.
12664 For example, the below will result in matching the output \"o\"
12665 against the previous example's module:
12667 /*AUTOINOUTCOMP(\"ExampMain\",\"\",\"^output.*\")*/
12669 You may also provide an optional fourth argument regular
12670 expression, which if not \"\" only signals which do NOT match
12671 that expression are included."
12672 ;; Beware spacing of quotes in above as can mess up Emacs indenter
12673 (verilog-auto-inout-module t nil))
12675 (defun verilog-auto-inout-in ()
12676 "Expand AUTOINOUTIN statements, as part of \\[verilog-auto].
12677 Take input/output/inout statements from the specified module and
12678 insert them as all inputs into the current module. This is
12679 useful for making monitor modules which need to see all signals
12680 as inputs based on another module. Any I/O which are already
12681 defined in this module will not be redefined. See also
12682 `verilog-auto-inout-module'.
12684 Limitations:
12685 If placed inside the parenthesis of a module declaration, it creates
12686 Verilog 2001 style, else uses Verilog 1995 style.
12688 Concatenation and outputting partial buses is not supported.
12690 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12692 Signals are not inserted in the same order as in the original module,
12693 though they will appear to be in the same order to an AUTOINST
12694 instantiating either module.
12696 An example:
12698 module ExampShell (/*AUTOARG*/);
12699 /*AUTOINOUTIN(\"ExampMain\")*/
12700 endmodule
12702 module ExampMain (i,o,io);
12703 input i;
12704 output o;
12705 inout io;
12706 endmodule
12708 Typing \\[verilog-auto] will make this into:
12710 module ExampShell (/*AUTOARG*/i,o,io);
12711 /*AUTOINOUTIN(\"ExampMain\")*/
12712 // Beginning of automatic in/out/inouts (from specific module)
12713 input i;
12714 input io;
12715 input o;
12716 // End of automatics
12717 endmodule
12719 You may also provide an optional regular expression, in which case only
12720 signals matching the regular expression will be included. For example the
12721 same expansion will result from only extracting signals starting with i:
12723 /*AUTOINOUTIN(\"ExampMain\",\"^i\")*/"
12724 (verilog-auto-inout-module nil t))
12726 (defun verilog-auto-inout-param ()
12727 "Expand AUTOINOUTPARAM statements, as part of \\[verilog-auto].
12728 Take input/output/inout statements from the specified module and insert
12729 into the current module. This is useful for making null templates and
12730 shell modules which need to have identical I/O with another module.
12731 Any I/O which are already defined in this module will not be redefined.
12732 For the complement of this function, see `verilog-auto-inout-comp',
12733 and to make monitors with all inputs, see `verilog-auto-inout-in'.
12735 Limitations:
12736 If placed inside the parenthesis of a module declaration, it creates
12737 Verilog 2001 style, else uses Verilog 1995 style.
12739 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12741 Parameters are inserted in the same order as in the original module.
12743 Parameters do not have values, which is SystemVerilog 2009 syntax.
12745 An example:
12747 module ExampShell ();
12748 /*AUTOINOUTPARAM(\"ExampMain\")*/
12749 endmodule
12751 module ExampMain ();
12752 parameter PARAM = 22;
12753 endmodule
12755 Typing \\[verilog-auto] will make this into:
12757 module ExampShell (/*AUTOARG*/i,o,io);
12758 /*AUTOINOUTPARAM(\"ExampMain\")*/
12759 // Beginning of automatic parameters (from specific module)
12760 parameter PARAM;
12761 // End of automatics
12762 endmodule
12764 You may also provide an optional regular expression, in which case only
12765 parameters matching the regular expression will be included. For example the
12766 same expansion will result from only extracting parameters starting with i:
12768 /*AUTOINOUTPARAM(\"ExampMain\",\"^i\")*/"
12769 (save-excursion
12770 (let* ((params (verilog-read-auto-params 1 2))
12771 (submod (nth 0 params))
12772 (regexp (nth 1 params))
12773 submodi)
12774 ;; Lookup position, etc of co-module
12775 ;; Note this may raise an error
12776 (when (setq submodi (verilog-modi-lookup submod t))
12777 (let* ((indent-pt (current-indentation))
12778 (v2k (verilog-in-paren-quick))
12779 (modi (verilog-modi-current))
12780 (moddecls (verilog-modi-get-decls modi))
12781 (submoddecls (verilog-modi-get-decls submodi))
12782 (sig-list-p (verilog-signals-not-in
12783 (verilog-decls-get-gparams submoddecls)
12784 (append (verilog-decls-get-gparams moddecls)))))
12785 (forward-line 1)
12786 (setq sig-list-p (verilog-signals-matching-regexp sig-list-p regexp))
12787 (when v2k (verilog-repair-open-comma))
12788 (when sig-list-p
12789 (verilog-insert-indent "// Beginning of automatic parameters (from specific module)\n")
12790 ;; Don't sort them so an upper AUTOINST will match the main module
12791 (verilog-insert-definition modi sig-list-p "parameter" indent-pt v2k t)
12792 (verilog-insert-indent "// End of automatics\n"))
12793 (when v2k (verilog-repair-close-comma)))))))
12795 (defun verilog-auto-inout-modport ()
12796 "Expand AUTOINOUTMODPORT statements, as part of \\[verilog-auto].
12797 Take input/output/inout statements from the specified interface
12798 and modport and insert into the current module. This is useful
12799 for making verification modules that connect to UVM interfaces.
12801 The first parameter is the name of an interface.
12803 The second parameter is a regexp of modports to read from in
12804 that interface.
12806 The optional third parameter is a regular expression, and only
12807 signals matching the regular expression will be included.
12809 Limitations:
12810 If placed inside the parenthesis of a module declaration, it creates
12811 Verilog 2001 style, else uses Verilog 1995 style.
12813 Interface names must be resolvable to filenames. See `verilog-auto-inst'.
12815 As with other autos, any inputs/outputs declared in the module
12816 will suppress the AUTO from redeclaring an inputs/outputs by
12817 the same name.
12819 An example:
12821 interface ExampIf
12822 ( input logic clk );
12823 logic req_val;
12824 logic [7:0] req_dat;
12825 clocking mon_clkblk @(posedge clk);
12826 input req_val;
12827 input req_dat;
12828 endclocking
12829 modport mp(clocking mon_clkblk);
12830 endinterface
12832 module ExampMain
12833 ( input clk,
12834 /*AUTOINOUTMODPORT(\"ExampIf\" \"mp\")*/
12835 // Beginning of automatic in/out/inouts (from modport)
12836 input [7:0] req_dat,
12837 input req_val
12838 // End of automatics
12840 /*AUTOASSIGNMODPORT(\"ExampIf\" \"mp\")*/
12841 endmodule
12843 Typing \\[verilog-auto] will make this into:
12846 module ExampMain
12847 ( input clk,
12848 /*AUTOINOUTMODPORT(\"ExampIf\" \"mp\")*/
12849 // Beginning of automatic in/out/inouts (from modport)
12850 input req_dat,
12851 input req_val
12852 // End of automatics
12855 If the modport is part of a UVM monitor/driver class, this
12856 creates a wrapper module that may be used to instantiate the
12857 driver/monitor using AUTOINST in the testbench."
12858 (save-excursion
12859 (let* ((params (verilog-read-auto-params 2 3))
12860 (submod (nth 0 params))
12861 (modport-re (nth 1 params))
12862 (regexp (nth 2 params))
12863 direction-re submodi) ; direction argument not supported until requested
12864 ;; Lookup position, etc of co-module
12865 ;; Note this may raise an error
12866 (when (setq submodi (verilog-modi-lookup submod t))
12867 (let* ((indent-pt (current-indentation))
12868 (v2k (verilog-in-paren-quick))
12869 (modi (verilog-modi-current))
12870 (moddecls (verilog-modi-get-decls modi))
12871 (submoddecls (verilog-modi-get-decls submodi))
12872 (submodportdecls (verilog-modi-modport-lookup submodi modport-re))
12873 (sig-list-i (verilog-signals-in ; Decls doesn't have data types, must resolve
12874 (verilog-decls-get-vars submoddecls)
12875 (verilog-signals-not-in
12876 (verilog-decls-get-inputs submodportdecls)
12877 (append (verilog-decls-get-ports submoddecls)
12878 (verilog-decls-get-ports moddecls)))))
12879 (sig-list-o (verilog-signals-in ; Decls doesn't have data types, must resolve
12880 (verilog-decls-get-vars submoddecls)
12881 (verilog-signals-not-in
12882 (verilog-decls-get-outputs submodportdecls)
12883 (append (verilog-decls-get-ports submoddecls)
12884 (verilog-decls-get-ports moddecls)))))
12885 (sig-list-io (verilog-signals-in ; Decls doesn't have data types, must resolve
12886 (verilog-decls-get-vars submoddecls)
12887 (verilog-signals-not-in
12888 (verilog-decls-get-inouts submodportdecls)
12889 (append (verilog-decls-get-ports submoddecls)
12890 (verilog-decls-get-ports moddecls))))))
12891 (forward-line 1)
12892 (setq sig-list-i (verilog-signals-edit-wire-reg
12893 (verilog-signals-matching-dir-re
12894 (verilog-signals-matching-regexp sig-list-i regexp)
12895 "input" direction-re))
12896 sig-list-o (verilog-signals-edit-wire-reg
12897 (verilog-signals-matching-dir-re
12898 (verilog-signals-matching-regexp sig-list-o regexp)
12899 "output" direction-re))
12900 sig-list-io (verilog-signals-edit-wire-reg
12901 (verilog-signals-matching-dir-re
12902 (verilog-signals-matching-regexp sig-list-io regexp)
12903 "inout" direction-re)))
12904 (when v2k (verilog-repair-open-comma))
12905 (when (or sig-list-i sig-list-o sig-list-io)
12906 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from modport)\n")
12907 ;; Don't sort them so an upper AUTOINST will match the main module
12908 (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
12909 (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
12910 (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
12911 (verilog-insert-indent "// End of automatics\n"))
12912 (when v2k (verilog-repair-close-comma)))))))
12914 (defun verilog-auto-insert-lisp ()
12915 "Expand AUTOINSERTLISP statements, as part of \\[verilog-auto].
12916 The Lisp code provided is called before other AUTOS are expanded,
12917 and the Lisp code generally will call `insert' to insert text
12918 into the current file beginning on the line after the
12919 AUTOINSERTLISP.
12921 See also AUTOINSERTLAST and `verilog-auto-insert-last' which
12922 executes after (as opposed to before) other AUTOs.
12924 See also AUTO_LISP, which takes a Lisp expression and evaluates
12925 it during `verilog-auto-inst' but does not insert any text.
12927 An example:
12929 module ExampInsertLisp;
12930 /*AUTOINSERTLISP(my-verilog-insert-hello \"world\")*/
12931 endmodule
12933 // For this example we declare the function in the
12934 // module's file itself. Often you'd define it instead
12935 // in a site-start.el or init file.
12937 Local Variables:
12938 eval:
12939 (defun my-verilog-insert-hello (who)
12940 (insert (concat \"initial $write(\\\"hello \" who \"\\\");\\n\")))
12941 End:
12944 Typing \\[verilog-auto] will call my-verilog-insert-hello and
12945 expand the above into:
12947 // Beginning of automatic insert lisp
12948 initial $write(\"hello world\");
12949 // End of automatics
12951 You can also call an external program and insert the returned
12952 text:
12954 /*AUTOINSERTLISP(insert (shell-command-to-string \"echo //hello\"))*/
12955 // Beginning of automatic insert lisp
12956 //hello
12957 // End of automatics"
12958 (save-excursion
12959 ;; Point is at end of /*AUTO...*/
12960 (let* ((indent-pt (current-indentation))
12961 (cmd-end-pt (save-excursion (search-backward ")")
12962 (forward-char)
12963 (point))) ; Closing paren
12964 (cmd-beg-pt (save-excursion (goto-char cmd-end-pt)
12965 (backward-sexp 1) ; Inside comment
12966 (point))) ; Beginning paren
12967 (cmd (buffer-substring-no-properties cmd-beg-pt cmd-end-pt)))
12968 (verilog-forward-or-insert-line)
12969 ;; Some commands don't move point (like insert-file) so we always
12970 ;; add the begin/end comments, then delete it if not needed
12971 (verilog-insert-indent "// Beginning of automatic insert lisp\n")
12972 (verilog-insert-indent "// End of automatics\n")
12973 (forward-line -1)
12974 (eval (read cmd))
12975 (forward-line -1)
12976 (setq verilog-scan-cache-tick nil) ; Clear cache; inserted unknown text
12977 (verilog-delete-empty-auto-pair))))
12979 (defun verilog-auto-insert-last ()
12980 "Expand AUTOINSERTLAST statements, as part of \\[verilog-auto].
12981 The Lisp code provided is called after all other AUTOS have been
12982 expanded, and the Lisp code generally will call `insert' to
12983 insert text into the current file beginning on the line after the
12984 AUTOINSERTLAST.
12986 Other than when called (after AUTOs are expanded), the functionality
12987 is otherwise identical to AUTOINSERTLISP and `verilog-auto-insert-lisp' which
12988 executes before (as opposed to after) other AUTOs.
12990 See `verilog-auto-insert-lisp' for examples."
12991 (verilog-auto-insert-lisp))
12993 (defun verilog-auto-sense-sigs (moddecls presense-sigs)
12994 "Return list of signals for current AUTOSENSE block."
12995 (let* ((sigss (save-excursion
12996 (search-forward ")")
12997 (verilog-read-always-signals)))
12998 (sig-list (verilog-signals-not-params
12999 (verilog-signals-not-in (verilog-alw-get-inputs sigss)
13000 (append (and (not verilog-auto-sense-include-inputs)
13001 (verilog-alw-get-outputs-delayed sigss))
13002 (and (not verilog-auto-sense-include-inputs)
13003 (verilog-alw-get-outputs-immediate sigss))
13004 (verilog-alw-get-temps sigss)
13005 (verilog-decls-get-consts moddecls)
13006 (verilog-decls-get-gparams moddecls)
13007 presense-sigs)))))
13008 sig-list))
13010 (defun verilog-auto-sense ()
13011 "Expand AUTOSENSE statements, as part of \\[verilog-auto].
13012 Replace the always (/*AUTOSENSE*/) sensitivity list (/*AS*/ for short)
13013 with one automatically derived from all inputs declared in the always
13014 statement. Signals that are generated within the same always block are NOT
13015 placed into the sensitivity list (see `verilog-auto-sense-include-inputs').
13016 Long lines are split based on the `fill-column', see \\[set-fill-column].
13018 Limitations:
13019 Verilog does not allow memories (multidimensional arrays) in sensitivity
13020 lists. AUTOSENSE will thus exclude them, and add a /*memory or*/ comment.
13022 Constant signals:
13023 AUTOSENSE cannot always determine if a \\=`define is a constant or a signal
13024 (it could be in an include file for example). If a \\=`define or other signal
13025 is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT
13026 declaration anywhere in the module (parenthesis are required):
13028 /* AUTO_CONSTANT ( \\=`this_is_really_constant_dont_autosense_it ) */
13030 Better yet, use a parameter, which will be understood to be constant
13031 automatically.
13033 OOps!
13034 If AUTOSENSE makes a mistake, please report it. (First try putting
13035 a begin/end after your always!) As a workaround, if a signal that
13036 shouldn't be in the sensitivity list was, use the AUTO_CONSTANT above.
13037 If a signal should be in the sensitivity list wasn't, placing it before
13038 the /*AUTOSENSE*/ comment will prevent it from being deleted when the
13039 autos are updated (or added if it occurs there already).
13041 An example:
13043 always @ (/*AS*/) begin
13044 /* AUTO_CONSTANT (\\=`constant) */
13045 outin = ina | inb | \\=`constant;
13046 out = outin;
13049 Typing \\[verilog-auto] will make this into:
13051 always @ (/*AS*/ina or inb) begin
13052 /* AUTO_CONSTANT (\\=`constant) */
13053 outin = ina | inb | \\=`constant;
13054 out = outin;
13057 Note in Verilog 2001, you can often get the same result from the new @*
13058 operator. (This was added to the language in part due to AUTOSENSE!)
13060 always @* begin
13061 outin = ina | inb | \\=`constant;
13062 out = outin;
13063 end"
13064 (save-excursion
13065 ;; Find beginning
13066 (let* ((start-pt (save-excursion
13067 (verilog-re-search-backward-quick "(" nil t)
13068 (point)))
13069 (indent-pt (save-excursion
13070 (or (and (goto-char start-pt) (1+ (current-column)))
13071 (current-indentation))))
13072 (modi (verilog-modi-current))
13073 (moddecls (verilog-modi-get-decls modi))
13074 (sig-memories (verilog-signals-memory
13075 (verilog-decls-get-vars moddecls)))
13076 sig-list not-first presense-sigs)
13077 ;; Read signals in always, eliminate outputs from sense list
13078 (setq presense-sigs (verilog-signals-from-signame
13079 (save-excursion
13080 (verilog-read-signals start-pt (point)))))
13081 (setq sig-list (verilog-auto-sense-sigs moddecls presense-sigs))
13082 (when sig-memories
13083 (let ((tlen (length sig-list)))
13084 (setq sig-list (verilog-signals-not-in sig-list sig-memories))
13085 (if (not (eq tlen (length sig-list))) (verilog-insert " /*memory or*/ "))))
13086 (if (and presense-sigs ; Add a "or" if not "(.... or /*AUTOSENSE*/"
13087 (save-excursion (goto-char (point))
13088 (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
13089 (verilog-re-search-backward-quick "\\s-" start-pt t)
13090 (while (looking-at "\\s-`endif")
13091 (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
13092 (verilog-re-search-backward-quick "\\s-" start-pt t))
13093 (not (looking-at "\\s-or\\b"))))
13094 (setq not-first t))
13095 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
13096 (while sig-list
13097 (cond ((> (+ 4 (current-column) (length (verilog-sig-name (car sig-list)))) fill-column) ;+4 for width of or
13098 (insert "\n")
13099 (indent-to indent-pt)
13100 (if not-first (insert "or ")))
13101 (not-first (insert " or ")))
13102 (insert (verilog-sig-name (car sig-list)))
13103 (setq sig-list (cdr sig-list)
13104 not-first t)))))
13106 (defun verilog-auto-reset ()
13107 "Expand AUTORESET statements, as part of \\[verilog-auto].
13108 Replace the /*AUTORESET*/ comment with code to initialize all
13109 registers set elsewhere in the always block.
13111 Limitations:
13112 AUTORESET will not clear memories.
13114 AUTORESET uses <= if the signal has a <= assignment in the block,
13115 else it uses =.
13117 If <= is used, all = assigned variables are ignored if
13118 `verilog-auto-reset-blocking-in-non' is nil; they are presumed
13119 to be temporaries.
13121 /*AUTORESET*/ presumes that any signals mentioned between the previous
13122 begin/case/if statement and the AUTORESET comment are being reset manually
13123 and should not be automatically reset. This includes omitting any signals
13124 used on the right hand side of assignments.
13126 By default, AUTORESET will include the width of the signal in the
13127 autos, SystemVerilog designs may want to change this. To control
13128 this behavior, see `verilog-auto-reset-widths'. In some cases
13129 AUTORESET must use a \\='0 assignment and it will print NOWIDTH; use
13130 `verilog-auto-reset-widths' unbased to prevent this.
13132 AUTORESET ties signals to deasserted, which is presumed to be zero.
13133 Signals that match `verilog-active-low-regexp' will be deasserted by tying
13134 them to a one.
13136 AUTORESET may try to reset arrays or structures that cannot be
13137 reset by a simple assignment, resulting in compile errors. This
13138 is a feature to be taken as a hint that you need to reset these
13139 signals manually (or put them into a \"\\=`ifdef NEVER signal<=\\=`0;
13140 \\=`endif\" so Verilog-Mode ignores them.)
13142 An example:
13144 always @(posedge clk or negedge reset_l) begin
13145 if (!reset_l) begin
13146 c <= 1;
13147 /*AUTORESET*/
13149 else begin
13150 a <= in_a;
13151 b <= in_b;
13152 c <= in_c;
13156 Typing \\[verilog-auto] will make this into:
13158 always @(posedge core_clk or negedge reset_l) begin
13159 if (!reset_l) begin
13160 c <= 1;
13161 /*AUTORESET*/
13162 // Beginning of autoreset for uninitialized flops
13163 a <= 0;
13164 b = 0; // if `verilog-auto-reset-blocking-in-non' true
13165 // End of automatics
13167 else begin
13168 a <= in_a;
13169 b = in_b;
13170 c <= in_c;
13172 end"
13174 (interactive)
13175 (save-excursion
13176 ;; Find beginning
13177 (let* ((indent-pt (current-indentation))
13178 (modi (verilog-modi-current))
13179 (moddecls (verilog-modi-get-decls modi))
13180 (all-list (verilog-decls-get-signals moddecls))
13181 sigss sig-list dly-list prereset-sigs)
13182 ;; Read signals in always, eliminate outputs from reset list
13183 (setq prereset-sigs (verilog-signals-from-signame
13184 (save-excursion
13185 (verilog-read-signals
13186 (save-excursion
13187 (verilog-re-search-backward-quick
13188 "\\(@\\|\\<\\(begin\\|if\\|case[xz]?\\|always\\(_latch\\|_ff\\|_comb\\)?\\)\\>\\)" nil t)
13189 (point))
13190 (point)))))
13191 (save-excursion
13192 (verilog-re-search-backward-quick "\\(@\\|\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\)\\>\\)" nil t)
13193 (setq sigss (verilog-read-always-signals)))
13194 (setq dly-list (verilog-alw-get-outputs-delayed sigss))
13195 (setq sig-list (verilog-signals-not-in-struct
13196 (append
13197 (verilog-alw-get-outputs-delayed sigss)
13198 (when (or (not (verilog-alw-get-uses-delayed sigss))
13199 verilog-auto-reset-blocking-in-non)
13200 (verilog-alw-get-outputs-immediate sigss)))
13201 (append
13202 (verilog-alw-get-temps sigss)
13203 prereset-sigs)))
13204 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
13205 (when sig-list
13206 (insert "\n");
13207 (verilog-insert-indent "// Beginning of autoreset for uninitialized flops\n");
13208 (while sig-list
13209 (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ; As sig-list has no widths
13210 (car sig-list))))
13211 (indent-to indent-pt)
13212 (insert (verilog-sig-name sig)
13213 (if (assoc (verilog-sig-name sig) dly-list)
13214 (concat " <= " verilog-assignment-delay)
13215 " = ")
13216 (verilog-sig-tieoff sig)
13217 ";\n")
13218 (setq sig-list (cdr sig-list))))
13219 (verilog-insert-indent "// End of automatics")))))
13221 (defun verilog-auto-tieoff ()
13222 "Expand AUTOTIEOFF statements, as part of \\[verilog-auto].
13223 Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output
13224 signals to deasserted.
13226 /*AUTOTIEOFF*/ is used to make stub modules; modules that have the same
13227 input/output list as another module, but no internals. Specifically, it
13228 finds all outputs in the module, and if that input is not otherwise declared
13229 as a register or wire, creates a tieoff.
13231 AUTORESET ties signals to deasserted, which is presumed to be zero.
13232 Signals that match `verilog-active-low-regexp' will be deasserted by tying
13233 them to a one.
13235 You can add signals you do not want included in AUTOTIEOFF with
13236 `verilog-auto-tieoff-ignore-regexp'.
13238 `verilog-auto-wire-type' may be used to change the datatype of
13239 the declarations.
13241 `verilog-auto-reset-widths' may be used to change how the tieoff
13242 value's width is generated.
13244 An example of making a stub for another module:
13246 module ExampStub (/*AUTOINST*/);
13247 /*AUTOINOUTPARAM(\"Foo\")*/
13248 /*AUTOINOUTMODULE(\"Foo\")*/
13249 /*AUTOTIEOFF*/
13250 // verilator lint_off UNUSED
13251 wire _unused_ok = &{1\\='b0,
13252 /*AUTOUNUSED*/
13253 1\\='b0};
13254 // verilator lint_on UNUSED
13255 endmodule
13257 Typing \\[verilog-auto] will make this into:
13259 module ExampStub (/*AUTOINST*/...);
13260 /*AUTOINOUTPARAM(\"Foo\")*/
13261 /*AUTOINOUTMODULE(\"Foo\")*/
13262 // Beginning of autotieoff
13263 output [2:0] foo;
13264 // End of automatics
13266 /*AUTOTIEOFF*/
13267 // Beginning of autotieoff
13268 wire [2:0] foo = 3\\='b0;
13269 // End of automatics
13271 endmodule"
13272 (interactive)
13273 (save-excursion
13274 ;; Find beginning
13275 (let* ((indent-pt (current-indentation))
13276 (modi (verilog-modi-current))
13277 (moddecls (verilog-modi-get-decls modi))
13278 (modsubdecls (verilog-modi-get-sub-decls modi))
13279 (sig-list (verilog-signals-not-in
13280 (verilog-decls-get-outputs moddecls)
13281 (append (verilog-decls-get-vars moddecls)
13282 (verilog-decls-get-assigns moddecls)
13283 (verilog-decls-get-consts moddecls)
13284 (verilog-decls-get-gparams moddecls)
13285 (verilog-subdecls-get-interfaced modsubdecls)
13286 (verilog-subdecls-get-outputs modsubdecls)
13287 (verilog-subdecls-get-inouts modsubdecls)))))
13288 (setq sig-list (verilog-signals-not-matching-regexp
13289 sig-list verilog-auto-tieoff-ignore-regexp))
13290 (when sig-list
13291 (verilog-forward-or-insert-line)
13292 (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n")
13293 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
13294 (verilog-modi-cache-add-vars modi sig-list) ; Before we trash list
13295 (while sig-list
13296 (let ((sig (car sig-list)))
13297 (cond ((equal verilog-auto-tieoff-declaration "assign")
13298 (indent-to indent-pt)
13299 (insert "assign " (verilog-sig-name sig)))
13301 (verilog-insert-one-definition sig verilog-auto-tieoff-declaration indent-pt)))
13302 (indent-to (max 48 (+ indent-pt 40)))
13303 (insert "= " (verilog-sig-tieoff sig)
13304 ";\n")
13305 (setq sig-list (cdr sig-list))))
13306 (verilog-insert-indent "// End of automatics\n")))))
13308 (defun verilog-auto-undef ()
13309 "Expand AUTOUNDEF statements, as part of \\[verilog-auto].
13310 Take any \\=`defines since the last AUTOUNDEF in the current file
13311 and create \\=`undefs for them. This is used to insure that
13312 file-local defines do not pollute the global \\=`define name space.
13314 Limitations:
13315 AUTOUNDEF presumes any identifier following \\=`define is the
13316 name of a define. Any \\=`ifdefs are ignored.
13318 AUTOUNDEF suppresses creating an \\=`undef for any define that was
13319 \\=`undefed before the AUTOUNDEF. This may be used to work around
13320 the ignoring of \\=`ifdefs as shown below.
13322 An example:
13324 \\=`define XX_FOO
13325 \\=`define M_BAR(x)
13326 \\=`define M_BAZ
13328 \\=`ifdef NEVER
13329 \\=`undef M_BAZ // Emacs will see this and not \\=`undef M_BAZ
13330 \\=`endif
13332 /*AUTOUNDEF*/
13334 Typing \\[verilog-auto] will make this into:
13337 /*AUTOUNDEF*/
13338 // Beginning of automatic undefs
13339 \\=`undef XX_FOO
13340 \\=`undef M_BAR
13341 // End of automatics
13343 You may also provide an optional regular expression, in which case only
13344 defines the regular expression will be undefed."
13345 (save-excursion
13346 (let* ((params (verilog-read-auto-params 0 1))
13347 (regexp (nth 0 params))
13348 (indent-pt (current-indentation))
13349 (end-pt (point))
13350 defs def)
13351 (save-excursion
13352 ;; Scan from start of file, or last AUTOUNDEF
13353 (or (verilog-re-search-backward-quick "/\\*AUTOUNDEF\\>" end-pt t)
13354 (goto-char (point-min)))
13355 (while (verilog-re-search-forward-quick
13356 "`\\(define\\|undef\\)\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" end-pt t)
13357 (cond ((equal (match-string-no-properties 1) "define")
13358 (setq def (match-string-no-properties 2))
13359 (when (and (or (not regexp)
13360 (string-match regexp def))
13361 (not (member def defs))) ; delete-dups not in 21.1
13362 (setq defs (cons def defs))))
13364 (setq defs (delete (match-string-no-properties 2) defs))))))
13365 ;; Insert
13366 (setq defs (sort defs 'string<))
13367 (when defs
13368 (verilog-forward-or-insert-line)
13369 (verilog-insert-indent "// Beginning of automatic undefs\n")
13370 (while defs
13371 (verilog-insert-indent "`undef " (car defs) "\n")
13372 (setq defs (cdr defs)))
13373 (verilog-insert-indent "// End of automatics\n")))))
13375 (defun verilog-auto-unused ()
13376 "Expand AUTOUNUSED statements, as part of \\[verilog-auto].
13377 Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused
13378 input and inout signals.
13380 /*AUTOUNUSED*/ is used to make stub modules; modules that have the same
13381 input/output list as another module, but no internals. Specifically, it
13382 finds all inputs and inouts in the module, and if that input is not otherwise
13383 used, adds it to a comma separated list.
13385 The comma separated list is intended to be used to create a _unused_ok
13386 signal. Using the exact name \"_unused_ok\" for name of the temporary
13387 signal is recommended as it will insure maximum forward compatibility, it
13388 also makes lint warnings easy to understand; ignore any unused warnings
13389 with \"unused\" in the signal name.
13391 To reduce simulation time, the _unused_ok signal should be forced to a
13392 constant to prevent wiggling. The easiest thing to do is use a
13393 reduction-and with 1\\='b0 as shown.
13395 This way all unused signals are in one place, making it convenient to add
13396 your tool's specific pragmas around the assignment to disable any unused
13397 warnings.
13399 You can add signals you do not want included in AUTOUNUSED with
13400 `verilog-auto-unused-ignore-regexp'.
13402 An example of making a stub for another module:
13404 module ExampStub (/*AUTOINST*/);
13405 /*AUTOINOUTPARAM(\"Examp\")*/
13406 /*AUTOINOUTMODULE(\"Examp\")*/
13407 /*AUTOTIEOFF*/
13408 // verilator lint_off UNUSED
13409 wire _unused_ok = &{1\\='b0,
13410 /*AUTOUNUSED*/
13411 1\\='b0};
13412 // verilator lint_on UNUSED
13413 endmodule
13415 Typing \\[verilog-auto] will make this into:
13418 // verilator lint_off UNUSED
13419 wire _unused_ok = &{1\\='b0,
13420 /*AUTOUNUSED*/
13421 // Beginning of automatics
13422 unused_input_a,
13423 unused_input_b,
13424 unused_input_c,
13425 // End of automatics
13426 1\\='b0};
13427 // verilator lint_on UNUSED
13428 endmodule"
13429 (interactive)
13430 (save-excursion
13431 ;; Find beginning
13432 (let* ((indent-pt (progn (search-backward "/*") (current-column)))
13433 (modi (verilog-modi-current))
13434 (moddecls (verilog-modi-get-decls modi))
13435 (modsubdecls (verilog-modi-get-sub-decls modi))
13436 (sig-list (verilog-signals-not-in
13437 (append (verilog-decls-get-inputs moddecls)
13438 (verilog-decls-get-inouts moddecls))
13439 (append (verilog-subdecls-get-inputs modsubdecls)
13440 (verilog-subdecls-get-inouts modsubdecls)))))
13441 (setq sig-list (verilog-signals-not-matching-regexp
13442 sig-list verilog-auto-unused-ignore-regexp))
13443 (when sig-list
13444 (verilog-forward-or-insert-line)
13445 (verilog-insert-indent "// Beginning of automatic unused inputs\n")
13446 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
13447 (while sig-list
13448 (let ((sig (car sig-list)))
13449 (indent-to indent-pt)
13450 (insert (verilog-sig-name sig) ",\n")
13451 (setq sig-list (cdr sig-list))))
13452 (verilog-insert-indent "// End of automatics\n")))))
13454 (defun verilog-enum-ascii (signm elim-regexp)
13455 "Convert an enum name SIGNM to an ascii string for insertion.
13456 Remove user provided prefix ELIM-REGEXP."
13457 (or elim-regexp (setq elim-regexp "_ DONT MATCH IT_"))
13458 (let ((case-fold-search t))
13459 ;; All upper becomes all lower for readability
13460 (downcase (verilog-string-replace-matches elim-regexp "" nil nil signm))))
13462 (defun verilog-auto-ascii-enum ()
13463 "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto].
13464 Create a register to contain the ASCII decode of an enumerated signal type.
13465 This will allow trace viewers to show the ASCII name of states.
13467 First, parameters are built into an enumeration using the synopsys enum
13468 comment. The comment must be between the keyword and the symbol.
13469 \(Annoying, but that's what Synopsys's dc_shell FSM reader requires.)
13471 Next, registers which that enum applies to are also tagged with the same
13472 enum.
13474 Finally, an AUTOASCIIENUM command is used.
13476 The first parameter is the name of the signal to be decoded.
13478 The second parameter is the name to store the ASCII code into. For the
13479 signal foo, I suggest the name _foo__ascii, where the leading _ indicates
13480 a signal that is just for simulation, and the magic characters _ascii
13481 tell viewers like Dinotrace to display in ASCII format.
13483 The third optional parameter is a string which will be removed
13484 from the state names. It defaults to \"\" which removes nothing.
13486 The fourth optional parameter is \"onehot\" to force one-hot
13487 decoding. If unspecified, if and only if the first parameter
13488 width is 2^(number of states in enum) and does NOT match the
13489 width of the enum, the signal is assumed to be a one-hot
13490 decode. Otherwise, it's a normal encoded state vector.
13492 `verilog-auto-wire-type' may be used to change the datatype of
13493 the declarations.
13495 \"auto enum\" may be used in place of \"synopsys enum\".
13497 An example:
13499 //== State enumeration
13500 parameter [2:0] // synopsys enum state_info
13501 SM_IDLE = 3\\='b000,
13502 SM_SEND = 3\\='b001,
13503 SM_WAIT1 = 3\\='b010;
13504 //== State variables
13505 reg [2:0] /* synopsys enum state_info */
13506 state_r; /* synopsys state_vector state_r */
13507 reg [2:0] /* synopsys enum state_info */
13508 state_e1;
13510 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
13512 Typing \\[verilog-auto] will make this into:
13514 ... same front matter ...
13516 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
13517 // Beginning of automatic ASCII enum decoding
13518 reg [39:0] state_ascii_r; // Decode of state_r
13519 always @(state_r) begin
13520 case ({state_r})
13521 SM_IDLE: state_ascii_r = \"idle \";
13522 SM_SEND: state_ascii_r = \"send \";
13523 SM_WAIT1: state_ascii_r = \"wait1\";
13524 default: state_ascii_r = \"%Erro\";
13525 endcase
13527 // End of automatics"
13528 (save-excursion
13529 (let* ((params (verilog-read-auto-params 2 4))
13530 (undecode-name (nth 0 params))
13531 (ascii-name (nth 1 params))
13532 (elim-regexp (and (nth 2 params)
13533 (not (equal (nth 2 params) ""))
13534 (nth 2 params)))
13535 (one-hot-flag (nth 3 params))
13537 (indent-pt (current-indentation))
13538 (modi (verilog-modi-current))
13539 (moddecls (verilog-modi-get-decls modi))
13541 (sig-list-consts (append (verilog-decls-get-consts moddecls)
13542 (verilog-decls-get-gparams moddecls)))
13543 (sig-list-all (verilog-decls-get-iovars moddecls))
13545 (undecode-sig (or (assoc undecode-name sig-list-all)
13546 (error "%s: Signal `%s' not found in design"
13547 (verilog-point-text) undecode-name)))
13548 (undecode-enum (or (verilog-sig-enum undecode-sig)
13549 (error "%s: Signal `%s' does not have an enum tag"
13550 (verilog-point-text) undecode-name)))
13552 (enum-sigs (verilog-signals-not-in
13553 (or (verilog-signals-matching-enum sig-list-consts undecode-enum)
13554 (error "%s: No state definitions for `%s'"
13555 (verilog-point-text) undecode-enum))
13556 nil))
13558 (one-hot (or
13559 (string-match "onehot" (or one-hot-flag ""))
13560 (and ; width(enum) != width(sig)
13561 (or (not (verilog-sig-bits (car enum-sigs)))
13562 (not (equal (verilog-sig-width (car enum-sigs))
13563 (verilog-sig-width undecode-sig))))
13564 ;; count(enums) == width(sig)
13565 (equal (number-to-string (length enum-sigs))
13566 (verilog-sig-width undecode-sig)))))
13567 (enum-chars 0)
13568 (ascii-chars 0))
13570 ;; Find number of ascii chars needed
13571 (let ((tmp-sigs enum-sigs))
13572 (while tmp-sigs
13573 (setq enum-chars (max enum-chars (length (verilog-sig-name (car tmp-sigs))))
13574 ascii-chars (max ascii-chars (length (verilog-enum-ascii
13575 (verilog-sig-name (car tmp-sigs))
13576 elim-regexp)))
13577 tmp-sigs (cdr tmp-sigs))))
13579 (verilog-forward-or-insert-line)
13580 (verilog-insert-indent "// Beginning of automatic ASCII enum decoding\n")
13581 (let ((decode-sig-list (list (list ascii-name (format "[%d:0]" (- (* ascii-chars 8) 1))
13582 (concat "Decode of " undecode-name) nil nil))))
13583 (verilog-insert-definition modi decode-sig-list "reg" indent-pt nil))
13585 (verilog-insert-indent "always @(" undecode-name ") begin\n")
13586 (setq indent-pt (+ indent-pt verilog-indent-level))
13587 (verilog-insert-indent "case ({" undecode-name "})\n")
13588 (setq indent-pt (+ indent-pt verilog-case-indent))
13590 (let ((tmp-sigs enum-sigs)
13591 (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n"
13592 (+ (if one-hot 9 1) (max 8 enum-chars))
13593 ascii-name ascii-chars))
13594 (errname (substring "%Error" 0 (min 6 ascii-chars))))
13595 (while tmp-sigs
13596 (verilog-insert-indent
13597 (concat
13598 (format chrfmt
13599 (concat (if one-hot "(")
13600 ;; Use enum-sigs length as that's numeric
13601 ;; verilog-sig-width undecode-sig might not be.
13602 (if one-hot (number-to-string (length enum-sigs)))
13603 ;; We use a shift instead of var[index]
13604 ;; so that a non-one hot value will show as error.
13605 (if one-hot "'b1<<")
13606 (verilog-sig-name (car tmp-sigs))
13607 (if one-hot ")") ":")
13608 (verilog-enum-ascii (verilog-sig-name (car tmp-sigs))
13609 elim-regexp))))
13610 (setq tmp-sigs (cdr tmp-sigs)))
13611 (verilog-insert-indent (format chrfmt "default:" errname)))
13613 (setq indent-pt (- indent-pt verilog-case-indent))
13614 (verilog-insert-indent "endcase\n")
13615 (setq indent-pt (- indent-pt verilog-indent-level))
13616 (verilog-insert-indent "end\n"
13617 "// End of automatics\n"))))
13619 (defun verilog-auto-templated-rel ()
13620 "Replace Templated relative line numbers with absolute line numbers.
13621 Internal use only. This hacks around the line numbers in AUTOINST Templates
13622 being different from the final output's line numbering."
13623 (let ((templateno 0) (template-line (list 0)) (buf-line 1))
13624 ;; Find line number each template is on
13625 ;; Count lines as we go, as otherwise it's O(n^2) to use count-lines
13626 (goto-char (point-min))
13627 (while (not (eobp))
13628 (when (looking-at ".*AUTO_TEMPLATE")
13629 (setq templateno (1+ templateno))
13630 (setq template-line (cons buf-line template-line)))
13631 (setq buf-line (1+ buf-line))
13632 (forward-line 1))
13633 (setq template-line (nreverse template-line))
13634 ;; Replace T# L# with absolute line number
13635 (goto-char (point-min))
13636 (while (re-search-forward " Templated T\\([0-9]+\\) L\\([0-9]+\\)" nil t)
13637 (replace-match
13638 (concat " Templated "
13639 (int-to-string (+ (nth (string-to-number (match-string 1))
13640 template-line)
13641 (string-to-number (match-string 2)))))
13642 t t))))
13644 (defun verilog-auto-template-lint ()
13645 "Check AUTO_TEMPLATEs for unused lines.
13646 Enable with `verilog-auto-template-warn-unused'."
13647 (let ((name1 (or (buffer-file-name) (buffer-name))))
13648 (save-excursion
13649 (goto-char (point-min))
13650 (while (re-search-forward
13651 "^\\s-*/?\\*?\\s-*[a-zA-Z0-9`_$]+\\s-+AUTO_TEMPLATE" nil t)
13652 (let* ((tpl-info (verilog-read-auto-template-middle))
13653 (tpl-list (aref tpl-info 1))
13654 (tlines (append (nth 0 tpl-list) (nth 1 tpl-list)))
13655 tpl-ass)
13656 (while tlines
13657 (setq tpl-ass (car tlines)
13658 tlines (cdr tlines))
13660 (unless (or (not (eval-when-compile (fboundp 'make-hash-table))) ; Not supported, no warning
13661 (not verilog-auto-template-hits)
13662 (gethash (vector (nth 2 tpl-ass) (nth 3 tpl-ass))
13663 verilog-auto-template-hits))
13664 (verilog-warn-error "%s:%d: AUTO_TEMPLATE line unused: \".%s (%s)\""
13665 name1
13666 (+ (elt tpl-ass 3) ; Template line number
13667 (count-lines (point-min) (point)))
13668 (elt tpl-ass 0) (elt tpl-ass 1))
13669 )))))))
13672 ;;; Auto top level:
13675 (defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing an arg
13676 "Expand AUTO statements.
13677 Look for any /*AUTO...*/ commands in the code, as used in
13678 instantiations or argument headers. Update the list of signals
13679 following the /*AUTO...*/ command.
13681 Use \\[verilog-delete-auto] to remove the AUTOs.
13683 Use \\[verilog-diff-auto] to see differences in AUTO expansion.
13685 Use \\[verilog-inject-auto] to insert AUTOs for the first time.
13687 Use \\[verilog-faq] for a pointer to frequently asked questions.
13689 For new users, we recommend setting `verilog-case-fold' to nil
13690 and `verilog-auto-arg-sort' to t.
13692 The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are
13693 called before and after this function, respectively.
13695 For example:
13696 module ModuleName (/*AUTOARG*/);
13697 /*AUTOINPUT*/
13698 /*AUTOOUTPUT*/
13699 /*AUTOWIRE*/
13700 /*AUTOREG*/
13701 InstMod instName #(/*AUTOINSTPARAM*/) (/*AUTOINST*/);
13703 You can also update the AUTOs from the shell using:
13704 emacs --batch <filenames.v> -f verilog-batch-auto
13705 Or fix indentation with:
13706 emacs --batch <filenames.v> -f verilog-batch-indent
13707 Likewise, you can delete or inject AUTOs with:
13708 emacs --batch <filenames.v> -f verilog-batch-delete-auto
13709 emacs --batch <filenames.v> -f verilog-batch-inject-auto
13710 Or check if AUTOs have the same expansion
13711 emacs --batch <filenames.v> -f verilog-batch-diff-auto
13713 Using \\[describe-function], see also:
13714 `verilog-auto-arg' for AUTOARG module instantiations
13715 `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding
13716 `verilog-auto-assign-modport' for AUTOASSIGNMODPORT assignment to/from modport
13717 `verilog-auto-inout' for AUTOINOUT making hierarchy inouts
13718 `verilog-auto-inout-comp' for AUTOINOUTCOMP copy complemented i/o
13719 `verilog-auto-inout-in' for AUTOINOUTIN inputs for all i/o
13720 `verilog-auto-inout-modport' for AUTOINOUTMODPORT i/o from an interface modport
13721 `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere
13722 `verilog-auto-inout-param' for AUTOINOUTPARAM copying params from elsewhere
13723 `verilog-auto-input' for AUTOINPUT making hierarchy inputs
13724 `verilog-auto-insert-lisp' for AUTOINSERTLISP insert code from lisp function
13725 `verilog-auto-insert-last' for AUTOINSERTLAST insert code from lisp function
13726 `verilog-auto-inst' for AUTOINST instantiation pins
13727 `verilog-auto-star' for AUTOINST .* SystemVerilog pins
13728 `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params
13729 `verilog-auto-logic' for AUTOLOGIC declaring logic signals
13730 `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs
13731 `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs
13732 `verilog-auto-reg' for AUTOREG registers
13733 `verilog-auto-reg-input' for AUTOREGINPUT instantiation registers
13734 `verilog-auto-reset' for AUTORESET flop resets
13735 `verilog-auto-sense' for AUTOSENSE or AS always sensitivity lists
13736 `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs
13737 `verilog-auto-undef' for AUTOUNDEF \\=`undef of local \\=`defines
13738 `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts
13739 `verilog-auto-wire' for AUTOWIRE instantiation wires
13741 `verilog-read-defines' for reading \\=`define values
13742 `verilog-read-includes' for reading \\=`includes
13744 If you have bugs with these autos, please file an issue at
13745 URL `http://www.veripool.org/verilog-mode' or contact the AUTOAUTHOR
13746 Wilson Snyder (wsnyder@wsnyder.org)."
13747 (interactive)
13748 (unless noninteractive (message "Updating AUTOs..."))
13749 (if (fboundp 'dinotrace-unannotate-all)
13750 (dinotrace-unannotate-all))
13751 ;; Disable change hooks for speed
13752 ;; This let can't be part of above let; must restore
13753 ;; after-change-functions before font-lock resumes
13754 (verilog-save-font-no-change-functions
13755 (let ((oldbuf (if (not (buffer-modified-p))
13756 (buffer-string)))
13757 (case-fold-search verilog-case-fold)
13758 ;; Cache directories; we don't write new files, so can't change
13759 (verilog-dir-cache-preserving t)
13760 ;; Cache current module
13761 (verilog-modi-cache-current-enable t)
13762 (verilog-modi-cache-current-max (point-min)) ; IE it's invalid
13763 verilog-modi-cache-current)
13764 (verilog-save-scan-cache
13765 (save-excursion
13766 ;; Wipe cache; otherwise if we AUTOed a block above this one,
13767 ;; we'll misremember we have generated IOs, confusing AUTOOUTPUT
13768 (setq verilog-modi-cache-list nil)
13769 ;; Local state
13770 (verilog-read-auto-template-init)
13771 ;; If we're not in verilog-mode, change syntax table so parsing works right
13772 (unless (eq major-mode `verilog-mode) (verilog-mode))
13773 ;; Allow user to customize
13774 (verilog-run-hooks 'verilog-before-auto-hook)
13775 ;; Try to save the user from needing to revert-file to reread file local-variables
13776 (verilog-auto-reeval-locals)
13777 (verilog-read-auto-lisp-present)
13778 (verilog-read-auto-lisp (point-min) (point-max))
13779 (verilog-getopt-flags)
13780 ;; From here on out, we can cache anything we read from disk
13781 (verilog-preserve-dir-cache
13782 ;; These two may seem obvious to do always, but on large includes it can be way too slow
13783 (when verilog-auto-read-includes
13784 (verilog-read-includes)
13785 (verilog-read-defines nil nil t))
13786 ;; Setup variables due to SystemVerilog expansion
13787 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic-setup)
13788 ;; This particular ordering is important
13789 ;; INST: Lower modules correct, no internal dependencies, FIRST
13790 (verilog-preserve-modi-cache
13791 ;; Clear existing autos else we'll be screwed by existing ones
13792 (verilog-delete-auto-buffer)
13793 ;; Injection if appropriate
13794 (when inject
13795 (verilog-inject-inst)
13796 (verilog-inject-sense)
13797 (verilog-inject-arg))
13799 ;; Do user inserts first, so their code can insert AUTOs
13800 (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/"
13801 'verilog-auto-insert-lisp)
13802 ;; Expand instances before need the signals the instances input/output
13803 (verilog-auto-re-search-do "/\\*AUTOINSTPARAM\\*/" 'verilog-auto-inst-param)
13804 (verilog-auto-re-search-do "/\\*AUTOINST\\*/" 'verilog-auto-inst)
13805 (verilog-auto-re-search-do "\\.\\*" 'verilog-auto-star)
13806 ;; Must be done before autoin/out as creates a reg
13807 (verilog-auto-re-search-do "/\\*AUTOASCIIENUM(.*?)\\*/" 'verilog-auto-ascii-enum)
13809 ;; first in/outs from other files
13810 (verilog-auto-re-search-do "/\\*AUTOINOUTMODPORT(.*?)\\*/" 'verilog-auto-inout-modport)
13811 (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE(.*?)\\*/" 'verilog-auto-inout-module)
13812 (verilog-auto-re-search-do "/\\*AUTOINOUTCOMP(.*?)\\*/" 'verilog-auto-inout-comp)
13813 (verilog-auto-re-search-do "/\\*AUTOINOUTIN(.*?)\\*/" 'verilog-auto-inout-in)
13814 (verilog-auto-re-search-do "/\\*AUTOINOUTPARAM(.*?)\\*/" 'verilog-auto-inout-param)
13815 ;; next in/outs which need previous sucked inputs first
13816 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\((.*?)\\)?\\*/" 'verilog-auto-output)
13817 (verilog-auto-re-search-do "/\\*AUTOINPUT\\((.*?)\\)?\\*/" 'verilog-auto-input)
13818 (verilog-auto-re-search-do "/\\*AUTOINOUT\\((.*?)\\)?\\*/" 'verilog-auto-inout)
13819 ;; Then tie off those in/outs
13820 (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff)
13821 ;; These can be anywhere after AUTOINSERTLISP
13822 (verilog-auto-re-search-do "/\\*AUTOUNDEF\\((.*?)\\)?\\*/" 'verilog-auto-undef)
13823 ;; Wires/regs must be after inputs/outputs
13824 (verilog-auto-re-search-do "/\\*AUTOASSIGNMODPORT(.*?)\\*/" 'verilog-auto-assign-modport)
13825 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic)
13826 (verilog-auto-re-search-do "/\\*AUTOWIRE\\*/" 'verilog-auto-wire)
13827 (verilog-auto-re-search-do "/\\*AUTOREG\\*/" 'verilog-auto-reg)
13828 (verilog-auto-re-search-do "/\\*AUTOREGINPUT\\*/" 'verilog-auto-reg-input)
13829 ;; outputevery needs AUTOOUTPUTs done first
13830 (verilog-auto-re-search-do "/\\*AUTOOUTPUTEVERY\\((.*?)\\)?\\*/" 'verilog-auto-output-every)
13831 ;; Doesn't matter when done, but combine it with a common changer
13832 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense)
13833 ;; After AUTOREG*, as they may have set signal widths
13834 (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset)
13835 ;; After we've created all new variables
13836 (verilog-auto-re-search-do "/\\*AUTOUNUSED\\*/" 'verilog-auto-unused)
13837 ;; Must be after all inputs outputs are generated
13838 (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg)
13839 ;; User inserts
13840 (verilog-auto-re-search-do "/\\*AUTOINSERTLAST(.*?)\\*/" 'verilog-auto-insert-last)
13841 ;; Fix line numbers (comments only)
13842 (when verilog-auto-inst-template-numbers
13843 (verilog-auto-templated-rel))
13844 (when verilog-auto-template-warn-unused
13845 (verilog-auto-template-lint))))
13847 (verilog-run-hooks 'verilog-auto-hook)
13849 (when verilog-auto-delete-trailing-whitespace
13850 (verilog-delete-trailing-whitespace))
13852 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))
13854 ;; If end result is same as when started, clear modified flag
13855 (cond ((and oldbuf (equal oldbuf (buffer-string)))
13856 (verilog-restore-buffer-modified-p nil)
13857 (unless noninteractive (message "Updating AUTOs...done (no changes)")))
13858 (t (unless noninteractive (message "Updating AUTOs...done"))))
13859 ;; End of save-cache
13860 )))))
13862 ;;; Skeletons:
13865 (defvar verilog-template-map
13866 (let ((map (make-sparse-keymap)))
13867 (define-key map "a" 'verilog-sk-always)
13868 (define-key map "b" 'verilog-sk-begin)
13869 (define-key map "c" 'verilog-sk-case)
13870 (define-key map "f" 'verilog-sk-for)
13871 (define-key map "g" 'verilog-sk-generate)
13872 (define-key map "h" 'verilog-sk-header)
13873 (define-key map "i" 'verilog-sk-initial)
13874 (define-key map "j" 'verilog-sk-fork)
13875 (define-key map "m" 'verilog-sk-module)
13876 (define-key map "o" 'verilog-sk-ovm-class)
13877 (define-key map "p" 'verilog-sk-primitive)
13878 (define-key map "r" 'verilog-sk-repeat)
13879 (define-key map "s" 'verilog-sk-specify)
13880 (define-key map "t" 'verilog-sk-task)
13881 (define-key map "u" 'verilog-sk-uvm-object)
13882 (define-key map "w" 'verilog-sk-while)
13883 (define-key map "x" 'verilog-sk-casex)
13884 (define-key map "z" 'verilog-sk-casez)
13885 (define-key map "?" 'verilog-sk-if)
13886 (define-key map ":" 'verilog-sk-else-if)
13887 (define-key map "/" 'verilog-sk-comment)
13888 (define-key map "A" 'verilog-sk-assign)
13889 (define-key map "F" 'verilog-sk-function)
13890 (define-key map "I" 'verilog-sk-input)
13891 (define-key map "O" 'verilog-sk-output)
13892 (define-key map "S" 'verilog-sk-state-machine)
13893 (define-key map "=" 'verilog-sk-inout)
13894 (define-key map "U" 'verilog-sk-uvm-component)
13895 (define-key map "W" 'verilog-sk-wire)
13896 (define-key map "R" 'verilog-sk-reg)
13897 (define-key map "D" 'verilog-sk-define-signal)
13898 map)
13899 "Keymap used in Verilog mode for smart template operations.")
13903 ;; Place the templates into Verilog Mode. They may be inserted under any key.
13904 ;; C-c C-t will be the default. If you use templates a lot, you
13905 ;; may want to consider moving the binding to another key in your init
13906 ;; file.
13908 ;; Note \C-c and letter are reserved for users
13909 (define-key verilog-mode-map "\C-c\C-t" verilog-template-map)
13911 ;; ---- statement skeletons ------------------------------------------
13913 (define-skeleton verilog-sk-prompt-condition
13914 "Prompt for the loop condition."
13915 "[condition]: " str )
13917 (define-skeleton verilog-sk-prompt-init
13918 "Prompt for the loop init statement."
13919 "[initial statement]: " str )
13921 (define-skeleton verilog-sk-prompt-inc
13922 "Prompt for the loop increment statement."
13923 "[increment statement]: " str )
13925 (define-skeleton verilog-sk-prompt-name
13926 "Prompt for the name of something."
13927 "[name]: " str)
13929 (define-skeleton verilog-sk-prompt-clock
13930 "Prompt for the name of something."
13931 "name and edge of clock(s): " str)
13933 (defvar verilog-sk-reset nil)
13934 (defun verilog-sk-prompt-reset ()
13935 "Prompt for the name of a state machine reset."
13936 (setq verilog-sk-reset (read-string "name of reset: " "rst")))
13939 (define-skeleton verilog-sk-prompt-state-selector
13940 "Prompt for the name of a state machine selector."
13941 "name of selector (eg {a,b,c,d}): " str )
13943 (define-skeleton verilog-sk-prompt-output
13944 "Prompt for the name of something."
13945 "output: " str)
13947 (define-skeleton verilog-sk-prompt-msb
13948 "Prompt for most significant bit specification."
13949 "msb:" str & ?: & '(verilog-sk-prompt-lsb) | -1 )
13951 (define-skeleton verilog-sk-prompt-lsb
13952 "Prompt for least significant bit specification."
13953 "lsb:" str )
13955 (defvar verilog-sk-p nil)
13956 (define-skeleton verilog-sk-prompt-width
13957 "Prompt for a width specification."
13959 (progn
13960 (setq verilog-sk-p (point))
13961 (verilog-sk-prompt-msb)
13962 (if (> (point) verilog-sk-p) "] " " ")))
13964 (defun verilog-sk-header ()
13965 "Insert a descriptive header at the top of the file.
13966 See also `verilog-header' for an alternative format."
13967 (interactive "*")
13968 (save-excursion
13969 (goto-char (point-min))
13970 (verilog-sk-header-tmpl)))
13972 (define-skeleton verilog-sk-header-tmpl
13973 "Insert a comment block containing the module title, author, etc."
13974 "[Description]: "
13975 "// -*- Mode: Verilog -*-"
13976 "\n// Filename : " (buffer-name)
13977 "\n// Description : " str
13978 "\n// Author : " (user-full-name)
13979 "\n// Created On : " (current-time-string)
13980 "\n// Last Modified By: " (user-full-name)
13981 "\n// Last Modified On: " (current-time-string)
13982 "\n// Update Count : 0"
13983 "\n// Status : Unknown, Use with caution!"
13984 "\n")
13986 (define-skeleton verilog-sk-module
13987 "Insert a module definition."
13989 > "module " '(verilog-sk-prompt-name) " (/*AUTOARG*/ ) ;" \n
13990 > _ \n
13991 > (- verilog-indent-level-behavioral) "endmodule" (progn (electric-verilog-terminate-line) nil))
13993 ;; ------------------------------------------------------------------------
13994 ;; Define a default OVM class, with macros and new()
13995 ;; ------------------------------------------------------------------------
13997 (define-skeleton verilog-sk-ovm-class
13998 "Insert a class definition"
14000 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
14001 > _ \n
14002 > "`ovm_object_utils_begin(" name ")" \n
14003 > (- verilog-indent-level) " `ovm_object_utils_end" \n
14004 > _ \n
14005 > "function new(string name=\"" name "\");" \n
14006 > "super.new(name);" \n
14007 > (- verilog-indent-level) "endfunction" \n
14008 > _ \n
14009 > "endclass" (progn (electric-verilog-terminate-line) nil))
14011 (define-skeleton verilog-sk-uvm-object
14012 "Insert a class definition"
14014 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
14015 > _ \n
14016 > "`uvm_object_utils_begin(" name ")" \n
14017 > (- verilog-indent-level) "`uvm_object_utils_end" \n
14018 > _ \n
14019 > "function new(string name=\"" name "\");" \n
14020 > "super.new(name);" \n
14021 > (- verilog-indent-level) "endfunction" \n
14022 > _ \n
14023 > "endclass" (progn (electric-verilog-terminate-line) nil))
14025 (define-skeleton verilog-sk-uvm-component
14026 "Insert a class definition"
14028 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
14029 > _ \n
14030 > "`uvm_component_utils_begin(" name ")" \n
14031 > (- verilog-indent-level) "`uvm_component_utils_end" \n
14032 > _ \n
14033 > "function new(string name=\"\", uvm_component parent);" \n
14034 > "super.new(name, parent);" \n
14035 > (- verilog-indent-level) "endfunction" \n
14036 > _ \n
14037 > "endclass" (progn (electric-verilog-terminate-line) nil))
14039 (define-skeleton verilog-sk-primitive
14040 "Insert a task definition."
14042 > "primitive " '(verilog-sk-prompt-name) " ( " '(verilog-sk-prompt-output) ("input:" ", " str ) " );"\n
14043 > _ \n
14044 > (- verilog-indent-level-behavioral) "endprimitive" (progn (electric-verilog-terminate-line) nil))
14046 (define-skeleton verilog-sk-task
14047 "Insert a task definition."
14049 > "task " '(verilog-sk-prompt-name) & ?\; \n
14050 > _ \n
14051 > "begin" \n
14052 > \n
14053 > (- verilog-indent-level-behavioral) "end" \n
14054 > (- verilog-indent-level-behavioral) "endtask" (progn (electric-verilog-terminate-line) nil))
14056 (define-skeleton verilog-sk-function
14057 "Insert a function definition."
14059 > "function [" '(verilog-sk-prompt-width) | -1 '(verilog-sk-prompt-name) ?\; \n
14060 > _ \n
14061 > "begin" \n
14062 > \n
14063 > (- verilog-indent-level-behavioral) "end" \n
14064 > (- verilog-indent-level-behavioral) "endfunction" (progn (electric-verilog-terminate-line) nil))
14066 (define-skeleton verilog-sk-always
14067 "Insert always block. Uses the minibuffer to prompt
14068 for sensitivity list."
14070 > "always @ ( /*AUTOSENSE*/ ) begin\n"
14071 > _ \n
14072 > (- verilog-indent-level-behavioral) "end" \n >
14075 (define-skeleton verilog-sk-initial
14076 "Insert an initial block."
14078 > "initial begin\n"
14079 > _ \n
14080 > (- verilog-indent-level-behavioral) "end" \n > )
14082 (define-skeleton verilog-sk-specify
14083 "Insert specify block. "
14085 > "specify\n"
14086 > _ \n
14087 > (- verilog-indent-level-behavioral) "endspecify" \n > )
14089 (define-skeleton verilog-sk-generate
14090 "Insert generate block. "
14092 > "generate\n"
14093 > _ \n
14094 > (- verilog-indent-level-behavioral) "endgenerate" \n > )
14096 (define-skeleton verilog-sk-begin
14097 "Insert begin end block. Uses the minibuffer to prompt for name."
14099 > "begin" '(verilog-sk-prompt-name) \n
14100 > _ \n
14101 > (- verilog-indent-level-behavioral) "end" )
14103 (define-skeleton verilog-sk-fork
14104 "Insert a fork join block."
14106 > "fork\n"
14107 > "begin" \n
14108 > _ \n
14109 > (- verilog-indent-level-behavioral) "end" \n
14110 > "begin" \n
14111 > \n
14112 > (- verilog-indent-level-behavioral) "end" \n
14113 > (- verilog-indent-level-behavioral) "join" \n
14117 (define-skeleton verilog-sk-case
14118 "Build skeleton case statement, prompting for the selector expression,
14119 and the case items."
14120 "[selector expression]: "
14121 > "case (" str ") " \n
14122 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
14123 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
14125 (define-skeleton verilog-sk-casex
14126 "Build skeleton casex statement, prompting for the selector expression,
14127 and the case items."
14128 "[selector expression]: "
14129 > "casex (" str ") " \n
14130 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
14131 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
14133 (define-skeleton verilog-sk-casez
14134 "Build skeleton casez statement, prompting for the selector expression,
14135 and the case items."
14136 "[selector expression]: "
14137 > "casez (" str ") " \n
14138 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
14139 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
14141 (define-skeleton verilog-sk-if
14142 "Insert a skeleton if statement."
14143 > "if (" '(verilog-sk-prompt-condition) & ")" " begin" \n
14144 > _ \n
14145 > (- verilog-indent-level-behavioral) "end " \n )
14147 (define-skeleton verilog-sk-else-if
14148 "Insert a skeleton else if statement."
14149 > (verilog-indent-line) "else if ("
14150 (progn (setq verilog-sk-p (point)) nil) '(verilog-sk-prompt-condition) (if (> (point) verilog-sk-p) ") " -1 ) & " begin" \n
14151 > _ \n
14152 > "end" (progn (electric-verilog-terminate-line) nil))
14154 (define-skeleton verilog-sk-datadef
14155 "Common routine to get data definition."
14157 '(verilog-sk-prompt-width) | -1 ("name (RET to end):" str ", ") -2 ";" \n)
14159 (define-skeleton verilog-sk-input
14160 "Insert an input definition."
14162 > "input [" '(verilog-sk-datadef))
14164 (define-skeleton verilog-sk-output
14165 "Insert an output definition."
14167 > "output [" '(verilog-sk-datadef))
14169 (define-skeleton verilog-sk-inout
14170 "Insert an inout definition."
14172 > "inout [" '(verilog-sk-datadef))
14174 (defvar verilog-sk-signal nil)
14175 (define-skeleton verilog-sk-def-reg
14176 "Insert a reg definition."
14178 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations-auto) )
14180 (defun verilog-sk-define-signal ()
14181 "Insert a definition of signal under point at top of module."
14182 (interactive "*")
14183 (let* ((sig-re "[a-zA-Z0-9_]*")
14184 (v1 (buffer-substring
14185 (save-excursion
14186 (skip-chars-backward sig-re)
14187 (point))
14188 (save-excursion
14189 (skip-chars-forward sig-re)
14190 (point)))))
14191 (if (not (member v1 verilog-keywords))
14192 (save-excursion
14193 (setq verilog-sk-signal v1)
14194 (verilog-beg-of-defun)
14195 (verilog-end-of-statement)
14196 (verilog-forward-syntactic-ws)
14197 (verilog-sk-def-reg)
14198 (message "signal at point is %s" v1))
14199 (message "object at point (%s) is a keyword" v1))))
14201 (define-skeleton verilog-sk-wire
14202 "Insert a wire definition."
14204 > "wire [" '(verilog-sk-datadef))
14206 (define-skeleton verilog-sk-reg
14207 "Insert a reg definition."
14209 > "reg [" '(verilog-sk-datadef))
14211 (define-skeleton verilog-sk-assign
14212 "Insert a skeleton assign statement."
14214 > "assign " '(verilog-sk-prompt-name) " = " _ ";" \n)
14216 (define-skeleton verilog-sk-while
14217 "Insert a skeleton while loop statement."
14219 > "while (" '(verilog-sk-prompt-condition) ") begin" \n
14220 > _ \n
14221 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
14223 (define-skeleton verilog-sk-repeat
14224 "Insert a skeleton repeat loop statement."
14226 > "repeat (" '(verilog-sk-prompt-condition) ") begin" \n
14227 > _ \n
14228 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
14230 (define-skeleton verilog-sk-for
14231 "Insert a skeleton while loop statement."
14233 > "for ("
14234 '(verilog-sk-prompt-init) "; "
14235 '(verilog-sk-prompt-condition) "; "
14236 '(verilog-sk-prompt-inc)
14237 ") begin" \n
14238 > _ \n
14239 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
14241 (define-skeleton verilog-sk-comment
14242 "Inserts three comment lines, making a display comment."
14244 > "/*\n"
14245 > "* " _ \n
14246 > "*/")
14248 (define-skeleton verilog-sk-state-machine
14249 "Insert a state machine definition."
14250 "Name of state variable: "
14251 '(setq input "state")
14252 > "// State registers for " str | -23 \n
14253 '(setq verilog-sk-state str)
14254 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-state ", next_" verilog-sk-state ?\; \n
14255 '(setq input nil)
14256 > \n
14257 > "// State FF for " verilog-sk-state \n
14258 > "always @ ( " (read-string "clock:" "posedge clk") " or " (verilog-sk-prompt-reset) " ) begin" \n
14259 > "if ( " verilog-sk-reset " ) " verilog-sk-state " = 0; else" \n
14260 > verilog-sk-state " = next_" verilog-sk-state ?\; \n
14261 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil)
14262 > \n
14263 > "// Next State Logic for " verilog-sk-state \n
14264 > "always @ ( /*AUTOSENSE*/ ) begin\n"
14265 > "case (" '(verilog-sk-prompt-state-selector) ") " \n
14266 > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n )
14267 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)
14268 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil))
14270 ;;; Mouse Events:
14272 ;; Include file loading with mouse/return event
14274 ;; idea & first impl.: M. Rouat (eldo-mode.el)
14275 ;; second (emacs/xemacs) impl.: G. Van der Plas (spice-mode.el)
14277 (if (featurep 'xemacs)
14278 (require 'overlay))
14280 (defconst verilog-include-file-regexp
14281 "^`include\\s-+\"\\([^\n\"]*\\)\""
14282 "Regexp that matches the include file.")
14284 (defvar verilog-mode-mouse-map
14285 (let ((map (make-sparse-keymap))) ; as described in info pages, make a map
14286 (set-keymap-parent map verilog-mode-map)
14287 ;; mouse button bindings
14288 (define-key map "\r" 'verilog-load-file-at-point)
14289 (if (featurep 'xemacs)
14290 (define-key map 'button2 'verilog-load-file-at-mouse);ffap-at-mouse ?
14291 (define-key map [mouse-2] 'verilog-load-file-at-mouse))
14292 (if (featurep 'xemacs)
14293 (define-key map 'Sh-button2 'mouse-yank) ; you wanna paste don't you ?
14294 (define-key map [S-mouse-2] 'mouse-yank-at-click))
14295 map)
14296 "Map containing mouse bindings for `verilog-mode'.")
14299 (defun verilog-highlight-region (beg end _old-len)
14300 "Colorize included files and modules in the (changed?) region.
14301 Clicking on the middle-mouse button loads them in a buffer (as in dired)."
14302 (when (or verilog-highlight-includes
14303 verilog-highlight-modules)
14304 (save-excursion
14305 (save-match-data ; A query-replace may call this function - do not disturb
14306 (verilog-save-buffer-state
14307 (verilog-save-scan-cache
14308 (let (end-point)
14309 (goto-char end)
14310 (setq end-point (point-at-eol))
14311 (goto-char beg)
14312 (beginning-of-line) ; scan entire line
14313 ;; delete overlays existing on this line
14314 (let ((overlays (overlays-in (point) end-point)))
14315 (while overlays
14316 (if (and
14317 (overlay-get (car overlays) 'detachable)
14318 (or (overlay-get (car overlays) 'verilog-include-file)
14319 (overlay-get (car overlays) 'verilog-inst-module)))
14320 (delete-overlay (car overlays)))
14321 (setq overlays (cdr overlays))))
14323 ;; make new include overlays
14324 (when verilog-highlight-includes
14325 (while (search-forward-regexp verilog-include-file-regexp end-point t)
14326 (goto-char (match-beginning 1))
14327 (let ((ov (make-overlay (match-beginning 1) (match-end 1))))
14328 (overlay-put ov 'start-closed 't)
14329 (overlay-put ov 'end-closed 't)
14330 (overlay-put ov 'evaporate 't)
14331 (overlay-put ov 'verilog-include-file 't)
14332 (overlay-put ov 'mouse-face 'highlight)
14333 (overlay-put ov 'local-map verilog-mode-mouse-map))))
14335 ;; make new module overlays
14336 (goto-char beg)
14337 ;; This scanner is syntax-fragile, so don't get bent
14338 (when verilog-highlight-modules
14339 (condition-case nil
14340 (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-point t)
14341 (save-excursion
14342 (goto-char (match-beginning 0))
14343 (unless (verilog-inside-comment-or-string-p)
14344 (verilog-read-inst-module-matcher) ; sets match 0
14345 (let* ((ov (make-overlay (match-beginning 0) (match-end 0))))
14346 (overlay-put ov 'start-closed 't)
14347 (overlay-put ov 'end-closed 't)
14348 (overlay-put ov 'evaporate 't)
14349 (overlay-put ov 'verilog-inst-module 't)
14350 (overlay-put ov 'mouse-face 'highlight)
14351 (overlay-put ov 'local-map verilog-mode-mouse-map)))))
14352 (error nil)))
14354 ;; Future highlights:
14355 ;; variables - make an Occur buffer of where referenced
14356 ;; pins - make an Occur buffer of the sig in the declaration module
14357 )))))))
14359 (defun verilog-highlight-buffer ()
14360 "Colorize included files and modules across the whole buffer."
14361 ;; Invoked via verilog-mode calling font-lock then `font-lock-mode-hook'
14362 (interactive)
14363 ;; delete and remake overlays
14364 (verilog-highlight-region (point-min) (point-max) nil))
14366 ;; Deprecated, but was interactive, so we'll keep it around
14367 (defalias 'verilog-colorize-include-files-buffer 'verilog-highlight-buffer)
14369 ;; ffap-at-mouse isn't useful for Verilog mode. It uses library paths.
14370 ;; so define this function to do more or less the same as ffap-at-mouse
14371 ;; but first resolve filename...
14372 (defun verilog-load-file-at-mouse (event)
14373 "Load file under button 2 click's EVENT.
14374 Files are checked based on `verilog-library-flags'."
14375 (interactive "@e")
14376 (save-excursion ; implement a Verilog specific ffap-at-mouse
14377 (mouse-set-point event)
14378 (verilog-load-file-at-point t)))
14380 ;; ffap isn't usable for Verilog mode. It uses library paths.
14381 ;; so define this function to do more or less the same as ffap
14382 ;; but first resolve filename...
14383 (defun verilog-load-file-at-point (&optional warn)
14384 "Load file under point.
14385 If WARN, throw warning if not found.
14386 Files are checked based on `verilog-library-flags'."
14387 (interactive)
14388 (save-excursion ; implement a Verilog specific ffap
14389 (let ((overlays (overlays-in (point) (point)))
14390 hit)
14391 (while (and overlays (not hit))
14392 (when (overlay-get (car overlays) 'verilog-inst-module)
14393 (verilog-goto-defun-file (buffer-substring
14394 (overlay-start (car overlays))
14395 (overlay-end (car overlays))))
14396 (setq hit t))
14397 (setq overlays (cdr overlays)))
14398 ;; Include?
14399 (beginning-of-line)
14400 (when (and (not hit)
14401 (looking-at verilog-include-file-regexp))
14402 (if (and (car (verilog-library-filenames
14403 (match-string 1) (buffer-file-name)))
14404 (file-readable-p (car (verilog-library-filenames
14405 (match-string 1) (buffer-file-name)))))
14406 (find-file (car (verilog-library-filenames
14407 (match-string 1) (buffer-file-name))))
14408 (when warn
14409 (message
14410 "File `%s' isn't readable, use shift-mouse2 to paste in this field"
14411 (match-string 1))))))))
14414 ;;; Bug reporting:
14417 (defun verilog-faq ()
14418 "Tell the user their current version, and where to get the FAQ etc."
14419 (interactive)
14420 (with-output-to-temp-buffer "*verilog-mode help*"
14421 (princ (format "You are using verilog-mode %s\n" verilog-mode-version))
14422 (princ "\n")
14423 (princ "For new releases, see http://www.verilog.com\n")
14424 (princ "\n")
14425 (princ "For frequently asked questions, see http://www.veripool.org/verilog-mode-faq.html\n")
14426 (princ "\n")
14427 (princ "To submit a bug, use M-x verilog-submit-bug-report\n")
14428 (princ "\n")))
14430 (autoload 'reporter-submit-bug-report "reporter")
14431 (defvar reporter-prompt-for-summary-p)
14433 (defun verilog-submit-bug-report ()
14434 "Submit via mail a bug report on verilog-mode.el."
14435 (interactive)
14436 (let ((reporter-prompt-for-summary-p t))
14437 (reporter-submit-bug-report
14438 "mac@verilog.com, wsnyder@wsnyder.org"
14439 (concat "verilog-mode v" verilog-mode-version)
14441 verilog-active-low-regexp
14442 verilog-after-save-font-hook
14443 verilog-align-ifelse
14444 verilog-assignment-delay
14445 verilog-auto-arg-sort
14446 verilog-auto-declare-nettype
14447 verilog-auto-delete-trailing-whitespace
14448 verilog-auto-endcomments
14449 verilog-auto-hook
14450 verilog-auto-ignore-concat
14451 verilog-auto-indent-on-newline
14452 verilog-auto-inout-ignore-regexp
14453 verilog-auto-input-ignore-regexp
14454 verilog-auto-inst-column
14455 verilog-auto-inst-dot-name
14456 verilog-auto-inst-interfaced-ports
14457 verilog-auto-inst-param-value
14458 verilog-auto-inst-sort
14459 verilog-auto-inst-template-numbers
14460 verilog-auto-inst-vector
14461 verilog-auto-lineup
14462 verilog-auto-newline
14463 verilog-auto-output-ignore-regexp
14464 verilog-auto-read-includes
14465 verilog-auto-reset-blocking-in-non
14466 verilog-auto-reset-widths
14467 verilog-auto-save-policy
14468 verilog-auto-sense-defines-constant
14469 verilog-auto-sense-include-inputs
14470 verilog-auto-star-expand
14471 verilog-auto-star-save
14472 verilog-auto-template-warn-unused
14473 verilog-auto-tieoff-declaration
14474 verilog-auto-tieoff-ignore-regexp
14475 verilog-auto-unused-ignore-regexp
14476 verilog-auto-wire-type
14477 verilog-before-auto-hook
14478 verilog-before-delete-auto-hook
14479 verilog-before-getopt-flags-hook
14480 verilog-before-save-font-hook
14481 verilog-cache-enabled
14482 verilog-case-fold
14483 verilog-case-indent
14484 verilog-cexp-indent
14485 verilog-compiler
14486 verilog-coverage
14487 verilog-delete-auto-hook
14488 verilog-getopt-flags-hook
14489 verilog-highlight-grouping-keywords
14490 verilog-highlight-includes
14491 verilog-highlight-modules
14492 verilog-highlight-p1800-keywords
14493 verilog-highlight-translate-off
14494 verilog-indent-begin-after-if
14495 verilog-indent-declaration-macros
14496 verilog-indent-level
14497 verilog-indent-level-behavioral
14498 verilog-indent-level-declaration
14499 verilog-indent-level-directive
14500 verilog-indent-level-module
14501 verilog-indent-lists
14502 verilog-library-directories
14503 verilog-library-extensions
14504 verilog-library-files
14505 verilog-library-flags
14506 verilog-linter
14507 verilog-minimum-comment-distance
14508 verilog-mode-hook
14509 verilog-mode-release-emacs
14510 verilog-mode-version
14511 verilog-preprocessor
14512 verilog-simulator
14513 verilog-tab-always-indent
14514 verilog-tab-to-comment
14515 verilog-typedef-regexp
14516 verilog-warn-fatal
14518 nil nil
14519 (concat "Hi Mac,
14521 I want to report a bug.
14523 Before I go further, I want to say that Verilog mode has changed my life.
14524 I save so much time, my files are colored nicely, my co workers respect
14525 my coding ability... until now. I'd really appreciate anything you
14526 could do to help me out with this minor deficiency in the product.
14528 I've taken a look at the Verilog-Mode FAQ at
14529 http://www.veripool.org/verilog-mode-faq.html.
14531 And, I've considered filing the bug on the issue tracker at
14532 http://www.veripool.org/verilog-mode-bugs
14533 since I realize that public bugs are easier for you to track,
14534 and for others to search, but would prefer to email.
14536 So, to reproduce the bug, start a fresh Emacs via " invocation-name "
14537 -no-init-file -no-site-file'. In a new buffer, in Verilog mode, type
14538 the code included below.
14540 Given those lines, I expected [[Fill in here]] to happen;
14541 but instead, [[Fill in here]] happens!.
14543 == The code: =="))))
14545 (provide 'verilog-mode)
14547 ;; Local Variables:
14548 ;; checkdoc-permit-comma-termination-flag:t
14549 ;; checkdoc-force-docstrings-flag:nil
14550 ;; indent-tabs-mode:nil
14551 ;; End:
14553 ;;; verilog-mode.el ends here