Remove unnecessary explicit subword-mode use from isearch
[emacs.git] / lisp / progmodes / verilog-mode.el
blob48dee4bef319ad656bfd17edf3b5611264755840
1 ;;; verilog-mode.el --- major mode for editing verilog source in Emacs
3 ;; Copyright (C) 1996-2018 Free Software Foundation, Inc.
5 ;; Author: Michael McNamara <mac@verilog.com>
6 ;; Wilson Snyder <wsnyder@wsnyder.org>
7 ;; X-URL: http://www.veripool.org
8 ;; Created: 3 Jan 1996
9 ;; Keywords: languages
11 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
12 ;; file on 19/3/2008, and the maintainer agreed that when a bug is
13 ;; filed in the Emacs bug reporting system against this file, a copy
14 ;; of the bug report be sent to the maintainer's email address.
16 ;; This code supports Emacs 21.1 and later
17 ;; And XEmacs 21.1 and later
18 ;; Please do not make changes that break Emacs 21. Thanks!
22 ;; This file is part of GNU Emacs.
24 ;; GNU Emacs is free software: you can redistribute it and/or modify
25 ;; it under the terms of the GNU General Public License as published by
26 ;; the Free Software Foundation, either version 3 of the License, or
27 ;; (at your option) any later version.
29 ;; GNU Emacs is distributed in the hope that it will be useful,
30 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
31 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 ;; GNU General Public License for more details.
34 ;; You should have received a copy of the GNU General Public License
35 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
37 ;;; Commentary:
39 ;; USAGE
40 ;; =====
42 ;; A major mode for editing Verilog and SystemVerilog HDL source code (IEEE
43 ;; 1364-2005 and IEEE 1800-2012 standards). When you have entered Verilog
44 ;; mode, you may get more info by pressing C-h m. You may also get online
45 ;; help describing various functions by: C-h f <Name of function you want
46 ;; described>
48 ;; KNOWN BUGS / BUG REPORTS
49 ;; =======================
51 ;; SystemVerilog is a rapidly evolving language, and hence this mode is
52 ;; under continuous development. Please report any issues to the issue
53 ;; tracker at
55 ;; http://www.veripool.org/verilog-mode
57 ;; Please use verilog-submit-bug-report to submit a report; type C-c
58 ;; C-b to invoke this and as a result we will have a much easier time
59 ;; of reproducing the bug you find, and hence fixing it.
61 ;; INSTALLING THE MODE
62 ;; ===================
64 ;; An older version of this mode may be already installed as a part of
65 ;; your environment, and one method of updating would be to update
66 ;; your Emacs environment. Sometimes this is difficult for local
67 ;; political/control reasons, and hence you can always install a
68 ;; private copy (or even a shared copy) which overrides the system
69 ;; default.
71 ;; You can get step by step help in installing this file by going to
72 ;; <http://www.veripool.com/verilog-mode>
74 ;; The short list of installation instructions are: To set up
75 ;; automatic Verilog mode, put this file in your load path, and put
76 ;; the following in code (please un comment it first!) in your
77 ;; .emacs, or in your site's site-load.el
79 ;; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
80 ;; (add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode))
82 ;; Be sure to examine at the help for verilog-auto, and the other
83 ;; verilog-auto-* functions for some major coding time savers.
85 ;; If you want to customize Verilog mode to fit your needs better,
86 ;; you may add the below lines (the values of the variables presented
87 ;; here are the defaults). Note also that if you use an Emacs that
88 ;; supports custom, it's probably better to use the custom menu to
89 ;; edit these. If working as a member of a large team these settings
90 ;; should be common across all users (in a site-start file), or set
91 ;; in Local Variables in every file. Otherwise, different people's
92 ;; AUTO expansion may result different whitespace changes.
94 ;; ;; Enable syntax highlighting of **all** languages
95 ;; (global-font-lock-mode t)
97 ;; ;; User customization for Verilog mode
98 ;; (setq verilog-indent-level 3
99 ;; verilog-indent-level-module 3
100 ;; verilog-indent-level-declaration 3
101 ;; verilog-indent-level-behavioral 3
102 ;; verilog-indent-level-directive 1
103 ;; verilog-case-indent 2
104 ;; verilog-auto-newline t
105 ;; verilog-auto-indent-on-newline t
106 ;; verilog-tab-always-indent t
107 ;; verilog-auto-endcomments t
108 ;; verilog-minimum-comment-distance 40
109 ;; verilog-indent-begin-after-if t
110 ;; verilog-auto-lineup 'declarations
111 ;; verilog-highlight-p1800-keywords nil
112 ;; verilog-linter "my_lint_shell_command"
113 ;; )
116 ;;; History:
118 ;; See commit history at http://www.veripool.org/verilog-mode.html
119 ;; (This section is required to appease checkdoc.)
121 ;;; Code:
124 ;; This variable will always hold the version number of the mode
125 (defconst verilog-mode-version "2017-08-07-c085e50-vpo-GNU"
126 "Version of this Verilog mode.")
127 (defconst verilog-mode-release-emacs t
128 "If non-nil, this version of Verilog mode was released with Emacs itself.")
130 (defun verilog-version ()
131 "Inform caller of the version of this file."
132 (interactive)
133 (message "Using verilog-mode version %s" verilog-mode-version))
135 ;; Insure we have certain packages, and deal with it if we don't
136 ;; Be sure to note which Emacs flavor and version added each feature.
137 (eval-when-compile
138 ;; Provide stuff if we are XEmacs
139 (when (featurep 'xemacs)
140 (condition-case nil
141 (require 'easymenu)
142 (error nil))
143 (condition-case nil
144 (require 'regexp-opt)
145 (error nil))
146 ;; Bug in 19.28 through 19.30 skeleton.el, not provided.
147 (condition-case nil
148 (load "skeleton")
149 (error nil))
150 (condition-case nil
151 (if (fboundp 'when)
152 nil ; fab
153 (defmacro when (cond &rest body)
154 (list 'if cond (cons 'progn body))))
155 (error nil))
156 (condition-case nil
157 (if (fboundp 'unless)
158 nil ; fab
159 (defmacro unless (cond &rest body)
160 (cons 'if (cons cond (cons nil body)))))
161 (error nil))
162 (condition-case nil
163 (if (fboundp 'store-match-data)
164 nil ; fab
165 (defmacro store-match-data (&rest _args) nil))
166 (error nil))
167 (condition-case nil
168 (if (fboundp 'char-before)
169 nil ; great
170 (defmacro char-before (&rest _body)
171 (char-after (1- (point)))))
172 (error nil))
173 (condition-case nil
174 (if (fboundp 'when)
175 nil ; fab
176 (defsubst point-at-bol (&optional N)
177 (save-excursion (beginning-of-line N) (point))))
178 (error nil))
179 (condition-case nil
180 (if (fboundp 'when)
181 nil ; fab
182 (defsubst point-at-eol (&optional N)
183 (save-excursion (end-of-line N) (point))))
184 (error nil))
185 (condition-case nil
186 (require 'custom)
187 (error nil))
188 (condition-case nil
189 (if (fboundp 'match-string-no-properties)
190 nil ; great
191 (defsubst match-string-no-properties (num &optional string)
192 "Return string of text matched by last search, without text properties.
193 NUM specifies which parenthesized expression in the last regexp.
194 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
195 Zero means the entire text matched by the whole regexp or whole string.
196 STRING should be given if the last search was by `string-match' on STRING."
197 (if (match-beginning num)
198 (if string
199 (let ((result
200 (substring string
201 (match-beginning num) (match-end num))))
202 (set-text-properties 0 (length result) nil result)
203 result)
204 (buffer-substring-no-properties (match-beginning num)
205 (match-end num)
206 (current-buffer)))))
208 (error nil))
209 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
210 nil ; We've got what we needed
211 ;; We have the old custom-library, hack around it!
212 (defmacro defgroup (&rest _args) nil)
213 (defmacro customize (&rest _args)
214 (message
215 "Sorry, Customize is not available with this version of Emacs"))
216 (defmacro defcustom (var value doc &rest _args)
217 `(defvar ,var ,value ,doc))
219 (if (fboundp 'defface)
220 nil ; great!
221 (defmacro defface (var values doc &rest _args)
222 `(make-face ,var))
225 (if (and (featurep 'custom) (fboundp 'customize-group))
226 nil ; We've got what we needed
227 ;; We have an intermediate custom-library, hack around it!
228 (defmacro customize-group (var &rest _args)
229 `(customize ,var))
232 (defvar inhibit-modification-hooks)
233 (defvar inhibit-point-motion-hooks)
234 (defvar deactivate-mark)
237 ;; OK, do this stuff if we are NOT XEmacs:
238 (unless (featurep 'xemacs)
239 (unless (fboundp 'region-active-p)
240 (defmacro region-active-p ()
241 `(and transient-mark-mode mark-active))))
244 ;; Provide a regular expression optimization routine, using regexp-opt
245 ;; if provided by the user's elisp libraries
246 (eval-and-compile
247 ;; The below were disabled when GNU Emacs 22 was released;
248 ;; perhaps some still need to be there to support Emacs 21.
249 (if (featurep 'xemacs)
250 (if (fboundp 'regexp-opt)
251 ;; regexp-opt is defined, does it take 3 or 2 arguments?
252 (if (fboundp 'function-max-args)
253 (let ((args (function-max-args `regexp-opt)))
254 (cond
255 ((eq args 3) ; It takes 3
256 (condition-case nil ; Hide this defun from emacses
257 ; with just a two input regexp
258 (defun verilog-regexp-opt (a b)
259 "Deal with differing number of required arguments for `regexp-opt'.
260 Call `regexp-opt' on A and B."
261 (regexp-opt a b t))
262 (error nil))
264 ((eq args 2) ; It takes 2
265 (defun verilog-regexp-opt (a b)
266 "Call `regexp-opt' on A and B."
267 (regexp-opt a b))
269 (t nil)))
270 ;; We can't tell; assume it takes 2
271 (defun verilog-regexp-opt (a b)
272 "Call `regexp-opt' on A and B."
273 (regexp-opt a b))
275 ;; There is no regexp-opt, provide our own
276 (defun verilog-regexp-opt (strings &optional paren _shy)
277 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
278 (concat open (mapconcat 'regexp-quote strings "\\|") close)))
280 ;; Emacs.
281 (defalias 'verilog-regexp-opt 'regexp-opt)))
283 ;; emacs >=22 has looking-back, but older emacs and xemacs don't.
284 ;; This function is lifted directly from emacs's subr.el
285 ;; so that it can be used by xemacs.
286 ;; The idea for this was borrowed from org-mode via this link:
287 ;; https://lists.gnu.org/r/emacs-orgmode/2009-12/msg00032.html
288 (eval-and-compile
289 (cond
290 ((fboundp 'looking-back)
291 (defalias 'verilog-looking-back 'looking-back))
293 (defun verilog-looking-back (regexp limit &optional greedy)
294 "Return non-nil if text before point matches regular expression REGEXP.
295 Like `looking-at' except matches before point, and is slower.
296 LIMIT if non-nil speeds up the search by specifying a minimum
297 starting position, to avoid checking matches that would start
298 before LIMIT.
300 If GREEDY is non-nil, extend the match backwards as far as
301 possible, stopping when a single additional previous character
302 cannot be part of a match for REGEXP. When the match is
303 extended, its starting position is allowed to occur before
304 LIMIT.
306 As a general recommendation, try to avoid using `looking-back'
307 wherever possible, since it is slow."
308 (let ((start (point))
309 (pos
310 (save-excursion
311 (and (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t)
312 (point)))))
313 (if (and greedy pos)
314 (save-restriction
315 (narrow-to-region (point-min) start)
316 (while (and (> pos (point-min))
317 (save-excursion
318 (goto-char pos)
319 (backward-char 1)
320 (looking-at (concat "\\(?:" regexp "\\)\\'"))))
321 (setq pos (1- pos)))
322 (save-excursion
323 (goto-char pos)
324 (looking-at (concat "\\(?:" regexp "\\)\\'")))))
325 (not (null pos)))))))
327 (eval-and-compile
328 (cond
329 ((fboundp 'restore-buffer-modified-p)
330 ;; Faster, as does not update mode line when nothing changes
331 (defalias 'verilog-restore-buffer-modified-p 'restore-buffer-modified-p))
333 (defalias 'verilog-restore-buffer-modified-p 'set-buffer-modified-p))))
335 (eval-and-compile
336 ;; Both xemacs and emacs
337 (condition-case nil
338 (require 'diff) ; diff-command and diff-switches
339 (error nil))
340 (condition-case nil
341 (require 'compile) ; compilation-error-regexp-alist-alist
342 (error nil))
343 (condition-case nil
344 (unless (fboundp 'buffer-chars-modified-tick) ; Emacs 22 added
345 (defmacro buffer-chars-modified-tick () (buffer-modified-tick)))
346 (error nil))
347 ;; Added in Emacs 23.1
348 (condition-case nil
349 (unless (fboundp 'ignore-errors)
350 (defmacro ignore-errors (&rest body)
351 (declare (debug t) (indent 0))
352 `(condition-case nil (progn ,@body) (error nil)))))
353 ;; Added in Emacs 24.1
354 (condition-case nil
355 (unless (fboundp 'prog-mode)
356 (define-derived-mode prog-mode fundamental-mode "Prog"))
357 (error nil))
358 ;; Added in Emacs 25.1
359 (condition-case nil
360 (unless (fboundp 'forward-word-strictly)
361 (defalias 'forward-word-strictly 'forward-word))
362 (error nil)))
364 (eval-when-compile
365 (defun verilog-regexp-words (a)
366 "Call `regexp-opt' with word delimiters for the words A."
367 (concat "\\<" (verilog-regexp-opt a t) "\\>")))
368 (defun verilog-regexp-words (a)
369 "Call `regexp-opt' with word delimiters for the words A."
370 ;; The FAQ references this function, so user LISP sometimes calls it
371 (concat "\\<" (verilog-regexp-opt a t) "\\>"))
373 (defun verilog-easy-menu-filter (menu)
374 "Filter `easy-menu-define' MENU to support new features."
375 (cond ((not (featurep 'xemacs))
376 menu) ; GNU Emacs - passthru
377 ;; XEmacs doesn't support :help. Strip it.
378 ;; Recursively filter the a submenu
379 ((listp menu)
380 (mapcar 'verilog-easy-menu-filter menu))
381 ;; Look for [:help "blah"] and remove
382 ((vectorp menu)
383 (let ((i 0) (out []))
384 (while (< i (length menu))
385 (if (equal `:help (aref menu i))
386 (setq i (+ 2 i))
387 (setq out (vconcat out (vector (aref menu i)))
388 i (1+ i))))
389 out))
390 (t menu))) ; Default - ok
391 ;;(verilog-easy-menu-filter
392 ;; `("Verilog" ("MA" ["SAA" nil :help "Help SAA"] ["SAB" nil :help "Help SAA"])
393 ;; "----" ["MB" nil :help "Help MB"]))
395 (defun verilog-define-abbrev-table (tablename definitions &optional docstring &rest props)
396 "Filter `define-abbrev-table' TABLENAME DEFINITIONS
397 Provides DOCSTRING PROPS in newer Emacs (23.1)."
398 (condition-case nil
399 (apply 'define-abbrev-table tablename definitions docstring props)
400 (error
401 (define-abbrev-table tablename definitions))))
403 (defun verilog-define-abbrev (table name expansion &optional hook)
404 "Filter `define-abbrev' TABLE NAME EXPANSION and call HOOK.
405 Provides SYSTEM-FLAG in newer Emacs."
406 (condition-case nil
407 (define-abbrev table name expansion hook 0 t)
408 (error
409 (define-abbrev table name expansion hook))))
411 (defun verilog-customize ()
412 "Customize variables and other settings used by Verilog-Mode."
413 (interactive)
414 (customize-group 'verilog-mode))
416 (defun verilog-font-customize ()
417 "Customize fonts used by Verilog-Mode."
418 (interactive)
419 (if (fboundp 'customize-apropos)
420 (customize-apropos "font-lock-*" 'faces)))
422 (defun verilog-booleanp (value)
423 "Return t if VALUE is boolean.
424 This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs.
425 This function may be removed when Emacs 21 is no longer supported."
426 (or (equal value t) (equal value nil)))
428 (defun verilog-insert-last-command-event ()
429 "Insert the `last-command-event'."
430 (insert (if (featurep 'xemacs)
431 ;; XEmacs 21.5 doesn't like last-command-event
432 last-command-char
433 ;; And GNU Emacs 22 has obsoleted last-command-char
434 last-command-event)))
436 (defvar verilog-no-change-functions nil
437 "True if `after-change-functions' is disabled.
438 Use of `syntax-ppss' may break, as ppss's cache may get corrupted.")
440 (defvar verilog-in-hooks nil
441 "True when within a `verilog-run-hooks' block.")
443 (defmacro verilog-run-hooks (&rest hooks)
444 "Run each hook in HOOKS using `run-hooks'.
445 Set `verilog-in-hooks' during this time, to assist AUTO caches."
446 `(let ((verilog-in-hooks t))
447 (run-hooks ,@hooks)))
449 (defun verilog-syntax-ppss (&optional pos)
450 (when verilog-no-change-functions
451 (if verilog-in-hooks
452 (verilog-scan-cache-flush)
453 ;; else don't let the AUTO code itself get away with flushing the cache,
454 ;; as that'll make things very slow
455 (backtrace)
456 (error "%s: Internal problem; use of syntax-ppss when cache may be corrupt"
457 (verilog-point-text))))
458 (if (fboundp 'syntax-ppss)
459 (syntax-ppss pos)
460 (parse-partial-sexp (point-min) (or pos (point)))))
462 (defgroup verilog-mode nil
463 "Major mode for Verilog source code."
464 :version "22.2"
465 :group 'languages)
467 ;; (defgroup verilog-mode-fonts nil
468 ;; "Facilitates easy customization fonts used in Verilog source text"
469 ;; :link '(customize-apropos "font-lock-*" 'faces)
470 ;; :group 'verilog-mode)
472 (defgroup verilog-mode-indent nil
473 "Customize indentation and highlighting of Verilog source text."
474 :group 'verilog-mode)
476 (defgroup verilog-mode-actions nil
477 "Customize actions on Verilog source text."
478 :group 'verilog-mode)
480 (defgroup verilog-mode-auto nil
481 "Customize AUTO actions when expanding Verilog source text."
482 :group 'verilog-mode)
484 (defvar verilog-debug nil
485 "Non-nil means enable debug messages for `verilog-mode' internals.")
487 (defvar verilog-warn-fatal nil
488 "Non-nil means `verilog-warn-error' warnings are fatal `error's.")
490 (defcustom verilog-linter
491 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
492 "Unix program and arguments to call to run a lint checker on Verilog source.
493 Depending on the `verilog-set-compile-command', this may be invoked when
494 you type \\[compile]. When the compile completes, \\[next-error] will take
495 you to the next lint error."
496 :type 'string
497 :group 'verilog-mode-actions)
498 ;; We don't mark it safe, as it's used as a shell command
500 (defcustom verilog-coverage
501 "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'"
502 "Program and arguments to use to annotate for coverage Verilog source.
503 Depending on the `verilog-set-compile-command', this may be invoked when
504 you type \\[compile]. When the compile completes, \\[next-error] will take
505 you to the next lint error."
506 :type 'string
507 :group 'verilog-mode-actions)
508 ;; We don't mark it safe, as it's used as a shell command
510 (defcustom verilog-simulator
511 "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'"
512 "Program and arguments to use to interpret Verilog source.
513 Depending on the `verilog-set-compile-command', this may be invoked when
514 you type \\[compile]. When the compile completes, \\[next-error] will take
515 you to the next lint error."
516 :type 'string
517 :group 'verilog-mode-actions)
518 ;; We don't mark it safe, as it's used as a shell command
520 (defcustom verilog-compiler
521 "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'"
522 "Program and arguments to use to compile Verilog source.
523 Depending on the `verilog-set-compile-command', this may be invoked when
524 you type \\[compile]. When the compile completes, \\[next-error] will take
525 you to the next lint error."
526 :type 'string
527 :group 'verilog-mode-actions)
528 ;; We don't mark it safe, as it's used as a shell command
530 (defcustom verilog-preprocessor
531 ;; Very few tools give preprocessed output, so we'll default to Verilog-Perl
532 "vppreproc __FLAGS__ __FILE__"
533 "Program and arguments to use to preprocess Verilog source.
534 This is invoked with `verilog-preprocess', and depending on the
535 `verilog-set-compile-command', may also be invoked when you type
536 \\[compile]. When the compile completes, \\[next-error] will
537 take you to the next lint error."
538 :type 'string
539 :group 'verilog-mode-actions)
540 ;; We don't mark it safe, as it's used as a shell command
542 (defvar verilog-preprocess-history nil
543 "History for `verilog-preprocess'.")
545 (defvar verilog-tool 'verilog-linter
546 "Which tool to use for building compiler-command.
547 Either nil, `verilog-linter', `verilog-compiler',
548 `verilog-coverage', `verilog-preprocessor', or `verilog-simulator'.
549 Alternatively use the \"Choose Compilation Action\" menu. See
550 `verilog-set-compile-command' for more information.")
552 (defcustom verilog-highlight-translate-off nil
553 "Non-nil means background-highlight code excluded from translation.
554 That is, all code between \"// synopsys translate_off\" and
555 \"// synopsys translate_on\" is highlighted using a different background color
556 \(face `verilog-font-lock-translate-off-face').
558 Note: This will slow down on-the-fly fontification (and thus editing).
560 Note: Activate the new setting in a Verilog buffer by re-fontifying it (menu
561 entry \"Fontify Buffer\"). XEmacs: turn off and on font locking."
562 :type 'boolean
563 :group 'verilog-mode-indent)
564 ;; Note we don't use :safe, as that would break on Emacsen before 22.0.
565 (put 'verilog-highlight-translate-off 'safe-local-variable 'verilog-booleanp)
567 (defcustom verilog-auto-lineup 'declarations
568 "Type of statements to lineup across multiple lines.
569 If `all' is selected, then all line ups described below are done.
571 If `declarations', then just declarations are lined up with any
572 preceding declarations, taking into account widths and the like,
573 so or example the code:
574 reg [31:0] a;
575 reg b;
576 would become
577 reg [31:0] a;
578 reg b;
580 If `assignment', then assignments are lined up with any preceding
581 assignments, so for example the code
582 a_long_variable <= b + c;
583 d = e + f;
584 would become
585 a_long_variable <= b + c;
586 d = e + f;
588 In order to speed up editing, large blocks of statements are lined up
589 only when a \\[verilog-pretty-expr] is typed; and large blocks of declarations
590 are lineup only when \\[verilog-pretty-declarations] is typed."
592 :type '(radio (const :tag "Line up Assignments and Declarations" all)
593 (const :tag "Line up Assignment statements" assignments )
594 (const :tag "Line up Declarations" declarations)
595 (function :tag "Other"))
596 :group 'verilog-mode-indent )
597 (put 'verilog-auto-lineup 'safe-local-variable
598 '(lambda (x) (memq x '(nil all assignments declarations))))
600 (defcustom verilog-indent-level 3
601 "Indentation of Verilog statements with respect to containing block."
602 :group 'verilog-mode-indent
603 :type 'integer)
604 (put 'verilog-indent-level 'safe-local-variable 'integerp)
606 (defcustom verilog-indent-level-module 3
607 "Indentation of Module level Verilog statements (eg always, initial).
608 Set to 0 to get initial and always statements lined up on the left side of
609 your screen."
610 :group 'verilog-mode-indent
611 :type 'integer)
612 (put 'verilog-indent-level-module 'safe-local-variable 'integerp)
614 (defcustom verilog-indent-level-declaration 3
615 "Indentation of declarations with respect to containing block.
616 Set to 0 to get them list right under containing block."
617 :group 'verilog-mode-indent
618 :type 'integer)
619 (put 'verilog-indent-level-declaration 'safe-local-variable 'integerp)
621 (defcustom verilog-indent-declaration-macros nil
622 "How to treat macro expansions in a declaration.
623 If nil, indent as:
624 input [31:0] a;
625 input \\=`CP;
626 output c;
627 If non nil, treat as:
628 input [31:0] a;
629 input \\=`CP ;
630 output c;"
631 :group 'verilog-mode-indent
632 :type 'boolean)
633 (put 'verilog-indent-declaration-macros 'safe-local-variable 'verilog-booleanp)
635 (defcustom verilog-indent-lists t
636 "How to treat indenting items in a list.
637 If t (the default), indent as:
638 always @( posedge a or
639 reset ) begin
641 If nil, treat as:
642 always @( posedge a or
643 reset ) begin"
644 :group 'verilog-mode-indent
645 :type 'boolean)
646 (put 'verilog-indent-lists 'safe-local-variable 'verilog-booleanp)
648 (defcustom verilog-indent-level-behavioral 3
649 "Absolute indentation of first begin in a task or function block.
650 Set to 0 to get such code to start at the left side of the screen."
651 :group 'verilog-mode-indent
652 :type 'integer)
653 (put 'verilog-indent-level-behavioral 'safe-local-variable 'integerp)
655 (defcustom verilog-indent-level-directive 1
656 "Indentation to add to each level of \\=`ifdef declarations.
657 Set to 0 to have all directives start at the left side of the screen."
658 :group 'verilog-mode-indent
659 :type 'integer)
660 (put 'verilog-indent-level-directive 'safe-local-variable 'integerp)
662 (defcustom verilog-cexp-indent 2
663 "Indentation of Verilog statements split across lines."
664 :group 'verilog-mode-indent
665 :type 'integer)
666 (put 'verilog-cexp-indent 'safe-local-variable 'integerp)
668 (defcustom verilog-case-indent 2
669 "Indentation for case statements."
670 :group 'verilog-mode-indent
671 :type 'integer)
672 (put 'verilog-case-indent 'safe-local-variable 'integerp)
674 (defcustom verilog-auto-newline t
675 "Non-nil means automatically newline after semicolons."
676 :group 'verilog-mode-indent
677 :type 'boolean)
678 (put 'verilog-auto-newline 'safe-local-variable 'verilog-booleanp)
680 (defcustom verilog-auto-indent-on-newline t
681 "Non-nil means automatically indent line after newline."
682 :group 'verilog-mode-indent
683 :type 'boolean)
684 (put 'verilog-auto-indent-on-newline 'safe-local-variable 'verilog-booleanp)
686 (defcustom verilog-tab-always-indent t
687 "Non-nil means TAB should always re-indent the current line.
688 A nil value means TAB will only reindent when at the beginning of the line."
689 :group 'verilog-mode-indent
690 :type 'boolean)
691 (put 'verilog-tab-always-indent 'safe-local-variable 'verilog-booleanp)
693 (defcustom verilog-tab-to-comment nil
694 "Non-nil means TAB moves to the right hand column in preparation for a comment."
695 :group 'verilog-mode-actions
696 :type 'boolean)
697 (put 'verilog-tab-to-comment 'safe-local-variable 'verilog-booleanp)
699 (defcustom verilog-indent-begin-after-if t
700 "Non-nil means indent begin statements following if, else, while, etc.
701 Otherwise, line them up."
702 :group 'verilog-mode-indent
703 :type 'boolean)
704 (put 'verilog-indent-begin-after-if 'safe-local-variable 'verilog-booleanp)
706 (defcustom verilog-align-ifelse nil
707 "Non-nil means align `else' under matching `if'.
708 Otherwise else is lined up with first character on line holding matching if."
709 :group 'verilog-mode-indent
710 :type 'boolean)
711 (put 'verilog-align-ifelse 'safe-local-variable 'verilog-booleanp)
713 (defcustom verilog-minimum-comment-distance 10
714 "Minimum distance (in lines) between begin and end required before a comment.
715 Setting this variable to zero results in every end acquiring a comment; the
716 default avoids too many redundant comments in tight quarters."
717 :group 'verilog-mode-indent
718 :type 'integer)
719 (put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp)
721 (defcustom verilog-highlight-p1800-keywords nil
722 "Non-nil means highlight words newly reserved by IEEE-1800.
723 These will appear in `verilog-font-lock-p1800-face' in order to gently
724 suggest changing where these words are used as variables to something else.
725 A nil value means highlight these words as appropriate for the SystemVerilog
726 IEEE-1800 standard. Note that changing this will require restarting Emacs
727 to see the effect as font color choices are cached by Emacs."
728 :group 'verilog-mode-indent
729 :type 'boolean)
730 (put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp)
732 (defcustom verilog-highlight-grouping-keywords nil
733 "Non-nil means highlight grouping keywords more dramatically.
734 If false, these words are in the `font-lock-type-face'; if True
735 then they are in `verilog-font-lock-grouping-keywords-face'.
736 Some find that special highlighting on these grouping constructs
737 allow the structure of the code to be understood at a glance."
738 :group 'verilog-mode-indent
739 :type 'boolean)
740 (put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp)
742 (defcustom verilog-highlight-modules nil
743 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
744 When true, mousing over module names will allow jumping to the
745 module definition. If false, this is not supported. Setting
746 this is experimental, and may lead to bad performance."
747 :group 'verilog-mode-indent
748 :type 'boolean)
749 (put 'verilog-highlight-modules 'safe-local-variable 'verilog-booleanp)
751 (defcustom verilog-highlight-includes t
752 "Non-nil means highlight module statements for `verilog-load-file-at-point'.
753 When true, mousing over include file names will allow jumping to the
754 file referenced. If false, this is not supported."
755 :group 'verilog-mode-indent
756 :type 'boolean)
757 (put 'verilog-highlight-includes 'safe-local-variable 'verilog-booleanp)
759 (defcustom verilog-auto-declare-nettype nil
760 "Non-nil specifies the data type to use with `verilog-auto-input' etc.
761 Set this to \"wire\" if the Verilog code uses \"\\=`default_nettype
762 none\". Note using \\=`default_nettype none isn't recommended practice; this
763 mode is experimental."
764 :version "24.1" ; rev670
765 :group 'verilog-mode-actions
766 :type 'boolean)
767 (put 'verilog-auto-declare-nettype 'safe-local-variable 'stringp)
769 (defcustom verilog-auto-wire-comment t
770 "Non-nil indicates to insert to/from comments with `verilog-auto-wire' etc."
771 :version "25.1"
772 :group 'verilog-mode-actions
773 :type 'boolean)
774 (put 'verilog-auto-wire-comment 'safe-local-variable 'verilog-booleanp)
776 (defcustom verilog-auto-wire-type nil
777 "Non-nil specifies the data type to use with `verilog-auto-wire' etc.
778 Set this to \"logic\" for SystemVerilog code, or use `verilog-auto-logic'.
779 Set this to \"wire\" to force use of wire when logic is otherwise appropriate;
780 this is generally only appropriate when making a non-SystemVerilog wrapper
781 containing SystemVerilog cells."
782 :version "24.1" ; rev673
783 :group 'verilog-mode-actions
784 :type '(choice (const nil) string))
785 (put 'verilog-auto-wire-type 'safe-local-variable 'stringp)
787 (defcustom verilog-auto-endcomments t
788 "Non-nil means insert a comment /* ... */ after `end's.
789 The name of the function or case will be set between the braces."
790 :group 'verilog-mode-actions
791 :type 'boolean)
792 (put 'verilog-auto-endcomments 'safe-local-variable 'verilog-booleanp)
794 (defcustom verilog-auto-delete-trailing-whitespace nil
795 "Non-nil means to `delete-trailing-whitespace' in `verilog-auto'."
796 :version "24.1" ; rev703
797 :group 'verilog-mode-actions
798 :type 'boolean)
799 (put 'verilog-auto-delete-trailing-whitespace 'safe-local-variable 'verilog-booleanp)
801 (defcustom verilog-auto-ignore-concat nil
802 "Non-nil means ignore signals in {...} concatenations for AUTOWIRE etc.
803 This will exclude signals referenced as pin connections in {...}
804 from AUTOWIRE, AUTOOUTPUT and friends. This flag should be set
805 for backward compatibility only and not set in new designs; it
806 may be removed in future versions."
807 :group 'verilog-mode-actions
808 :type 'boolean)
809 (put 'verilog-auto-ignore-concat 'safe-local-variable 'verilog-booleanp)
811 (defcustom verilog-auto-read-includes nil
812 "Non-nil means to automatically read includes before AUTOs.
813 This will do a `verilog-read-defines' and `verilog-read-includes' before
814 each AUTO expansion. This makes it easier to embed defines and includes,
815 but can result in very slow reading times if there are many or large
816 include files."
817 :group 'verilog-mode-actions
818 :type 'boolean)
819 (put 'verilog-auto-read-includes 'safe-local-variable 'verilog-booleanp)
821 (defcustom verilog-auto-save-policy nil
822 "Non-nil indicates action to take when saving a Verilog buffer with AUTOs.
823 A value of `force' will always do a \\[verilog-auto] automatically if
824 needed on every save. A value of `detect' will do \\[verilog-auto]
825 automatically when it thinks necessary. A value of `ask' will query the
826 user when it thinks updating is needed.
828 You should not rely on the `ask' or `detect' policies, they are safeguards
829 only. They do not detect when AUTOINSTs need to be updated because a
830 sub-module's port list has changed."
831 :group 'verilog-mode-actions
832 :type '(choice (const nil) (const ask) (const detect) (const force)))
834 (defcustom verilog-auto-star-expand t
835 "Non-nil means to expand SystemVerilog .* instance ports.
836 They will be expanded in the same way as if there was an AUTOINST in the
837 instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'."
838 :group 'verilog-mode-actions
839 :type 'boolean)
840 (put 'verilog-auto-star-expand 'safe-local-variable 'verilog-booleanp)
842 (defcustom verilog-auto-star-save nil
843 "Non-nil means save to disk SystemVerilog .* instance expansions.
844 A nil value indicates direct connections will be removed before saving.
845 Only meaningful to those created due to `verilog-auto-star-expand' being set.
847 Instead of setting this, you may want to use /*AUTOINST*/, which will
848 always be saved."
849 :group 'verilog-mode-actions
850 :type 'boolean)
851 (put 'verilog-auto-star-save 'safe-local-variable 'verilog-booleanp)
853 (defvar verilog-auto-update-tick nil
854 "Modification tick at which autos were last performed.")
856 (defvar verilog-auto-last-file-locals nil
857 "Text from file-local-variables during last evaluation.")
859 (defvar verilog-diff-function 'verilog-diff-report
860 "Function to run when `verilog-diff-auto' detects differences.
861 Function takes three arguments, the original buffer, the
862 difference buffer, and the point in original buffer with the
863 first difference.")
865 (defvar verilog-diff-ignore-regexp nil
866 "Non-nil specifies regexp which `verilog-diff-auto' will ignore.
867 This is typically nil.")
869 ;;; Compile support:
872 (require 'compile)
874 (defvar verilog-error-regexp-added nil)
876 (defvar verilog-error-regexp-emacs-alist
878 (verilog-xl-1
879 "\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
880 (verilog-xl-2
881 "([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 3)
882 (verilog-IES
883 ".*\\*[WE],[0-9A-Z]+\\(\\[[0-9A-Z_,]+\\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)" 2 3)
884 (verilog-surefire-1
885 "[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2)
886 (verilog-surefire-2
887 "\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\),\\s-+\\(line \\)?\\([0-9]+\\):" 2 4 )
888 (verilog-verbose
890 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
891 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
892 (verilog-xsim
893 "\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3)
894 (verilog-vcs-1
895 "\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3)
896 (verilog-vcs-2
897 "Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2)
898 (verilog-vcs-3
899 "\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3)
900 (verilog-vcs-4
901 "syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
902 (verilog-verilator
903 "%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
904 (verilog-leda
905 "^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 2)
907 "List of regexps for Verilog compilers.
908 See `compilation-error-regexp-alist' for the formatting. For Emacs 22+.")
910 (defvar verilog-error-regexp-xemacs-alist
911 ;; Emacs form is '((v-tool "re" 1 2) ...)
912 ;; XEmacs form is '(verilog ("re" 1 2) ...)
913 ;; So we can just map from Emacs to XEmacs
914 (cons 'verilog (mapcar 'cdr verilog-error-regexp-emacs-alist))
915 "List of regexps for Verilog compilers.
916 See `compilation-error-regexp-alist-alist' for the formatting. For XEmacs.")
918 (defvar verilog-error-font-lock-keywords
920 ;; verilog-xl-1
921 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
922 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
923 ;; verilog-xl-2
924 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 bold t)
925 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 3 bold t)
926 ;; verilog-IES (nc-verilog)
927 (".*\\*[WE],[0-9A-Z]+\\(\\[[0-9A-Z_,]+\\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t)
928 (".*\\*[WE],[0-9A-Z]+\\(\\[[0-9A-Z_,]+\\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 3 bold t)
929 ;; verilog-surefire-1
930 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t)
931 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t)
932 ;; verilog-surefire-2
933 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t)
934 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t)
935 ;; verilog-verbose
937 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
938 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
940 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
941 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
942 ;; verilog-vcs-1
943 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t)
944 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t)
945 ;; verilog-vcs-2
946 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
947 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
948 ;; verilog-vcs-3
949 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
950 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t)
951 ;; verilog-vcs-4
952 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t)
953 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
954 ;; verilog-verilator
955 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t)
956 (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t)
957 ;; verilog-leda
958 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 bold t)
959 ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 2 bold t)
961 "Keywords to also highlight in Verilog *compilation* buffers.
962 Only used in XEmacs; GNU Emacs uses `verilog-error-regexp-emacs-alist'.")
964 (defcustom verilog-library-flags '("")
965 "List of standard Verilog arguments to use for /*AUTOINST*/.
966 These arguments are used to find files for `verilog-auto', and match
967 the flags accepted by a standard Verilog-XL simulator.
969 -f filename Reads absolute `verilog-library-flags' from the filename.
970 -F filename Reads relative `verilog-library-flags' from the filename.
971 +incdir+dir Adds the directory to `verilog-library-directories'.
972 -Idir Adds the directory to `verilog-library-directories'.
973 -y dir Adds the directory to `verilog-library-directories'.
974 +libext+.v Adds the extensions to `verilog-library-extensions'.
975 -v filename Adds the filename to `verilog-library-files'.
977 filename Adds the filename to `verilog-library-files'.
978 This is not recommended, -v is a better choice.
980 You might want these defined in each file; put at the *END* of your file
981 something like:
983 // Local Variables:
984 // verilog-library-flags:(\"-y dir -y otherdir\")
985 // End:
987 Verilog-mode attempts to detect changes to this local variable, but they
988 are only insured to be correct when the file is first visited. Thus if you
989 have problems, use \\[find-alternate-file] RET to have these take effect.
991 See also the variables mentioned above."
992 :group 'verilog-mode-auto
993 :type '(repeat string))
994 (put 'verilog-library-flags 'safe-local-variable 'listp)
996 (defcustom verilog-library-directories '(".")
997 "List of directories when looking for files for /*AUTOINST*/.
998 The directory may be relative to the current file, or absolute.
999 Environment variables are also expanded in the directory names.
1000 Having at least the current directory is a good idea.
1002 You might want these defined in each file; put at the *END* of your file
1003 something like:
1005 // Local Variables:
1006 // verilog-library-directories:(\".\" \"subdir\" \"subdir2\")
1007 // End:
1009 Verilog-mode attempts to detect changes to this local variable, but they
1010 are only insured to be correct when the file is first visited. Thus if you
1011 have problems, use \\[find-alternate-file] RET to have these take effect.
1013 See also `verilog-library-flags', `verilog-library-files'
1014 and `verilog-library-extensions'."
1015 :group 'verilog-mode-auto
1016 :type '(repeat file))
1017 (put 'verilog-library-directories 'safe-local-variable 'listp)
1019 (defcustom verilog-library-files '()
1020 "List of files to search for modules.
1021 AUTOINST will use this when it needs to resolve a module name.
1022 This is a complete path, usually to a technology file with many standard
1023 cells defined in it.
1025 You might want these defined in each file; put at the *END* of your file
1026 something like:
1028 // Local Variables:
1029 // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\")
1030 // End:
1032 Verilog-mode attempts to detect changes to this local variable, but they
1033 are only insured to be correct when the file is first visited. Thus if you
1034 have problems, use \\[find-alternate-file] RET to have these take effect.
1036 See also `verilog-library-flags', `verilog-library-directories'."
1037 :group 'verilog-mode-auto
1038 :type '(repeat directory))
1039 (put 'verilog-library-files 'safe-local-variable 'listp)
1041 (defcustom verilog-library-extensions '(".v" ".sv")
1042 "List of extensions to use when looking for files for /*AUTOINST*/.
1043 See also `verilog-library-flags', `verilog-library-directories'."
1044 :type '(repeat string)
1045 :group 'verilog-mode-auto)
1046 (put 'verilog-library-extensions 'safe-local-variable 'listp)
1048 (defcustom verilog-active-low-regexp nil
1049 "If true, treat signals matching this regexp as active low.
1050 This is used for AUTORESET and AUTOTIEOFF. For proper behavior,
1051 you will probably also need `verilog-auto-reset-widths' set."
1052 :group 'verilog-mode-auto
1053 :type '(choice (const nil) regexp))
1054 (put 'verilog-active-low-regexp 'safe-local-variable 'stringp)
1056 (defcustom verilog-auto-sense-include-inputs nil
1057 "Non-nil means AUTOSENSE should include all inputs.
1058 If nil, only inputs that are NOT output signals in the same block are
1059 included."
1060 :group 'verilog-mode-auto
1061 :type 'boolean)
1062 (put 'verilog-auto-sense-include-inputs 'safe-local-variable 'verilog-booleanp)
1064 (defcustom verilog-auto-sense-defines-constant nil
1065 "Non-nil means AUTOSENSE should assume all defines represent constants.
1066 When true, the defines will not be included in sensitivity lists. To
1067 maintain compatibility with other sites, this should be set at the bottom
1068 of each Verilog file that requires it, rather than being set globally."
1069 :group 'verilog-mode-auto
1070 :type 'boolean)
1071 (put 'verilog-auto-sense-defines-constant 'safe-local-variable 'verilog-booleanp)
1073 (defcustom verilog-auto-reset-blocking-in-non t
1074 "Non-nil means AUTORESET will reset blocking statements.
1075 When true, AUTORESET will reset in blocking statements those
1076 signals which were assigned with blocking assignments (=) even in
1077 a block with non-blocking assignments (<=).
1079 If nil, all blocking assigned signals are ignored when any
1080 non-blocking assignment is in the AUTORESET block. This allows
1081 blocking assignments to be used for temporary values and not have
1082 those temporaries reset. See example in `verilog-auto-reset'."
1083 :version "24.1" ; rev718
1084 :type 'boolean
1085 :group 'verilog-mode-auto)
1086 (put 'verilog-auto-reset-blocking-in-non 'safe-local-variable 'verilog-booleanp)
1088 (defcustom verilog-auto-reset-widths t
1089 "True means AUTORESET should determine the width of signals.
1090 This is then used to set the width of the zero (32'h0 for example). This
1091 is required by some lint tools that aren't smart enough to ignore widths of
1092 the constant zero. This may result in ugly code when parameters determine
1093 the MSB or LSB of a signal inside an AUTORESET.
1095 If nil, AUTORESET uses \"0\" as the constant.
1097 If `unbased', AUTORESET used the unbased unsized literal \"\\='0\"
1098 as the constant. This setting is strongly recommended for
1099 SystemVerilog designs."
1100 :type 'boolean
1101 :group 'verilog-mode-auto)
1102 (put 'verilog-auto-reset-widths 'safe-local-variable
1103 '(lambda (x) (memq x '(nil t unbased))))
1105 (defcustom verilog-assignment-delay ""
1106 "Text used for delays in delayed assignments. Add a trailing space if set."
1107 :group 'verilog-mode-auto
1108 :type 'string)
1109 (put 'verilog-assignment-delay 'safe-local-variable 'stringp)
1111 (defcustom verilog-auto-arg-format 'packed
1112 "Formatting to use for AUTOARG signal names.
1113 If `packed', then as many inputs and outputs that fit within
1114 `fill-column' will be put onto one line.
1116 If `single', then a single input or output will be put onto each
1117 line."
1118 :version "25.1"
1119 :type '(radio (const :tag "Line up Assignments and Declarations" packed)
1120 (const :tag "Line up Assignment statements" single))
1121 :group 'verilog-mode-auto)
1122 (put 'verilog-auto-arg-format 'safe-local-variable
1123 '(lambda (x) (memq x '(packed single))))
1125 (defcustom verilog-auto-arg-sort nil
1126 "Non-nil means AUTOARG signal names will be sorted, not in declaration order.
1127 Declaration order is advantageous with order based instantiations
1128 and is the default for backward compatibility. Sorted order
1129 reduces changes when declarations are moved around in a file, and
1130 it's bad practice to rely on order based instantiations anyhow.
1132 See also `verilog-auto-inst-sort'."
1133 :group 'verilog-mode-auto
1134 :type 'boolean)
1135 (put 'verilog-auto-arg-sort 'safe-local-variable 'verilog-booleanp)
1137 (defcustom verilog-auto-inst-dot-name nil
1138 "Non-nil means when creating ports with AUTOINST, use .name syntax.
1139 This will use \".port\" instead of \".port(port)\" when possible.
1140 This is only legal in SystemVerilog files, and will confuse older
1141 simulators. Setting `verilog-auto-inst-vector' to nil may also
1142 be desirable to increase how often .name will be used."
1143 :group 'verilog-mode-auto
1144 :type 'boolean)
1145 (put 'verilog-auto-inst-dot-name 'safe-local-variable 'verilog-booleanp)
1147 (defcustom verilog-auto-inst-param-value nil
1148 "Non-nil means AUTOINST will replace parameters with the parameter value.
1149 If nil, leave parameters as symbolic names.
1151 Parameters must be in Verilog 2001 format #(...), and if a parameter is not
1152 listed as such there (as when the default value is acceptable), it will not
1153 be replaced, and will remain symbolic.
1155 For example, imagine a submodule uses parameters to declare the size of its
1156 inputs. This is then used by an upper module:
1158 module InstModule (o,i);
1159 parameter WIDTH;
1160 input [WIDTH-1:0] i;
1161 parameter type OUT_t;
1162 output OUT_t o;
1163 endmodule
1165 module ExampInst;
1166 /*AUTOOUTPUT*/
1167 // Beginning of automatic outputs
1168 output OUT_t o;
1169 // End of automatics
1171 InstModule
1172 #(.WIDTH(10),
1173 ,.OUT_t(upper_t))
1174 instName
1175 (/*AUTOINST*/
1176 .i (i[WIDTH-1:0]),
1177 .o (o));
1179 Note even though WIDTH=10, the AUTOINST has left the parameter as
1180 a symbolic name. Likewise the OUT_t is preserved as the name
1181 from the instantiated module.
1183 If `verilog-auto-inst-param-value' is set, this will
1184 instead expand to:
1186 module ExampInst;
1187 /*AUTOOUTPUT*/
1188 // Beginning of automatic outputs
1189 output upper_t o;
1190 // End of automatics
1192 InstModule
1193 #(.WIDTH(10),
1194 ,.OUT_t(upper_t))
1195 instName
1196 (/*AUTOINST*/
1197 .i (i[9:0]),
1198 .o (o));
1200 Note that the instantiation now has \"i[9:0]\" as the WIDTH
1201 was expanded. Likewise the data type of \"o\" in the AUTOOUTPUT
1202 is now upper_t, from the OUT_t parameter override.
1203 This second expansion of parameter types can be overridden with
1204 `verilog-auto-inst-param-value-type'."
1205 :group 'verilog-mode-auto
1206 :type 'boolean)
1207 (put 'verilog-auto-inst-param-value 'safe-local-variable 'verilog-booleanp)
1209 (defcustom verilog-auto-inst-param-value-type t
1210 "Non-nil means expand parameter type in instantiations.
1211 If nil, leave parameter types as symbolic names.
1213 See `verilog-auto-inst-param-value'."
1214 :version "25.1"
1215 :group 'verilog-mode-auto
1216 :type 'boolean)
1217 (put 'verilog-auto-inst-param-value-type 'safe-local-variable 'verilog-booleanp)
1219 (defcustom verilog-auto-inst-sort nil
1220 "Non-nil means AUTOINST signals will be sorted, not in declaration order.
1221 Also affects AUTOINSTPARAM. Declaration order is the default for
1222 backward compatibility, and as some teams prefer signals that are
1223 declared together to remain together. Sorted order reduces
1224 changes when declarations are moved around in a file.
1226 See also `verilog-auto-arg-sort'."
1227 :version "24.1" ; rev688
1228 :group 'verilog-mode-auto
1229 :type 'boolean)
1230 (put 'verilog-auto-inst-sort 'safe-local-variable 'verilog-booleanp)
1232 (defcustom verilog-auto-inst-vector t
1233 "Non-nil means when creating default ports with AUTOINST, use bus subscripts.
1234 If nil, skip the subscript when it matches the entire bus as declared in
1235 the module (AUTOWIRE signals always are subscripted, you must manually
1236 declare the wire to have the subscripts removed.) Setting this to nil may
1237 speed up some simulators, but is less general and harder to read, so avoid."
1238 :group 'verilog-mode-auto
1239 :type 'boolean)
1240 (put 'verilog-auto-inst-vector 'safe-local-variable 'verilog-booleanp)
1242 (defcustom verilog-auto-inst-template-numbers nil
1243 "If true, when creating templated ports with AUTOINST, add a comment.
1245 If t, the comment will add the line number of the template that
1246 was used for that port declaration. This setting is suggested
1247 only for debugging use, as regular use may cause a large numbers
1248 of merge conflicts.
1250 If `lhs', the comment will show the left hand side of the
1251 AUTO_TEMPLATE rule that is matched. This is less precise than
1252 numbering (t) when multiple rules have the same pin name, but
1253 won't merge conflict."
1254 :group 'verilog-mode-auto
1255 :type '(choice (const nil) (const t) (const lhs)))
1256 (put 'verilog-auto-inst-template-numbers 'safe-local-variable
1257 '(lambda (x) (memq x '(nil t lhs))))
1259 (defcustom verilog-auto-inst-column 40
1260 "Indent-to column number for net name part of AUTOINST created pin."
1261 :group 'verilog-mode-indent
1262 :type 'integer)
1263 (put 'verilog-auto-inst-column 'safe-local-variable 'integerp)
1265 (defcustom verilog-auto-inst-interfaced-ports nil
1266 "Non-nil means include interfaced ports in AUTOINST expansions."
1267 :version "24.3" ; rev773, default change rev815
1268 :group 'verilog-mode-auto
1269 :type 'boolean)
1270 (put 'verilog-auto-inst-interfaced-ports 'safe-local-variable 'verilog-booleanp)
1272 (defcustom verilog-auto-input-ignore-regexp nil
1273 "If non-nil, when creating AUTOINPUT, ignore signals matching this regexp.
1274 See the \\[verilog-faq] for examples on using this."
1275 :group 'verilog-mode-auto
1276 :type '(choice (const nil) regexp))
1277 (put 'verilog-auto-input-ignore-regexp 'safe-local-variable 'stringp)
1279 (defcustom verilog-auto-inout-ignore-regexp nil
1280 "If non-nil, when creating AUTOINOUT, ignore signals matching this regexp.
1281 See the \\[verilog-faq] for examples on using this."
1282 :group 'verilog-mode-auto
1283 :type '(choice (const nil) regexp))
1284 (put 'verilog-auto-inout-ignore-regexp 'safe-local-variable 'stringp)
1286 (defcustom verilog-auto-output-ignore-regexp nil
1287 "If non-nil, when creating AUTOOUTPUT, ignore signals matching this regexp.
1288 See the \\[verilog-faq] for examples on using this."
1289 :group 'verilog-mode-auto
1290 :type '(choice (const nil) regexp))
1291 (put 'verilog-auto-output-ignore-regexp 'safe-local-variable 'stringp)
1293 (defcustom verilog-auto-template-warn-unused nil
1294 "Non-nil means report warning if an AUTO_TEMPLATE line is not used.
1295 This feature is not supported before Emacs 21.1 or XEmacs 21.4."
1296 :version "24.3" ; rev787
1297 :group 'verilog-mode-auto
1298 :type 'boolean)
1299 (put 'verilog-auto-template-warn-unused 'safe-local-variable 'verilog-booleanp)
1301 (defcustom verilog-auto-tieoff-declaration "wire"
1302 "Data type used for the declaration for AUTOTIEOFF.
1303 If \"wire\" then create a wire, if \"assign\" create an
1304 assignment, else the data type for variable creation."
1305 :version "24.1" ; rev713
1306 :group 'verilog-mode-auto
1307 :type 'string)
1308 (put 'verilog-auto-tieoff-declaration 'safe-local-variable 'stringp)
1310 (defcustom verilog-auto-tieoff-ignore-regexp nil
1311 "If non-nil, when creating AUTOTIEOFF, ignore signals matching this regexp.
1312 See the \\[verilog-faq] for examples on using this."
1313 :group 'verilog-mode-auto
1314 :type '(choice (const nil) regexp))
1315 (put 'verilog-auto-tieoff-ignore-regexp 'safe-local-variable 'stringp)
1317 (defcustom verilog-auto-unused-ignore-regexp nil
1318 "If non-nil, when creating AUTOUNUSED, ignore signals matching this regexp.
1319 See the \\[verilog-faq] for examples on using this."
1320 :group 'verilog-mode-auto
1321 :type '(choice (const nil) regexp))
1322 (put 'verilog-auto-unused-ignore-regexp 'safe-local-variable 'stringp)
1324 (defcustom verilog-case-fold t
1325 "Non-nil means `verilog-mode' regexps should ignore case.
1326 This variable is t for backward compatibility; nil is suggested."
1327 :version "24.4"
1328 :group 'verilog-mode
1329 :type 'boolean)
1330 (put 'verilog-case-fold 'safe-local-variable 'verilog-booleanp)
1332 (defcustom verilog-typedef-regexp nil
1333 "If non-nil, regular expression that matches Verilog-2001 typedef names.
1334 For example, \"_t$\" matches typedefs named with _t, as in the C language.
1335 See also `verilog-case-fold'."
1336 :group 'verilog-mode-auto
1337 :type '(choice (const nil) regexp))
1338 (put 'verilog-typedef-regexp 'safe-local-variable 'stringp)
1340 (defcustom verilog-mode-hook 'verilog-set-compile-command
1341 "Hook run after Verilog mode is loaded."
1342 :type 'hook
1343 :group 'verilog-mode)
1345 (defcustom verilog-auto-hook nil
1346 "Hook run after `verilog-mode' updates AUTOs."
1347 :group 'verilog-mode-auto
1348 :type 'hook)
1350 (defcustom verilog-before-auto-hook nil
1351 "Hook run before `verilog-mode' updates AUTOs."
1352 :group 'verilog-mode-auto
1353 :type 'hook)
1355 (defcustom verilog-delete-auto-hook nil
1356 "Hook run after `verilog-mode' deletes AUTOs."
1357 :group 'verilog-mode-auto
1358 :type 'hook)
1360 (defcustom verilog-before-delete-auto-hook nil
1361 "Hook run before `verilog-mode' deletes AUTOs."
1362 :group 'verilog-mode-auto
1363 :type 'hook)
1365 (defcustom verilog-getopt-flags-hook nil
1366 "Hook run after `verilog-getopt-flags' determines the Verilog option lists."
1367 :group 'verilog-mode-auto
1368 :type 'hook)
1370 (defcustom verilog-before-getopt-flags-hook nil
1371 "Hook run before `verilog-getopt-flags' determines the Verilog option lists."
1372 :group 'verilog-mode-auto
1373 :type 'hook)
1375 (defcustom verilog-before-save-font-hook nil
1376 "Hook run before `verilog-save-font-no-change-functions' removes highlighting."
1377 :version "24.3" ; rev735
1378 :group 'verilog-mode-auto
1379 :type 'hook)
1381 (defcustom verilog-after-save-font-hook nil
1382 "Hook run after `verilog-save-font-no-change-functions' restores highlighting."
1383 :version "24.3" ; rev735
1384 :group 'verilog-mode-auto
1385 :type 'hook)
1387 (defvar verilog-imenu-generic-expression
1388 '((nil "^\\s-*\\(?:m\\(?:odule\\|acromodule\\)\\|p\\(?:rimitive\\|rogram\\|ackage\\)\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 1)
1389 ("*Variables*" "^\\s-*\\(reg\\|wire\\|logic\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3)
1390 ("*Classes*" "^\\s-*\\(?:\\(?:virtual\\|interface\\)\\s-+\\)?class\\s-+\\([A-Za-z_][A-Za-z0-9_]+\\)" 1)
1391 ("*Tasks*" "^\\s-*\\(?:\\(?:static\\|pure\\|virtual\\|local\\|protected\\)\\s-+\\)*task\\s-+\\(?:\\(?:static\\|automatic\\)\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_:]+\\)" 1)
1392 ("*Functions*" "^\\s-*\\(?:\\(?:static\\|pure\\|virtual\\|local\\|protected\\)\\s-+\\)*function\\s-+\\(?:\\(?:static\\|automatic\\)\\s-+\\)?\\(?:\\w+\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_:]+\\)" 1)
1393 ("*Interfaces*" "^\\s-*interface\\s-+\\([a-zA-Z_0-9]+\\)" 1)
1394 ("*Types*" "^\\s-*typedef\\s-+.*\\s-+\\([a-zA-Z_0-9]+\\)\\s-*;" 1))
1395 "Imenu expression for Verilog mode. See `imenu-generic-expression'.")
1398 ;; provide a verilog-header function.
1399 ;; Customization variables:
1401 (defvar verilog-date-scientific-format nil
1402 "If non-nil, dates are written in scientific format (e.g. 1997/09/17).
1403 If nil, in European format (e.g. 17.09.1997). The brain-dead American
1404 format (e.g. 09/17/1997) is not supported.")
1406 (defvar verilog-company nil
1407 "Default name of Company for Verilog header.
1408 If set will become buffer local.")
1409 (make-variable-buffer-local 'verilog-company)
1411 (defvar verilog-project nil
1412 "Default name of Project for Verilog header.
1413 If set will become buffer local.")
1414 (make-variable-buffer-local 'verilog-project)
1416 ;;; Keymap and Menu:
1419 (defvar verilog-mode-map
1420 (let ((map (make-sparse-keymap)))
1421 (define-key map ";" 'electric-verilog-semi)
1422 (define-key map [(control 59)] 'electric-verilog-semi-with-comment)
1423 (define-key map ":" 'electric-verilog-colon)
1424 ;;(define-key map "=" 'electric-verilog-equal)
1425 (define-key map "`" 'electric-verilog-tick)
1426 (define-key map "\t" 'electric-verilog-tab)
1427 (define-key map "\r" 'electric-verilog-terminate-line)
1428 ;; backspace/delete key bindings
1429 (define-key map [backspace] 'backward-delete-char-untabify)
1430 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
1431 (define-key map [delete] 'delete-char)
1432 (define-key map [(meta delete)] 'kill-word))
1433 (define-key map "\M-\C-b" 'electric-verilog-backward-sexp)
1434 (define-key map "\M-\C-f" 'electric-verilog-forward-sexp)
1435 (define-key map "\M-\r" `electric-verilog-terminate-and-indent)
1436 (define-key map "\M-\t" (if (fboundp 'completion-at-point)
1437 'completion-at-point 'verilog-complete-word))
1438 (define-key map "\M-?" (if (fboundp 'completion-help-at-point)
1439 'completion-help-at-point 'verilog-show-completions))
1440 ;; Note \C-c and letter are reserved for users
1441 (define-key map "\C-c`" 'verilog-lint-off)
1442 (define-key map "\C-c*" 'verilog-delete-auto-star-implicit)
1443 (define-key map "\C-c?" 'verilog-diff-auto)
1444 (define-key map "\C-c\C-r" 'verilog-label-be)
1445 (define-key map "\C-c\C-i" 'verilog-pretty-declarations)
1446 (define-key map "\C-c=" 'verilog-pretty-expr)
1447 (define-key map "\C-c\C-b" 'verilog-submit-bug-report)
1448 (define-key map "\C-c/" 'verilog-star-comment)
1449 (define-key map "\C-c\C-c" 'verilog-comment-region)
1450 (define-key map "\C-c\C-u" 'verilog-uncomment-region)
1451 (when (featurep 'xemacs)
1452 (define-key map [(meta control h)] 'verilog-mark-defun)
1453 (define-key map "\M-\C-a" 'verilog-beg-of-defun)
1454 (define-key map "\M-\C-e" 'verilog-end-of-defun))
1455 (define-key map "\C-c\C-d" 'verilog-goto-defun)
1456 (define-key map "\C-c\C-k" 'verilog-delete-auto)
1457 (define-key map "\C-c\C-a" 'verilog-auto)
1458 (define-key map "\C-c\C-s" 'verilog-auto-save-compile)
1459 (define-key map "\C-c\C-p" 'verilog-preprocess)
1460 (define-key map "\C-c\C-z" 'verilog-inject-auto)
1461 (define-key map "\C-c\C-e" 'verilog-expand-vector)
1462 (define-key map "\C-c\C-h" 'verilog-header)
1463 map)
1464 "Keymap used in Verilog mode.")
1466 ;; menus
1467 (easy-menu-define
1468 verilog-menu verilog-mode-map "Menu for Verilog mode"
1469 (verilog-easy-menu-filter
1470 `("Verilog"
1471 ("Choose Compilation Action"
1472 ["None"
1473 (progn
1474 (setq verilog-tool nil)
1475 (verilog-set-compile-command))
1476 :style radio
1477 :selected (equal verilog-tool nil)
1478 :help "When invoking compilation, use compile-command"]
1479 ["Lint"
1480 (progn
1481 (setq verilog-tool 'verilog-linter)
1482 (verilog-set-compile-command))
1483 :style radio
1484 :selected (equal verilog-tool `verilog-linter)
1485 :help "When invoking compilation, use lint checker"]
1486 ["Coverage"
1487 (progn
1488 (setq verilog-tool 'verilog-coverage)
1489 (verilog-set-compile-command))
1490 :style radio
1491 :selected (equal verilog-tool `verilog-coverage)
1492 :help "When invoking compilation, annotate for coverage"]
1493 ["Simulator"
1494 (progn
1495 (setq verilog-tool 'verilog-simulator)
1496 (verilog-set-compile-command))
1497 :style radio
1498 :selected (equal verilog-tool `verilog-simulator)
1499 :help "When invoking compilation, interpret Verilog source"]
1500 ["Compiler"
1501 (progn
1502 (setq verilog-tool 'verilog-compiler)
1503 (verilog-set-compile-command))
1504 :style radio
1505 :selected (equal verilog-tool `verilog-compiler)
1506 :help "When invoking compilation, compile Verilog source"]
1507 ["Preprocessor"
1508 (progn
1509 (setq verilog-tool 'verilog-preprocessor)
1510 (verilog-set-compile-command))
1511 :style radio
1512 :selected (equal verilog-tool `verilog-preprocessor)
1513 :help "When invoking compilation, preprocess Verilog source, see also `verilog-preprocess'"]
1515 ("Move"
1516 ["Beginning of function" verilog-beg-of-defun
1517 :keys "C-M-a"
1518 :help "Move backward to the beginning of the current function or procedure"]
1519 ["End of function" verilog-end-of-defun
1520 :keys "C-M-e"
1521 :help "Move forward to the end of the current function or procedure"]
1522 ["Mark function" verilog-mark-defun
1523 :keys "C-M-h"
1524 :help "Mark the current Verilog function or procedure"]
1525 ["Goto function/module" verilog-goto-defun
1526 :help "Move to specified Verilog module/task/function"]
1527 ["Move to beginning of block" electric-verilog-backward-sexp
1528 :help "Move backward over one balanced expression"]
1529 ["Move to end of block" electric-verilog-forward-sexp
1530 :help "Move forward over one balanced expression"]
1532 ("Comments"
1533 ["Comment Region" verilog-comment-region
1534 :help "Put marked area into a comment"]
1535 ["UnComment Region" verilog-uncomment-region
1536 :help "Uncomment an area commented with Comment Region"]
1537 ["Multi-line comment insert" verilog-star-comment
1538 :help "Insert Verilog /* */ comment at point"]
1539 ["Lint error to comment" verilog-lint-off
1540 :help "Convert a Verilog linter warning line into a disable statement"]
1542 "----"
1543 ["Compile" compile
1544 :help "Perform compilation-action (above) on the current buffer"]
1545 ["AUTO, Save, Compile" verilog-auto-save-compile
1546 :help "Recompute AUTOs, save buffer, and compile"]
1547 ["Next Compile Error" next-error
1548 :help "Visit next compilation error message and corresponding source code"]
1549 ["Ignore Lint Warning at point" verilog-lint-off
1550 :help "Convert a Verilog linter warning line into a disable statement"]
1551 "----"
1552 ["Line up declarations around point" verilog-pretty-declarations
1553 :help "Line up declarations around point"]
1554 ["Line up equations around point" verilog-pretty-expr
1555 :help "Line up expressions around point"]
1556 ["Redo/insert comments on every end" verilog-label-be
1557 :help "Label matching begin ... end statements"]
1558 ["Expand [x:y] vector line" verilog-expand-vector
1559 :help "Take a signal vector on the current line and expand it to multiple lines"]
1560 ["Insert begin-end block" verilog-insert-block
1561 :help "Insert begin ... end"]
1562 ["Complete word" ,(if (fboundp 'completion-at-point)
1563 'completion-at-point 'verilog-complete-word)
1564 :help "Complete word at point"]
1565 "----"
1566 ["Recompute AUTOs" verilog-auto
1567 :help "Expand AUTO meta-comment statements"]
1568 ["Kill AUTOs" verilog-delete-auto
1569 :help "Remove AUTO expansions"]
1570 ["Diff AUTOs" verilog-diff-auto
1571 :help "Show differences in AUTO expansions"]
1572 ["Inject AUTOs" verilog-inject-auto
1573 :help "Inject AUTOs into legacy non-AUTO buffer"]
1574 ("AUTO Help..."
1575 ["AUTO General" (describe-function 'verilog-auto)
1576 :help "Help introduction on AUTOs"]
1577 ["AUTO Library Flags" (describe-variable 'verilog-library-flags)
1578 :help "Help on verilog-library-flags"]
1579 ["AUTO Library Path" (describe-variable 'verilog-library-directories)
1580 :help "Help on verilog-library-directories"]
1581 ["AUTO Library Files" (describe-variable 'verilog-library-files)
1582 :help "Help on verilog-library-files"]
1583 ["AUTO Library Extensions" (describe-variable 'verilog-library-extensions)
1584 :help "Help on verilog-library-extensions"]
1585 ["AUTO `define Reading" (describe-function 'verilog-read-defines)
1586 :help "Help on reading `defines"]
1587 ["AUTO `include Reading" (describe-function 'verilog-read-includes)
1588 :help "Help on parsing `includes"]
1589 ["AUTOARG" (describe-function 'verilog-auto-arg)
1590 :help "Help on AUTOARG - declaring module port list"]
1591 ["AUTOASCIIENUM" (describe-function 'verilog-auto-ascii-enum)
1592 :help "Help on AUTOASCIIENUM - creating ASCII for enumerations"]
1593 ["AUTOASSIGNMODPORT" (describe-function 'verilog-auto-assign-modport)
1594 :help "Help on AUTOASSIGNMODPORT - creating assignments to/from modports"]
1595 ["AUTOINOUT" (describe-function 'verilog-auto-inout)
1596 :help "Help on AUTOINOUT - adding inouts from cells"]
1597 ["AUTOINOUTCOMP" (describe-function 'verilog-auto-inout-comp)
1598 :help "Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
1599 ["AUTOINOUTIN" (describe-function 'verilog-auto-inout-in)
1600 :help "Help on AUTOINOUTIN - copying i/o from another file as all inputs"]
1601 ["AUTOINOUTMODPORT" (describe-function 'verilog-auto-inout-modport)
1602 :help "Help on AUTOINOUTMODPORT - copying i/o from an interface modport"]
1603 ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module)
1604 :help "Help on AUTOINOUTMODULE - copying i/o from another file"]
1605 ["AUTOINOUTPARAM" (describe-function 'verilog-auto-inout-param)
1606 :help "Help on AUTOINOUTPARAM - copying parameters from another file"]
1607 ["AUTOINPUT" (describe-function 'verilog-auto-input)
1608 :help "Help on AUTOINPUT - adding inputs from cells"]
1609 ["AUTOINSERTLISP" (describe-function 'verilog-auto-insert-lisp)
1610 :help "Help on AUTOINSERTLISP - insert text from a lisp function"]
1611 ["AUTOINSERTLAST" (describe-function 'verilog-auto-insert-last)
1612 :help "Help on AUTOINSERTLISPLAST - insert text from a lisp function"]
1613 ["AUTOINST" (describe-function 'verilog-auto-inst)
1614 :help "Help on AUTOINST - adding pins for cells"]
1615 ["AUTOINST (.*)" (describe-function 'verilog-auto-star)
1616 :help "Help on expanding Verilog-2001 .* pins"]
1617 ["AUTOINSTPARAM" (describe-function 'verilog-auto-inst-param)
1618 :help "Help on AUTOINSTPARAM - adding parameter pins to cells"]
1619 ["AUTOLOGIC" (describe-function 'verilog-auto-logic)
1620 :help "Help on AUTOLOGIC - declaring logic signals"]
1621 ["AUTOOUTPUT" (describe-function 'verilog-auto-output)
1622 :help "Help on AUTOOUTPUT - adding outputs from cells"]
1623 ["AUTOOUTPUTEVERY" (describe-function 'verilog-auto-output-every)
1624 :help "Help on AUTOOUTPUTEVERY - adding outputs of all signals"]
1625 ["AUTOREG" (describe-function 'verilog-auto-reg)
1626 :help "Help on AUTOREG - declaring registers for non-wires"]
1627 ["AUTOREGINPUT" (describe-function 'verilog-auto-reg-input)
1628 :help "Help on AUTOREGINPUT - declaring inputs for non-wires"]
1629 ["AUTORESET" (describe-function 'verilog-auto-reset)
1630 :help "Help on AUTORESET - resetting always blocks"]
1631 ["AUTOSENSE or AS" (describe-function 'verilog-auto-sense)
1632 :help "Help on AUTOSENSE - sensitivity lists for always blocks"]
1633 ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff)
1634 :help "Help on AUTOTIEOFF - tying off unused outputs"]
1635 ["AUTOUNDEF" (describe-function 'verilog-auto-undef)
1636 :help "Help on AUTOUNDEF - undefine all local defines"]
1637 ["AUTOUNUSED" (describe-function 'verilog-auto-unused)
1638 :help "Help on AUTOUNUSED - terminating unused inputs"]
1639 ["AUTOWIRE" (describe-function 'verilog-auto-wire)
1640 :help "Help on AUTOWIRE - declaring wires for cells"]
1642 "----"
1643 ["Submit bug report" verilog-submit-bug-report
1644 :help "Submit via mail a bug report on verilog-mode.el"]
1645 ["Version and FAQ" verilog-faq
1646 :help "Show the current version, and where to get the FAQ etc"]
1647 ["Customize Verilog Mode..." verilog-customize
1648 :help "Customize variables and other settings used by Verilog-Mode"]
1649 ["Customize Verilog Fonts & Colors" verilog-font-customize
1650 :help "Customize fonts used by Verilog-Mode."])))
1652 (easy-menu-define
1653 verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog."
1654 (verilog-easy-menu-filter
1655 '("Statements"
1656 ["Header" verilog-sk-header
1657 :help "Insert a header block at the top of file"]
1658 ["Comment" verilog-sk-comment
1659 :help "Insert a comment block"]
1660 "----"
1661 ["Module" verilog-sk-module
1662 :help "Insert a module .. (/*AUTOARG*/);.. endmodule block"]
1663 ["OVM Class" verilog-sk-ovm-class
1664 :help "Insert an OVM class block"]
1665 ["UVM Object" verilog-sk-uvm-object
1666 :help "Insert an UVM object block"]
1667 ["UVM Component" verilog-sk-uvm-component
1668 :help "Insert an UVM component block"]
1669 ["Primitive" verilog-sk-primitive
1670 :help "Insert a primitive .. (.. );.. endprimitive block"]
1671 "----"
1672 ["Input" verilog-sk-input
1673 :help "Insert an input declaration"]
1674 ["Output" verilog-sk-output
1675 :help "Insert an output declaration"]
1676 ["Inout" verilog-sk-inout
1677 :help "Insert an inout declaration"]
1678 ["Wire" verilog-sk-wire
1679 :help "Insert a wire declaration"]
1680 ["Reg" verilog-sk-reg
1681 :help "Insert a register declaration"]
1682 ["Define thing under point as a register" verilog-sk-define-signal
1683 :help "Define signal under point as a register at the top of the module"]
1684 "----"
1685 ["Initial" verilog-sk-initial
1686 :help "Insert an initial begin .. end block"]
1687 ["Always" verilog-sk-always
1688 :help "Insert an always @(AS) begin .. end block"]
1689 ["Function" verilog-sk-function
1690 :help "Insert a function .. begin .. end endfunction block"]
1691 ["Task" verilog-sk-task
1692 :help "Insert a task .. begin .. end endtask block"]
1693 ["Specify" verilog-sk-specify
1694 :help "Insert a specify .. endspecify block"]
1695 ["Generate" verilog-sk-generate
1696 :help "Insert a generate .. endgenerate block"]
1697 "----"
1698 ["Begin" verilog-sk-begin
1699 :help "Insert a begin .. end block"]
1700 ["If" verilog-sk-if
1701 :help "Insert an if (..) begin .. end block"]
1702 ["(if) else" verilog-sk-else-if
1703 :help "Insert an else if (..) begin .. end block"]
1704 ["For" verilog-sk-for
1705 :help "Insert a for (...) begin .. end block"]
1706 ["While" verilog-sk-while
1707 :help "Insert a while (...) begin .. end block"]
1708 ["Fork" verilog-sk-fork
1709 :help "Insert a fork begin .. end .. join block"]
1710 ["Repeat" verilog-sk-repeat
1711 :help "Insert a repeat (..) begin .. end block"]
1712 ["Case" verilog-sk-case
1713 :help "Insert a case block, prompting for details"]
1714 ["Casex" verilog-sk-casex
1715 :help "Insert a casex (...) item: begin.. end endcase block"]
1716 ["Casez" verilog-sk-casez
1717 :help "Insert a casez (...) item: begin.. end endcase block"])))
1719 (defvar verilog-mode-abbrev-table nil
1720 "Abbrev table in use in Verilog-mode buffers.")
1722 ;;(makunbound 'verilog-mode-abbrev-table) ; For testing, clear out old defvar
1723 (verilog-define-abbrev-table
1724 'verilog-mode-abbrev-table ()
1725 "Abbrev table for Verilog mode skeletons."
1726 :case-fixed t
1727 ;; Only expand in code.
1728 :enable-function (lambda () (not (verilog-in-comment-or-string-p))))
1729 (verilog-define-abbrev verilog-mode-abbrev-table "class" "" 'verilog-sk-ovm-class)
1730 (verilog-define-abbrev verilog-mode-abbrev-table "always" "" 'verilog-sk-always)
1731 (verilog-define-abbrev verilog-mode-abbrev-table "begin" nil `verilog-sk-begin)
1732 (verilog-define-abbrev verilog-mode-abbrev-table "case" "" `verilog-sk-case)
1733 (verilog-define-abbrev verilog-mode-abbrev-table "for" "" `verilog-sk-for)
1734 (verilog-define-abbrev verilog-mode-abbrev-table "generate" "" `verilog-sk-generate)
1735 (verilog-define-abbrev verilog-mode-abbrev-table "initial" "" `verilog-sk-initial)
1736 (verilog-define-abbrev verilog-mode-abbrev-table "fork" "" `verilog-sk-fork)
1737 (verilog-define-abbrev verilog-mode-abbrev-table "module" "" `verilog-sk-module)
1738 (verilog-define-abbrev verilog-mode-abbrev-table "primitive" "" `verilog-sk-primitive)
1739 (verilog-define-abbrev verilog-mode-abbrev-table "repeat" "" `verilog-sk-repeat)
1740 (verilog-define-abbrev verilog-mode-abbrev-table "specify" "" `verilog-sk-specify)
1741 (verilog-define-abbrev verilog-mode-abbrev-table "task" "" `verilog-sk-task)
1742 (verilog-define-abbrev verilog-mode-abbrev-table "while" "" `verilog-sk-while)
1743 (verilog-define-abbrev verilog-mode-abbrev-table "casex" "" `verilog-sk-casex)
1744 (verilog-define-abbrev verilog-mode-abbrev-table "casez" "" `verilog-sk-casez)
1745 (verilog-define-abbrev verilog-mode-abbrev-table "if" "" `verilog-sk-if)
1746 (verilog-define-abbrev verilog-mode-abbrev-table "else if" "" `verilog-sk-else-if)
1747 (verilog-define-abbrev verilog-mode-abbrev-table "assign" "" `verilog-sk-assign)
1748 (verilog-define-abbrev verilog-mode-abbrev-table "function" "" `verilog-sk-function)
1749 (verilog-define-abbrev verilog-mode-abbrev-table "input" "" `verilog-sk-input)
1750 (verilog-define-abbrev verilog-mode-abbrev-table "output" "" `verilog-sk-output)
1751 (verilog-define-abbrev verilog-mode-abbrev-table "inout" "" `verilog-sk-inout)
1752 (verilog-define-abbrev verilog-mode-abbrev-table "wire" "" `verilog-sk-wire)
1753 (verilog-define-abbrev verilog-mode-abbrev-table "reg" "" `verilog-sk-reg)
1756 ;; Macros
1759 (defsubst verilog-within-string ()
1760 (nth 3 (parse-partial-sexp (point-at-bol) (point))))
1762 (defsubst verilog-string-match-fold (regexp string &optional start)
1763 "Like `string-match', but use `verilog-case-fold'.
1764 Return index of start of first match for REGEXP in STRING, or nil.
1765 Matching ignores case if `verilog-case-fold' is non-nil.
1766 If third arg START is non-nil, start search at that index in STRING."
1767 (let ((case-fold-search verilog-case-fold))
1768 (string-match regexp string start)))
1770 (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string)
1771 "Replace occurrences of FROM-STRING with TO-STRING.
1772 FIXEDCASE and LITERAL as in `replace-match'. STRING is what to replace.
1773 The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\")
1774 will break, as the o's continuously replace. xa -> x works ok though."
1775 ;; Hopefully soon to an Emacs built-in
1776 ;; Also note \ in the replacement prevent multiple replacements; IE
1777 ;; (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil "wire@_@")
1778 ;; Gives "wire\([0-9]+\)_@" not "wire\([0-9]+\)_\([0-9]+\)"
1779 (let ((start 0))
1780 (while (string-match from-string string start)
1781 (setq string (replace-match to-string fixedcase literal string)
1782 start (min (length string) (+ (match-beginning 0) (length to-string)))))
1783 string))
1785 (defsubst verilog-string-remove-spaces (string)
1786 "Remove spaces surrounding STRING."
1787 (save-match-data
1788 (setq string (verilog-string-replace-matches "^\\s-+" "" nil nil string))
1789 (setq string (verilog-string-replace-matches "\\s-+$" "" nil nil string))
1790 string))
1792 (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR)
1793 ;; checkdoc-params: (REGEXP BOUND NOERROR)
1794 "Like `re-search-forward', but skips over match in comments or strings."
1795 (let ((mdata '(nil nil))) ; So match-end will return nil if no matches found
1796 (while (and
1797 (re-search-forward REGEXP BOUND NOERROR)
1798 (setq mdata (match-data))
1799 (and (verilog-skip-forward-comment-or-string)
1800 (progn
1801 (setq mdata '(nil nil))
1802 (if BOUND
1803 (< (point) BOUND)
1804 t)))))
1805 (store-match-data mdata)
1806 (match-end 0)))
1808 (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR)
1809 ;; checkdoc-params: (REGEXP BOUND NOERROR)
1810 "Like `re-search-backward', but skips over match in comments or strings."
1811 (let ((mdata '(nil nil))) ; So match-end will return nil if no matches found
1812 (while (and
1813 (re-search-backward REGEXP BOUND NOERROR)
1814 (setq mdata (match-data))
1815 (and (verilog-skip-backward-comment-or-string)
1816 (progn
1817 (setq mdata '(nil nil))
1818 (if BOUND
1819 (> (point) BOUND)
1820 t)))))
1821 (store-match-data mdata)
1822 (match-end 0)))
1824 (defsubst verilog-re-search-forward-quick (regexp bound noerror)
1825 "Like `verilog-re-search-forward', including use of REGEXP BOUND and NOERROR,
1826 but trashes match data and is faster for REGEXP that doesn't match often.
1827 This uses `verilog-scan' and text properties to ignore comments,
1828 so there may be a large up front penalty for the first search."
1829 (let (pt)
1830 (while (and (not pt)
1831 (re-search-forward regexp bound noerror))
1832 (if (verilog-inside-comment-or-string-p (match-beginning 0))
1833 (re-search-forward "[/\"\n]" nil t) ; Only way a comment or quote can end
1834 (setq pt (match-end 0))))
1835 pt))
1837 (defsubst verilog-re-search-backward-quick (regexp bound noerror)
1838 ;; checkdoc-params: (REGEXP BOUND NOERROR)
1839 "Like `verilog-re-search-backward', including use of REGEXP BOUND and NOERROR,
1840 but trashes match data and is faster for REGEXP that doesn't match often.
1841 This uses `verilog-scan' and text properties to ignore comments,
1842 so there may be a large up front penalty for the first search."
1843 (let (pt)
1844 (while (and (not pt)
1845 (re-search-backward regexp bound noerror))
1846 (if (verilog-inside-comment-or-string-p (match-beginning 0))
1847 (re-search-backward "[/\"]" nil t) ; Only way a comment or quote can begin
1848 (setq pt (match-beginning 0))))
1849 pt))
1851 (defsubst verilog-re-search-forward-substr (substr regexp bound noerror)
1852 "Like `re-search-forward', but first search for SUBSTR constant.
1853 Then searched for the normal REGEXP (which contains SUBSTR), with given
1854 BOUND and NOERROR. The REGEXP must fit within a single line.
1855 This speeds up complicated regexp matches."
1856 ;; Problem with overlap: search-forward BAR then FOOBARBAZ won't match.
1857 ;; thus require matches to be on one line, and use beginning-of-line.
1858 (let (done)
1859 (while (and (not done)
1860 (search-forward substr bound noerror))
1861 (save-excursion
1862 (beginning-of-line)
1863 (setq done (re-search-forward regexp (point-at-eol) noerror)))
1864 (unless (and (<= (match-beginning 0) (point))
1865 (>= (match-end 0) (point)))
1866 (setq done nil)))
1867 (when done (goto-char done))
1868 done))
1869 ;;(verilog-re-search-forward-substr "-end" "get-end-of" nil t) ; -end (test bait)
1871 (defsubst verilog-re-search-backward-substr (substr regexp bound noerror)
1872 "Like `re-search-backward', but first search for SUBSTR constant.
1873 Then searched for the normal REGEXP (which contains SUBSTR), with given
1874 BOUND and NOERROR. The REGEXP must fit within a single line.
1875 This speeds up complicated regexp matches."
1876 ;; Problem with overlap: search-backward BAR then FOOBARBAZ won't match.
1877 ;; thus require matches to be on one line, and use beginning-of-line.
1878 (let (done)
1879 (while (and (not done)
1880 (search-backward substr bound noerror))
1881 (save-excursion
1882 (end-of-line)
1883 (setq done (re-search-backward regexp (point-at-bol) noerror)))
1884 (unless (and (<= (match-beginning 0) (point))
1885 (>= (match-end 0) (point)))
1886 (setq done nil)))
1887 (when done (goto-char done))
1888 done))
1889 ;;(verilog-re-search-backward-substr "-end" "get-end-of" nil t) ; -end (test bait)
1891 (defun verilog-delete-trailing-whitespace ()
1892 "Delete trailing spaces or tabs, but not newlines nor linefeeds.
1893 Also add missing final newline.
1895 To call this from the command line, see \\[verilog-batch-diff-auto].
1897 To call on \\[verilog-auto], set `verilog-auto-delete-trailing-whitespace'."
1898 ;; Similar to `delete-trailing-whitespace' but that's not present in XEmacs
1899 (save-excursion
1900 (goto-char (point-min))
1901 (while (re-search-forward "[ \t]+$" nil t) ; Not syntactic WS as no formfeed
1902 (replace-match "" nil nil))
1903 (goto-char (point-max))
1904 (unless (bolp) (insert "\n"))))
1906 (defvar compile-command)
1907 (defvar create-lockfiles) ; Emacs 24
1909 ;; compilation program
1910 (defun verilog-set-compile-command ()
1911 "Function to compute shell command to compile Verilog.
1913 This reads `verilog-tool' and sets `compile-command'. This specifies the
1914 program that executes when you type \\[compile] or
1915 \\[verilog-auto-save-compile].
1917 By default `verilog-tool' uses a Makefile if one exists in the
1918 current directory. If not, it is set to the `verilog-linter',
1919 `verilog-compiler', `verilog-coverage', `verilog-preprocessor',
1920 or `verilog-simulator' variables, as selected with the Verilog ->
1921 \"Choose Compilation Action\" menu.
1923 You should set `verilog-tool' or the other variables to the path and
1924 arguments for your Verilog simulator. For example:
1925 \"vcs -p123 -O\"
1926 or a string like:
1927 \"(cd /tmp; surecov %s)\".
1929 In the former case, the path to the current buffer is concat'ed to the
1930 value of `verilog-tool'; in the later, the path to the current buffer is
1931 substituted for the %s.
1933 Where __FLAGS__ appears in the string `verilog-current-flags'
1934 will be substituted.
1936 Where __FILE__ appears in the string, the variable
1937 `buffer-file-name' of the current buffer, without the directory
1938 portion, will be substituted."
1939 (interactive)
1940 (cond
1941 ((or (file-exists-p "makefile") ;If there is a makefile, use it
1942 (file-exists-p "Makefile"))
1943 (set (make-local-variable 'compile-command) "make "))
1945 (set (make-local-variable 'compile-command)
1946 (if verilog-tool
1947 (if (string-match "%s" (eval verilog-tool))
1948 (format (eval verilog-tool) (or buffer-file-name ""))
1949 (concat (eval verilog-tool) " " (or buffer-file-name "")))
1950 ""))))
1951 (verilog-modify-compile-command))
1953 (defun verilog-expand-command (command)
1954 "Replace meta-information in COMMAND and return it.
1955 Where __FLAGS__ appears in the string `verilog-current-flags'
1956 will be substituted. Where __FILE__ appears in the string, the
1957 current buffer's file-name, without the directory portion, will
1958 be substituted."
1959 (setq command (verilog-string-replace-matches
1960 ;; Note \\b only works if under verilog syntax table
1961 "\\b__FLAGS__\\b" (verilog-current-flags)
1962 t t command))
1963 (setq command (verilog-string-replace-matches
1964 "\\b__FILE__\\b" (file-name-nondirectory
1965 (or (buffer-file-name) ""))
1966 t t command))
1967 command)
1969 ;; Eliminate compile warning
1970 (defvar verilog-compile-command-pre-mod)
1971 (defvar verilog-compile-command-post-mod)
1973 (defun verilog-modify-compile-command ()
1974 "Update `compile-command' using `verilog-expand-command'."
1975 ;; Entry into verilog-mode a call to this before Local Variables exist
1976 ;; Likewise user may have hook or something that changes the flags.
1977 ;; So, remember we're responsible for the expansion and on re-entry
1978 ;; recompute __FLAGS__ on each reentry.
1979 (when (stringp compile-command)
1980 (when (and
1981 (boundp 'verilog-compile-command-post-mod)
1982 (equal compile-command verilog-compile-command-post-mod))
1983 (setq compile-command verilog-compile-command-pre-mod))
1984 (when (and
1985 (string-match "\\b\\(__FLAGS__\\|__FILE__\\)\\b" compile-command))
1986 (set (make-local-variable 'verilog-compile-command-pre-mod)
1987 compile-command)
1988 (set (make-local-variable 'compile-command)
1989 (verilog-expand-command compile-command))
1990 (set (make-local-variable 'verilog-compile-command-post-mod)
1991 compile-command))))
1993 (if (featurep 'xemacs)
1994 ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling.
1995 (defun verilog-error-regexp-add-xemacs ()
1996 "Teach XEmacs about verilog errors.
1997 Called by `compilation-mode-hook'. This allows \\[next-error] to
1998 find the errors."
1999 (interactive)
2000 (if (boundp 'compilation-error-regexp-systems-alist)
2001 (if (and
2002 (not (equal compilation-error-regexp-systems-list 'all))
2003 (not (member compilation-error-regexp-systems-list 'verilog)))
2004 (push 'verilog compilation-error-regexp-systems-list)))
2005 (if (boundp 'compilation-error-regexp-alist-alist)
2006 (if (not (assoc 'verilog compilation-error-regexp-alist-alist))
2007 (setcdr compilation-error-regexp-alist-alist
2008 (cons verilog-error-regexp-xemacs-alist
2009 (cdr compilation-error-regexp-alist-alist)))))
2010 (if (boundp 'compilation-font-lock-keywords)
2011 (progn
2012 (set (make-local-variable 'compilation-font-lock-keywords)
2013 verilog-error-font-lock-keywords)
2014 (font-lock-set-defaults)))
2015 ;; Need to re-run compilation-error-regexp builder
2016 (if (fboundp 'compilation-build-compilation-error-regexp-alist)
2017 (compilation-build-compilation-error-regexp-alist))
2020 ;; Following code only gets called from compilation-mode-hook on Emacs to add error handling.
2021 (defun verilog-error-regexp-add-emacs ()
2022 "Tell Emacs compile that we are Verilog.
2023 Called by `compilation-mode-hook'. This allows \\[next-error] to
2024 find the errors."
2025 (interactive)
2026 (when (boundp 'compilation-error-regexp-alist-alist)
2027 (when (not (assoc 'verilog-xl-1 compilation-error-regexp-alist-alist))
2028 (mapcar
2029 (lambda (item)
2030 (push (car item) compilation-error-regexp-alist)
2031 (push item compilation-error-regexp-alist-alist))
2032 verilog-error-regexp-emacs-alist))))
2034 (if (featurep 'xemacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-xemacs))
2035 (if (featurep 'emacs) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-emacs))
2037 (defconst verilog-compiler-directives
2038 (eval-when-compile
2040 ;; compiler directives, from IEEE 1800-2012 section 22.1
2041 "`__FILE__" "`__LINE" "`begin_keywords" "`celldefine" "`default_nettype"
2042 "`define" "`else" "`elsif" "`end_keywords" "`endcelldefine" "`endif"
2043 "`ifdef" "`ifndef" "`include" "`line" "`nounconnected_drive" "`pragma"
2044 "`resetall" "`timescale" "`unconnected_drive" "`undef" "`undefineall"
2045 ;; compiler directives not covered by IEEE 1800
2046 "`case" "`default" "`endfor" "`endprotect" "`endswitch" "`endwhile" "`for"
2047 "`format" "`if" "`let" "`protect" "`switch" "`timescale" "`time_scale"
2048 "`while"
2050 "List of Verilog compiler directives.")
2052 (defconst verilog-directive-re
2053 (verilog-regexp-words verilog-compiler-directives))
2055 (defconst verilog-directive-re-1
2056 (concat "[ \t]*" verilog-directive-re))
2058 (defconst verilog-directive-begin
2059 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>")
2061 (defconst verilog-directive-middle
2062 "\\<`\\(else\\|elsif\\|default\\|case\\)\\>")
2064 (defconst verilog-directive-end
2065 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>")
2067 (defconst verilog-ovm-begin-re
2068 (eval-when-compile
2069 (verilog-regexp-opt
2071 "`ovm_component_utils_begin"
2072 "`ovm_component_param_utils_begin"
2073 "`ovm_field_utils_begin"
2074 "`ovm_object_utils_begin"
2075 "`ovm_object_param_utils_begin"
2076 "`ovm_sequence_utils_begin"
2077 "`ovm_sequencer_utils_begin"
2078 ) nil )))
2080 (defconst verilog-ovm-end-re
2081 (eval-when-compile
2082 (verilog-regexp-opt
2084 "`ovm_component_utils_end"
2085 "`ovm_field_utils_end"
2086 "`ovm_object_utils_end"
2087 "`ovm_sequence_utils_end"
2088 "`ovm_sequencer_utils_end"
2089 ) nil )))
2091 (defconst verilog-uvm-begin-re
2092 (eval-when-compile
2093 (verilog-regexp-opt
2095 "`uvm_component_utils_begin"
2096 "`uvm_component_param_utils_begin"
2097 "`uvm_field_utils_begin"
2098 "`uvm_object_utils_begin"
2099 "`uvm_object_param_utils_begin"
2100 "`uvm_sequence_utils_begin"
2101 "`uvm_sequencer_utils_begin"
2102 ) nil )))
2104 (defconst verilog-uvm-end-re
2105 (eval-when-compile
2106 (verilog-regexp-opt
2108 "`uvm_component_utils_end"
2109 "`uvm_field_utils_end"
2110 "`uvm_object_utils_end"
2111 "`uvm_sequence_utils_end"
2112 "`uvm_sequencer_utils_end"
2113 ) nil )))
2115 (defconst verilog-vmm-begin-re
2116 (eval-when-compile
2117 (verilog-regexp-opt
2119 "`vmm_data_member_begin"
2120 "`vmm_env_member_begin"
2121 "`vmm_scenario_member_begin"
2122 "`vmm_subenv_member_begin"
2123 "`vmm_xactor_member_begin"
2124 ) nil ) ) )
2126 (defconst verilog-vmm-end-re
2127 (eval-when-compile
2128 (verilog-regexp-opt
2130 "`vmm_data_member_end"
2131 "`vmm_env_member_end"
2132 "`vmm_scenario_member_end"
2133 "`vmm_subenv_member_end"
2134 "`vmm_xactor_member_end"
2135 ) nil ) ) )
2137 (defconst verilog-vmm-statement-re
2138 (eval-when-compile
2139 (verilog-regexp-opt
2141 "`vmm_\\(data\\|env\\|scenario\\|subenv\\|xactor\\)_member_\\(scalar\\|string\\|enum\\|vmm_data\\|channel\\|xactor\\|subenv\\|user_defined\\)\\(_array\\)?"
2142 ;; "`vmm_xactor_member_enum_array"
2143 ;; "`vmm_xactor_member_scalar_array"
2144 ;; "`vmm_xactor_member_scalar"
2145 ) nil )))
2147 (defconst verilog-ovm-statement-re
2148 (eval-when-compile
2149 (verilog-regexp-opt
2151 ;; Statements
2152 "`DUT_ERROR"
2153 "`MESSAGE"
2154 "`dut_error"
2155 "`message"
2156 "`ovm_analysis_imp_decl"
2157 "`ovm_blocking_get_imp_decl"
2158 "`ovm_blocking_get_peek_imp_decl"
2159 "`ovm_blocking_master_imp_decl"
2160 "`ovm_blocking_peek_imp_decl"
2161 "`ovm_blocking_put_imp_decl"
2162 "`ovm_blocking_slave_imp_decl"
2163 "`ovm_blocking_transport_imp_decl"
2164 "`ovm_component_registry"
2165 "`ovm_component_registry_param"
2166 "`ovm_component_utils"
2167 "`ovm_create"
2168 "`ovm_create_seq"
2169 "`ovm_declare_sequence_lib"
2170 "`ovm_do"
2171 "`ovm_do_seq"
2172 "`ovm_do_seq_with"
2173 "`ovm_do_with"
2174 "`ovm_error"
2175 "`ovm_fatal"
2176 "`ovm_field_aa_int_byte"
2177 "`ovm_field_aa_int_byte_unsigned"
2178 "`ovm_field_aa_int_int"
2179 "`ovm_field_aa_int_int_unsigned"
2180 "`ovm_field_aa_int_integer"
2181 "`ovm_field_aa_int_integer_unsigned"
2182 "`ovm_field_aa_int_key"
2183 "`ovm_field_aa_int_longint"
2184 "`ovm_field_aa_int_longint_unsigned"
2185 "`ovm_field_aa_int_shortint"
2186 "`ovm_field_aa_int_shortint_unsigned"
2187 "`ovm_field_aa_int_string"
2188 "`ovm_field_aa_object_int"
2189 "`ovm_field_aa_object_string"
2190 "`ovm_field_aa_string_int"
2191 "`ovm_field_aa_string_string"
2192 "`ovm_field_array_int"
2193 "`ovm_field_array_object"
2194 "`ovm_field_array_string"
2195 "`ovm_field_enum"
2196 "`ovm_field_event"
2197 "`ovm_field_int"
2198 "`ovm_field_object"
2199 "`ovm_field_queue_int"
2200 "`ovm_field_queue_object"
2201 "`ovm_field_queue_string"
2202 "`ovm_field_sarray_int"
2203 "`ovm_field_string"
2204 "`ovm_field_utils"
2205 "`ovm_file"
2206 "`ovm_get_imp_decl"
2207 "`ovm_get_peek_imp_decl"
2208 "`ovm_info"
2209 "`ovm_info1"
2210 "`ovm_info2"
2211 "`ovm_info3"
2212 "`ovm_info4"
2213 "`ovm_line"
2214 "`ovm_master_imp_decl"
2215 "`ovm_msg_detail"
2216 "`ovm_non_blocking_transport_imp_decl"
2217 "`ovm_nonblocking_get_imp_decl"
2218 "`ovm_nonblocking_get_peek_imp_decl"
2219 "`ovm_nonblocking_master_imp_decl"
2220 "`ovm_nonblocking_peek_imp_decl"
2221 "`ovm_nonblocking_put_imp_decl"
2222 "`ovm_nonblocking_slave_imp_decl"
2223 "`ovm_object_registry"
2224 "`ovm_object_registry_param"
2225 "`ovm_object_utils"
2226 "`ovm_peek_imp_decl"
2227 "`ovm_phase_func_decl"
2228 "`ovm_phase_task_decl"
2229 "`ovm_print_aa_int_object"
2230 "`ovm_print_aa_string_int"
2231 "`ovm_print_aa_string_object"
2232 "`ovm_print_aa_string_string"
2233 "`ovm_print_array_int"
2234 "`ovm_print_array_object"
2235 "`ovm_print_array_string"
2236 "`ovm_print_object_queue"
2237 "`ovm_print_queue_int"
2238 "`ovm_print_string_queue"
2239 "`ovm_put_imp_decl"
2240 "`ovm_rand_send"
2241 "`ovm_rand_send_with"
2242 "`ovm_send"
2243 "`ovm_sequence_utils"
2244 "`ovm_slave_imp_decl"
2245 "`ovm_transport_imp_decl"
2246 "`ovm_update_sequence_lib"
2247 "`ovm_update_sequence_lib_and_item"
2248 "`ovm_warning"
2249 "`static_dut_error"
2250 "`static_message") nil )))
2252 (defconst verilog-uvm-statement-re
2253 (eval-when-compile
2254 (verilog-regexp-opt
2256 ;; Statements
2257 "`uvm_analysis_imp_decl"
2258 "`uvm_blocking_get_imp_decl"
2259 "`uvm_blocking_get_peek_imp_decl"
2260 "`uvm_blocking_master_imp_decl"
2261 "`uvm_blocking_peek_imp_decl"
2262 "`uvm_blocking_put_imp_decl"
2263 "`uvm_blocking_slave_imp_decl"
2264 "`uvm_blocking_transport_imp_decl"
2265 "`uvm_component_param_utils"
2266 "`uvm_component_registry"
2267 "`uvm_component_registry_param"
2268 "`uvm_component_utils"
2269 "`uvm_create"
2270 "`uvm_create_on"
2271 "`uvm_create_seq" ; Undocumented in 1.1
2272 "`uvm_declare_p_sequencer"
2273 "`uvm_declare_sequence_lib" ; Deprecated in 1.1
2274 "`uvm_do"
2275 "`uvm_do_callbacks"
2276 "`uvm_do_callbacks_exit_on"
2277 "`uvm_do_obj_callbacks"
2278 "`uvm_do_obj_callbacks_exit_on"
2279 "`uvm_do_on"
2280 "`uvm_do_on_pri"
2281 "`uvm_do_on_pri_with"
2282 "`uvm_do_on_with"
2283 "`uvm_do_pri"
2284 "`uvm_do_pri_with"
2285 "`uvm_do_seq" ; Undocumented in 1.1
2286 "`uvm_do_seq_with" ; Undocumented in 1.1
2287 "`uvm_do_with"
2288 "`uvm_error"
2289 "`uvm_error_context"
2290 "`uvm_fatal"
2291 "`uvm_fatal_context"
2292 "`uvm_field_aa_int_byte"
2293 "`uvm_field_aa_int_byte_unsigned"
2294 "`uvm_field_aa_int_enum"
2295 "`uvm_field_aa_int_int"
2296 "`uvm_field_aa_int_int_unsigned"
2297 "`uvm_field_aa_int_integer"
2298 "`uvm_field_aa_int_integer_unsigned"
2299 "`uvm_field_aa_int_key"
2300 "`uvm_field_aa_int_longint"
2301 "`uvm_field_aa_int_longint_unsigned"
2302 "`uvm_field_aa_int_shortint"
2303 "`uvm_field_aa_int_shortint_unsigned"
2304 "`uvm_field_aa_int_string"
2305 "`uvm_field_aa_object_int"
2306 "`uvm_field_aa_object_string"
2307 "`uvm_field_aa_string_int"
2308 "`uvm_field_aa_string_string"
2309 "`uvm_field_array_enum"
2310 "`uvm_field_array_int"
2311 "`uvm_field_array_object"
2312 "`uvm_field_array_string"
2313 "`uvm_field_enum"
2314 "`uvm_field_event"
2315 "`uvm_field_int"
2316 "`uvm_field_object"
2317 "`uvm_field_queue_enum"
2318 "`uvm_field_queue_int"
2319 "`uvm_field_queue_object"
2320 "`uvm_field_queue_string"
2321 "`uvm_field_real"
2322 "`uvm_field_sarray_enum"
2323 "`uvm_field_sarray_int"
2324 "`uvm_field_sarray_object"
2325 "`uvm_field_sarray_string"
2326 "`uvm_field_string"
2327 "`uvm_field_utils"
2328 "`uvm_file" ; Undocumented in 1.1, use `__FILE__
2329 "`uvm_get_imp_decl"
2330 "`uvm_get_peek_imp_decl"
2331 "`uvm_info"
2332 "`uvm_info_context"
2333 "`uvm_line" ; Undocumented in 1.1, use `__LINE__
2334 "`uvm_master_imp_decl"
2335 "`uvm_non_blocking_transport_imp_decl" ; Deprecated in 1.1
2336 "`uvm_nonblocking_get_imp_decl"
2337 "`uvm_nonblocking_get_peek_imp_decl"
2338 "`uvm_nonblocking_master_imp_decl"
2339 "`uvm_nonblocking_peek_imp_decl"
2340 "`uvm_nonblocking_put_imp_decl"
2341 "`uvm_nonblocking_slave_imp_decl"
2342 "`uvm_nonblocking_transport_imp_decl"
2343 "`uvm_object_param_utils"
2344 "`uvm_object_registry"
2345 "`uvm_object_registry_param" ; Undocumented in 1.1
2346 "`uvm_object_utils"
2347 "`uvm_pack_array"
2348 "`uvm_pack_arrayN"
2349 "`uvm_pack_enum"
2350 "`uvm_pack_enumN"
2351 "`uvm_pack_int"
2352 "`uvm_pack_intN"
2353 "`uvm_pack_queue"
2354 "`uvm_pack_queueN"
2355 "`uvm_pack_real"
2356 "`uvm_pack_sarray"
2357 "`uvm_pack_sarrayN"
2358 "`uvm_pack_string"
2359 "`uvm_peek_imp_decl"
2360 "`uvm_put_imp_decl"
2361 "`uvm_rand_send"
2362 "`uvm_rand_send_pri"
2363 "`uvm_rand_send_pri_with"
2364 "`uvm_rand_send_with"
2365 "`uvm_record_attribute"
2366 "`uvm_record_field"
2367 "`uvm_register_cb"
2368 "`uvm_send"
2369 "`uvm_send_pri"
2370 "`uvm_sequence_utils" ; Deprecated in 1.1
2371 "`uvm_set_super_type"
2372 "`uvm_slave_imp_decl"
2373 "`uvm_transport_imp_decl"
2374 "`uvm_unpack_array"
2375 "`uvm_unpack_arrayN"
2376 "`uvm_unpack_enum"
2377 "`uvm_unpack_enumN"
2378 "`uvm_unpack_int"
2379 "`uvm_unpack_intN"
2380 "`uvm_unpack_queue"
2381 "`uvm_unpack_queueN"
2382 "`uvm_unpack_real"
2383 "`uvm_unpack_sarray"
2384 "`uvm_unpack_sarrayN"
2385 "`uvm_unpack_string"
2386 "`uvm_update_sequence_lib" ; Deprecated in 1.1
2387 "`uvm_update_sequence_lib_and_item" ; Deprecated in 1.1
2388 "`uvm_warning"
2389 "`uvm_warning_context") nil )))
2393 ;; Regular expressions used to calculate indent, etc.
2395 (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
2396 ;; Want to match
2397 ;; aa :
2398 ;; aa,bb :
2399 ;; a[34:32] :
2400 ;; a,
2401 ;; b :
2402 (defconst verilog-assignment-operator-re
2403 (eval-when-compile
2404 (verilog-regexp-opt
2406 ;; blocking assignment_operator
2407 "=" "+=" "-=" "*=" "/=" "%=" "&=" "|=" "^=" "<<=" ">>=" "<<<=" ">>>="
2408 ;; non blocking assignment operator
2409 "<="
2410 ;; comparison
2411 "==" "!=" "===" "!==" "<=" ">=" "==?" "!=?" "<->"
2412 ;; event_trigger
2413 "->" "->>"
2414 ;; property_expr
2415 "|->" "|=>" "#-#" "#=#"
2416 ;; distribution weighting
2417 ":=" ":/"
2418 ) 't
2420 (defconst verilog-assignment-operation-re
2421 (concat
2422 ;; "\\(^\\s-*[A-Za-z0-9_]+\\(\\[\\([A-Za-z0-9_]+\\)\\]\\)*\\s-*\\)"
2423 ;; "\\(^\\s-*[^=<>+-*/%&|^:\\s-]+[^=<>+-*/%&|^\n]*?\\)"
2424 "\\(^.*?\\)" "\\B" verilog-assignment-operator-re "\\B" ))
2426 (defconst verilog-label-re (concat verilog-symbol-re "\\s-*:\\s-*"))
2427 (defconst verilog-property-re
2428 (concat "\\(" verilog-label-re "\\)?"
2429 ;; "\\(assert\\|assume\\|cover\\)\\s-+property\\>"
2430 "\\(\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(assert\\)"))
2432 (defconst verilog-no-indent-begin-re
2433 (eval-when-compile
2434 (verilog-regexp-words
2435 '("always" "always_comb" "always_ff" "always_latch" "initial" "final" ; procedural blocks
2436 "if" "else" ; conditional statements
2437 "while" "for" "foreach" "repeat" "do" "forever" )))) ; loop statements
2439 (defconst verilog-ends-re
2440 ;; Parenthesis indicate type of keyword found
2441 (concat
2442 "\\(\\<else\\>\\)\\|" ; 1
2443 "\\(\\<if\\>\\)\\|" ; 2
2444 "\\(\\<assert\\>\\)\\|" ; 3
2445 "\\(\\<end\\>\\)\\|" ; 3.1
2446 "\\(\\<endcase\\>\\)\\|" ; 4
2447 "\\(\\<endfunction\\>\\)\\|" ; 5
2448 "\\(\\<endtask\\>\\)\\|" ; 6
2449 "\\(\\<endspecify\\>\\)\\|" ; 7
2450 "\\(\\<endtable\\>\\)\\|" ; 8
2451 "\\(\\<endgenerate\\>\\)\\|" ; 9
2452 "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10
2453 "\\(\\<endclass\\>\\)\\|" ; 11
2454 "\\(\\<endgroup\\>\\)\\|" ; 12
2455 ;; VMM
2456 "\\(\\<`vmm_data_member_end\\>\\)\\|"
2457 "\\(\\<`vmm_env_member_end\\>\\)\\|"
2458 "\\(\\<`vmm_scenario_member_end\\>\\)\\|"
2459 "\\(\\<`vmm_subenv_member_end\\>\\)\\|"
2460 "\\(\\<`vmm_xactor_member_end\\>\\)\\|"
2461 ;; OVM
2462 "\\(\\<`ovm_component_utils_end\\>\\)\\|"
2463 "\\(\\<`ovm_field_utils_end\\>\\)\\|"
2464 "\\(\\<`ovm_object_utils_end\\>\\)\\|"
2465 "\\(\\<`ovm_sequence_utils_end\\>\\)\\|"
2466 "\\(\\<`ovm_sequencer_utils_end\\>\\)"
2467 ;; UVM
2468 "\\(\\<`uvm_component_utils_end\\>\\)\\|"
2469 "\\(\\<`uvm_field_utils_end\\>\\)\\|"
2470 "\\(\\<`uvm_object_utils_end\\>\\)\\|"
2471 "\\(\\<`uvm_sequence_utils_end\\>\\)\\|"
2472 "\\(\\<`uvm_sequencer_utils_end\\>\\)"
2475 (defconst verilog-auto-end-comment-lines-re
2476 ;; Matches to names in this list cause auto-end-commenting
2477 (concat "\\("
2478 verilog-directive-re "\\)\\|\\("
2479 (eval-when-compile
2480 (verilog-regexp-words
2481 `( "begin"
2482 "else"
2483 "end"
2484 "endcase"
2485 "endclass"
2486 "endclocking"
2487 "endgroup"
2488 "endfunction"
2489 "endmodule"
2490 "endprogram"
2491 "endprimitive"
2492 "endinterface"
2493 "endpackage"
2494 "endsequence"
2495 "endproperty"
2496 "endspecify"
2497 "endtable"
2498 "endtask"
2499 "join"
2500 "join_any"
2501 "join_none"
2502 "module"
2503 "macromodule"
2504 "primitive"
2505 "interface"
2506 "package")))
2507 "\\)"))
2509 ;; NOTE: verilog-leap-to-head expects that verilog-end-block-re and
2510 ;; verilog-end-block-ordered-re matches exactly the same strings.
2511 (defconst verilog-end-block-ordered-re
2512 ;; Parenthesis indicate type of keyword found
2513 (concat "\\(\\<endcase\\>\\)\\|" ; 1
2514 "\\(\\<end\\>\\)\\|" ; 2
2515 "\\(\\<end" ; 3, but not used
2516 "\\(" ; 4, but not used
2517 "\\(function\\)\\|" ; 5
2518 "\\(task\\)\\|" ; 6
2519 "\\(module\\)\\|" ; 7
2520 "\\(primitive\\)\\|" ; 8
2521 "\\(interface\\)\\|" ; 9
2522 "\\(package\\)\\|" ; 10
2523 "\\(class\\)\\|" ; 11
2524 "\\(group\\)\\|" ; 12
2525 "\\(program\\)\\|" ; 13
2526 "\\(sequence\\)\\|" ; 14
2527 "\\(clocking\\)\\|" ; 15
2528 "\\(property\\)\\|" ; 16
2529 "\\)\\>\\)"))
2530 (defconst verilog-end-block-re
2531 (eval-when-compile
2532 (verilog-regexp-words
2534 `("end" ; closes begin
2535 "endcase" ; closes any of case, casex casez or randcase
2536 "join" "join_any" "join_none" ; closes fork
2537 "endclass"
2538 "endtable"
2539 "endspecify"
2540 "endfunction"
2541 "endgenerate"
2542 "endtask"
2543 "endgroup"
2544 "endproperty"
2545 "endinterface"
2546 "endpackage"
2547 "endprogram"
2548 "endsequence"
2549 "endclocking"
2550 ;; OVM
2551 "`ovm_component_utils_end"
2552 "`ovm_field_utils_end"
2553 "`ovm_object_utils_end"
2554 "`ovm_sequence_utils_end"
2555 "`ovm_sequencer_utils_end"
2556 ;; UVM
2557 "`uvm_component_utils_end"
2558 "`uvm_field_utils_end"
2559 "`uvm_object_utils_end"
2560 "`uvm_sequence_utils_end"
2561 "`uvm_sequencer_utils_end"
2562 ;; VMM
2563 "`vmm_data_member_end"
2564 "`vmm_env_member_end"
2565 "`vmm_scenario_member_end"
2566 "`vmm_subenv_member_end"
2567 "`vmm_xactor_member_end"
2568 ))))
2571 (defconst verilog-endcomment-reason-re
2572 ;; Parenthesis indicate type of keyword found
2573 (concat
2574 "\\(\\<begin\\>\\)\\|" ; 1
2575 "\\(\\<else\\>\\)\\|" ; 2
2576 "\\(\\<end\\>\\s-+\\<else\\>\\)\\|" ; 3
2577 "\\(\\<always\\(?:_ff\\)?\\>\\(?:[ \t]*@\\)\\)\\|" ; 4 (matches always or always_ff w/ @...)
2578 "\\(\\<always\\(?:_comb\\|_latch\\)?\\>\\)\\|" ; 5 (matches always, always_comb, always_latch w/o @...)
2579 "\\(\\<fork\\>\\)\\|" ; 7
2580 "\\(\\<if\\>\\)\\|"
2581 verilog-property-re "\\|"
2582 "\\(\\(" verilog-label-re "\\)?\\<assert\\>\\)\\|"
2583 "\\(\\<clocking\\>\\)\\|"
2584 "\\(\\<task\\>\\)\\|"
2585 "\\(\\<function\\>\\)\\|"
2586 "\\(\\<initial\\>\\)\\|"
2587 "\\(\\<interface\\>\\)\\|"
2588 "\\(\\<package\\>\\)\\|"
2589 "\\(\\<final\\>\\)\\|"
2590 "\\(@\\)\\|"
2591 "\\(\\<while\\>\\)\\|\\(\\<do\\>\\)\\|"
2592 "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|"
2593 "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|"
2594 "#"))
2596 (defconst verilog-named-block-re "begin[ \t]*:")
2598 ;; These words begin a block which can occur inside a module which should be indented,
2599 ;; and closed with the respective word from the end-block list
2601 (defconst verilog-beg-block-re
2602 (eval-when-compile
2603 (verilog-regexp-words
2604 `("begin"
2605 "case" "casex" "casez" "randcase"
2606 "clocking"
2607 "generate"
2608 "fork"
2609 "function"
2610 "property"
2611 "specify"
2612 "table"
2613 "task"
2614 ;; OVM
2615 "`ovm_component_utils_begin"
2616 "`ovm_component_param_utils_begin"
2617 "`ovm_field_utils_begin"
2618 "`ovm_object_utils_begin"
2619 "`ovm_object_param_utils_begin"
2620 "`ovm_sequence_utils_begin"
2621 "`ovm_sequencer_utils_begin"
2622 ;; UVM
2623 "`uvm_component_utils_begin"
2624 "`uvm_component_param_utils_begin"
2625 "`uvm_field_utils_begin"
2626 "`uvm_object_utils_begin"
2627 "`uvm_object_param_utils_begin"
2628 "`uvm_sequence_utils_begin"
2629 "`uvm_sequencer_utils_begin"
2630 ;; VMM
2631 "`vmm_data_member_begin"
2632 "`vmm_env_member_begin"
2633 "`vmm_scenario_member_begin"
2634 "`vmm_subenv_member_begin"
2635 "`vmm_xactor_member_begin"
2636 ))))
2637 ;; These are the same words, in a specific order in the regular
2638 ;; expression so that matching will work nicely for
2639 ;; verilog-forward-sexp and verilog-calc-indent
2640 (defconst verilog-beg-block-re-ordered
2641 ( concat "\\(\\<begin\\>\\)" ;1
2642 "\\|\\(\\<randcase\\>\\|\\(\\<unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\>\\)" ; 2,3
2643 "\\|\\(\\(\\<disable\\>\\s-+\\|\\<wait\\>\\s-+\\)?fork\\>\\)" ;4,5
2644 "\\|\\(\\<class\\>\\)" ;6
2645 "\\|\\(\\<table\\>\\)" ;7
2646 "\\|\\(\\<specify\\>\\)" ;8
2647 "\\|\\(\\<function\\>\\)" ;9
2648 "\\|\\(\\(?:\\<\\(?:virtual\\|protected\\|static\\)\\>\\s-+\\)*\\<function\\>\\)" ;10
2649 "\\|\\(\\<task\\>\\)" ;11
2650 "\\|\\(\\(?:\\<\\(?:virtual\\|protected\\|static\\)\\>\\s-+\\)*\\<task\\>\\)" ;12
2651 "\\|\\(\\<generate\\>\\)" ;13
2652 "\\|\\(\\<covergroup\\>\\)" ;14
2653 "\\|\\(\\(?:\\(?:\\<cover\\>\\s-+\\)\\|\\(?:\\<assert\\>\\s-+\\)\\)*\\<property\\>\\)" ;15
2654 "\\|\\(\\<\\(?:rand\\)?sequence\\>\\)" ;16
2655 "\\|\\(\\<clocking\\>\\)" ;17
2656 "\\|\\(\\<`[ou]vm_[a-z_]+_begin\\>\\)" ;18
2657 "\\|\\(\\<`vmm_[a-z_]+_member_begin\\>\\)"
2661 (defconst verilog-end-block-ordered-rry
2662 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2663 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)"
2664 "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
2665 "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)"
2666 "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)"
2667 "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)"
2668 "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)"
2669 "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)"
2670 "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)"
2671 "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)"
2672 "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)"
2673 "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)"
2674 "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)"
2677 (defconst verilog-nameable-item-re
2678 (eval-when-compile
2679 (verilog-regexp-words
2680 `("begin"
2681 "fork"
2682 "join" "join_any" "join_none"
2683 "end"
2684 "endcase"
2685 "endchecker"
2686 "endclass"
2687 "endclocking"
2688 "endconfig"
2689 "endfunction"
2690 "endgenerate"
2691 "endgroup"
2692 "endmodule"
2693 "endprimitive"
2694 "endinterface"
2695 "endpackage"
2696 "endprogram"
2697 "endproperty"
2698 "endsequence"
2699 "endspecify"
2700 "endtable"
2701 "endtask" )
2704 (defconst verilog-declaration-opener
2705 (eval-when-compile
2706 (verilog-regexp-words
2707 `("module" "begin" "task" "function"))))
2709 (defconst verilog-declaration-prefix-re
2710 (eval-when-compile
2711 (verilog-regexp-words
2713 ;; port direction
2714 "inout" "input" "output" "ref"
2715 ;; changeableness
2716 "const" "static" "protected" "local"
2717 ;; parameters
2718 "localparam" "parameter" "var"
2719 ;; type creation
2720 "typedef"
2721 ))))
2722 (defconst verilog-declaration-core-re
2723 (eval-when-compile
2724 (verilog-regexp-words
2726 ;; port direction (by themselves)
2727 "inout" "input" "output"
2728 ;; integer_atom_type
2729 "byte" "shortint" "int" "longint" "integer" "time"
2730 ;; integer_vector_type
2731 "bit" "logic" "reg"
2732 ;; non_integer_type
2733 "shortreal" "real" "realtime"
2734 ;; net_type
2735 "supply0" "supply1" "tri" "triand" "trior" "trireg" "tri0" "tri1" "uwire" "wire" "wand" "wor"
2736 ;; misc
2737 "string" "event" "chandle" "virtual" "enum" "genvar"
2738 "struct" "union"
2739 ;; builtin classes
2740 "mailbox" "semaphore"
2741 ))))
2742 (defconst verilog-declaration-re
2743 (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re))
2744 (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+")
2745 (defconst verilog-optional-signed-re "\\s-*\\(\\(un\\)?signed\\)?")
2746 (defconst verilog-optional-signed-range-re
2747 (concat
2748 "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<\\(un\\)?signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?"))
2749 (defconst verilog-macroexp-re "`\\sw+")
2751 (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)")
2752 (defconst verilog-declaration-re-2-no-macro
2753 (concat "\\s-*" verilog-declaration-re
2754 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2755 "\\)?"))
2756 (defconst verilog-declaration-re-2-macro
2757 (concat "\\s-*" verilog-declaration-re
2758 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
2759 "\\|\\(" verilog-macroexp-re "\\)"
2760 "\\)?"))
2761 (defconst verilog-declaration-re-1-macro
2762 (concat "^" verilog-declaration-re-2-macro))
2764 (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro))
2766 (defconst verilog-defun-re
2767 (eval-when-compile (verilog-regexp-words `("macromodule" "module" "class" "program" "interface" "package" "primitive" "config"))))
2768 (defconst verilog-end-defun-re
2769 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig"))))
2770 (defconst verilog-zero-indent-re
2771 (concat verilog-defun-re "\\|" verilog-end-defun-re))
2772 (defconst verilog-inst-comment-re
2773 (eval-when-compile (verilog-regexp-words `("Outputs" "Inouts" "Inputs" "Interfaces" "Interfaced"))))
2775 (defconst verilog-behavioral-block-beg-re
2776 (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff"
2777 "function" "task"))))
2778 (defconst verilog-coverpoint-re "\\w+\\s*:\\s*\\(coverpoint\\|cross\\constraint\\)" )
2779 (defconst verilog-in-constraint-re ; keywords legal in constraint blocks starting a statement/block
2780 (eval-when-compile (verilog-regexp-words `("if" "else" "solve" "foreach"))))
2782 (defconst verilog-indent-re
2783 (eval-when-compile
2784 (verilog-regexp-words
2787 "always" "always_latch" "always_ff" "always_comb"
2788 "begin" "end"
2789 ;; "unique" "priority"
2790 "case" "casex" "casez" "randcase" "endcase"
2791 "class" "endclass"
2792 "clocking" "endclocking"
2793 "config" "endconfig"
2794 "covergroup" "endgroup"
2795 "fork" "join" "join_any" "join_none"
2796 "function" "endfunction"
2797 "final"
2798 "generate" "endgenerate"
2799 "initial"
2800 "interface" "endinterface"
2801 "module" "macromodule" "endmodule"
2802 "package" "endpackage"
2803 "primitive" "endprimitive"
2804 "program" "endprogram"
2805 "property" "endproperty"
2806 "sequence" "randsequence" "endsequence"
2807 "specify" "endspecify"
2808 "table" "endtable"
2809 "task" "endtask"
2810 "virtual"
2811 "`case"
2812 "`default"
2813 "`define" "`undef"
2814 "`if" "`ifdef" "`ifndef" "`else" "`elsif" "`endif"
2815 "`while" "`endwhile"
2816 "`for" "`endfor"
2817 "`format"
2818 "`include"
2819 "`let"
2820 "`protect" "`endprotect"
2821 "`switch" "`endswitch"
2822 "`timescale"
2823 "`time_scale"
2824 ;; OVM Begin tokens
2825 "`ovm_component_utils_begin"
2826 "`ovm_component_param_utils_begin"
2827 "`ovm_field_utils_begin"
2828 "`ovm_object_utils_begin"
2829 "`ovm_object_param_utils_begin"
2830 "`ovm_sequence_utils_begin"
2831 "`ovm_sequencer_utils_begin"
2832 ;; OVM End tokens
2833 "`ovm_component_utils_end"
2834 "`ovm_field_utils_end"
2835 "`ovm_object_utils_end"
2836 "`ovm_sequence_utils_end"
2837 "`ovm_sequencer_utils_end"
2838 ;; UVM Begin tokens
2839 "`uvm_component_utils_begin"
2840 "`uvm_component_param_utils_begin"
2841 "`uvm_field_utils_begin"
2842 "`uvm_object_utils_begin"
2843 "`uvm_object_param_utils_begin"
2844 "`uvm_sequence_utils_begin"
2845 "`uvm_sequencer_utils_begin"
2846 ;; UVM End tokens
2847 "`uvm_component_utils_end" ; Typo in spec, it's not uvm_component_end
2848 "`uvm_field_utils_end"
2849 "`uvm_object_utils_end"
2850 "`uvm_sequence_utils_end"
2851 "`uvm_sequencer_utils_end"
2852 ;; VMM Begin tokens
2853 "`vmm_data_member_begin"
2854 "`vmm_env_member_begin"
2855 "`vmm_scenario_member_begin"
2856 "`vmm_subenv_member_begin"
2857 "`vmm_xactor_member_begin"
2858 ;; VMM End tokens
2859 "`vmm_data_member_end"
2860 "`vmm_env_member_end"
2861 "`vmm_scenario_member_end"
2862 "`vmm_subenv_member_end"
2863 "`vmm_xactor_member_end"
2864 ))))
2866 (defconst verilog-defun-level-not-generate-re
2867 (eval-when-compile
2868 (verilog-regexp-words
2869 `( "module" "macromodule" "primitive" "class" "program"
2870 "interface" "package" "config"))))
2872 (defconst verilog-defun-level-re
2873 (eval-when-compile
2874 (verilog-regexp-words
2875 (append
2876 `( "module" "macromodule" "primitive" "class" "program"
2877 "interface" "package" "config")
2878 `( "initial" "final" "always" "always_comb" "always_ff"
2879 "always_latch" "endtask" "endfunction" )))))
2881 (defconst verilog-defun-level-generate-only-re
2882 (eval-when-compile
2883 (verilog-regexp-words
2884 `( "initial" "final" "always" "always_comb" "always_ff"
2885 "always_latch" "endtask" "endfunction" ))))
2887 (defconst verilog-cpp-level-re
2888 (eval-when-compile
2889 (verilog-regexp-words
2891 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
2892 ))))
2894 (defconst verilog-dpi-import-export-re
2895 (eval-when-compile
2896 "\\(\\<\\(import\\|export\\)\\>\\s-+\"DPI\\(-C\\)?\"\\s-+\\(\\<\\(context\\|pure\\)\\>\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_]*\\s-*=\\s-*\\)?\\<\\(function\\|task\\)\\>\\)"
2899 (defconst verilog-default-clocking-re "\\<default\\s-+clocking\\>")
2900 (defconst verilog-disable-fork-re "\\(disable\\|wait\\)\\s-+fork\\>")
2901 (defconst verilog-extended-case-re "\\(\\(unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\|randcase\\)")
2902 (defconst verilog-extended-complete-re
2903 ;; verilog-beg-of-statement also looks backward one token to extend this match
2904 (concat "\\(\\(\\<extern\\s-+\\|\\<\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?virtual\\s-+\\|\\<protected\\s-+\\|\\<static\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)\\)"
2905 "\\|\\(\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)\\)"
2906 "\\|\\(\\(\\<\\(import\\|export\\)\\>\\s-+\\)?\\(\"DPI\\(-C\\)?\"\\s-+\\)?\\(\\<\\(pure\\|context\\)\\>\\s-+\\)?\\([A-Za-z_][A-Za-z0-9_]*\\s-*=\\s-*\\)?\\(function\\>\\|task\\>\\)\\)"
2907 "\\|" verilog-extended-case-re ))
2908 (defconst verilog-basic-complete-re
2909 (eval-when-compile
2910 (verilog-regexp-words
2912 "always" "assign" "always_latch" "always_ff" "always_comb" "constraint"
2913 "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while"
2914 "if" "for" "forever" "foreach" "else" "parameter" "do" "localparam" "assert"
2915 ))))
2916 (defconst verilog-complete-reg
2917 (concat
2918 verilog-extended-complete-re "\\|\\(" verilog-basic-complete-re "\\)"))
2920 (defconst verilog-end-statement-re
2921 (concat "\\(" verilog-beg-block-re "\\)\\|\\("
2922 verilog-end-block-re "\\)"))
2924 (defconst verilog-endcase-re
2925 (concat verilog-extended-case-re "\\|"
2926 "\\(endcase\\)\\|"
2927 verilog-defun-re
2930 (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----"
2931 "String used to mark beginning of excluded text.")
2932 (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */"
2933 "String used to mark end of excluded text.")
2934 (defconst verilog-preprocessor-re
2935 (eval-when-compile
2936 (concat
2937 ;; single words
2938 "\\(?:"
2939 (verilog-regexp-words
2940 `("`__FILE__"
2941 "`__LINE__"
2942 "`celldefine"
2943 "`else"
2944 "`end_keywords"
2945 "`endcelldefine"
2946 "`endif"
2947 "`nounconnected_drive"
2948 "`resetall"
2949 "`unconnected_drive"
2950 "`undefineall"))
2951 "\\)\\|\\(?:"
2952 ;; two words: i.e. `ifdef DEFINE
2953 "\\<\\(`elsif\\|`ifn?def\\|`undef\\|`default_nettype\\|`begin_keywords\\)\\>\\s-"
2954 "\\)\\|\\(?:"
2955 ;; `line number "filename" level
2956 "\\<\\(`line\\)\\>\\s-+[0-9]+\\s-+\"[^\"]+\"\\s-+[012]"
2957 "\\)\\|\\(?:"
2958 ;;`include "file" or `include <file>
2959 "\\<\\(`include\\)\\>\\s-+\\(?:\"[^\"]+\"\\|<[^>]+>\\)"
2960 "\\)\\|\\(?:"
2961 ;; `pragma <stuff> (no mention in IEEE 1800-2012 that pragma can span multiple lines
2962 "\\<\\(`pragma\\)\\>\\s-+.+$"
2963 "\\)\\|\\(?:"
2964 ;; `timescale time_unit / time_precision
2965 "\\<\\(`timescale\\)\\>\\s-+10\\{0,2\\}\\s-*[munpf]?s\\s-*\\/\\s-*10\\{0,2\\}\\s-*[munpf]?s"
2966 "\\)\\|\\(?:"
2967 ;; `define and `if can span multiple lines if line ends in '\'. NOTE: `if is not IEEE 1800-2012
2968 ;; from http://www.emacswiki.org/emacs/MultilineRegexp
2969 (concat "\\<\\(`define\\|`if\\)\\>" ; directive
2970 "\\s-+" ; separator
2971 "\\(?:.*?\\(?:\n.*\\)*?\\)" ; definition: to end of line, then maybe more lines (excludes any trailing \n)
2972 "\\(?:\n\\s-*\n\\|\\'\\)") ; blank line or EOF
2973 "\\)\\|\\(?:"
2974 ;; `<macro>() : i.e. `uvm_info(a,b,c) or any other pre-defined macro
2975 ;; Since parameters inside the macro can have parentheses, and
2976 ;; the macro can span multiple lines, just look for the opening
2977 ;; parentheses and then continue to the end of the first
2978 ;; non-escaped EOL
2979 (concat "\\<`\\w+\\>\\s-*("
2980 "\\(?:.*?\\(?:\n.*\\)*?\\)" ; definition: to end of line, then maybe more lines (excludes any trailing \n)
2981 "\\(?:\n\\s-*\n\\|\\'\\)") ; blank line or EOF
2982 "\\)"
2985 (defconst verilog-keywords
2986 (append verilog-compiler-directives
2988 "after" "alias" "always" "always_comb" "always_ff" "always_latch" "and"
2989 "assert" "assign" "assume" "automatic" "before" "begin" "bind"
2990 "bins" "binsof" "bit" "break" "buf" "bufif0" "bufif1" "byte"
2991 "case" "casex" "casez" "cell" "chandle" "class" "clocking" "cmos"
2992 "config" "const" "constraint" "context" "continue" "cover"
2993 "covergroup" "coverpoint" "cross" "deassign" "default" "defparam"
2994 "design" "disable" "dist" "do" "edge" "else" "end" "endcase"
2995 "endclass" "endclocking" "endconfig" "endfunction" "endgenerate"
2996 "endgroup" "endinterface" "endmodule" "endpackage" "endprimitive"
2997 "endprogram" "endproperty" "endspecify" "endsequence" "endtable"
2998 "endtask" "enum" "event" "expect" "export" "extends" "extern"
2999 "final" "first_match" "for" "force" "foreach" "forever" "fork"
3000 "forkjoin" "function" "generate" "genvar" "highz0" "highz1" "if"
3001 "iff" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir"
3002 "include" "initial" "inout" "input" "inside" "instance" "int"
3003 "integer" "interface" "intersect" "join" "join_any" "join_none"
3004 "large" "liblist" "library" "local" "localparam" "logic"
3005 "longint" "macromodule" "mailbox" "matches" "medium" "modport" "module"
3006 "nand" "negedge" "new" "nmos" "nor" "noshowcancelled" "not"
3007 "notif0" "notif1" "null" "or" "output" "package" "packed"
3008 "parameter" "pmos" "posedge" "primitive" "priority" "program"
3009 "property" "protected" "pull0" "pull1" "pulldown" "pullup"
3010 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
3011 "randcase" "randsequence" "rcmos" "real" "realtime" "ref" "reg"
3012 "release" "repeat" "return" "rnmos" "rpmos" "rtran" "rtranif0"
3013 "rtranif1" "scalared" "semaphore" "sequence" "shortint" "shortreal"
3014 "showcancelled" "signed" "small" "solve" "specify" "specparam"
3015 "static" "string" "strong0" "strong1" "struct" "super" "supply0"
3016 "supply1" "table" "tagged" "task" "this" "throughout" "time"
3017 "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri"
3018 "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union"
3019 "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void"
3020 "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard"
3021 "wire" "with" "within" "wor" "xnor" "xor"
3022 ;; 1800-2009
3023 "accept_on" "checker" "endchecker" "eventually" "global" "implies"
3024 "let" "nexttime" "reject_on" "restrict" "s_always" "s_eventually"
3025 "s_nexttime" "s_until" "s_until_with" "strong" "sync_accept_on"
3026 "sync_reject_on" "unique0" "until" "until_with" "untyped" "weak"
3027 ;; 1800-2012
3028 "implements" "interconnect" "nettype" "soft"
3030 "List of Verilog keywords.")
3032 (defconst verilog-comment-start-regexp "//\\|/\\*"
3033 "Dual comment value for `comment-start-regexp'.")
3035 (defvar verilog-mode-syntax-table
3036 (let ((table (make-syntax-table)))
3037 ;; Populate the syntax TABLE.
3038 (modify-syntax-entry ?\\ "\\" table)
3039 (modify-syntax-entry ?+ "." table)
3040 (modify-syntax-entry ?- "." table)
3041 (modify-syntax-entry ?= "." table)
3042 (modify-syntax-entry ?% "." table)
3043 (modify-syntax-entry ?< "." table)
3044 (modify-syntax-entry ?> "." table)
3045 (modify-syntax-entry ?& "." table)
3046 (modify-syntax-entry ?| "." table)
3047 (modify-syntax-entry ?` "w" table) ; ` is part of definition symbols in Verilog
3048 (modify-syntax-entry ?_ "w" table)
3049 (modify-syntax-entry ?\' "." table)
3051 ;; Set up TABLE to handle block and line style comments.
3052 (if (featurep 'xemacs)
3053 (progn
3054 ;; XEmacs (formerly Lucid) has the best implementation
3055 (modify-syntax-entry ?/ ". 1456" table)
3056 (modify-syntax-entry ?* ". 23" table)
3057 (modify-syntax-entry ?\n "> b" table))
3058 ;; Emacs does things differently, but we can work with it
3059 (modify-syntax-entry ?/ ". 124b" table)
3060 (modify-syntax-entry ?* ". 23" table)
3061 (modify-syntax-entry ?\n "> b" table))
3062 table)
3063 "Syntax table used in Verilog mode buffers.")
3065 (defvar verilog-font-lock-keywords nil
3066 "Default highlighting for Verilog mode.")
3068 (defvar verilog-font-lock-keywords-1 nil
3069 "Subdued level highlighting for Verilog mode.")
3071 (defvar verilog-font-lock-keywords-2 nil
3072 "Medium level highlighting for Verilog mode.
3073 See also `verilog-font-lock-extra-types'.")
3075 (defvar verilog-font-lock-keywords-3 nil
3076 "Gaudy level highlighting for Verilog mode.
3077 See also `verilog-font-lock-extra-types'.")
3079 (defvar verilog-font-lock-translate-off-face
3080 'verilog-font-lock-translate-off-face
3081 "Font to use for translated off regions.")
3082 (defface verilog-font-lock-translate-off-face
3083 '((((class color)
3084 (background light))
3085 (:background "gray90" :italic t ))
3086 (((class color)
3087 (background dark))
3088 (:background "gray10" :italic t ))
3089 (((class grayscale) (background light))
3090 (:foreground "DimGray" :italic t))
3091 (((class grayscale) (background dark))
3092 (:foreground "LightGray" :italic t))
3093 (t (:italis t)))
3094 "Font lock mode face used to background highlight translate-off regions."
3095 :group 'font-lock-highlighting-faces)
3097 (defvar verilog-font-lock-p1800-face
3098 'verilog-font-lock-p1800-face
3099 "Font to use for p1800 keywords.")
3100 (defface verilog-font-lock-p1800-face
3101 '((((class color)
3102 (background light))
3103 (:foreground "DarkOrange3" :bold t ))
3104 (((class color)
3105 (background dark))
3106 (:foreground "orange1" :bold t ))
3107 (t (:italic t)))
3108 "Font lock mode face used to highlight P1800 keywords."
3109 :group 'font-lock-highlighting-faces)
3111 (defvar verilog-font-lock-ams-face
3112 'verilog-font-lock-ams-face
3113 "Font to use for Analog/Mixed Signal keywords.")
3114 (defface verilog-font-lock-ams-face
3115 '((((class color)
3116 (background light))
3117 (:foreground "Purple" :bold t ))
3118 (((class color)
3119 (background dark))
3120 (:foreground "orange1" :bold t ))
3121 (t (:italic t)))
3122 "Font lock mode face used to highlight AMS keywords."
3123 :group 'font-lock-highlighting-faces)
3125 (defvar verilog-font-lock-grouping-keywords-face
3126 'verilog-font-lock-grouping-keywords-face
3127 "Font to use for Verilog Grouping Keywords (such as begin..end).")
3128 (defface verilog-font-lock-grouping-keywords-face
3129 '((((class color)
3130 (background light))
3131 (:foreground "Purple" :bold t ))
3132 (((class color)
3133 (background dark))
3134 (:foreground "orange1" :bold t ))
3135 (t (:italic t)))
3136 "Font lock mode face used to highlight verilog grouping keywords."
3137 :group 'font-lock-highlighting-faces)
3139 (let* ((verilog-type-font-keywords
3140 (eval-when-compile
3141 (verilog-regexp-opt
3143 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
3144 "event" "genvar" "inout" "input" "integer" "localparam"
3145 "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0" "notif1" "or"
3146 "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
3147 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran"
3148 "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply"
3149 "supply0" "supply1" "time" "tran" "tranif0" "tranif1"
3150 "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef"
3151 "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor"
3152 ) nil )))
3154 (verilog-pragma-keywords
3155 (eval-when-compile
3156 (verilog-regexp-opt
3157 '("surefire" "auto" "synopsys" "rtl_synthesis" "verilint" "leda" "0in"
3158 ) nil )))
3160 (verilog-1800-2005-keywords
3161 (eval-when-compile
3162 (verilog-regexp-opt
3163 '("alias" "assert" "assume" "automatic" "before" "bind"
3164 "bins" "binsof" "break" "byte" "cell" "chandle" "class"
3165 "clocking" "config" "const" "constraint" "context" "continue"
3166 "cover" "covergroup" "coverpoint" "cross" "deassign" "design"
3167 "dist" "do" "edge" "endclass" "endclocking" "endconfig"
3168 "endgroup" "endprogram" "endproperty" "endsequence" "enum"
3169 "expect" "export" "extends" "extern" "first_match" "foreach"
3170 "forkjoin" "genvar" "highz0" "highz1" "ifnone" "ignore_bins"
3171 "illegal_bins" "import" "incdir" "include" "inside" "instance"
3172 "int" "intersect" "large" "liblist" "library" "local" "longint"
3173 "matches" "medium" "modport" "new" "noshowcancelled" "null"
3174 "packed" "program" "property" "protected" "pull0" "pull1"
3175 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
3176 "randcase" "randsequence" "ref" "release" "return" "scalared"
3177 "sequence" "shortint" "shortreal" "showcancelled" "small" "solve"
3178 "specparam" "static" "string" "strong0" "strong1" "struct"
3179 "super" "tagged" "this" "throughout" "timeprecision" "timeunit"
3180 "type" "union" "unsigned" "use" "var" "virtual" "void"
3181 "wait_order" "weak0" "weak1" "wildcard" "with" "within"
3182 ) nil )))
3184 (verilog-1800-2009-keywords
3185 (eval-when-compile
3186 (verilog-regexp-opt
3187 '("accept_on" "checker" "endchecker" "eventually" "global"
3188 "implies" "let" "nexttime" "reject_on" "restrict" "s_always"
3189 "s_eventually" "s_nexttime" "s_until" "s_until_with" "strong"
3190 "sync_accept_on" "sync_reject_on" "unique0" "until"
3191 "until_with" "untyped" "weak" ) nil )))
3193 (verilog-1800-2012-keywords
3194 (eval-when-compile
3195 (verilog-regexp-opt
3196 '("implements" "interconnect" "nettype" "soft" ) nil )))
3198 (verilog-ams-keywords
3199 (eval-when-compile
3200 (verilog-regexp-opt
3201 '("above" "abs" "absdelay" "acos" "acosh" "ac_stim"
3202 "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh"
3203 "branch" "ceil" "connectmodule" "connectrules" "cos" "cosh" "ddt"
3204 "ddx" "discipline" "driver_update" "enddiscipline" "endconnectrules"
3205 "endnature" "endparamset" "exclude" "exp" "final_step" "flicker_noise"
3206 "floor" "flow" "from" "ground" "hypot" "idt" "idtmod" "inf"
3207 "initial_step" "laplace_nd" "laplace_np" "laplace_zd" "laplace_zp"
3208 "last_crossing" "limexp" "ln" "log" "max" "min" "nature"
3209 "net_resolution" "noise_table" "paramset" "potential" "pow" "sin"
3210 "sinh" "slew" "sqrt" "tan" "tanh" "timer" "transition" "white_noise"
3211 "wreal" "zi_nd" "zi_np" "zi_zd" ) nil )))
3213 (verilog-font-keywords
3214 (eval-when-compile
3215 (verilog-regexp-opt
3217 "assign" "case" "casex" "casez" "randcase" "deassign"
3218 "default" "disable" "else" "endcase" "endfunction"
3219 "endgenerate" "endinterface" "endmodule" "endprimitive"
3220 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break"
3221 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial"
3222 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge"
3223 "package" "endpackage" "always" "always_comb" "always_ff"
3224 "always_latch" "posedge" "primitive" "priority" "release"
3225 "repeat" "specify" "table" "task" "unique" "wait" "while"
3226 "class" "program" "endclass" "endprogram"
3227 ) nil )))
3229 (verilog-font-grouping-keywords
3230 (eval-when-compile
3231 (verilog-regexp-opt
3232 '( "begin" "end" ) nil ))))
3234 (setq verilog-font-lock-keywords
3235 (list
3236 ;; Fontify all builtin keywords
3237 (concat "\\<\\(" verilog-font-keywords "\\|"
3238 ;; And user/system tasks and functions
3239 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*"
3240 "\\)\\>")
3241 ;; Fontify all types
3242 (if verilog-highlight-grouping-keywords
3243 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
3244 'verilog-font-lock-grouping-keywords-face)
3245 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
3246 'font-lock-type-face))
3247 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>")
3248 'font-lock-type-face)
3249 ;; Fontify IEEE-1800-2005 keywords appropriately
3250 (if verilog-highlight-p1800-keywords
3251 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
3252 'verilog-font-lock-p1800-face)
3253 (cons (concat "\\<\\(" verilog-1800-2005-keywords "\\)\\>")
3254 'font-lock-type-face))
3255 ;; Fontify IEEE-1800-2009 keywords appropriately
3256 (if verilog-highlight-p1800-keywords
3257 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
3258 'verilog-font-lock-p1800-face)
3259 (cons (concat "\\<\\(" verilog-1800-2009-keywords "\\)\\>")
3260 'font-lock-type-face))
3261 ;; Fontify IEEE-1800-2012 keywords appropriately
3262 (if verilog-highlight-p1800-keywords
3263 (cons (concat "\\<\\(" verilog-1800-2012-keywords "\\)\\>")
3264 'verilog-font-lock-p1800-face)
3265 (cons (concat "\\<\\(" verilog-1800-2012-keywords "\\)\\>")
3266 'font-lock-type-face))
3267 ;; Fontify Verilog-AMS keywords
3268 (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>")
3269 'verilog-font-lock-ams-face)))
3271 (setq verilog-font-lock-keywords-1
3272 (append verilog-font-lock-keywords
3273 (list
3274 ;; Fontify module definitions
3275 (list
3276 "\\<\\(\\(macro\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)"
3277 '(1 font-lock-keyword-face)
3278 '(3 font-lock-function-name-face 'prepend))
3279 ;; Fontify function definitions
3280 (list
3281 (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" )
3282 '(1 font-lock-keyword-face)
3283 '(3 font-lock-constant-face prepend))
3284 '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)"
3285 (1 font-lock-keyword-face)
3286 (2 font-lock-constant-face append))
3287 '("\\<function\\>\\s-+\\(\\sw+\\)"
3288 1 'font-lock-constant-face append))))
3290 (setq verilog-font-lock-keywords-2
3291 (append verilog-font-lock-keywords-1
3292 (list
3293 ;; Fontify pragmas
3294 (concat "\\(//\\s-*\\(" verilog-pragma-keywords "\\)\\s-.*\\)")
3295 ;; Fontify escaped names
3296 '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face)
3297 ;; Fontify macro definitions/ uses
3298 '("`\\s-*[A-Za-z][A-Za-z0-9_]*" 0 (if (boundp 'font-lock-preprocessor-face)
3299 'font-lock-preprocessor-face
3300 'font-lock-type-face))
3301 ;; Fontify delays/numbers
3302 '("\\(@\\)\\|\\([ \t\n\f\r]#\\s-*\\(\\([0-9_.]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)"
3303 0 font-lock-type-face append)
3304 ;; Fontify property/sequence cycle delays - these start with '##'
3305 '("\\(##\\(\\sw+\\|\\[[^]]+\\]\\)\\)"
3306 0 font-lock-type-face append)
3307 ;; Fontify instantiation names
3308 '("\\([A-Za-z][A-Za-z0-9_]*\\)\\s-*(" 1 font-lock-function-name-face)
3311 (setq verilog-font-lock-keywords-3
3312 (append verilog-font-lock-keywords-2
3313 (when verilog-highlight-translate-off
3314 (list
3315 ;; Fontify things in translate off regions
3316 '(verilog-match-translate-off
3317 (0 'verilog-font-lock-translate-off-face prepend))
3318 )))))
3321 ;; Buffer state preservation
3323 (defmacro verilog-save-buffer-state (&rest body)
3324 "Execute BODY forms, saving state around insignificant change.
3325 Changes in text properties like `face' or `syntax-table' are
3326 considered insignificant. This macro allows text properties to
3327 be changed, even in a read-only buffer.
3329 A change is considered significant if it affects the buffer text
3330 in any way that isn't completely restored again. Any
3331 user-visible changes to the buffer must not be within a
3332 `verilog-save-buffer-state'."
3333 `(let ((inhibit-point-motion-hooks t)
3334 (verilog-no-change-functions t))
3335 ,(if (fboundp 'with-silent-modifications)
3336 `(with-silent-modifications ,@body)
3337 ;; Backward compatible version of with-silent-modifications
3338 `(let* ((modified (buffer-modified-p))
3339 (buffer-undo-list t)
3340 (inhibit-read-only t)
3341 (inhibit-modification-hooks t)
3342 ;; XEmacs ignores inhibit-modification-hooks.
3343 before-change-functions after-change-functions
3344 deactivate-mark
3345 buffer-file-name ; Prevent primitives checking
3346 buffer-file-truename) ; for file modification
3347 (unwind-protect
3348 (progn ,@body)
3349 (and (not modified)
3350 (buffer-modified-p)
3351 (verilog-restore-buffer-modified-p nil)))))))
3354 (defvar verilog-save-font-mod-hooked nil
3355 "Local variable when inside a `verilog-save-font-no-change-functions' block.")
3356 (make-variable-buffer-local 'verilog-save-font-mod-hooked)
3358 (defmacro verilog-save-font-no-change-functions (&rest body)
3359 "Execute BODY forms, disabling all change hooks in BODY.
3360 Includes temporary disabling of `font-lock' to restore the buffer
3361 to full text form for parsing. Additional actions may be specified with
3362 `verilog-before-save-font-hook' and `verilog-after-save-font-hook'.
3363 For insignificant changes, see instead `verilog-save-buffer-state'."
3364 `(if verilog-save-font-mod-hooked ; Short-circuit a recursive call
3365 (progn ,@body)
3366 ;; Before version 20, match-string with font-lock returns a
3367 ;; vector that is not equal to the string. IE if on "input"
3368 ;; nil==(equal "input" (progn (looking-at "input") (match-string 0)))
3369 ;; Therefore we must remove and restore font-lock mode
3370 (verilog-run-hooks 'verilog-before-save-font-hook)
3371 (let* ((verilog-save-font-mod-hooked (- (point-max) (point-min)))
3372 ;; Significant speed savings with no font-lock properties
3373 (fontlocked (when (and (boundp 'font-lock-mode) font-lock-mode)
3374 (font-lock-mode 0)
3375 t)))
3376 (run-hook-with-args 'before-change-functions (point-min) (point-max))
3377 (unwind-protect
3378 ;; Must inhibit and restore hooks before restoring font-lock
3379 (let* ((inhibit-point-motion-hooks t)
3380 (inhibit-modification-hooks t)
3381 (verilog-no-change-functions t)
3382 ;; XEmacs and pre-Emacs 21 ignore inhibit-modification-hooks.
3383 before-change-functions after-change-functions)
3384 (progn ,@body))
3385 ;; Unwind forms
3386 (run-hook-with-args 'after-change-functions (point-min) (point-max)
3387 verilog-save-font-mod-hooked) ; old length
3388 (when fontlocked (font-lock-mode t))
3389 (verilog-run-hooks 'verilog-after-save-font-hook)))))
3392 ;; Comment detection and caching
3394 (defvar verilog-scan-cache-preserving nil
3395 "If true, the specified buffer's comment properties are static.
3396 Buffer changes will be ignored. See `verilog-inside-comment-or-string-p'
3397 and `verilog-scan'.")
3399 (defvar verilog-scan-cache-tick nil
3400 "Modification tick at which `verilog-scan' was last completed.")
3401 (make-variable-buffer-local 'verilog-scan-cache-tick)
3403 (defun verilog-scan-cache-flush ()
3404 "Flush the `verilog-scan' cache."
3405 (setq verilog-scan-cache-tick nil))
3407 (defun verilog-scan-cache-ok-p ()
3408 "Return t if the scan cache is up to date."
3409 (or (and verilog-scan-cache-preserving
3410 (eq verilog-scan-cache-preserving (current-buffer))
3411 verilog-scan-cache-tick)
3412 (equal verilog-scan-cache-tick (buffer-chars-modified-tick))))
3414 (defmacro verilog-save-scan-cache (&rest body)
3415 "Execute the BODY forms, allowing scan cache preservation within BODY.
3416 This requires that insertions must use `verilog-insert'."
3417 ;; If the buffer is out of date, trash it, as we'll not check later the tick
3418 ;; Note this must work properly if there's multiple layers of calls
3419 ;; to verilog-save-scan-cache even with differing ticks.
3420 `(progn
3421 (unless (verilog-scan-cache-ok-p) ; Must be before let
3422 (setq verilog-scan-cache-tick nil))
3423 (let* ((verilog-scan-cache-preserving (current-buffer)))
3424 (progn ,@body))))
3426 (defun verilog-scan-region (beg end)
3427 "Parse between BEG and END for `verilog-inside-comment-or-string-p'.
3428 This creates v-cmts properties where comments are in force."
3429 ;; Why properties and not overlays? Overlays have much slower non O(1)
3430 ;; lookup times.
3431 ;; This function is warm - called on every verilog-insert
3432 (save-excursion
3433 (save-match-data
3434 (verilog-save-buffer-state
3435 (let (pt)
3436 (goto-char beg)
3437 (while (< (point) end)
3438 (cond ((looking-at "//")
3439 (setq pt (point))
3440 (or (search-forward "\n" end t)
3441 (goto-char end))
3442 ;; "1+": The leading // or /* itself isn't considered as
3443 ;; being "inside" the comment, so that a (search-backward)
3444 ;; that lands at the start of the // won't mis-indicate
3445 ;; it's inside a comment. Also otherwise it would be
3446 ;; hard to find a commented out /*AS*/ vs one that isn't
3447 (put-text-property (1+ pt) (point) 'v-cmts t))
3448 ((looking-at "/\\*")
3449 (setq pt (point))
3450 (or (search-forward "*/" end t)
3451 ;; No error - let later code indicate it so we can
3452 ;; use inside functions on-the-fly
3453 ;;(error "%s: Unmatched /* */, at char %d"
3454 ;; (verilog-point-text) (point))
3455 (goto-char end))
3456 (put-text-property (1+ pt) (point) 'v-cmts t))
3457 ((looking-at "\"")
3458 (setq pt (point))
3459 (or (re-search-forward "[^\\]\"" end t) ; don't forward-char first, since we look for a non backslash first
3460 ;; No error - let later code indicate it so we can
3461 (goto-char end))
3462 (put-text-property (1+ pt) (point) 'v-cmts t))
3464 (forward-char 1)
3465 (if (re-search-forward "[/\"]" end t)
3466 (backward-char 1)
3467 (goto-char end))))))))))
3469 (defun verilog-scan ()
3470 "Parse the buffer, marking all comments with properties.
3471 Also assumes any text inserted since `verilog-scan-cache-tick'
3472 either is ok to parse as a non-comment, or `verilog-insert' was used."
3473 ;; See also `verilog-scan-debug' and `verilog-scan-and-debug'
3474 (unless (verilog-scan-cache-ok-p)
3475 (save-excursion
3476 (verilog-save-buffer-state
3477 (when verilog-debug
3478 (message "Scanning %s cache=%s cachetick=%S tick=%S" (current-buffer)
3479 verilog-scan-cache-preserving verilog-scan-cache-tick
3480 (buffer-chars-modified-tick)))
3481 (remove-text-properties (point-min) (point-max) '(v-cmts nil))
3482 (verilog-scan-region (point-min) (point-max))
3483 (setq verilog-scan-cache-tick (buffer-chars-modified-tick))
3484 (when verilog-debug (message "Scanning... done"))))))
3486 (defun verilog-scan-debug ()
3487 "For debugging, show with display face results of `verilog-scan'."
3488 (font-lock-mode 0)
3489 ;;(if dbg (setq dbg (concat dbg (format "verilog-scan-debug\n"))))
3490 (save-excursion
3491 (goto-char (point-min))
3492 (remove-text-properties (point-min) (point-max) '(face nil))
3493 (while (not (eobp))
3494 (cond ((get-text-property (point) 'v-cmts)
3495 (put-text-property (point) (1+ (point)) `face 'underline)
3496 ;;(if dbg (setq dbg (concat dbg (format " v-cmts at %S\n" (point)))))
3497 (forward-char 1))
3499 (goto-char (or (next-property-change (point)) (point-max))))))))
3501 (defun verilog-scan-and-debug ()
3502 "For debugging, run `verilog-scan' and `verilog-scan-debug'."
3503 (let (verilog-scan-cache-preserving
3504 verilog-scan-cache-tick)
3505 (goto-char (point-min))
3506 (verilog-scan)
3507 (verilog-scan-debug)))
3509 (defun verilog-inside-comment-or-string-p (&optional pos)
3510 "Check if optional point POS is inside a comment.
3511 This may require a slow pre-parse of the buffer with `verilog-scan'
3512 to establish comment properties on all text."
3513 ;; This function is very hot
3514 (verilog-scan)
3515 (if pos
3516 (and (>= pos (point-min))
3517 (get-text-property pos 'v-cmts))
3518 (get-text-property (point) 'v-cmts)))
3520 (defun verilog-insert (&rest stuff)
3521 "Insert STUFF arguments, tracking for `verilog-inside-comment-or-string-p'.
3522 Any insert that includes a comment must have the entire comment
3523 inserted using a single call to `verilog-insert'."
3524 (let ((pt (point)))
3525 (while stuff
3526 (insert (car stuff))
3527 (setq stuff (cdr stuff)))
3528 (verilog-scan-region pt (point))))
3530 ;; More searching
3532 (defun verilog-declaration-end ()
3533 (search-forward ";"))
3535 (defun verilog-point-text (&optional pointnum)
3536 "Return text describing where POINTNUM or current point is (for errors).
3537 Use filename, if current buffer being edited shorten to just buffer name."
3538 (concat (or (and (equal (window-buffer) (current-buffer))
3539 (buffer-name))
3540 buffer-file-name
3541 (buffer-name))
3542 ":" (int-to-string (1+ (count-lines (point-min) (or pointnum (point)))))))
3544 (defun electric-verilog-backward-sexp ()
3545 "Move backward over one balanced expression."
3546 (interactive)
3547 ;; before that see if we are in a comment
3548 (verilog-backward-sexp))
3550 (defun electric-verilog-forward-sexp ()
3551 "Move forward over one balanced expression."
3552 (interactive)
3553 ;; before that see if we are in a comment
3554 (verilog-forward-sexp))
3556 (defun verilog-forward-sexp-function (arg)
3557 "Move forward ARG sexps."
3558 ;; Used by hs-minor-mode
3559 (if (< arg 0)
3560 (verilog-backward-sexp)
3561 (verilog-forward-sexp)))
3563 (defun verilog-backward-sexp ()
3564 (let ((reg)
3565 (elsec 1)
3566 (found nil)
3567 (st (point)))
3568 (if (not (looking-at "\\<"))
3569 (forward-word-strictly -1))
3570 (cond
3571 ((verilog-skip-backward-comment-or-string))
3572 ((looking-at "\\<else\\>")
3573 (setq reg (concat
3574 verilog-end-block-re
3575 "\\|\\(\\<else\\>\\)"
3576 "\\|\\(\\<if\\>\\)"))
3577 (while (and (not found)
3578 (verilog-re-search-backward reg nil 'move))
3579 (cond
3580 ((match-end 1) ; matched verilog-end-block-re
3581 ;; try to leap back to matching outward block by striding across
3582 ;; indent level changing tokens then immediately
3583 ;; previous line governs indentation.
3584 (verilog-leap-to-head))
3585 ((match-end 2) ; else, we're in deep
3586 (setq elsec (1+ elsec)))
3587 ((match-end 3) ; found it
3588 (setq elsec (1- elsec))
3589 (if (= 0 elsec)
3590 ;; Now previous line describes syntax
3591 (setq found 't))))))
3592 ((looking-at verilog-end-block-re)
3593 (verilog-leap-to-head))
3594 ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)\\|\\(\\<endclass\\>\\)\\|\\(\\<endprogram\\>\\)\\|\\(\\<endinterface\\>\\)\\|\\(\\<endpackage\\>\\)")
3595 (cond
3596 ((match-end 1)
3597 (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move))
3598 ((match-end 2)
3599 (verilog-re-search-backward "\\<primitive\\>" nil 'move))
3600 ((match-end 3)
3601 (verilog-re-search-backward "\\<class\\>" nil 'move))
3602 ((match-end 4)
3603 (verilog-re-search-backward "\\<program\\>" nil 'move))
3604 ((match-end 5)
3605 (verilog-re-search-backward "\\<interface\\>" nil 'move))
3606 ((match-end 6)
3607 (verilog-re-search-backward "\\<package\\>" nil 'move))
3609 (goto-char st)
3610 (backward-sexp 1))))
3612 (goto-char st)
3613 (backward-sexp)))))
3615 (defun verilog-forward-sexp ()
3616 (let ((reg)
3617 (md 2)
3618 (st (point))
3619 (nest 'yes))
3620 (if (not (looking-at "\\<"))
3621 (forward-word-strictly -1))
3622 (cond
3623 ((verilog-skip-forward-comment-or-string)
3624 (verilog-forward-syntactic-ws))
3625 ((looking-at verilog-beg-block-re-ordered)
3626 (cond
3627 ((match-end 1);
3628 ;; Search forward for matching end
3629 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
3630 ((match-end 2)
3631 ;; Search forward for matching endcase
3632 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique0?\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
3633 (setq md 3) ; ender is third item in regexp
3635 ((match-end 4)
3636 ;; might be "disable fork" or "wait fork"
3637 (let
3638 (here)
3639 (if (or
3640 (looking-at verilog-disable-fork-re)
3641 (and (looking-at "fork")
3642 (progn
3643 (setq here (point)) ; sometimes a fork is just a fork
3644 (forward-word-strictly -1)
3645 (looking-at verilog-disable-fork-re))))
3646 (progn ; it is a disable fork; ignore it
3647 (goto-char (match-end 0))
3648 (forward-word-strictly 1)
3649 (setq reg nil))
3650 (progn ; it is a nice simple fork
3651 (goto-char here) ; return from looking for "disable fork"
3652 ;; Search forward for matching join
3653 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))))
3654 ((match-end 6)
3655 ;; Search forward for matching endclass
3656 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
3658 ((match-end 7)
3659 ;; Search forward for matching endtable
3660 (setq reg "\\<endtable\\>" )
3661 (setq nest 'no))
3662 ((match-end 8)
3663 ;; Search forward for matching endspecify
3664 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
3665 ((match-end 9)
3666 ;; Search forward for matching endfunction
3667 (setq reg "\\<endfunction\\>" )
3668 (setq nest 'no))
3669 ((match-end 10)
3670 ;; Search forward for matching endfunction
3671 (setq reg "\\<endfunction\\>" )
3672 (setq nest 'no))
3673 ((match-end 11)
3674 ;; Search forward for matching endtask
3675 (setq reg "\\<endtask\\>" )
3676 (setq nest 'no))
3677 ((match-end 12)
3678 ;; Search forward for matching endtask
3679 (setq reg "\\<endtask\\>" )
3680 (setq nest 'no))
3681 ((match-end 12)
3682 ;; Search forward for matching endgenerate
3683 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
3684 ((match-end 13)
3685 ;; Search forward for matching endgroup
3686 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
3687 ((match-end 14)
3688 ;; Search forward for matching endproperty
3689 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
3690 ((match-end 15)
3691 ;; Search forward for matching endsequence
3692 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )
3693 (setq md 3)) ; 3 to get to endsequence in the reg above
3694 ((match-end 17)
3695 ;; Search forward for matching endclocking
3696 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )))
3697 (if (and reg
3698 (forward-word-strictly 1))
3699 (catch 'skip
3700 (if (eq nest 'yes)
3701 (let ((depth 1)
3702 here)
3703 (while (verilog-re-search-forward reg nil 'move)
3704 (cond
3705 ((match-end md) ; a closer in regular expression, so we are climbing out
3706 (setq depth (1- depth))
3707 (if (= 0 depth) ; we are out!
3708 (throw 'skip 1)))
3709 ((match-end 1) ; an opener in the r-e, so we are in deeper now
3710 (setq here (point)) ; remember where we started
3711 (goto-char (match-beginning 1))
3712 (cond
3713 ((if (or
3714 (looking-at verilog-disable-fork-re)
3715 (and (looking-at "fork")
3716 (progn
3717 (forward-word-strictly -1)
3718 (looking-at verilog-disable-fork-re))))
3719 (progn ; it is a disable fork; another false alarm
3720 (goto-char (match-end 0)))
3721 (progn ; it is a simple fork (or has nothing to do with fork)
3722 (goto-char here)
3723 (setq depth (1+ depth))))))))))
3724 (if (verilog-re-search-forward reg nil 'move)
3725 (throw 'skip 1))))))
3727 ((looking-at (concat
3728 "\\(\\<\\(macro\\)?module\\>\\)\\|"
3729 "\\(\\<primitive\\>\\)\\|"
3730 "\\(\\<class\\>\\)\\|"
3731 "\\(\\<program\\>\\)\\|"
3732 "\\(\\<interface\\>\\)\\|"
3733 "\\(\\<package\\>\\)"))
3734 (cond
3735 ((match-end 1)
3736 (verilog-re-search-forward "\\<endmodule\\>" nil 'move))
3737 ((match-end 2)
3738 (verilog-re-search-forward "\\<endprimitive\\>" nil 'move))
3739 ((match-end 3)
3740 (verilog-re-search-forward "\\<endclass\\>" nil 'move))
3741 ((match-end 4)
3742 (verilog-re-search-forward "\\<endprogram\\>" nil 'move))
3743 ((match-end 5)
3744 (verilog-re-search-forward "\\<endinterface\\>" nil 'move))
3745 ((match-end 6)
3746 (verilog-re-search-forward "\\<endpackage\\>" nil 'move))
3748 (goto-char st)
3749 (if (= (following-char) ?\) )
3750 (forward-char 1)
3751 (forward-sexp 1)))))
3753 (goto-char st)
3754 (if (= (following-char) ?\) )
3755 (forward-char 1)
3756 (forward-sexp 1))))))
3758 (defun verilog-declaration-beg ()
3759 (verilog-re-search-backward verilog-declaration-re (bobp) t))
3763 ;; Mode
3765 (defvar verilog-which-tool 1)
3766 ;;;###autoload
3767 (define-derived-mode verilog-mode prog-mode "Verilog"
3768 "Major mode for editing Verilog code.
3769 \\<verilog-mode-map>
3770 See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how
3771 AUTOs can improve coding efficiency.
3773 Use \\[verilog-faq] for a pointer to frequently asked questions.
3775 NEWLINE, TAB indents for Verilog code.
3776 Delete converts tabs to spaces as it moves back.
3778 Supports highlighting.
3780 Turning on Verilog mode calls the value of the variable `verilog-mode-hook'
3781 with no args, if that value is non-nil.
3783 Variables controlling indentation/edit style:
3785 variable `verilog-indent-level' (default 3)
3786 Indentation of Verilog statements with respect to containing block.
3787 `verilog-indent-level-module' (default 3)
3788 Absolute indentation of Module level Verilog statements.
3789 Set to 0 to get initial and always statements lined up
3790 on the left side of your screen.
3791 `verilog-indent-level-declaration' (default 3)
3792 Indentation of declarations with respect to containing block.
3793 Set to 0 to get them list right under containing block.
3794 `verilog-indent-level-behavioral' (default 3)
3795 Indentation of first begin in a task or function block
3796 Set to 0 to get such code to lined up underneath the task or
3797 function keyword.
3798 `verilog-indent-level-directive' (default 1)
3799 Indentation of \\=`ifdef/\\=`endif blocks.
3800 `verilog-cexp-indent' (default 1)
3801 Indentation of Verilog statements broken across lines i.e.:
3802 if (a)
3803 begin
3804 `verilog-case-indent' (default 2)
3805 Indentation for case statements.
3806 `verilog-auto-newline' (default nil)
3807 Non-nil means automatically newline after semicolons and the punctuation
3808 mark after an end.
3809 `verilog-auto-indent-on-newline' (default t)
3810 Non-nil means automatically indent line after newline.
3811 `verilog-tab-always-indent' (default t)
3812 Non-nil means TAB in Verilog mode should always reindent the current line,
3813 regardless of where in the line point is when the TAB command is used.
3814 `verilog-indent-begin-after-if' (default t)
3815 Non-nil means to indent begin statements following a preceding
3816 if, else, while, for and repeat statements, if any. Otherwise,
3817 the begin is lined up with the preceding token. If t, you get:
3818 if (a)
3819 begin // amount of indent based on `verilog-cexp-indent'
3820 otherwise you get:
3821 if (a)
3822 begin
3823 `verilog-auto-endcomments' (default t)
3824 Non-nil means a comment /* ... */ is set after the ends which ends
3825 cases, tasks, functions and modules.
3826 The type and name of the object will be set between the braces.
3827 `verilog-minimum-comment-distance' (default 10)
3828 Minimum distance (in lines) between begin and end required before a comment
3829 will be inserted. Setting this variable to zero results in every
3830 end acquiring a comment; the default avoids too many redundant
3831 comments in tight quarters.
3832 `verilog-auto-lineup' (default `declarations')
3833 List of contexts where auto lineup of code should be done.
3835 Variables controlling other actions:
3837 `verilog-linter' (default `surelint')
3838 Unix program to call to run the lint checker. This is the default
3839 command for \\[compile-command] and \\[verilog-auto-save-compile].
3841 See \\[customize] for the complete list of variables.
3843 AUTO expansion functions are, in part:
3845 \\[verilog-auto] Expand AUTO statements.
3846 \\[verilog-delete-auto] Remove the AUTOs.
3847 \\[verilog-inject-auto] Insert AUTOs for the first time.
3849 Some other functions are:
3851 \\[completion-at-point] Complete word with appropriate possibilities.
3852 \\[verilog-mark-defun] Mark function.
3853 \\[verilog-beg-of-defun] Move to beginning of current function.
3854 \\[verilog-end-of-defun] Move to end of current function.
3855 \\[verilog-label-be] Label matching begin ... end, fork ... join, etc statements.
3857 \\[verilog-comment-region] Put marked area in a comment.
3858 \\[verilog-uncomment-region] Uncomment an area commented with \\[verilog-comment-region].
3859 \\[verilog-insert-block] Insert begin ... end.
3860 \\[verilog-star-comment] Insert /* ... */.
3862 \\[verilog-sk-always] Insert an always @(AS) begin .. end block.
3863 \\[verilog-sk-begin] Insert a begin .. end block.
3864 \\[verilog-sk-case] Insert a case block, prompting for details.
3865 \\[verilog-sk-for] Insert a for (...) begin .. end block, prompting for details.
3866 \\[verilog-sk-generate] Insert a generate .. endgenerate block.
3867 \\[verilog-sk-header] Insert a header block at the top of file.
3868 \\[verilog-sk-initial] Insert an initial begin .. end block.
3869 \\[verilog-sk-fork] Insert a fork begin .. end .. join block.
3870 \\[verilog-sk-module] Insert a module .. (/*AUTOARG*/);.. endmodule block.
3871 \\[verilog-sk-ovm-class] Insert an OVM Class block.
3872 \\[verilog-sk-uvm-object] Insert an UVM Object block.
3873 \\[verilog-sk-uvm-component] Insert an UVM Component block.
3874 \\[verilog-sk-primitive] Insert a primitive .. (.. );.. endprimitive block.
3875 \\[verilog-sk-repeat] Insert a repeat (..) begin .. end block.
3876 \\[verilog-sk-specify] Insert a specify .. endspecify block.
3877 \\[verilog-sk-task] Insert a task .. begin .. end endtask block.
3878 \\[verilog-sk-while] Insert a while (...) begin .. end block, prompting for details.
3879 \\[verilog-sk-casex] Insert a casex (...) item: begin.. end endcase block, prompting for details.
3880 \\[verilog-sk-casez] Insert a casez (...) item: begin.. end endcase block, prompting for details.
3881 \\[verilog-sk-if] Insert an if (..) begin .. end block.
3882 \\[verilog-sk-else-if] Insert an else if (..) begin .. end block.
3883 \\[verilog-sk-comment] Insert a comment block.
3884 \\[verilog-sk-assign] Insert an assign .. = ..; statement.
3885 \\[verilog-sk-function] Insert a function .. begin .. end endfunction block.
3886 \\[verilog-sk-input] Insert an input declaration, prompting for details.
3887 \\[verilog-sk-output] Insert an output declaration, prompting for details.
3888 \\[verilog-sk-state-machine] Insert a state machine definition, prompting for details.
3889 \\[verilog-sk-inout] Insert an inout declaration, prompting for details.
3890 \\[verilog-sk-wire] Insert a wire declaration, prompting for details.
3891 \\[verilog-sk-reg] Insert a register declaration, prompting for details.
3892 \\[verilog-sk-define-signal] Define signal under point as a register at the top of the module.
3894 All key bindings can be seen in a Verilog-buffer with \\[describe-bindings].
3895 Key bindings specific to `verilog-mode-map' are:
3897 \\{verilog-mode-map}"
3898 :abbrev-table verilog-mode-abbrev-table
3899 (set (make-local-variable 'beginning-of-defun-function)
3900 'verilog-beg-of-defun)
3901 (set (make-local-variable 'end-of-defun-function)
3902 'verilog-end-of-defun)
3903 (set-syntax-table verilog-mode-syntax-table)
3904 (set (make-local-variable 'indent-line-function)
3905 #'verilog-indent-line-relative)
3906 (set (make-local-variable 'comment-indent-function) 'verilog-comment-indent)
3907 (set (make-local-variable 'parse-sexp-ignore-comments) nil)
3908 (set (make-local-variable 'comment-start) "// ")
3909 (set (make-local-variable 'comment-end) "")
3910 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *")
3911 (set (make-local-variable 'comment-multi-line) nil)
3912 ;; Set up for compilation
3913 (setq verilog-which-tool 1)
3914 (setq verilog-tool 'verilog-linter)
3915 (verilog-set-compile-command)
3916 (when (boundp 'hack-local-variables-hook) ; Also modify any file-local-variables
3917 (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t))
3919 ;; Setting up menus
3920 (when (featurep 'xemacs)
3921 (easy-menu-add verilog-stmt-menu)
3922 (easy-menu-add verilog-menu)
3923 (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu)))
3925 ;; Stuff for GNU Emacs
3926 (set (make-local-variable 'font-lock-defaults)
3927 `((verilog-font-lock-keywords
3928 verilog-font-lock-keywords-1
3929 verilog-font-lock-keywords-2
3930 verilog-font-lock-keywords-3)
3931 nil nil nil
3932 ,(if (functionp 'syntax-ppss)
3933 ;; verilog-beg-of-defun uses syntax-ppss, and syntax-ppss uses
3934 ;; font-lock-beginning-of-syntax-function, so
3935 ;; font-lock-beginning-of-syntax-function, can't use
3936 ;; verilog-beg-of-defun.
3938 'verilog-beg-of-defun)))
3939 ;;------------------------------------------------------------
3940 ;; now hook in 'verilog-highlight-include-files (eldo-mode.el&spice-mode.el)
3941 ;; all buffer local:
3942 (unless noninteractive ; Else can't see the result, and change hooks are slow
3943 (when (featurep 'xemacs)
3944 (make-local-hook 'font-lock-mode-hook)
3945 (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in Emacs
3946 (make-local-hook 'after-change-functions))
3947 (add-hook 'font-lock-mode-hook 'verilog-highlight-buffer t t)
3948 (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-highlight-buffer t t) ; not in Emacs
3949 (add-hook 'after-change-functions 'verilog-highlight-region t t))
3951 ;; Tell imenu how to handle Verilog.
3952 (set (make-local-variable 'imenu-generic-expression)
3953 verilog-imenu-generic-expression)
3954 ;; Tell which-func-modes that imenu knows about verilog
3955 (when (and (boundp 'which-func-modes) (listp which-func-modes))
3956 (add-to-list 'which-func-modes 'verilog-mode))
3957 ;; hideshow support
3958 (when (boundp 'hs-special-modes-alist)
3959 (unless (assq 'verilog-mode hs-special-modes-alist)
3960 (setq hs-special-modes-alist
3961 (cons '(verilog-mode "\\<begin\\>" "\\<end\\>" nil
3962 verilog-forward-sexp-function)
3963 hs-special-modes-alist))))
3965 (add-hook 'completion-at-point-functions
3966 #'verilog-completion-at-point nil 'local)
3968 ;; Stuff for autos
3969 (add-hook 'write-contents-hooks 'verilog-auto-save-check nil 'local)
3970 ;; verilog-mode-hook call added by define-derived-mode
3973 ;;; Integration with the speedbar
3976 ;; Avoid problems with XEmacs byte-compiles.
3977 ;; For GNU Emacs, the eval-after-load will handle if it isn't loaded yet.
3978 (when (eval-when-compile (fboundp 'declare-function))
3979 (declare-function speedbar-add-supported-extension "speedbar" (extension)))
3981 (defun verilog-speedbar-initialize ()
3982 "Initialize speedbar to understand `verilog-mode'."
3983 ;; Set Verilog file extensions (extracted from `auto-mode-alist')
3984 (let ((mode-alist auto-mode-alist))
3985 (while mode-alist
3986 (when (eq (cdar mode-alist) 'verilog-mode)
3987 (speedbar-add-supported-extension (caar mode-alist)))
3988 (setq mode-alist (cdr mode-alist)))))
3990 ;; If the speedbar is loaded, execute initialization instructions right away,
3991 ;; otherwise add the initialization instructions to the speedbar loader.
3992 (eval-after-load "speedbar" '(verilog-speedbar-initialize))
3995 ;;; Electric functions:
3998 (defun electric-verilog-terminate-line (&optional arg)
3999 "Terminate line and indent next line.
4000 With optional ARG, remove existing end of line comments."
4001 (interactive)
4002 ;; before that see if we are in a comment
4003 (let ((state (save-excursion (verilog-syntax-ppss))))
4004 (cond
4005 ((nth 7 state) ; Inside // comment
4006 (if (eolp)
4007 (progn
4008 (delete-horizontal-space)
4009 (newline))
4010 (progn
4011 (newline)
4012 (insert "// ")
4013 (beginning-of-line)))
4014 (verilog-indent-line))
4015 ((nth 4 state) ; Inside any comment (hence /**/)
4016 (newline)
4017 (verilog-more-comment))
4018 ((eolp)
4019 ;; First, check if current line should be indented
4020 (if (save-excursion
4021 (delete-horizontal-space)
4022 (beginning-of-line)
4023 (skip-chars-forward " \t")
4024 (if (looking-at verilog-auto-end-comment-lines-re)
4025 (let ((indent-str (verilog-indent-line)))
4026 ;; Maybe we should set some endcomments
4027 (if verilog-auto-endcomments
4028 (verilog-set-auto-endcomments indent-str arg))
4029 (end-of-line)
4030 (delete-horizontal-space)
4031 (if arg
4033 (newline))
4034 nil)
4035 (progn
4036 (end-of-line)
4037 (delete-horizontal-space)
4038 't)))
4039 ;; see if we should line up assignments
4040 (progn
4041 (if (or (eq 'all verilog-auto-lineup)
4042 (eq 'assignments verilog-auto-lineup))
4043 (verilog-pretty-expr :quiet))
4044 (newline))
4045 (forward-line 1))
4046 ;; Indent next line
4047 (if verilog-auto-indent-on-newline
4048 (verilog-indent-line)))
4050 (newline)))))
4052 (defun electric-verilog-terminate-and-indent ()
4053 "Insert a newline and indent for the next statement."
4054 (interactive)
4055 (electric-verilog-terminate-line 1))
4057 (defun electric-verilog-semi ()
4058 "Insert `;' character and reindent the line."
4059 (interactive)
4060 (verilog-insert-last-command-event)
4062 (if (or (verilog-in-comment-or-string-p)
4063 (verilog-in-escaped-name-p))
4065 (save-excursion
4066 (beginning-of-line)
4067 (verilog-forward-ws&directives)
4068 (verilog-indent-line))
4069 (if (and verilog-auto-newline
4070 (not (verilog-parenthesis-depth)))
4071 (electric-verilog-terminate-line))))
4073 (defun electric-verilog-semi-with-comment ()
4074 "Insert `;' character, reindent the line and indent for comment."
4075 (interactive)
4076 (insert ";")
4077 (save-excursion
4078 (beginning-of-line)
4079 (verilog-indent-line))
4080 (indent-for-comment))
4082 (defun electric-verilog-colon ()
4083 "Insert `:' and do all indentations except line indent on this line."
4084 (interactive)
4085 (verilog-insert-last-command-event)
4086 ;; Do nothing if within string.
4087 (if (or
4088 (verilog-within-string)
4089 (not (verilog-in-case-region-p)))
4091 (save-excursion
4092 (let ((p (point))
4093 (lim (progn (verilog-beg-of-statement) (point))))
4094 (goto-char p)
4095 (verilog-backward-case-item lim)
4096 (verilog-indent-line)))
4097 ;; (let ((verilog-tab-always-indent nil))
4098 ;; (verilog-indent-line))
4101 ;;(defun electric-verilog-equal ()
4102 ;; "Insert `=', and do indentation if within block."
4103 ;; (interactive)
4104 ;; (verilog-insert-last-command-event)
4105 ;; Could auto line up expressions, but not yet
4106 ;; (if (eq (car (verilog-calculate-indent)) 'block)
4107 ;; (let ((verilog-tab-always-indent nil))
4108 ;; (verilog-indent-command)))
4109 ;; )
4111 (defun electric-verilog-tick ()
4112 "Insert back-tick, and indent to column 0 if this is a CPP directive."
4113 (interactive)
4114 (verilog-insert-last-command-event)
4115 (save-excursion
4116 (if (verilog-in-directive-p)
4117 (verilog-indent-line))))
4119 (defun electric-verilog-tab ()
4120 "Function called when TAB is pressed in Verilog mode."
4121 (interactive)
4122 ;; If verilog-tab-always-indent, indent the beginning of the line.
4123 (cond
4124 ;; The region is active, indent it.
4125 ((and (region-active-p)
4126 (not (eq (region-beginning) (region-end))))
4127 (indent-region (region-beginning) (region-end) nil))
4128 ((or verilog-tab-always-indent
4129 (save-excursion
4130 (skip-chars-backward " \t")
4131 (bolp)))
4132 (let* ((oldpnt (point))
4133 (boi-point
4134 (save-excursion
4135 (beginning-of-line)
4136 (skip-chars-forward " \t")
4137 (verilog-indent-line)
4138 (back-to-indentation)
4139 (point))))
4140 (if (< (point) boi-point)
4141 (back-to-indentation)
4142 (cond ((not verilog-tab-to-comment))
4143 ((not (eolp))
4144 (end-of-line))
4146 (indent-for-comment)
4147 (when (and (eolp) (= oldpnt (point)))
4148 ;; kill existing comment
4149 (beginning-of-line)
4150 (re-search-forward comment-start-skip oldpnt 'move)
4151 (goto-char (match-beginning 0))
4152 (skip-chars-backward " \t")
4153 (kill-region (point) oldpnt)))))))
4154 (t (progn (insert "\t")))))
4157 ;;; Interactive functions:
4160 (defun verilog-indent-buffer ()
4161 "Indent-region the entire buffer as Verilog code.
4162 To call this from the command line, see \\[verilog-batch-indent]."
4163 (interactive)
4164 (verilog-mode)
4165 (indent-region (point-min) (point-max) nil))
4167 (defun verilog-insert-block ()
4168 "Insert Verilog begin ... end; block in the code with right indentation."
4169 (interactive)
4170 (verilog-indent-line)
4171 (insert "begin")
4172 (electric-verilog-terminate-line)
4173 (save-excursion
4174 (electric-verilog-terminate-line)
4175 (insert "end")
4176 (beginning-of-line)
4177 (verilog-indent-line)))
4179 (defun verilog-star-comment ()
4180 "Insert Verilog star comment at point."
4181 (interactive)
4182 (verilog-indent-line)
4183 (insert "/*")
4184 (save-excursion
4185 (newline)
4186 (insert " */"))
4187 (newline)
4188 (insert " * "))
4190 (defun verilog-insert-1 (fmt max)
4191 "Use format string FMT to insert integers 0 to MAX - 1.
4192 Inserts one integer per line, at the current column. Stops early
4193 if it reaches the end of the buffer."
4194 (let ((col (current-column))
4195 (n 0))
4196 (save-excursion
4197 (while (< n max)
4198 (insert (format fmt n))
4199 (forward-line 1)
4200 ;; Note that this function does not bother to check for lines
4201 ;; shorter than col.
4202 (if (eobp)
4203 (setq n max)
4204 (setq n (1+ n))
4205 (move-to-column col))))))
4207 (defun verilog-insert-indices (max)
4208 "Insert a set of indices into a rectangle.
4209 The upper left corner is defined by point. Indices begin with 0
4210 and extend to the MAX - 1. If no prefix arg is given, the user
4211 is prompted for a value. The indices are surrounded by square
4212 brackets []. For example, the following code with the point
4213 located after the first `a' gives:
4215 a = b a[ 0] = b
4216 a = b a[ 1] = b
4217 a = b a[ 2] = b
4218 a = b a[ 3] = b
4219 a = b ==> insert-indices ==> a[ 4] = b
4220 a = b a[ 5] = b
4221 a = b a[ 6] = b
4222 a = b a[ 7] = b
4223 a = b a[ 8] = b"
4225 (interactive "NMAX: ")
4226 (verilog-insert-1 "[%3d]" max))
4228 (defun verilog-generate-numbers (max)
4229 "Insert a set of generated numbers into a rectangle.
4230 The upper left corner is defined by point. The numbers are padded to three
4231 digits, starting with 000 and extending to (MAX - 1). If no prefix argument
4232 is supplied, then the user is prompted for the MAX number. Consider the
4233 following code fragment:
4235 buf buf buf buf000
4236 buf buf buf buf001
4237 buf buf buf buf002
4238 buf buf buf buf003
4239 buf buf ==> generate-numbers ==> buf buf004
4240 buf buf buf buf005
4241 buf buf buf buf006
4242 buf buf buf buf007
4243 buf buf buf buf008"
4245 (interactive "NMAX: ")
4246 (verilog-insert-1 "%3.3d" max))
4248 (defun verilog-mark-defun ()
4249 "Mark the current Verilog function (or procedure).
4250 This puts the mark at the end, and point at the beginning."
4251 (interactive)
4252 (if (featurep 'xemacs)
4253 (progn
4254 (push-mark)
4255 (verilog-end-of-defun)
4256 (push-mark)
4257 (verilog-beg-of-defun)
4258 (if (fboundp 'zmacs-activate-region)
4259 (zmacs-activate-region)))
4260 (mark-defun)))
4262 (defun verilog-comment-region (start end)
4263 ;; checkdoc-params: (start end)
4264 "Put the region into a Verilog comment.
4265 The comments that are in this area are \"deformed\":
4266 `*)' becomes `!(*' and `}' becomes `!{'.
4267 These deformed comments are returned to normal if you use
4268 \\[verilog-uncomment-region] to undo the commenting.
4270 The commented area starts with `verilog-exclude-str-start', and ends with
4271 `verilog-exclude-str-end'. But if you change these variables,
4272 \\[verilog-uncomment-region] won't recognize the comments."
4273 (interactive "r")
4274 (save-excursion
4275 ;; Insert start and endcomments
4276 (goto-char end)
4277 (if (and (save-excursion (skip-chars-forward " \t") (eolp))
4278 (not (save-excursion (skip-chars-backward " \t") (bolp))))
4279 (forward-line 1)
4280 (beginning-of-line))
4281 (insert verilog-exclude-str-end)
4282 (setq end (point))
4283 (newline)
4284 (goto-char start)
4285 (beginning-of-line)
4286 (insert verilog-exclude-str-start)
4287 (newline)
4288 ;; Replace end-comments within commented area
4289 (goto-char end)
4290 (save-excursion
4291 (while (re-search-backward "\\*/" start t)
4292 (replace-match "*-/" t t)))
4293 (save-excursion
4294 (let ((s+1 (1+ start)))
4295 (while (re-search-backward "/\\*" s+1 t)
4296 (replace-match "/-*" t t))))))
4298 (defun verilog-uncomment-region ()
4299 "Uncomment a commented area; change deformed comments back to normal.
4300 This command does nothing if the pointer is not in a commented
4301 area. See also `verilog-comment-region'."
4302 (interactive)
4303 (save-excursion
4304 (let ((start (point))
4305 (end (point)))
4306 ;; Find the boundaries of the comment
4307 (save-excursion
4308 (setq start (progn (search-backward verilog-exclude-str-start nil t)
4309 (point)))
4310 (setq end (progn (search-forward verilog-exclude-str-end nil t)
4311 (point))))
4312 ;; Check if we're really inside a comment
4313 (if (or (equal start (point)) (<= end (point)))
4314 (message "Not standing within commented area.")
4315 (progn
4316 ;; Remove endcomment
4317 (goto-char end)
4318 (beginning-of-line)
4319 (let ((pos (point)))
4320 (end-of-line)
4321 (delete-region pos (1+ (point))))
4322 ;; Change comments back to normal
4323 (save-excursion
4324 (while (re-search-backward "\\*-/" start t)
4325 (replace-match "*/" t t)))
4326 (save-excursion
4327 (while (re-search-backward "/-\\*" start t)
4328 (replace-match "/*" t t)))
4329 ;; Remove start comment
4330 (goto-char start)
4331 (beginning-of-line)
4332 (let ((pos (point)))
4333 (end-of-line)
4334 (delete-region pos (1+ (point)))))))))
4336 (defun verilog-beg-of-defun ()
4337 "Move backward to the beginning of the current function or procedure."
4338 (interactive)
4339 (verilog-re-search-backward verilog-defun-re nil 'move))
4341 (defun verilog-beg-of-defun-quick ()
4342 "Move backward to the beginning of the current function or procedure.
4343 Uses `verilog-scan' cache."
4344 (interactive)
4345 (verilog-re-search-backward-quick verilog-defun-re nil 'move))
4347 (defun verilog-end-of-defun ()
4348 "Move forward to the end of the current function or procedure."
4349 (interactive)
4350 (verilog-re-search-forward verilog-end-defun-re nil 'move))
4352 (defun verilog-get-end-of-defun ()
4353 (save-excursion
4354 (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t)
4355 (point))
4357 (error "%s: Can't find endmodule" (verilog-point-text))
4358 (point-max)))))
4360 (defun verilog-label-be ()
4361 "Label matching begin ... end, fork ... join and case ... endcase statements."
4362 (interactive)
4363 (let ((cnt 0)
4364 (case-fold-search nil)
4365 (oldpos (point))
4366 (b (progn
4367 (verilog-beg-of-defun)
4368 (point-marker)))
4369 (e (progn
4370 (verilog-end-of-defun)
4371 (point-marker))))
4372 (goto-char (marker-position b))
4373 (if (> (- e b) 200)
4374 (message "Relabeling module..."))
4375 (while (and
4376 (> (marker-position e) (point))
4377 (verilog-re-search-forward
4378 verilog-auto-end-comment-lines-re
4379 nil 'move))
4380 (goto-char (match-beginning 0))
4381 (let ((indent-str (verilog-indent-line)))
4382 (verilog-set-auto-endcomments indent-str 't)
4383 (end-of-line)
4384 (delete-horizontal-space))
4385 (setq cnt (1+ cnt))
4386 (if (= 9 (% cnt 10))
4387 (message "%d..." cnt)))
4388 (goto-char oldpos)
4389 (if (or
4390 (> (- e b) 200)
4391 (> cnt 20))
4392 (message "%d lines auto commented" cnt))))
4394 (defun verilog-beg-of-statement ()
4395 "Move backward to beginning of statement."
4396 (interactive)
4397 ;; Move back token by token until we see the end
4398 ;; of some earlier line.
4399 (let (h)
4400 (while
4401 ;; If the current point does not begin a new
4402 ;; statement, as in the character ahead of us is a ';', or SOF
4403 ;; or the string after us unambiguously starts a statement,
4404 ;; or the token before us unambiguously ends a statement,
4405 ;; then move back a token and test again.
4406 (not (or
4407 ;; stop if beginning of buffer
4408 (bobp)
4409 ;; stop if looking at a pre-processor directive
4410 (looking-at "`\\w+")
4411 ;; stop if we find a ;
4412 (= (preceding-char) ?\;)
4413 ;; stop if we see a named coverpoint
4414 (looking-at "\\w+\\W*:\\W*\\(coverpoint\\|cross\\|constraint\\)")
4415 ;; keep going if we are in the middle of a word
4416 (not (or (looking-at "\\<") (forward-word-strictly -1)))
4417 ;; stop if we see an assertion (perhaps labeled)
4418 (and
4419 (looking-at "\\(\\w+\\W*:\\W*\\)?\\(\\<\\(assert\\|assume\\|cover\\)\\>\\s-+\\<property\\>\\)\\|\\(\\<assert\\>\\)")
4420 (progn
4421 (setq h (point))
4422 (save-excursion
4423 (verilog-backward-token)
4424 (if (and (looking-at verilog-label-re)
4425 (not (looking-at verilog-end-block-re)))
4426 (setq h (point))))
4427 (goto-char h)))
4428 ;; stop if we see an extended complete reg, perhaps a complete one
4429 (and
4430 (looking-at verilog-complete-reg)
4431 (let* ((p (point)))
4432 (while (and (looking-at verilog-extended-complete-re)
4433 (progn (setq p (point))
4434 (verilog-backward-token)
4435 (/= p (point)))))
4436 (goto-char p)))
4437 ;; stop if we see a complete reg (previous found extended ones)
4438 (looking-at verilog-basic-complete-re)
4439 ;; stop if previous token is an ender
4440 (save-excursion
4441 (verilog-backward-token)
4442 (looking-at verilog-end-block-re))))
4443 (verilog-backward-syntactic-ws)
4444 (verilog-backward-token))
4445 ;; Now point is where the previous line ended.
4446 (verilog-forward-syntactic-ws)
4447 ;; Skip forward over any preprocessor directives, as they have wacky indentation
4448 (if (looking-at verilog-preprocessor-re)
4449 (progn (goto-char (match-end 0))
4450 (verilog-forward-syntactic-ws)))))
4452 (defun verilog-beg-of-statement-1 ()
4453 "Move backward to beginning of statement."
4454 (interactive)
4455 (if (verilog-in-comment-p)
4456 (verilog-backward-syntactic-ws))
4457 (let ((pt (point)))
4458 (catch 'done
4459 (while (not (looking-at verilog-complete-reg))
4460 (setq pt (point))
4461 (verilog-backward-syntactic-ws)
4462 (if (or (bolp)
4463 (= (preceding-char) ?\;)
4464 (progn
4465 (verilog-backward-token)
4466 (looking-at verilog-ends-re)))
4467 (progn
4468 (goto-char pt)
4469 (throw 'done t)))))
4470 (verilog-forward-syntactic-ws)))
4472 ;; (while (and
4473 ;; (not (looking-at verilog-complete-reg))
4474 ;; (not (bolp))
4475 ;; (not (= (preceding-char) ?\;)))
4476 ;; (verilog-backward-token)
4477 ;; (verilog-backward-syntactic-ws)
4478 ;; (setq pt (point)))
4479 ;; (goto-char pt)
4480 ;; ;(verilog-forward-syntactic-ws)
4482 (defun verilog-end-of-statement ()
4483 "Move forward to end of current statement."
4484 (interactive)
4485 (let ((nest 0) pos)
4486 (cond
4487 ((verilog-in-directive-p)
4488 (forward-line 1)
4489 (backward-char 1))
4491 ((looking-at verilog-beg-block-re)
4492 (verilog-forward-sexp))
4494 ((equal (char-after) ?\})
4495 (forward-char))
4497 ;; Skip to end of statement
4498 ((condition-case nil
4499 (setq pos
4500 (catch 'found
4501 (while t
4502 (forward-sexp 1)
4503 (verilog-skip-forward-comment-or-string)
4504 (if (eolp)
4505 (forward-line 1))
4506 (cond ((looking-at "[ \t]*;")
4507 (skip-chars-forward "^;")
4508 (forward-char 1)
4509 (throw 'found (point)))
4510 ((save-excursion
4511 (forward-sexp -1)
4512 (looking-at verilog-beg-block-re))
4513 (goto-char (match-beginning 0))
4514 (throw 'found nil))
4515 ((looking-at "[ \t]*)")
4516 (throw 'found (point)))
4517 ((eobp)
4518 (throw 'found (point)))
4522 (error nil))
4523 (if (not pos)
4524 ;; Skip a whole block
4525 (catch 'found
4526 (while t
4527 (verilog-re-search-forward verilog-end-statement-re nil 'move)
4528 (setq nest (if (match-end 1)
4529 (1+ nest)
4530 (1- nest)))
4531 (cond ((eobp)
4532 (throw 'found (point)))
4533 ((= 0 nest)
4534 (throw 'found (verilog-end-of-statement))))))
4535 pos)))))
4537 (defun verilog-in-case-region-p ()
4538 "Return true if in a case region.
4539 More specifically, point @ in the line foo : @ begin"
4540 (interactive)
4541 (save-excursion
4542 (if (and
4543 (progn (verilog-forward-syntactic-ws)
4544 (looking-at "\\<begin\\>"))
4545 (progn (verilog-backward-syntactic-ws)
4546 (= (preceding-char) ?\:)))
4547 (catch 'found
4548 (let ((nest 1))
4549 (while t
4550 (verilog-re-search-backward
4551 (concat "\\(\\<module\\>\\)\\|\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|"
4552 "\\(\\<endcase\\>\\)\\>")
4553 nil 'move)
4554 (cond
4555 ((match-end 3)
4556 (setq nest (1+ nest)))
4557 ((match-end 2)
4558 (if (= nest 1)
4559 (throw 'found 1))
4560 (setq nest (1- nest)))
4562 (throw 'found (= nest 0)))))))
4563 nil)))
4565 (defun verilog-backward-up-list (arg)
4566 "Call `backward-up-list' ARG, ignoring comments."
4567 (let ((parse-sexp-ignore-comments t))
4568 (backward-up-list arg)))
4570 (defun verilog-forward-sexp-cmt (arg)
4571 "Call `forward-sexp' ARG, inside comments."
4572 (let ((parse-sexp-ignore-comments nil))
4573 (forward-sexp arg)))
4575 (defun verilog-forward-sexp-ign-cmt (arg)
4576 "Call `forward-sexp' ARG, ignoring comments."
4577 (let ((parse-sexp-ignore-comments t))
4578 (forward-sexp arg)))
4580 (defun verilog-in-generate-region-p ()
4581 "Return true if in a generate region.
4582 More specifically, after a generate and before an endgenerate."
4583 (interactive)
4584 (let ((nest 1))
4585 (save-excursion
4586 (catch 'done
4587 (while (and
4588 (/= nest 0)
4589 (verilog-re-search-backward
4590 "\\<\\(module\\)\\|\\(generate\\)\\|\\(endgenerate\\)\\>" nil 'move)
4591 (cond
4592 ((match-end 1) ; module - we have crawled out
4593 (throw 'done 1))
4594 ((match-end 2) ; generate
4595 (setq nest (1- nest)))
4596 ((match-end 3) ; endgenerate
4597 (setq nest (1+ nest))))))))
4598 (= nest 0) )) ; return nest
4600 (defun verilog-in-fork-region-p ()
4601 "Return true if between a fork and join."
4602 (interactive)
4603 (let ((lim (save-excursion (verilog-beg-of-defun) (point)))
4604 (nest 1))
4605 (save-excursion
4606 (while (and
4607 (/= nest 0)
4608 (verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\(_any\\|_none\\)?\\)\\>" lim 'move)
4609 (cond
4610 ((match-end 1) ; fork
4611 (setq nest (1- nest)))
4612 ((match-end 2) ; join
4613 (setq nest (1+ nest)))))))
4614 (= nest 0) )) ; return nest
4616 (defun verilog-in-deferred-immediate-final-p ()
4617 "Return true if inside an `assert/assume/cover final' statement."
4618 (interactive)
4619 (and (looking-at "final")
4620 (verilog-looking-back "\\<\\(?:assert\\|assume\\|cover\\)\\>\\s-+" nil))
4623 (defun verilog-backward-case-item (lim)
4624 "Skip backward to nearest enclosing case item.
4625 Limit search to point LIM."
4626 (interactive)
4627 (let ((str 'nil)
4628 (lim1
4629 (progn
4630 (save-excursion
4631 (verilog-re-search-backward verilog-endcomment-reason-re
4632 lim 'move)
4633 (point)))))
4634 ;; Try to find the real :
4635 (if (save-excursion (search-backward ":" lim1 t))
4636 (let ((colon 0)
4637 b e )
4638 (while
4639 (and
4640 (< colon 1)
4641 (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)"
4642 lim1 'move))
4643 (cond
4644 ((match-end 1) ; [
4645 (setq colon (1+ colon))
4646 (if (>= colon 0)
4647 (error "%s: unbalanced [" (verilog-point-text))))
4648 ((match-end 2) ; ]
4649 (setq colon (1- colon)))
4651 ((match-end 3) ; :
4652 (setq colon (1+ colon)))))
4653 ;; Skip back to beginning of case item
4654 (skip-chars-backward "\t ")
4655 (verilog-skip-backward-comment-or-string)
4656 (setq e (point))
4657 (setq b
4658 (progn
4660 (verilog-re-search-backward
4661 "\\<\\(randcase\\|case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move)
4662 (progn
4663 (cond
4664 ((match-end 1)
4665 (goto-char (match-end 1))
4666 (verilog-forward-ws&directives)
4667 (if (looking-at "(")
4668 (progn
4669 (forward-sexp)
4670 (verilog-forward-ws&directives)))
4671 (point))
4673 (goto-char (match-end 0))
4674 (verilog-forward-ws&directives)
4675 (point))))
4676 (error "Malformed case item"))))
4677 (setq str (buffer-substring b e))
4679 (setq e
4680 (string-match
4681 "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
4682 (setq str (concat (substring str 0 e) "...")))
4683 str)
4684 'nil)))
4686 ;;; Other functions:
4689 (defun verilog-kill-existing-comment ()
4690 "Kill auto comment on this line."
4691 (save-excursion
4692 (let* (
4693 (e (progn
4694 (end-of-line)
4695 (point)))
4696 (b (progn
4697 (beginning-of-line)
4698 (search-forward "//" e t))))
4699 (if b
4700 (delete-region (- b 2) e)))))
4702 (defconst verilog-directive-nest-re
4703 (concat "\\(`else\\>\\)\\|"
4704 "\\(`endif\\>\\)\\|"
4705 "\\(`if\\>\\)\\|"
4706 "\\(`ifdef\\>\\)\\|"
4707 "\\(`ifndef\\>\\)\\|"
4708 "\\(`elsif\\>\\)"))
4710 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment)
4711 "Add ending comment with given INDENT-STR.
4712 With KILL-EXISTING-COMMENT, remove what was there before.
4713 Insert `// case: 7 ' or `// NAME ' on this line if appropriate.
4714 Insert `// case expr ' if this line ends a case block.
4715 Insert `// ifdef FOO ' if this line ends code conditional on FOO.
4716 Insert `// NAME ' if this line ends a function, task, module,
4717 primitive or interface named NAME."
4718 (save-excursion
4719 (cond
4720 (; Comment close preprocessor directives
4721 (and
4722 (looking-at "\\(`endif\\)\\|\\(`else\\)")
4723 (or kill-existing-comment
4724 (not (save-excursion
4725 (end-of-line)
4726 (search-backward "//" (point-at-bol) t)))))
4727 (let ((nest 1) b e
4729 (else (if (match-end 2) "!" " ")))
4730 (end-of-line)
4731 (if kill-existing-comment
4732 (verilog-kill-existing-comment))
4733 (delete-horizontal-space)
4734 (save-excursion
4735 (backward-sexp 1)
4736 (while (and (/= nest 0)
4737 (verilog-re-search-backward verilog-directive-nest-re nil 'move))
4738 (cond
4739 ((match-end 1) ; `else
4740 (if (= nest 1)
4741 (setq else "!")))
4742 ((match-end 2) ; `endif
4743 (setq nest (1+ nest)))
4744 ((match-end 3) ; `if
4745 (setq nest (1- nest)))
4746 ((match-end 4) ; `ifdef
4747 (setq nest (1- nest)))
4748 ((match-end 5) ; `ifndef
4749 (setq nest (1- nest)))
4750 ((match-end 6) ; `elsif
4751 (if (= nest 1)
4752 (progn
4753 (setq else "!")
4754 (setq nest 0))))))
4755 (if (match-end 0)
4756 (setq
4757 m (buffer-substring
4758 (match-beginning 0)
4759 (match-end 0))
4760 b (progn
4761 (skip-chars-forward "^ \t")
4762 (verilog-forward-syntactic-ws)
4763 (point))
4764 e (progn
4765 (skip-chars-forward "a-zA-Z0-9_")
4766 (point)))))
4767 (if b
4768 (if (> (count-lines (point) b) verilog-minimum-comment-distance)
4769 (insert (concat " // " else m " " (buffer-substring b e))))
4770 (progn
4771 (insert " // unmatched `else, `elsif or `endif")
4772 (ding 't)))))
4774 (; Comment close case/class/function/task/module and named block
4775 (and (looking-at "\\<end")
4776 (or kill-existing-comment
4777 (not (save-excursion
4778 (end-of-line)
4779 (search-backward "//" (point-at-bol) t)))))
4780 (let ((type (car indent-str)))
4781 (unless (eq type 'declaration)
4782 (unless (looking-at (concat "\\(" verilog-end-block-ordered-re "\\)[ \t]*:")) ; ignore named ends
4783 (if (looking-at verilog-end-block-ordered-re)
4784 (cond
4785 (;- This is a case block; search back for the start of this case
4786 (match-end 1) ; of verilog-end-block-ordered-re
4788 (let ((err 't)
4789 (str "UNMATCHED!!"))
4790 (save-excursion
4791 (verilog-leap-to-head)
4792 (cond
4793 ((looking-at "\\<randcase\\>")
4794 (setq str "randcase")
4795 (setq err nil))
4796 ((looking-at "\\(\\(unique0?\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
4797 (goto-char (match-end 0))
4798 (setq str (concat (match-string 0) " " (verilog-get-expr)))
4799 (setq err nil))
4801 (end-of-line)
4802 (if kill-existing-comment
4803 (verilog-kill-existing-comment))
4804 (delete-horizontal-space)
4805 (insert (concat " // " str ))
4806 (if err (ding 't))))
4808 (;- This is a begin..end block
4809 (match-end 2) ; of verilog-end-block-ordered-re
4810 (let ((str " // UNMATCHED !!")
4811 (err 't)
4812 (here (point))
4813 there
4814 cntx)
4815 (save-excursion
4816 (verilog-leap-to-head)
4817 (setq there (point))
4818 (if (not (match-end 0))
4819 (progn
4820 (goto-char here)
4821 (end-of-line)
4822 (if kill-existing-comment
4823 (verilog-kill-existing-comment))
4824 (delete-horizontal-space)
4825 (insert str)
4826 (ding 't))
4827 (let ((lim
4828 (save-excursion (verilog-beg-of-defun) (point)))
4829 (here (point)))
4830 (cond
4831 (;-- handle named block differently
4832 (looking-at verilog-named-block-re)
4833 (search-forward ":")
4834 (setq there (point))
4835 (setq str (verilog-get-expr))
4836 (setq err nil)
4837 (setq str (concat " // block: " str )))
4839 ((verilog-in-case-region-p) ;-- handle case item differently
4840 (goto-char here)
4841 (setq str (verilog-backward-case-item lim))
4842 (setq there (point))
4843 (setq err nil)
4844 (setq str (concat " // case: " str )))
4846 (;- try to find "reason" for this begin
4847 (cond
4849 (eq here (progn
4850 ;; (verilog-backward-token)
4851 (verilog-beg-of-statement)
4852 (point)))
4853 (setq err nil)
4854 (setq str ""))
4855 ((looking-at verilog-endcomment-reason-re)
4856 (setq there (match-end 0))
4857 (setq cntx (concat (match-string 0) " "))
4858 (cond
4859 (;- begin
4860 (match-end 1)
4861 (setq err nil)
4862 (save-excursion
4863 (if (and (verilog-continued-line)
4864 (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>"))
4865 (progn
4866 (goto-char (match-end 0))
4867 (setq there (point))
4868 (setq str
4869 (concat " // " (match-string 0) " " (verilog-get-expr))))
4870 (setq str ""))))
4872 (;- else
4873 (match-end 2)
4874 (let ((nest 0)
4875 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4876 (catch 'skip
4877 (while (verilog-re-search-backward reg nil 'move)
4878 (cond
4879 ((match-end 1) ; begin
4880 (setq nest (1- nest)))
4881 ((match-end 2) ; end
4882 (setq nest (1+ nest)))
4883 ((match-end 3)
4884 (if (= 0 nest)
4885 (progn
4886 (goto-char (match-end 0))
4887 (setq there (point))
4888 (setq err nil)
4889 (setq str (verilog-get-expr))
4890 (setq str (concat " // else: !if" str ))
4891 (throw 'skip 1))))
4892 ((match-end 4)
4893 (if (= 0 nest)
4894 (progn
4895 (goto-char (match-end 0))
4896 (setq there (point))
4897 (setq err nil)
4898 (setq str (verilog-get-expr))
4899 (setq str (concat " // else: !assert " str ))
4900 (throw 'skip 1)))))))))
4901 (;- end else
4902 (match-end 3)
4903 (goto-char there)
4904 (let ((nest 0)
4905 (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)\\|\\(assert\\)"))
4906 (catch 'skip
4907 (while (verilog-re-search-backward reg nil 'move)
4908 (cond
4909 ((match-end 1) ; begin
4910 (setq nest (1- nest)))
4911 ((match-end 2) ; end
4912 (setq nest (1+ nest)))
4913 ((match-end 3)
4914 (if (= 0 nest)
4915 (progn
4916 (goto-char (match-end 0))
4917 (setq there (point))
4918 (setq err nil)
4919 (setq str (verilog-get-expr))
4920 (setq str (concat " // else: !if" str ))
4921 (throw 'skip 1))))
4922 ((match-end 4)
4923 (if (= 0 nest)
4924 (progn
4925 (goto-char (match-end 0))
4926 (setq there (point))
4927 (setq err nil)
4928 (setq str (verilog-get-expr))
4929 (setq str (concat " // else: !assert " str ))
4930 (throw 'skip 1)))))))))
4932 (; always, always_comb, always_latch w/o @...
4933 (match-end 5)
4934 (goto-char (match-end 0))
4935 (setq there (point))
4936 (setq err nil)
4937 (setq str (concat " // " cntx )))
4939 (;- task/function/initial et cetera
4941 (match-end 0)
4942 (goto-char (match-end 0))
4943 (setq there (point))
4944 (setq err nil)
4945 (setq str (concat " // " cntx (verilog-get-expr))))
4947 (;-- otherwise...
4948 (setq str " // auto-endcomment confused "))))
4950 ((and
4951 (verilog-in-case-region-p) ;-- handle case item differently
4952 (progn
4953 (setq there (point))
4954 (goto-char here)
4955 (setq str (verilog-backward-case-item lim))))
4956 (setq err nil)
4957 (setq str (concat " // case: " str )))
4959 ((verilog-in-fork-region-p)
4960 (setq err nil)
4961 (setq str " // fork branch" ))
4963 ((looking-at "\\<end\\>")
4964 ;; HERE
4965 (forward-word-strictly 1)
4966 (verilog-forward-syntactic-ws)
4967 (setq err nil)
4968 (setq str (verilog-get-expr))
4969 (setq str (concat " // " cntx str )))
4971 ))))
4972 (goto-char here)
4973 (end-of-line)
4974 (if kill-existing-comment
4975 (verilog-kill-existing-comment))
4976 (delete-horizontal-space)
4977 (if (or err
4978 (> (count-lines here there) verilog-minimum-comment-distance))
4979 (insert str))
4980 (if err (ding 't))
4981 ))))
4982 (;- this is endclass, which can be nested
4983 (match-end 11) ; of verilog-end-block-ordered-re
4984 ;;(goto-char there)
4985 (let ((nest 0)
4986 (reg "\\<\\(class\\)\\|\\(endclass\\)\\|\\(package\\|primitive\\|\\(macro\\)?module\\)\\>")
4987 string)
4988 (save-excursion
4989 (catch 'skip
4990 (while (verilog-re-search-backward reg nil 'move)
4991 (cond
4992 ((match-end 3) ; endclass
4993 (ding 't)
4994 (setq string "unmatched endclass")
4995 (throw 'skip 1))
4997 ((match-end 2) ; endclass
4998 (setq nest (1+ nest)))
5000 ((match-end 1) ; class
5001 (setq nest (1- nest))
5002 (if (< nest 0)
5003 (progn
5004 (goto-char (match-end 0))
5005 (let (b e)
5006 (setq b (progn
5007 (skip-chars-forward "^ \t")
5008 (verilog-forward-ws&directives)
5009 (point))
5010 e (progn
5011 (skip-chars-forward "a-zA-Z0-9_")
5012 (point)))
5013 (setq string (buffer-substring b e)))
5014 (throw 'skip 1))))
5015 ))))
5016 (end-of-line)
5017 (if kill-existing-comment
5018 (verilog-kill-existing-comment))
5019 (delete-horizontal-space)
5020 (insert (concat " // " string ))))
5022 (; - this is end{function,generate,task,module,primitive,table,generate}
5023 ;; - which can not be nested.
5025 (let (string reg (name-re nil))
5026 (end-of-line)
5027 (if kill-existing-comment
5028 (save-match-data
5029 (verilog-kill-existing-comment)))
5030 (delete-horizontal-space)
5031 (backward-sexp)
5032 (cond
5033 ((match-end 5) ; of verilog-end-block-ordered-re
5034 (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
5035 (setq name-re "\\w+\\(?:\n\\|\\s-\\)*[(;]"))
5036 ((match-end 6) ; of verilog-end-block-ordered-re
5037 (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
5038 (setq name-re "\\w+\\(?:\n\\|\\s-\\)*[(;]"))
5039 ((match-end 7) ; of verilog-end-block-ordered-re
5040 (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>"))
5041 ((match-end 8) ; of verilog-end-block-ordered-re
5042 (setq reg "\\(\\<primitive\\>\\)\\|\\(\\<\\(endprimitive\\|package\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5043 ((match-end 9) ; of verilog-end-block-ordered-re
5044 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<\\(endinterface\\|package\\|primitive\\|\\(macro\\)?module\\)\\>\\)"))
5045 ((match-end 10) ; of verilog-end-block-ordered-re
5046 (setq reg "\\(\\<package\\>\\)\\|\\(\\<\\(endpackage\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5047 ((match-end 11) ; of verilog-end-block-ordered-re
5048 (setq reg "\\(\\<class\\>\\)\\|\\(\\<\\(endclass\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5049 ((match-end 12) ; of verilog-end-block-ordered-re
5050 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<\\(endcovergroup\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5051 ((match-end 13) ; of verilog-end-block-ordered-re
5052 (setq reg "\\(\\<program\\>\\)\\|\\(\\<\\(endprogram\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5053 ((match-end 14) ; of verilog-end-block-ordered-re
5054 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<\\(endsequence\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
5055 ((match-end 15) ; of verilog-end-block-ordered-re
5056 (setq reg "\\(\\<clocking\\>\\)\\|\\<endclocking\\>"))
5057 ((match-end 16) ; of verilog-end-block-ordered-re
5058 (setq reg "\\(\\<property\\>\\)\\|\\<endproperty\\>"))
5060 (t (error "Problem in verilog-set-auto-endcomments")))
5061 (let (b e)
5062 (save-excursion
5063 (verilog-re-search-backward reg nil 'move)
5064 (cond
5065 ((match-end 1)
5066 (setq b (progn
5067 (skip-chars-forward "^ \t")
5068 (verilog-forward-ws&directives)
5069 (if (looking-at "static\\|automatic")
5070 (progn
5071 (goto-char (match-end 0))
5072 (verilog-forward-ws&directives)))
5073 (if (and name-re (verilog-re-search-forward name-re nil 'move))
5074 (progn
5075 (goto-char (match-beginning 0))
5076 (verilog-forward-ws&directives)))
5077 (point))
5078 e (progn
5079 (skip-chars-forward "a-zA-Z0-9_")
5080 (point)))
5081 (setq string (buffer-substring b e)))
5083 (ding 't)
5084 (setq string "unmatched end(function|task|module|primitive|interface|package|class|clocking)")))))
5085 (end-of-line)
5086 (insert (concat " // " string )))
5087 ))))))))))
5089 (defun verilog-get-expr()
5090 "Grab expression at point, e.g., case ( a | b & (c ^d))."
5091 (let* ((b (progn
5092 (verilog-forward-syntactic-ws)
5093 (skip-chars-forward " \t")
5094 (point)))
5095 (e (let ((par 1))
5096 (cond
5097 ((looking-at "@")
5098 (forward-char 1)
5099 (verilog-forward-syntactic-ws)
5100 (if (looking-at "(")
5101 (progn
5102 (forward-char 1)
5103 (while (and (/= par 0)
5104 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
5105 (cond
5106 ((match-end 1)
5107 (setq par (1+ par)))
5108 ((match-end 2)
5109 (setq par (1- par)))))))
5110 (point))
5111 ((looking-at "(")
5112 (forward-char 1)
5113 (while (and (/= par 0)
5114 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
5115 (cond
5116 ((match-end 1)
5117 (setq par (1+ par)))
5118 ((match-end 2)
5119 (setq par (1- par)))))
5120 (point))
5121 ((looking-at "\\[")
5122 (forward-char 1)
5123 (while (and (/= par 0)
5124 (verilog-re-search-forward "\\(\\[\\)\\|\\(\\]\\)" nil 'move))
5125 (cond
5126 ((match-end 1)
5127 (setq par (1+ par)))
5128 ((match-end 2)
5129 (setq par (1- par)))))
5130 (verilog-forward-syntactic-ws)
5131 (skip-chars-forward "^ \t\n\f")
5132 (point))
5133 ((looking-at "/[/\\*]")
5136 (skip-chars-forward "^: \t\n\f")
5137 (point)))))
5138 (str (buffer-substring b e)))
5139 (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
5140 (setq str (concat (substring str 0 e) "...")))
5141 str))
5143 (defun verilog-expand-vector ()
5144 "Take a signal vector on the current line and expand it to multiple lines.
5145 Useful for creating tri's and other expanded fields."
5146 (interactive)
5147 (verilog-expand-vector-internal "[" "]"))
5149 (defun verilog-expand-vector-internal (bra ket)
5150 "Given BRA, the start brace and KET, the end brace, expand one line into many lines."
5151 (save-excursion
5152 (forward-line 0)
5153 (let ((signal-string (buffer-substring (point)
5154 (progn
5155 (end-of-line) (point)))))
5156 (if (string-match
5157 (concat "\\(.*\\)"
5158 (regexp-quote bra)
5159 "\\([0-9]*\\)\\(:[0-9]*\\|\\)\\(::[0-9---]*\\|\\)"
5160 (regexp-quote ket)
5161 "\\(.*\\)$") signal-string)
5162 (let* ((sig-head (match-string 1 signal-string))
5163 (vec-start (string-to-number (match-string 2 signal-string)))
5164 (vec-end (if (= (match-beginning 3) (match-end 3))
5165 vec-start
5166 (string-to-number
5167 (substring signal-string (1+ (match-beginning 3))
5168 (match-end 3)))))
5169 (vec-range
5170 (if (= (match-beginning 4) (match-end 4))
5172 (string-to-number
5173 (substring signal-string (+ 2 (match-beginning 4))
5174 (match-end 4)))))
5175 (sig-tail (match-string 5 signal-string))
5176 vec)
5177 ;; Decode vectors
5178 (setq vec nil)
5179 (if (< vec-range 0)
5180 (let ((tmp vec-start))
5181 (setq vec-start vec-end
5182 vec-end tmp
5183 vec-range (- vec-range))))
5184 (if (< vec-end vec-start)
5185 (while (<= vec-end vec-start)
5186 (setq vec (append vec (list vec-start)))
5187 (setq vec-start (- vec-start vec-range)))
5188 (while (<= vec-start vec-end)
5189 (setq vec (append vec (list vec-start)))
5190 (setq vec-start (+ vec-start vec-range))))
5192 ;; Delete current line
5193 (delete-region (point) (progn (forward-line 0) (point)))
5195 ;; Expand vector
5196 (while vec
5197 (insert (concat sig-head bra
5198 (int-to-string (car vec)) ket sig-tail "\n"))
5199 (setq vec (cdr vec)))
5200 (delete-char -1)
5202 )))))
5204 (defun verilog-strip-comments ()
5205 "Strip all comments from the Verilog code."
5206 (interactive)
5207 (goto-char (point-min))
5208 (while (re-search-forward "//" nil t)
5209 (if (verilog-within-string)
5210 (re-search-forward "\"" nil t)
5211 (if (verilog-in-star-comment-p)
5212 (re-search-forward "\\*/" nil t)
5213 (let ((bpt (- (point) 2)))
5214 (end-of-line)
5215 (delete-region bpt (point))))))
5217 (goto-char (point-min))
5218 (while (re-search-forward "/\\*" nil t)
5219 (if (verilog-within-string)
5220 (re-search-forward "\"" nil t)
5221 (let ((bpt (- (point) 2)))
5222 (re-search-forward "\\*/")
5223 (delete-region bpt (point))))))
5225 (defun verilog-one-line ()
5226 "Convert structural Verilog instances to occupy one line."
5227 (interactive)
5228 (goto-char (point-min))
5229 (while (re-search-forward "\\([^;]\\)[ \t]*\n[ \t]*" nil t)
5230 (replace-match "\\1 " nil nil)))
5232 (defun verilog-linter-name ()
5233 "Return name of linter, either surelint or verilint."
5234 (let ((compile-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
5235 compile-command))
5236 (lint-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
5237 verilog-linter)))
5238 (cond ((equal compile-word1 "surelint") `surelint)
5239 ((equal compile-word1 "verilint") `verilint)
5240 ((equal lint-word1 "surelint") `surelint)
5241 ((equal lint-word1 "verilint") `verilint)
5242 (t `surelint)))) ; back compatibility
5244 (defun verilog-lint-off ()
5245 "Convert a Verilog linter warning line into a disable statement.
5246 For example:
5247 pci_bfm_null.v, line 46: Unused input: pci_rst_
5248 becomes a comment for the appropriate tool.
5250 The first word of the `compile-command' or `verilog-linter'
5251 variables is used to determine which product is being used.
5253 See \\[verilog-surelint-off] and \\[verilog-verilint-off]."
5254 (interactive)
5255 (let ((linter (verilog-linter-name)))
5256 (cond ((equal linter `surelint)
5257 (verilog-surelint-off))
5258 ((equal linter `verilint)
5259 (verilog-verilint-off))
5260 (t (error "Linter name not set")))))
5262 (defvar compilation-last-buffer)
5263 (defvar next-error-last-buffer)
5265 (defun verilog-surelint-off ()
5266 "Convert a SureLint warning line into a disable statement.
5267 Run from Verilog source window; assumes there is a *compile* buffer
5268 with point set appropriately.
5270 For example:
5271 WARNING [STD-UDDONX]: xx.v, line 8: output out is never assigned.
5272 becomes:
5273 // surefire lint_line_off UDDONX"
5274 (interactive)
5275 (let ((buff (if (boundp 'next-error-last-buffer)
5276 next-error-last-buffer
5277 compilation-last-buffer)))
5278 (when (buffer-live-p buff)
5279 (save-excursion
5280 (switch-to-buffer buff)
5281 (beginning-of-line)
5282 (when
5283 (looking-at "\\(INFO\\|WARNING\\|ERROR\\) \\[[^-]+-\\([^]]+\\)\\]: \\([^,]+\\), line \\([0-9]+\\): \\(.*\\)$")
5284 (let* ((code (match-string 2))
5285 (file (match-string 3))
5286 (line (match-string 4))
5287 (buffer (get-file-buffer file))
5288 dir filename)
5289 (unless buffer
5290 (progn
5291 (setq buffer
5292 (and (file-exists-p file)
5293 (find-file-noselect file)))
5294 (or buffer
5295 (let* ((pop-up-windows t))
5296 (let ((name (expand-file-name
5297 (read-file-name
5298 (format "Find this error in: (default %s) "
5299 file)
5300 dir file t))))
5301 (if (file-directory-p name)
5302 (setq name (expand-file-name filename name)))
5303 (setq buffer
5304 (and (file-exists-p name)
5305 (find-file-noselect name))))))))
5306 (switch-to-buffer buffer)
5307 (goto-char (point-min))
5308 (forward-line (- (string-to-number line)))
5309 (end-of-line)
5310 (catch 'already
5311 (cond
5312 ((verilog-in-slash-comment-p)
5313 (re-search-backward "//")
5314 (cond
5315 ((looking-at "// surefire lint_off_line ")
5316 (goto-char (match-end 0))
5317 (let ((lim (point-at-eol)))
5318 (if (re-search-forward code lim 'move)
5319 (throw 'already t)
5320 (insert (concat " " code)))))
5323 ((verilog-in-star-comment-p)
5324 (re-search-backward "/\\*")
5325 (insert (format " // surefire lint_off_line %6s" code )))
5327 (insert (format " // surefire lint_off_line %6s" code ))
5328 )))))))))
5330 (defun verilog-verilint-off ()
5331 "Convert a Verilint warning line into a disable statement.
5333 For example:
5334 (W240) pci_bfm_null.v, line 46: Unused input: pci_rst_
5335 becomes:
5336 //Verilint 240 off // WARNING: Unused input"
5337 (interactive)
5338 (save-excursion
5339 (beginning-of-line)
5340 (when (looking-at "\\(.*\\)([WE]\\([0-9A-Z]+\\)).*,\\s +line\\s +[0-9]+:\\s +\\([^:\n]+\\):?.*$")
5341 (replace-match (format
5342 ;; %3s makes numbers 1-999 line up nicely
5343 "\\1//Verilint %3s off // WARNING: \\3"
5344 (match-string 2)))
5345 (beginning-of-line)
5346 (verilog-indent-line))))
5348 (defun verilog-auto-save-compile ()
5349 "Update automatics with \\[verilog-auto], save the buffer, and compile."
5350 (interactive)
5351 (verilog-auto) ; Always do it for safety
5352 (save-buffer)
5353 (compile compile-command))
5355 (defun verilog-preprocess (&optional command filename)
5356 "Preprocess the buffer, similar to `compile', but put output in Verilog-Mode.
5357 Takes optional COMMAND or defaults to `verilog-preprocessor', and
5358 FILENAME to find directory to run in, or defaults to `buffer-file-name'."
5359 (interactive
5360 (list
5361 (let ((default (verilog-expand-command verilog-preprocessor)))
5362 (set (make-local-variable `verilog-preprocessor)
5363 (read-from-minibuffer "Run Preprocessor (like this): "
5364 default nil nil
5365 'verilog-preprocess-history default)))))
5366 (unless command (setq command (verilog-expand-command verilog-preprocessor)))
5367 (let* ((fontlocked (and (boundp 'font-lock-mode) font-lock-mode))
5368 (dir (file-name-directory (or filename buffer-file-name)))
5369 (cmd (concat "cd " dir "; " command)))
5370 (with-output-to-temp-buffer "*Verilog-Preprocessed*"
5371 (with-current-buffer (get-buffer "*Verilog-Preprocessed*")
5372 (insert (concat "// " cmd "\n"))
5373 (call-process shell-file-name nil t nil shell-command-switch cmd)
5374 (verilog-mode)
5375 ;; Without this force, it takes a few idle seconds
5376 ;; to get the color, which is very jarring
5377 (unless (fboundp 'font-lock-ensure)
5378 ;; We should use font-lock-ensure in preference to
5379 ;; font-lock-fontify-buffer, but IIUC the problem this is supposed to
5380 ;; solve only appears in Emacsen older than font-lock-ensure anyway.
5381 ;; So avoid bytecomp's interactive-only by going through intern.
5382 (when fontlocked (funcall (intern "font-lock-fontify-buffer"))))))))
5384 ;;; Batch:
5387 (defun verilog-warn (string &rest args)
5388 "Print a warning with `format' using STRING and optional ARGS."
5389 (apply 'message (concat "%%Warning: " string) args))
5391 (defun verilog-warn-error (string &rest args)
5392 "Call `error' using STRING and optional ARGS.
5393 If `verilog-warn-fatal' is non-nil, call `verilog-warn' instead."
5394 (if verilog-warn-fatal
5395 (apply 'error string args)
5396 (apply 'verilog-warn string args)))
5398 (defmacro verilog-batch-error-wrapper (&rest body)
5399 "Execute BODY and add error prefix to any errors found.
5400 This lets programs calling batch mode to easily extract error messages."
5401 `(let ((verilog-warn-fatal nil))
5402 (condition-case err
5403 (progn ,@body)
5404 (error
5405 (error "%%Error: %s%s" (error-message-string err)
5406 (if (featurep 'xemacs) "\n" "")))))) ; XEmacs forgets to add a newline
5408 (defun verilog-batch-execute-func (funref &optional no-save)
5409 "Internal processing of a batch command.
5410 Runs FUNREF on all command arguments.
5411 Save the result unless optional NO-SAVE is t."
5412 (verilog-batch-error-wrapper
5413 ;; Setting global variables like that is *VERY NASTY* !!! --Stef
5414 ;; However, this function is called only when Emacs is being used as
5415 ;; a standalone language instead of as an editor, so we'll live.
5417 ;; General globals needed
5418 (setq make-backup-files nil)
5419 (setq-default make-backup-files nil)
5420 (setq enable-local-variables t)
5421 (setq enable-local-eval t)
5422 (setq create-lockfiles nil)
5423 ;; Make sure any sub-files we read get proper mode
5424 (setq-default major-mode 'verilog-mode)
5425 ;; Ditto files already read in
5426 ;; Remember buffer list, so don't later pickup any verilog-getopt files
5427 (let ((orig-buffer-list (buffer-list)))
5428 (mapc (lambda (buf)
5429 (when (buffer-file-name buf)
5430 (with-current-buffer buf
5431 (verilog-mode)
5432 (verilog-auto-reeval-locals)
5433 (verilog-getopt-flags))))
5434 orig-buffer-list)
5435 ;; Process the files
5436 (mapcar (lambda (buf)
5437 (when (buffer-file-name buf)
5438 (save-excursion
5439 (if (not (file-exists-p (buffer-file-name buf)))
5440 (error
5441 "File not found: %s" (buffer-file-name buf)))
5442 (message "Processing %s" (buffer-file-name buf))
5443 (set-buffer buf)
5444 (funcall funref)
5445 (when (and (not no-save)
5446 (buffer-modified-p)) ; Avoid "no changes to be saved"
5447 (save-buffer)))))
5448 orig-buffer-list))))
5450 (defun verilog-batch-auto ()
5451 "For use with --batch, perform automatic expansions as a stand-alone tool.
5452 This sets up the appropriate Verilog mode environment, updates automatics
5453 with \\[verilog-auto] on all command-line files, and saves the buffers.
5454 For proper results, multiple filenames need to be passed on the command
5455 line in bottom-up order."
5456 (unless noninteractive
5457 (error "Use verilog-batch-auto only with --batch")) ; Otherwise we'd mess up buffer modes
5458 (verilog-batch-execute-func `verilog-auto))
5460 (defun verilog-batch-delete-auto ()
5461 "For use with --batch, perform automatic deletion as a stand-alone tool.
5462 This sets up the appropriate Verilog mode environment, deletes automatics
5463 with \\[verilog-delete-auto] on all command-line files, and saves the buffers."
5464 (unless noninteractive
5465 (error "Use verilog-batch-delete-auto only with --batch")) ; Otherwise we'd mess up buffer modes
5466 (verilog-batch-execute-func `verilog-delete-auto))
5468 (defun verilog-batch-delete-trailing-whitespace ()
5469 "For use with --batch, perform whitespace deletion as a stand-alone tool.
5470 This sets up the appropriate Verilog mode environment, removes
5471 whitespace with \\[verilog-delete-trailing-whitespace] on all
5472 command-line files, and saves the buffers."
5473 (unless noninteractive
5474 (error "Use verilog-batch-delete-trailing-whitespace only with --batch")) ; Otherwise we'd mess up buffer modes
5475 (verilog-batch-execute-func `verilog-delete-trailing-whitespace))
5477 (defun verilog-batch-diff-auto ()
5478 "For use with --batch, perform automatic differences as a stand-alone tool.
5479 This sets up the appropriate Verilog mode environment, expand automatics
5480 with \\[verilog-diff-auto] on all command-line files, and reports an error
5481 if any differences are observed. This is appropriate for adding to regressions
5482 to insure automatics are always properly maintained."
5483 (unless noninteractive
5484 (error "Use verilog-batch-diff-auto only with --batch")) ; Otherwise we'd mess up buffer modes
5485 (verilog-batch-execute-func `verilog-diff-auto t))
5487 (defun verilog-batch-inject-auto ()
5488 "For use with --batch, perform automatic injection as a stand-alone tool.
5489 This sets up the appropriate Verilog mode environment, injects new automatics
5490 with \\[verilog-inject-auto] on all command-line files, and saves the buffers.
5491 For proper results, multiple filenames need to be passed on the command
5492 line in bottom-up order."
5493 (unless noninteractive
5494 (error "Use verilog-batch-inject-auto only with --batch")) ; Otherwise we'd mess up buffer modes
5495 (verilog-batch-execute-func `verilog-inject-auto))
5497 (defun verilog-batch-indent ()
5498 "For use with --batch, reindent an entire file as a stand-alone tool.
5499 This sets up the appropriate Verilog mode environment, calls
5500 \\[verilog-indent-buffer] on all command-line files, and saves the buffers."
5501 (unless noninteractive
5502 (error "Use verilog-batch-indent only with --batch")) ; Otherwise we'd mess up buffer modes
5503 (verilog-batch-execute-func `verilog-indent-buffer))
5505 ;;; Indentation:
5507 (defconst verilog-indent-alist
5508 '((block . (+ ind verilog-indent-level))
5509 (case . (+ ind verilog-case-indent))
5510 (cparenexp . (+ ind verilog-indent-level))
5511 (cexp . (+ ind verilog-cexp-indent))
5512 (defun . verilog-indent-level-module)
5513 (declaration . verilog-indent-level-declaration)
5514 (directive . (verilog-calculate-indent-directive))
5515 (tf . verilog-indent-level)
5516 (behavioral . (+ verilog-indent-level-behavioral verilog-indent-level-module))
5517 (statement . ind)
5518 (cpp . 0)
5519 (comment . (verilog-comment-indent))
5520 (unknown . 3)
5521 (string . 0)))
5523 (defun verilog-continued-line-1 (lim)
5524 "Return true if this is a continued line.
5525 Set point to where line starts. Limit search to point LIM."
5526 (let ((continued 't))
5527 (if (eq 0 (forward-line -1))
5528 (progn
5529 (end-of-line)
5530 (verilog-backward-ws&directives lim)
5531 (if (bobp)
5532 (setq continued nil)
5533 (setq continued (verilog-backward-token))))
5534 (setq continued nil))
5535 continued))
5537 (defun verilog-calculate-indent ()
5538 "Calculate the indent of the current Verilog line.
5539 Examine previous lines. Once a line is found that is definitive as to the
5540 type of the current line, return that lines' indent level and its type.
5541 Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
5542 (save-excursion
5543 (let* ((starting_position (point))
5544 (case-fold-search nil)
5545 (par 0)
5546 (begin (looking-at "[ \t]*begin\\>"))
5547 (lim (save-excursion (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil t)))
5548 (structres nil)
5549 (type (catch 'nesting
5550 ;; Keep working backwards until we can figure out
5551 ;; what type of statement this is.
5552 ;; Basically we need to figure out
5553 ;; 1) if this is a continuation of the previous line;
5554 ;; 2) are we in a block scope (begin..end)
5556 ;; if we are in a comment, done.
5557 (if (verilog-in-star-comment-p)
5558 (throw 'nesting 'comment))
5560 ;; if we have a directive, done.
5561 (if (save-excursion (beginning-of-line)
5562 (and (looking-at verilog-directive-re-1)
5563 (not (or (looking-at "[ \t]*`[ou]vm_")
5564 (looking-at "[ \t]*`vmm_")))))
5565 (throw 'nesting 'directive))
5566 ;; indent structs as if there were module level
5567 (setq structres (verilog-in-struct-nested-p))
5568 (cond ((not structres) nil)
5569 ;;((and structres (equal (char-after) ?\})) (throw 'nesting 'struct-close))
5570 ((> structres 0) (throw 'nesting 'nested-struct))
5571 ((= structres 0) (throw 'nesting 'block))
5572 (t nil))
5574 ;; if we are in a parenthesized list, and the user likes to indent these, return.
5575 ;; unless we are in the newfangled coverpoint or constraint blocks
5576 (if (and
5577 verilog-indent-lists
5578 (verilog-in-paren)
5579 (not (verilog-in-coverage-p))
5581 (progn (setq par 1)
5582 (throw 'nesting 'block)))
5584 ;; See if we are continuing a previous line
5585 (while t
5586 ;; trap out if we crawl off the top of the buffer
5587 (if (bobp) (throw 'nesting 'cpp))
5589 (if (and (verilog-continued-line-1 lim)
5590 (or (not (verilog-in-coverage-p))
5591 (looking-at verilog-in-constraint-re) )) ; may still get hosed if concat in constraint
5592 (let ((sp (point)))
5593 (if (and
5594 (not (looking-at verilog-complete-reg))
5595 (verilog-continued-line-1 lim))
5596 (progn (goto-char sp)
5597 (throw 'nesting 'cexp))
5599 (goto-char sp))
5600 (if (and (verilog-in-coverage-p)
5601 (looking-at verilog-in-constraint-re))
5602 (progn
5603 (beginning-of-line)
5604 (skip-chars-forward " \t")
5605 (throw 'nesting 'constraint)))
5606 (if (and begin
5607 (not verilog-indent-begin-after-if)
5608 (looking-at verilog-no-indent-begin-re))
5609 (progn
5610 (beginning-of-line)
5611 (skip-chars-forward " \t")
5612 (throw 'nesting 'statement))
5613 (progn
5614 (throw 'nesting 'cexp))))
5615 ;; not a continued line
5616 (goto-char starting_position))
5618 (if (looking-at "\\<else\\>")
5619 ;; search back for governing if, striding across begin..end pairs
5620 ;; appropriately
5621 (let ((elsec 1))
5622 (while (verilog-re-search-backward verilog-ends-re nil 'move)
5623 (cond
5624 ((match-end 1) ; else, we're in deep
5625 (setq elsec (1+ elsec)))
5626 ((match-end 2) ; if
5627 (setq elsec (1- elsec))
5628 (if (= 0 elsec)
5629 (if verilog-align-ifelse
5630 (throw 'nesting 'statement)
5631 (progn ; back up to first word on this line
5632 (beginning-of-line)
5633 (verilog-forward-syntactic-ws)
5634 (throw 'nesting 'statement)))))
5635 ((match-end 3) ; assert block
5636 (setq elsec (1- elsec))
5637 (verilog-beg-of-statement) ; doesn't get to beginning
5638 (if (looking-at verilog-property-re)
5639 (throw 'nesting 'statement) ; We don't need an endproperty for these
5640 (throw 'nesting 'block) ; We still need an endproperty
5642 (t ; endblock
5643 ;; try to leap back to matching outward block by striding across
5644 ;; indent level changing tokens then immediately
5645 ;; previous line governs indentation.
5646 (let (( reg) (nest 1))
5647 ;; verilog-ends => else|if|end|join(_any|_none|)|endcase|endclass|endtable|endspecify|endfunction|endtask|endgenerate|endgroup
5648 (cond
5649 ((match-end 4) ; end
5650 ;; Search back for matching begin
5651 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
5652 ((match-end 5) ; endcase
5653 ;; Search back for matching case
5654 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
5655 ((match-end 6) ; endfunction
5656 ;; Search back for matching function
5657 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
5658 ((match-end 7) ; endtask
5659 ;; Search back for matching task
5660 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" ))
5661 ((match-end 8) ; endspecify
5662 ;; Search back for matching specify
5663 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
5664 ((match-end 9) ; endtable
5665 ;; Search back for matching table
5666 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
5667 ((match-end 10) ; endgenerate
5668 ;; Search back for matching generate
5669 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
5670 ((match-end 11) ; joins
5671 ;; Search back for matching fork
5672 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|none\\)?\\>\\)" ))
5673 ((match-end 12) ; class
5674 ;; Search back for matching class
5675 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
5676 ((match-end 13) ; covergroup
5677 ;; Search back for matching covergroup
5678 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )))
5679 (catch 'skip
5680 (while (verilog-re-search-backward reg nil 'move)
5681 (cond
5682 ((match-end 1) ; begin
5683 (setq nest (1- nest))
5684 (if (= 0 nest)
5685 (throw 'skip 1)))
5686 ((match-end 2) ; end
5687 (setq nest (1+ nest)))))
5688 )))))))
5689 (throw 'nesting (verilog-calc-1)))
5690 ) ; catch nesting
5691 ) ; type
5693 ;; Return type of block and indent level.
5694 (if (not type)
5695 (setq type 'cpp))
5696 (if (> par 0) ; Unclosed Parenthesis
5697 (list 'cparenexp par)
5698 (cond
5699 ((eq type 'case)
5700 (list type (verilog-case-indent-level)))
5701 ((eq type 'statement)
5702 (list type (current-column)))
5703 ((eq type 'defun)
5704 (list type 0))
5705 ((eq type 'constraint)
5706 (list 'block (current-column)))
5707 ((eq type 'nested-struct)
5708 (list 'block structres))
5710 (list type (verilog-current-indent-level))))))))
5712 (defun verilog-wai ()
5713 "Show matching nesting block for debugging."
5714 (interactive)
5715 (save-excursion
5716 (let* ((type (verilog-calc-1))
5717 depth)
5718 ;; Return type of block and indent level.
5719 (if (not type)
5720 (setq type 'cpp))
5721 (if (and
5722 verilog-indent-lists
5723 (not(or (verilog-in-coverage-p)
5724 (verilog-in-struct-p)))
5725 (verilog-in-paren))
5726 (setq depth 1)
5727 (cond
5728 ((eq type 'case)
5729 (setq depth (verilog-case-indent-level)))
5730 ((eq type 'statement)
5731 (setq depth (current-column)))
5732 ((eq type 'defun)
5733 (setq depth 0))
5735 (setq depth (verilog-current-indent-level)))))
5736 (message "You are at nesting %s depth %d" type depth))))
5738 (defun verilog-calc-1 ()
5739 (catch 'nesting
5740 (let ((re (concat "\\({\\|}\\|" verilog-indent-re "\\)"))
5741 (inconstraint (verilog-in-coverage-p)))
5742 (while (verilog-re-search-backward re nil 'move)
5743 (catch 'continue
5744 (cond
5745 ((equal (char-after) ?\{)
5746 ;; block type returned based on outer constraint { or inner
5747 (if (verilog-at-constraint-p)
5748 (cond (inconstraint
5749 (beginning-of-line nil)
5750 (skip-chars-forward " \t")
5751 (throw 'nesting 'constraint))
5753 (throw 'nesting 'statement)))))
5754 ((equal (char-after) ?\})
5755 (let (par-pos
5756 (there (verilog-at-close-constraint-p)))
5757 (if there ; we are at the } that closes a constraint. Find the { that opens it
5758 (progn
5759 (if (> (verilog-in-paren-count) 0)
5760 (forward-char 1))
5761 (setq par-pos (verilog-parenthesis-depth))
5762 (cond (par-pos
5763 (goto-char par-pos)
5764 (forward-char 1))
5766 (backward-char 1)))))))
5768 ((looking-at verilog-beg-block-re-ordered)
5769 (cond
5770 ((match-end 2) ; *sigh* could be "unique case" or "priority casex"
5771 (let ((here (point)))
5772 (verilog-beg-of-statement)
5773 (if (looking-at verilog-extended-case-re)
5774 (throw 'nesting 'case)
5775 (goto-char here)))
5776 (throw 'nesting 'case))
5778 ((match-end 4) ; *sigh* could be "disable fork"
5779 (let ((here (point)))
5780 (verilog-beg-of-statement)
5781 (if (looking-at verilog-disable-fork-re)
5782 t ; this is a normal statement
5783 (progn ; or is fork, starts a new block
5784 (goto-char here)
5785 (throw 'nesting 'block)))))
5787 ((match-end 17) ; *sigh* might be a clocking declaration
5788 (let ((here (point)))
5789 (cond ((verilog-in-paren)
5790 t) ; this is a normal statement
5791 ((save-excursion
5792 (verilog-beg-of-statement)
5793 (looking-at verilog-default-clocking-re))
5794 t) ; default clocking, normal statement
5796 (goto-char here) ; or is clocking, starts a new block
5797 (throw 'nesting 'block)))))
5799 ((looking-at "\\<class\\|struct\\|function\\|task\\>")
5800 ;; *sigh* These words have an optional prefix:
5801 ;; extern {virtual|protected}? function a();
5802 ;; and we don't want to confuse this with
5803 ;; function a();
5804 ;; property
5805 ;; ...
5806 ;; endfunction
5807 (verilog-beg-of-statement)
5808 (cond
5809 ((looking-at verilog-dpi-import-export-re)
5810 (throw 'continue 'foo))
5811 ((or
5812 (looking-at "\\<pure\\>\\s-+\\<virtual\\>\\s-+\\(?:\\<\\(local\\|protected\\|static\\)\\>\\s-+\\)?\\<\\(function\\|task\\)\\>\\s-+")
5813 ;; Do not throw 'defun for class typedefs like
5814 ;; typedef class foo;
5815 (looking-at "\\<typedef\\>\\s-+\\(?:\\<virtual\\>\\s-+\\)?\\<class\\>\\s-+"))
5816 (throw 'nesting 'statement))
5817 ((looking-at verilog-beg-block-re-ordered)
5818 (throw 'nesting 'block))
5820 (throw 'nesting 'defun))))
5823 ((looking-at "\\<property\\>")
5824 ;; *sigh*
5825 ;; {assert|assume|cover} property (); are complete
5826 ;; and could also be labeled: - foo: assert property
5827 ;; but
5828 ;; property ID () ... needs end_property
5829 (verilog-beg-of-statement)
5830 (if (looking-at verilog-property-re)
5831 (throw 'continue 'statement) ; We don't need an endproperty for these
5832 (throw 'nesting 'block) ;We still need an endproperty
5835 (t (throw 'nesting 'block))))
5837 ((looking-at verilog-end-block-re)
5838 (verilog-leap-to-head)
5839 (if (verilog-in-case-region-p)
5840 (progn
5841 (verilog-leap-to-case-head)
5842 (if (looking-at verilog-extended-case-re)
5843 (throw 'nesting 'case)))))
5845 ((looking-at verilog-defun-level-re)
5846 (if (looking-at verilog-defun-level-generate-only-re)
5847 (if (or (verilog-in-generate-region-p)
5848 (verilog-in-deferred-immediate-final-p))
5849 (throw 'continue 'foo) ; always block in a generate - keep looking
5850 (throw 'nesting 'defun))
5851 (throw 'nesting 'defun)))
5853 ((looking-at verilog-cpp-level-re)
5854 (throw 'nesting 'cpp))
5856 ((bobp)
5857 (throw 'nesting 'cpp)))))
5859 (throw 'nesting 'cpp))))
5861 (defun verilog-calculate-indent-directive ()
5862 "Return indentation level for directive.
5863 For speed, the searcher looks at the last directive, not the indent
5864 of the appropriate enclosing block."
5865 (let ((base -1) ; Indent of the line that determines our indentation
5866 (ind 0)) ; Relative offset caused by other directives (like `endif on same line as `else)
5867 ;; Start at current location, scan back for another directive
5869 (save-excursion
5870 (beginning-of-line)
5871 (while (and (< base 0)
5872 (verilog-re-search-backward verilog-directive-re nil t))
5873 (cond ((save-excursion (skip-chars-backward " \t") (bolp))
5874 (setq base (current-indentation))))
5875 (cond ((and (looking-at verilog-directive-end) (< base 0)) ; Only matters when not at BOL
5876 (setq ind (- ind verilog-indent-level-directive)))
5877 ((and (looking-at verilog-directive-middle) (>= base 0)) ; Only matters when at BOL
5878 (setq ind (+ ind verilog-indent-level-directive)))
5879 ((looking-at verilog-directive-begin)
5880 (setq ind (+ ind verilog-indent-level-directive)))))
5881 ;; Adjust indent to starting indent of critical line
5882 (setq ind (max 0 (+ ind base))))
5884 (save-excursion
5885 (beginning-of-line)
5886 (skip-chars-forward " \t")
5887 (cond ((or (looking-at verilog-directive-middle)
5888 (looking-at verilog-directive-end))
5889 (setq ind (max 0 (- ind verilog-indent-level-directive))))))
5890 ind))
5892 (defun verilog-leap-to-case-head ()
5893 (let ((nest 1))
5894 (while (/= 0 nest)
5895 (verilog-re-search-backward
5896 (concat
5897 "\\(\\<randcase\\>\\|\\(\\<unique0?\\s-+\\|priority\\s-+\\)?\\<case[xz]?\\>\\)"
5898 "\\|\\(\\<endcase\\>\\)" )
5899 nil 'move)
5900 (cond
5901 ((match-end 1)
5902 (let ((here (point)))
5903 (verilog-beg-of-statement)
5904 (unless (looking-at verilog-extended-case-re)
5905 (goto-char here)))
5906 (setq nest (1- nest)))
5907 ((match-end 3)
5908 (setq nest (1+ nest)))
5909 ((bobp)
5910 (ding 't)
5911 (setq nest 0))))))
5913 (defun verilog-leap-to-head ()
5914 "Move point to the head of this block.
5915 Jump from end to matching begin, from endcase to matching case, and so on."
5916 (let ((reg nil)
5917 snest
5918 (nesting 'yes)
5919 (nest 1))
5920 (cond
5921 ((looking-at "\\<end\\>")
5922 ;; 1: Search back for matching begin
5923 (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|"
5924 "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))
5925 ((looking-at "\\<endtask\\>")
5926 ;; 2: Search back for matching task
5927 (setq reg "\\(\\<task\\>\\)\\|\\(\\(\\<\\(virtual\\|protected\\|static\\)\\>\\s-+\\)+\\<task\\>\\)")
5928 (setq nesting 'no))
5929 ((looking-at "\\<endcase\\>")
5930 (catch 'nesting
5931 (verilog-leap-to-case-head) )
5932 (setq reg nil) ; to force skip
5935 ((looking-at "\\<join\\(_any\\|_none\\)?\\>")
5936 ;; 4: Search back for matching fork
5937 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
5938 ((looking-at "\\<endclass\\>")
5939 ;; 5: Search back for matching class
5940 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
5941 ((looking-at "\\<endtable\\>")
5942 ;; 6: Search back for matching table
5943 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
5944 ((looking-at "\\<endspecify\\>")
5945 ;; 7: Search back for matching specify
5946 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
5947 ((looking-at "\\<endfunction\\>")
5948 ;; 8: Search back for matching function
5949 (setq reg "\\(\\<function\\>\\)\\|\\(\\(\\<\\(virtual\\|protected\\|static\\)\\>\\s-+\\)+\\<function\\>\\)")
5950 (setq nesting 'no))
5951 ;;(setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
5952 ((looking-at "\\<endgenerate\\>")
5953 ;; 8: Search back for matching generate
5954 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
5955 ((looking-at "\\<endgroup\\>")
5956 ;; 10: Search back for matching covergroup
5957 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
5958 ((looking-at "\\<endproperty\\>")
5959 ;; 11: Search back for matching property
5960 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
5961 ((looking-at verilog-uvm-end-re)
5962 ;; 12: Search back for matching sequence
5963 (setq reg (concat "\\(" verilog-uvm-begin-re "\\|" verilog-uvm-end-re "\\)")))
5964 ((looking-at verilog-ovm-end-re)
5965 ;; 12: Search back for matching sequence
5966 (setq reg (concat "\\(" verilog-ovm-begin-re "\\|" verilog-ovm-end-re "\\)")))
5967 ((looking-at verilog-vmm-end-re)
5968 ;; 12: Search back for matching sequence
5969 (setq reg (concat "\\(" verilog-vmm-begin-re "\\|" verilog-vmm-end-re "\\)")))
5970 ((looking-at "\\<endinterface\\>")
5971 ;; 12: Search back for matching interface
5972 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" ))
5973 ((looking-at "\\<endsequence\\>")
5974 ;; 12: Search back for matching sequence
5975 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ))
5976 ((looking-at "\\<endclocking\\>")
5977 ;; 12: Search back for matching clocking
5978 (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" )))
5979 (if reg
5980 (catch 'skip
5981 (if (eq nesting 'yes)
5982 (let (sreg)
5983 (while (verilog-re-search-backward reg nil 'move)
5984 (cond
5985 ((match-end 1) ; begin
5986 (if (looking-at "fork")
5987 (let ((here (point)))
5988 (verilog-beg-of-statement)
5989 (unless (looking-at verilog-disable-fork-re)
5990 (goto-char here)
5991 (setq nest (1- nest))))
5992 (setq nest (1- nest)))
5993 (if (= 0 nest)
5994 ;; Now previous line describes syntax
5995 (throw 'skip 1))
5996 (if (and snest
5997 (= snest nest))
5998 (setq reg sreg)))
5999 ((match-end 2) ; end
6000 (setq nest (1+ nest)))
6001 ((match-end 3)
6002 ;; endcase, jump to case
6003 (setq snest nest)
6004 (setq nest (1+ nest))
6005 (setq sreg reg)
6006 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
6007 ((match-end 4)
6008 ;; join, jump to fork
6009 (setq snest nest)
6010 (setq nest (1+ nest))
6011 (setq sreg reg)
6012 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
6014 ;; no nesting
6015 (if (and
6016 (verilog-re-search-backward reg nil 'move)
6017 (match-end 1)) ; task -> could be virtual and/or protected
6018 (progn
6019 (verilog-beg-of-statement)
6020 (throw 'skip 1))
6021 (throw 'skip 1)))))))
6023 (defun verilog-continued-line ()
6024 "Return true if this is a continued line.
6025 Set point to where line starts."
6026 (let ((continued 't))
6027 (if (eq 0 (forward-line -1))
6028 (progn
6029 (end-of-line)
6030 (verilog-backward-ws&directives)
6031 (if (bobp)
6032 (setq continued nil)
6033 (while (and continued
6034 (save-excursion
6035 (skip-chars-backward " \t")
6036 (not (bolp))))
6037 (setq continued (verilog-backward-token)))))
6038 (setq continued nil))
6039 continued))
6041 (defun verilog-backward-token ()
6042 "Step backward token, returning true if this is a continued line."
6043 (interactive)
6044 (verilog-backward-syntactic-ws)
6045 (cond
6046 ((bolp)
6047 nil)
6048 (;-- Anything ending in a ; is complete
6049 (= (preceding-char) ?\;)
6050 nil)
6051 (; If a "}" is prefixed by a ";", then this is a complete statement
6052 ;; i.e.: constraint foo { a = b; }
6053 (= (preceding-char) ?\})
6054 (progn
6055 (backward-char)
6056 (not(verilog-at-close-constraint-p))))
6057 (;-- constraint foo { a = b }
6058 ;; is a complete statement. *sigh*
6059 (= (preceding-char) ?\{)
6060 (progn
6061 (backward-char)
6062 (not (verilog-at-constraint-p))))
6063 (;" string "
6064 (= (preceding-char) ?\")
6065 (backward-char)
6066 (verilog-skip-backward-comment-or-string)
6067 nil)
6069 (; [3:4]
6070 (= (preceding-char) ?\])
6071 (backward-char)
6072 (verilog-backward-open-bracket)
6075 (;-- Could be 'case (foo)' or 'always @(bar)' which is complete
6076 ;; also could be simply '@(foo)'
6077 ;; or foo u1 #(a=8)
6078 ;; (b, ... which ISN'T complete
6079 ;; Do we need this???
6080 (= (preceding-char) ?\))
6081 (progn
6082 (backward-char)
6083 (verilog-backward-up-list 1)
6084 (verilog-backward-syntactic-ws)
6085 (let ((back (point)))
6086 (forward-word-strictly -1)
6087 (cond
6088 ;;XX
6089 ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>")
6090 (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]")))
6091 ((looking-at verilog-uvm-statement-re)
6092 nil)
6093 ((looking-at verilog-uvm-begin-re)
6095 ((looking-at verilog-uvm-end-re)
6097 ((looking-at verilog-ovm-statement-re)
6098 nil)
6099 ((looking-at verilog-ovm-begin-re)
6101 ((looking-at verilog-ovm-end-re)
6103 ;; JBA find VMM macros
6104 ((looking-at verilog-vmm-statement-re)
6105 nil )
6106 ((looking-at verilog-vmm-begin-re)
6108 ((looking-at verilog-vmm-end-re)
6109 nil)
6110 ;; JBA trying to catch macro lines with no ; at end
6111 ((looking-at "\\<`")
6112 nil)
6114 (goto-char back)
6115 (cond
6116 ((= (preceding-char) ?\@)
6117 (backward-char)
6118 (save-excursion
6119 (verilog-backward-token)
6120 (not (looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|initial\\|while\\)\\>"))))
6121 ((= (preceding-char) ?\#)
6122 (backward-char))
6123 (t t)))))))
6125 (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete
6127 (forward-word-strictly -1)
6128 (while (or (= (preceding-char) ?\_)
6129 (= (preceding-char) ?\@)
6130 (= (preceding-char) ?\.))
6131 (forward-word-strictly -1))
6132 (cond
6133 ((looking-at "\\<else\\>")
6135 ((looking-at verilog-behavioral-block-beg-re)
6137 ((looking-at verilog-indent-re)
6138 nil)
6140 (let
6141 ((back (point)))
6142 (verilog-backward-syntactic-ws)
6143 (cond
6144 ((= (preceding-char) ?\:)
6145 (backward-char)
6146 (verilog-backward-syntactic-ws)
6147 (backward-sexp)
6148 (if (looking-at verilog-nameable-item-re )
6151 ((= (preceding-char) ?\#)
6152 (backward-char)
6154 ((= (preceding-char) ?\`)
6155 (backward-char)
6159 (goto-char back)
6160 t))))))))
6162 (defun verilog-backward-syntactic-ws ()
6163 "Move backwards putting point after first non-whitespace non-comment."
6164 (verilog-skip-backward-comments)
6165 (forward-comment (- (buffer-size))))
6167 (defun verilog-backward-syntactic-ws-quick ()
6168 "As with `verilog-backward-syntactic-ws' but use `verilog-scan' cache."
6169 (while (cond ((bobp)
6170 nil) ; Done
6171 ((< (skip-syntax-backward " ") 0)
6173 ((eq (preceding-char) ?\n) ; \n's terminate // so aren't space syntax
6174 (forward-char -1)
6176 ((or (verilog-inside-comment-or-string-p (1- (point)))
6177 (verilog-inside-comment-or-string-p (point)))
6178 (re-search-backward "[/\"]" nil t) ; Only way a comment or quote can begin
6179 t))))
6181 (defun verilog-forward-syntactic-ws ()
6182 (verilog-skip-forward-comment-p)
6183 (forward-comment (buffer-size)))
6185 (defun verilog-backward-ws&directives (&optional bound)
6186 "Backward skip over syntactic whitespace and compiler directives for Emacs 19.
6187 Optional BOUND limits search."
6188 (save-restriction
6189 (let* ((bound (or bound (point-min)))
6190 (here bound)
6191 (p nil) )
6192 (if (< bound (point))
6193 (progn
6194 (let ((state (save-excursion (verilog-syntax-ppss))))
6195 (cond
6196 ((nth 7 state) ; in // comment
6197 (verilog-re-search-backward "//" nil 'move)
6198 (skip-chars-backward "/"))
6199 ((nth 4 state) ; in /* */ comment
6200 (verilog-re-search-backward "/\\*" nil 'move))))
6201 (narrow-to-region bound (point))
6202 (while (/= here (point))
6203 (setq here (point))
6204 (verilog-skip-backward-comments)
6205 (setq p
6206 (save-excursion
6207 (beginning-of-line)
6208 ;; for as long as we're right after a continued line, keep moving up
6209 (while (and (verilog-looking-back "\\\\[\n\r\f]" nil)
6210 (forward-line -1)))
6211 (cond
6212 ((and verilog-highlight-translate-off
6213 (verilog-within-translate-off))
6214 (verilog-back-to-start-translate-off (point-min)))
6215 ((looking-at verilog-directive-re-1)
6216 (point))
6218 nil))))
6219 (if p (goto-char p))))))))
6221 (defun verilog-forward-ws&directives (&optional bound)
6222 "Forward skip over syntactic whitespace and compiler directives for Emacs 19.
6223 Optional BOUND limits search."
6224 (save-restriction
6225 (let* ((bound (or bound (point-max)))
6226 (here bound)
6227 jump)
6228 (if (> bound (point))
6229 (progn
6230 (let ((state (save-excursion (verilog-syntax-ppss))))
6231 (cond
6232 ((nth 7 state) ; in // comment
6233 (end-of-line)
6234 (forward-char 1)
6235 (skip-chars-forward " \t\n\f")
6237 ((nth 4 state) ; in /* */ comment
6238 (verilog-re-search-forward "\\*/\\s-*" nil 'move))))
6239 (narrow-to-region (point) bound)
6240 (while (/= here (point))
6241 (setq here (point)
6242 jump nil)
6243 (forward-comment (buffer-size))
6244 (and (looking-at "\\s-*(\\*.*\\*)\\s-*") ; Attribute
6245 (goto-char (match-end 0)))
6246 (save-excursion
6247 (beginning-of-line)
6248 (if (looking-at verilog-directive-re-1)
6249 (setq jump t)))
6250 (if jump
6251 (beginning-of-line 2))))))))
6253 (defun verilog-in-comment-p ()
6254 "Return true if in a star or // comment."
6255 (let ((state (save-excursion (verilog-syntax-ppss))))
6256 (or (nth 4 state) (nth 7 state))))
6258 (defun verilog-in-star-comment-p ()
6259 "Return true if in a star comment."
6260 (let ((state (save-excursion (verilog-syntax-ppss))))
6261 (and
6262 (nth 4 state) ; t if in a comment of style a // or b /**/
6263 (not
6264 (nth 7 state) ; t if in a comment of style b /**/
6265 ))))
6267 (defun verilog-in-slash-comment-p ()
6268 "Return true if in a slash comment."
6269 (let ((state (save-excursion (verilog-syntax-ppss))))
6270 (nth 7 state)))
6272 (defun verilog-in-comment-or-string-p ()
6273 "Return true if in a string or comment."
6274 (let ((state (save-excursion (verilog-syntax-ppss))))
6275 (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment)
6277 (defun verilog-in-attribute-p ()
6278 "Return true if point is in an attribute (* [] attribute *)."
6279 (save-match-data
6280 (save-excursion
6281 (verilog-re-search-backward "\\((\\*\\)\\|\\(\\*)\\)" nil 'move)
6282 (cond
6283 ((match-end 1)
6284 (progn (goto-char (match-end 1))
6285 (not (looking-at "\\s-*)")))
6286 nil)
6287 ((match-end 2)
6288 (progn (goto-char (match-beginning 2))
6289 (not (looking-at "(\\s-*")))
6290 nil)
6291 (t nil)))))
6293 (defun verilog-in-parameter-p ()
6294 "Return true if point is in a parameter assignment #( p1=1, p2=5)."
6295 (save-match-data
6296 (save-excursion
6297 (verilog-re-search-backward "\\(#(\\)\\|\\()\\)" nil 'move)
6298 (numberp (match-beginning 1)))))
6300 (defun verilog-in-escaped-name-p ()
6301 "Return true if in an escaped name."
6302 (save-excursion
6303 (backward-char)
6304 (skip-chars-backward "^ \t\n\f")
6305 (if (equal (char-after (point) ) ?\\ )
6307 nil)))
6309 (defun verilog-in-directive-p ()
6310 "Return true if in a directive."
6311 (save-excursion
6312 (beginning-of-line)
6313 (looking-at verilog-directive-re-1)))
6315 (defun verilog-in-parenthesis-p ()
6316 "Return true if in a ( ) expression (but not { } or [ ])."
6317 (save-match-data
6318 (save-excursion
6319 (verilog-re-search-backward "\\((\\)\\|\\()\\)" nil 'move)
6320 (numberp (match-beginning 1)))))
6322 (defun verilog-in-paren ()
6323 "Return true if in a parenthetical expression.
6324 May cache result using `verilog-syntax-ppss'."
6325 (let ((state (save-excursion (verilog-syntax-ppss))))
6326 (> (nth 0 state) 0 )))
6328 (defun verilog-in-paren-count ()
6329 "Return paren depth, floor to 0.
6330 May cache result using `verilog-syntax-ppss'."
6331 (let ((state (save-excursion (verilog-syntax-ppss))))
6332 (if (> (nth 0 state) 0)
6333 (nth 0 state)
6334 0 )))
6336 (defun verilog-in-paren-quick ()
6337 "Return true if in a parenthetical expression.
6338 Always starts from `point-min', to allow inserts with hooks disabled."
6339 ;; The -quick refers to its use alongside the other -quick functions,
6340 ;; not that it's likely to be faster than verilog-in-paren.
6341 (let ((state (save-excursion (parse-partial-sexp (point-min) (point)))))
6342 (> (nth 0 state) 0 )))
6344 (defun verilog-in-struct-p ()
6345 "Return true if in a struct declaration."
6346 (interactive)
6347 (save-excursion
6348 (if (verilog-in-paren)
6349 (progn
6350 (verilog-backward-up-list 1)
6351 (verilog-at-struct-p)
6353 nil)))
6355 (defun verilog-in-struct-nested-p ()
6356 "Return nil for not in struct.
6357 Return 0 for in non-nested struct.
6358 Return >0 for nested struct."
6359 (interactive)
6360 (let (col)
6361 (save-excursion
6362 (if (verilog-in-paren)
6363 (progn
6364 (verilog-backward-up-list 1)
6365 (setq col (verilog-at-struct-mv-p))
6366 (if col
6367 (if (verilog-in-struct-p) (current-column) 0)))
6368 nil))))
6370 (defun verilog-in-coverage-p ()
6371 "Return true if in a constraint or coverpoint expression."
6372 (interactive)
6373 (save-excursion
6374 (if (verilog-in-paren)
6375 (progn
6376 (verilog-backward-up-list 1)
6377 (verilog-at-constraint-p)
6379 nil)))
6381 (defun verilog-at-close-constraint-p ()
6382 "If at the } that closes a constraint or covergroup, return true."
6383 (if (and
6384 (equal (char-after) ?\})
6385 (verilog-in-coverage-p))
6387 (save-excursion
6388 (verilog-backward-ws&directives)
6389 (if (or (equal (char-before) ?\;)
6390 (equal (char-before) ?\}) ; can end with inner constraint { } block or ;
6391 (equal (char-before) ?\{)) ; empty constraint block
6392 (point)
6393 nil))))
6395 (defun verilog-at-constraint-p ()
6396 "If at the { of a constraint or coverpoint definition, return true, moving point to constraint."
6397 (if (save-excursion
6398 (let ((p (point)))
6399 (and
6400 (equal (char-after) ?\{)
6401 (ignore-errors (forward-list))
6402 (progn (backward-char 1)
6403 (verilog-backward-ws&directives)
6404 (and
6405 (or (equal (char-before) ?\{) ; empty case
6406 (equal (char-before) ?\;)
6407 (equal (char-before) ?\}))
6408 ;; skip what looks like bus repetition operator {#{
6409 (not (string-match "^{\\s-*[0-9]+\\s-*{" (buffer-substring p (point)))))))))
6410 (progn
6411 (let ( (pt (point)) (pass 0))
6412 (verilog-backward-ws&directives)
6413 (verilog-backward-token)
6414 (if (looking-at (concat "\\<constraint\\|coverpoint\\|cross\\|with\\>\\|" verilog-in-constraint-re))
6415 (progn (setq pass 1)
6416 (if (looking-at "\\<with\\>")
6417 (progn (verilog-backward-ws&directives)
6418 (beginning-of-line) ; 1
6419 (verilog-forward-ws&directives)
6421 (verilog-beg-of-statement)
6423 ;; if first word token not keyword, it maybe the instance name
6424 ;; check next word token
6425 (if (looking-at "\\<\\w+\\>\\|\\s-*(\\s-*\\S-+")
6426 (progn (verilog-beg-of-statement)
6427 (if (looking-at (concat "\\<\\(constraint\\|"
6428 "\\(?:\\w+\\s-*:\\s-*\\)?\\(coverpoint\\|cross\\)"
6429 "\\|with\\)\\>\\|" verilog-in-constraint-re))
6430 (setq pass 1)))))
6431 (if (eq pass 0)
6432 (progn (goto-char pt) nil) 1)))
6433 ;; not
6434 nil))
6436 (defun verilog-at-struct-p ()
6437 "If at the { of a struct, return true, not moving point."
6438 (save-excursion
6439 (if (and (equal (char-after) ?\{)
6440 (verilog-backward-token))
6441 (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
6442 nil)))
6444 (defun verilog-at-struct-mv-p ()
6445 "If at the { of a struct, return true, moving point to struct."
6446 (let ((pt (point)))
6447 (if (and (equal (char-after) ?\{)
6448 (verilog-backward-token))
6449 (if (looking-at "\\<struct\\|union\\|packed\\|\\(un\\)?signed\\>")
6450 (progn (verilog-beg-of-statement) (point))
6451 (progn (goto-char pt) nil))
6452 (progn (goto-char pt) nil))))
6454 (defun verilog-at-close-struct-p ()
6455 "If at the } that closes a struct, return true."
6456 (if (and
6457 (equal (char-after) ?\})
6458 (verilog-in-struct-p))
6459 ;; true
6460 (save-excursion
6461 (if (looking-at "}\\(?:\\s-*\\w+\\s-*\\)?;") 1))
6462 ;; false
6463 nil))
6465 (defun verilog-parenthesis-depth ()
6466 "Return non zero if in parenthetical-expression."
6467 (save-excursion (nth 1 (verilog-syntax-ppss))))
6470 (defun verilog-skip-forward-comment-or-string ()
6471 "Return true if in a string or comment."
6472 (let ((state (save-excursion (verilog-syntax-ppss))))
6473 (cond
6474 ((nth 3 state) ;Inside string
6475 (search-forward "\"")
6477 ((nth 7 state) ;Inside // comment
6478 (forward-line 1)
6480 ((nth 4 state) ;Inside any comment (hence /**/)
6481 (search-forward "*/"))
6483 nil))))
6485 (defun verilog-skip-backward-comment-or-string ()
6486 "Return true if in a string or comment."
6487 (let ((state (save-excursion (verilog-syntax-ppss))))
6488 (cond
6489 ((nth 3 state) ;Inside string
6490 (search-backward "\"")
6492 ((nth 7 state) ;Inside // comment
6493 (search-backward "//")
6494 (skip-chars-backward "/")
6496 ((nth 4 state) ;Inside /* */ comment
6497 (search-backward "/*")
6500 nil))))
6502 (defun verilog-skip-backward-comments ()
6503 "Return true if a comment was skipped."
6504 (let ((more t))
6505 (while more
6506 (setq more
6507 (let ((state (save-excursion (verilog-syntax-ppss))))
6508 (cond
6509 ((nth 7 state) ;Inside // comment
6510 (search-backward "//")
6511 (skip-chars-backward "/")
6512 (skip-chars-backward " \t\n\f")
6514 ((nth 4 state) ;Inside /* */ comment
6515 (search-backward "/*")
6516 (skip-chars-backward " \t\n\f")
6518 ((and (not (bobp))
6519 (= (char-before) ?\/)
6520 (= (char-before (1- (point))) ?\*))
6521 (goto-char (- (point) 2))
6522 t) ; Let nth 4 state handle the rest
6523 ((and (not (bobp))
6524 ;;(verilog-looking-back "\\*)" nil) ;; super slow, use two char-before instead
6525 (= (char-before) ?\))
6526 (= (char-before (1- (point))) ?\*)
6527 (not (verilog-looking-back "(\\s-*\\*)" nil))) ;; slow but unlikely to be called
6528 (goto-char (- (point) 2))
6529 (if (search-backward "(*" nil t)
6530 (progn
6531 (skip-chars-backward " \t\n\f")
6533 (progn
6534 (goto-char (+ (point) 2))
6535 nil)))
6537 (/= (skip-chars-backward " \t\n\f") 0))))))))
6539 (defun verilog-skip-forward-comment-p ()
6540 "If in comment, move to end and return true."
6541 (let* (h
6542 (state (save-excursion (verilog-syntax-ppss)))
6543 (skip (cond
6544 ((nth 3 state) ;Inside string
6546 ((nth 7 state) ;Inside // comment
6547 (end-of-line)
6548 (forward-char 1)
6550 ((nth 4 state) ;Inside /* comment
6551 (search-forward "*/")
6553 ((verilog-in-attribute-p) ;Inside (* attribute
6554 (search-forward "*)" nil t)
6556 (t nil))))
6557 (skip-chars-forward " \t\n\f")
6558 (while
6559 (cond
6560 ((looking-at "\\/\\*")
6561 (progn
6562 (setq h (point))
6563 (goto-char (match-end 0))
6564 (if (search-forward "*/" nil t)
6565 (progn
6566 (skip-chars-forward " \t\n\f")
6567 (setq skip 't))
6568 (progn
6569 (goto-char h)
6570 nil))))
6571 ((and (looking-at "(\\*") ; attribute start, but not an event (*) or (* )
6572 (not (looking-at "(\\*\\s-*)")))
6573 (progn
6574 (setq h (point))
6575 (goto-char (match-end 0))
6576 (if (search-forward "*)" nil t)
6577 (progn
6578 (skip-chars-forward " \t\n\f")
6579 (setq skip 't))
6580 (progn
6581 (goto-char h)
6582 nil))))
6583 (t nil)))
6584 skip))
6586 (defun verilog-indent-line-relative ()
6587 "Cheap version of indent line.
6588 Only look at a few lines to determine indent level."
6589 (interactive)
6590 (let ((indent-str)
6591 (sp (point)))
6592 (if (looking-at "^[ \t]*$")
6593 (cond ;- A blank line; No need to be too smart.
6594 ((bobp)
6595 (setq indent-str (list 'cpp 0)))
6596 ((verilog-continued-line)
6597 (let ((sp1 (point)))
6598 (if (verilog-continued-line)
6599 (progn
6600 (goto-char sp)
6601 (setq indent-str
6602 (list 'statement (verilog-current-indent-level))))
6603 (goto-char sp1)
6604 (setq indent-str (list 'block (verilog-current-indent-level)))))
6605 (goto-char sp))
6606 ((goto-char sp)
6607 (setq indent-str (verilog-calculate-indent))))
6608 (progn (skip-chars-forward " \t")
6609 (setq indent-str (verilog-calculate-indent))))
6610 (verilog-do-indent indent-str)))
6612 (defun verilog-indent-line ()
6613 "Indent for special part of code."
6614 (verilog-do-indent (verilog-calculate-indent)))
6616 (defun verilog-do-indent (indent-str)
6617 (let ((type (car indent-str))
6618 (ind (car (cdr indent-str))))
6619 (cond
6620 (; handle continued exp
6621 (eq type 'cexp)
6622 (let ((here (point)))
6623 (verilog-backward-syntactic-ws)
6624 (cond
6625 ((or
6626 (= (preceding-char) ?\,)
6627 (save-excursion
6628 (verilog-beg-of-statement-1)
6629 (looking-at verilog-declaration-re)))
6630 (let* ( fst
6631 (val
6632 (save-excursion
6633 (backward-char 1)
6634 (verilog-beg-of-statement-1)
6635 (setq fst (point))
6636 (if (looking-at verilog-declaration-re)
6637 (progn ; we have multiple words
6638 (goto-char (match-end 0))
6639 (skip-chars-forward " \t")
6640 (cond
6641 ((and verilog-indent-declaration-macros
6642 (= (following-char) ?\`))
6643 (progn
6644 (forward-char 1)
6645 (forward-word-strictly 1)
6646 (skip-chars-forward " \t")))
6647 ((= (following-char) ?\[)
6648 (progn
6649 (forward-char 1)
6650 (verilog-backward-up-list -1)
6651 (skip-chars-forward " \t"))))
6652 (current-column))
6653 (progn
6654 (goto-char fst)
6655 (+ (current-column) verilog-cexp-indent))))))
6656 (goto-char here)
6657 (indent-line-to val)
6658 (if (and (not verilog-indent-lists)
6659 (verilog-in-paren))
6660 (verilog-pretty-declarations-auto))
6662 ((= (preceding-char) ?\) )
6663 (goto-char here)
6664 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6665 (indent-line-to val)))
6667 (goto-char here)
6668 (let ((val))
6669 (verilog-beg-of-statement-1)
6670 (if (and (< (point) here)
6671 (verilog-re-search-forward "=[ \t]*" here 'move)
6672 ;; not at a |=>, #=#, or [=n] operator
6673 (not (string-match "\\[=.\\|#=#\\||=>"
6674 (or (buffer-substring (- (point) 2) (1+ (point)))
6675 "")))) ; don't let buffer over/under-run spoil the party
6676 (setq val (current-column))
6677 (setq val (eval (cdr (assoc type verilog-indent-alist)))))
6678 (goto-char here)
6679 (indent-line-to val))))))
6681 (; handle inside parenthetical expressions
6682 (eq type 'cparenexp)
6683 (let* ( here
6684 (val (save-excursion
6685 (verilog-backward-up-list 1)
6686 (forward-char 1)
6687 (if verilog-indent-lists
6688 (skip-chars-forward " \t")
6689 (verilog-forward-syntactic-ws))
6690 (setq here (point))
6691 (current-column)))
6693 (decl (save-excursion
6694 (goto-char here)
6695 (verilog-forward-syntactic-ws)
6696 (setq here (point))
6697 (looking-at verilog-declaration-re))))
6698 (indent-line-to val)
6699 (if decl
6700 (verilog-pretty-declarations-auto))))
6702 (;-- Handle the ends
6704 (looking-at verilog-end-block-re)
6705 (verilog-at-close-constraint-p)
6706 (verilog-at-close-struct-p))
6707 (let ((val (if (eq type 'statement)
6708 (- ind verilog-indent-level)
6709 ind)))
6710 (indent-line-to val)))
6712 (;-- Case -- maybe line 'em up
6713 (and (eq type 'case) (not (looking-at "^[ \t]*$")))
6714 (progn
6715 (cond
6716 ((looking-at "\\<endcase\\>")
6717 (indent-line-to ind))
6719 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6720 (indent-line-to val))))))
6722 (;-- defun
6723 (and (eq type 'defun)
6724 (looking-at verilog-zero-indent-re))
6725 (indent-line-to 0))
6727 (;-- declaration
6728 (and (or
6729 (eq type 'defun)
6730 (eq type 'block))
6731 (looking-at verilog-declaration-re)
6732 ;; Do not consider "virtual function", "virtual task", "virtual class"
6733 ;; as declarations
6734 (not (looking-at (concat verilog-declaration-re
6735 "\\s-+\\(function\\|task\\|class\\)\\b"))))
6736 (verilog-indent-declaration ind))
6738 (;-- form feeds - ignored as bug in indent-line-to in < 24.5
6739 (looking-at "\f"))
6741 (;-- Everything else
6743 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
6744 (indent-line-to val))))
6746 (if (looking-at "[ \t]+$")
6747 (skip-chars-forward " \t"))
6748 indent-str ; Return indent data
6751 (defun verilog-current-indent-level ()
6752 "Return the indent-level of the current statement."
6753 (save-excursion
6754 (let (par-pos)
6755 (beginning-of-line)
6756 (setq par-pos (verilog-parenthesis-depth))
6757 (while par-pos
6758 (goto-char par-pos)
6759 (beginning-of-line)
6760 (setq par-pos (verilog-parenthesis-depth)))
6761 (skip-chars-forward " \t")
6762 (current-column))))
6764 (defun verilog-case-indent-level ()
6765 "Return the indent-level of the current statement.
6766 Do not count named blocks or case-statements."
6767 (save-excursion
6768 (skip-chars-forward " \t")
6769 (cond
6770 ((looking-at verilog-named-block-re)
6771 (current-column))
6772 ((and (not (looking-at verilog-extended-case-re))
6773 (looking-at "^[^:;]+[ \t]*:"))
6774 (verilog-re-search-forward ":" nil t)
6775 (skip-chars-forward " \t")
6776 (current-column))
6778 (current-column)))))
6780 (defun verilog-indent-comment ()
6781 "Indent current line as comment."
6782 (let* ((stcol
6783 (cond
6784 ((verilog-in-star-comment-p)
6785 (save-excursion
6786 (re-search-backward "/\\*" nil t)
6787 (1+(current-column))))
6788 (comment-column
6789 comment-column )
6791 (save-excursion
6792 (re-search-backward "//" nil t)
6793 (current-column))))))
6794 (indent-line-to stcol)
6795 stcol))
6797 (defun verilog-more-comment ()
6798 "Make more comment lines like the previous."
6799 (let* ((star 0)
6800 (stcol
6801 (cond
6802 ((verilog-in-star-comment-p)
6803 (save-excursion
6804 (setq star 1)
6805 (re-search-backward "/\\*" nil t)
6806 (1+(current-column))))
6807 (comment-column
6808 comment-column )
6810 (save-excursion
6811 (re-search-backward "//" nil t)
6812 (current-column))))))
6813 (progn
6814 (indent-to stcol)
6815 (if (and star
6816 (save-excursion
6817 (forward-line -1)
6818 (skip-chars-forward " \t")
6819 (looking-at "\\*")))
6820 (insert "* ")))))
6822 (defun verilog-comment-indent (&optional _arg)
6823 "Return the column number the line should be indented to.
6824 _ARG is ignored, for `comment-indent-function' compatibility."
6825 (cond
6826 ((verilog-in-star-comment-p)
6827 (save-excursion
6828 (re-search-backward "/\\*" nil t)
6829 (1+(current-column))))
6830 ( comment-column
6831 comment-column )
6833 (save-excursion
6834 (re-search-backward "//" nil t)
6835 (current-column)))))
6839 (defun verilog-pretty-declarations-auto (&optional quiet)
6840 "Call `verilog-pretty-declarations' QUIET based on `verilog-auto-lineup'."
6841 (when (or (eq 'all verilog-auto-lineup)
6842 (eq 'declarations verilog-auto-lineup))
6843 (verilog-pretty-declarations quiet)))
6845 (defun verilog-pretty-declarations (&optional quiet)
6846 "Line up declarations around point.
6847 Be verbose about progress unless optional QUIET set."
6848 (interactive)
6849 (let* ((m1 (make-marker))
6850 (e (point))
6853 (here (point))
6855 start
6856 startpos
6858 endpos
6859 base-ind
6861 (save-excursion
6862 (if (progn
6863 ;; (verilog-beg-of-statement-1)
6864 (beginning-of-line)
6865 (verilog-forward-syntactic-ws)
6866 (and (not (verilog-in-directive-p)) ; could have `define input foo
6867 (looking-at verilog-declaration-re)))
6868 (progn
6869 (if (verilog-parenthesis-depth)
6870 ;; in an argument list or parameter block
6871 (setq el (verilog-backward-up-list -1)
6872 start (progn
6873 (goto-char e)
6874 (verilog-backward-up-list 1)
6875 (forward-line) ; ignore ( input foo,
6876 (verilog-re-search-forward verilog-declaration-re el 'move)
6877 (goto-char (match-beginning 0))
6878 (skip-chars-backward " \t")
6879 (point))
6880 startpos (set-marker (make-marker) start)
6881 end (progn
6882 (goto-char start)
6883 (verilog-backward-up-list -1)
6884 (forward-char -1)
6885 (verilog-backward-syntactic-ws)
6886 (point))
6887 endpos (set-marker (make-marker) end)
6888 base-ind (progn
6889 (goto-char start)
6890 (forward-char 1)
6891 (skip-chars-forward " \t")
6892 (current-column)))
6893 ;; in a declaration block (not in argument list)
6894 (setq
6895 start (progn
6896 (verilog-beg-of-statement-1)
6897 (while (and (looking-at verilog-declaration-re)
6898 (not (bobp)))
6899 (skip-chars-backward " \t")
6900 (setq e (point))
6901 (beginning-of-line)
6902 (verilog-backward-syntactic-ws)
6903 (backward-char)
6904 (verilog-beg-of-statement-1))
6906 startpos (set-marker (make-marker) start)
6907 end (progn
6908 (goto-char here)
6909 (verilog-end-of-statement)
6910 (setq e (point)) ;Might be on last line
6911 (verilog-forward-syntactic-ws)
6912 (while (looking-at verilog-declaration-re)
6913 (verilog-end-of-statement)
6914 (setq e (point))
6915 (verilog-forward-syntactic-ws))
6917 endpos (set-marker (make-marker) end)
6918 base-ind (progn
6919 (goto-char start)
6920 (verilog-do-indent (verilog-calculate-indent))
6921 (verilog-forward-ws&directives)
6922 (current-column))))
6923 ;; OK, start and end are set
6924 (goto-char (marker-position startpos))
6925 (if (and (not quiet)
6926 (> (- end start) 100))
6927 (message "Lining up declarations..(please stand by)"))
6928 ;; Get the beginning of line indent first
6929 (while (progn (setq e (marker-position endpos))
6930 (< (point) e))
6931 (cond
6932 ((save-excursion (skip-chars-backward " \t")
6933 (bolp))
6934 (verilog-forward-ws&directives)
6935 (indent-line-to base-ind)
6936 (verilog-forward-ws&directives)
6937 (if (< (point) e)
6938 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
6940 (just-one-space)
6941 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
6942 ;;(forward-line)
6944 ;; Now find biggest prefix
6945 (setq ind (verilog-get-lineup-indent (marker-position startpos) endpos))
6946 ;; Now indent each line.
6947 (goto-char (marker-position startpos))
6948 (while (progn (setq e (marker-position endpos))
6949 (setq r (- e (point)))
6950 (> r 0))
6951 (setq e (point))
6952 (unless quiet (message "%d" r))
6953 ;; (verilog-do-indent (verilog-calculate-indent)))
6954 (verilog-forward-ws&directives)
6955 (cond
6956 ((or (and verilog-indent-declaration-macros
6957 (looking-at verilog-declaration-re-2-macro))
6958 (looking-at verilog-declaration-re-2-no-macro))
6959 (let ((p (match-end 0)))
6960 (set-marker m1 p)
6961 (if (verilog-re-search-forward "[[#`]" p 'move)
6962 (progn
6963 (forward-char -1)
6964 (just-one-space)
6965 (goto-char (marker-position m1))
6966 (just-one-space)
6967 (indent-to ind))
6968 (progn
6969 (just-one-space)
6970 (indent-to ind)))))
6971 ((verilog-continued-line-1 (marker-position startpos))
6972 (goto-char e)
6973 (indent-line-to ind))
6974 ((verilog-in-struct-p)
6975 ;; could have a declaration of a user defined item
6976 (goto-char e)
6977 (verilog-end-of-statement))
6978 (t ; Must be comment or white space
6979 (goto-char e)
6980 (verilog-forward-ws&directives)
6981 (forward-line -1)))
6982 (forward-line 1))
6983 (unless quiet (message "")))))))
6985 (defun verilog-pretty-expr (&optional quiet)
6986 "Line up expressions around point.
6987 If QUIET is non-nil, do not print messages showing the progress of line-up."
6988 (interactive)
6989 (unless (verilog-in-comment-or-string-p)
6990 (save-excursion
6991 (let ((regexp (concat "^\\s-*" verilog-complete-reg))
6992 (regexp1 (concat "^\\s-*" verilog-basic-complete-re)))
6993 (beginning-of-line)
6994 (when (and (not (looking-at regexp))
6995 (looking-at verilog-assignment-operation-re)
6996 (save-excursion
6997 (goto-char (match-end 2))
6998 (and (not (verilog-in-attribute-p))
6999 (not (verilog-in-parameter-p))
7000 (not (verilog-in-comment-or-string-p)))))
7001 (let* ((start (save-excursion ; BOL of the first line of the assignment block
7002 (beginning-of-line)
7003 (let ((pt (point)))
7004 (verilog-backward-syntactic-ws)
7005 (beginning-of-line)
7006 (while (and (not (looking-at regexp1))
7007 (looking-at verilog-assignment-operation-re)
7008 (not (bobp)))
7009 (setq pt (point))
7010 (verilog-backward-syntactic-ws)
7011 (beginning-of-line)) ; Ack, need to grok `define
7012 pt)))
7013 (end (save-excursion ; EOL of the last line of the assignment block
7014 (end-of-line)
7015 (let ((pt (point))) ; Might be on last line
7016 (verilog-forward-syntactic-ws)
7017 (beginning-of-line)
7018 (while (and
7019 (not (looking-at regexp1))
7020 (looking-at verilog-assignment-operation-re)
7021 (progn
7022 (end-of-line)
7023 (not (eq pt (point)))))
7024 (setq pt (point))
7025 (verilog-forward-syntactic-ws)
7026 (beginning-of-line))
7027 pt)))
7028 (contains-2-char-operator (string-match "<=" (buffer-substring-no-properties start end)))
7029 (endmark (set-marker (make-marker) end)))
7030 (goto-char start)
7031 (verilog-do-indent (verilog-calculate-indent))
7032 (when (and (not quiet)
7033 (> (- end start) 100))
7034 (message "Lining up expressions.. (please stand by)"))
7036 ;; Set indent to minimum throughout region
7037 ;; Rely on mark rather than on point as the indentation changes can
7038 ;; make the older point reference obsolete
7039 (while (< (point) (marker-position endmark))
7040 (beginning-of-line)
7041 (save-excursion
7042 (verilog-just-one-space verilog-assignment-operation-re))
7043 (verilog-do-indent (verilog-calculate-indent))
7044 (end-of-line)
7045 (verilog-forward-syntactic-ws))
7047 (let ((ind (verilog-get-lineup-indent-2 verilog-assignment-operation-re start (marker-position endmark))) ; Find the biggest prefix
7049 ;; Now indent each line.
7050 (goto-char start)
7051 (while (progn
7052 (setq e (marker-position endmark))
7053 (> e (point)))
7054 (unless quiet
7055 (message " verilog-pretty-expr: %d" (- e (point))))
7056 (setq e (point))
7057 (cond
7058 ((looking-at verilog-assignment-operation-re)
7059 (goto-char (match-beginning 2))
7060 (unless (or (verilog-in-parenthesis-p) ; Leave attributes and comparisons alone
7061 (verilog-in-coverage-p))
7062 (if (and contains-2-char-operator
7063 (eq (char-after) ?=))
7064 (indent-to (1+ ind)) ; Line up the = of the <= with surrounding =
7065 (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)))
7073 (forward-line 1))
7074 (unless quiet
7075 (message "")))))))))
7077 (defun verilog-just-one-space (myre)
7078 "Remove extra spaces around regular expression MYRE."
7079 (interactive)
7080 (if (and (not(looking-at verilog-complete-reg))
7081 (looking-at myre))
7082 (let ((p1 (match-end 1))
7083 (p2 (match-end 2)))
7084 (progn
7085 (goto-char p2)
7086 (just-one-space)
7087 (goto-char p1)
7088 (just-one-space)))))
7090 (defun verilog-indent-declaration (baseind)
7091 "Indent current lines as declaration.
7092 Line up the variable names based on previous declaration's indentation.
7093 BASEIND is the base indent to offset everything."
7094 (interactive)
7095 (let ((pos (point-marker))
7096 (lim (save-excursion
7097 ;; (verilog-re-search-backward verilog-declaration-opener nil 'move)
7098 (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)\\|\\(\\<task\\>\\)" nil 'move)
7099 (point)))
7100 (ind)
7101 (val)
7102 (m1 (make-marker)))
7103 (setq val
7104 (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist)))))
7105 (indent-line-to val)
7107 ;; Use previous declaration (in this module) as template.
7108 (if (or (eq 'all verilog-auto-lineup)
7109 (eq 'declarations verilog-auto-lineup))
7110 (if (verilog-re-search-backward
7111 (or (and verilog-indent-declaration-macros
7112 verilog-declaration-re-1-macro)
7113 verilog-declaration-re-1-no-macro) lim t)
7114 (progn
7115 (goto-char (match-end 0))
7116 (skip-chars-forward " \t")
7117 (setq ind (current-column))
7118 (goto-char pos)
7119 (setq val
7120 (+ baseind
7121 (eval (cdr (assoc 'declaration verilog-indent-alist)))))
7122 (indent-line-to val)
7123 (if (and verilog-indent-declaration-macros
7124 (looking-at verilog-declaration-re-2-macro))
7125 (let ((p (match-end 0)))
7126 (set-marker m1 p)
7127 (if (verilog-re-search-forward "[[#`]" p 'move)
7128 (progn
7129 (forward-char -1)
7130 (just-one-space)
7131 (goto-char (marker-position m1))
7132 (just-one-space)
7133 (indent-to ind))
7134 (if (/= (current-column) ind)
7135 (progn
7136 (just-one-space)
7137 (indent-to ind)))))
7138 (if (looking-at verilog-declaration-re-2-no-macro)
7139 (let ((p (match-end 0)))
7140 (set-marker m1 p)
7141 (if (verilog-re-search-forward "[[`#]" p 'move)
7142 (progn
7143 (forward-char -1)
7144 (just-one-space)
7145 (goto-char (marker-position m1))
7146 (just-one-space)
7147 (indent-to ind))
7148 (if (/= (current-column) ind)
7149 (progn
7150 (just-one-space)
7151 (indent-to ind))))))))))
7152 (goto-char pos)))
7154 (defun verilog-get-lineup-indent (b edpos)
7155 "Return the indent level that will line up several lines within the region.
7156 Region is defined by B and EDPOS."
7157 (save-excursion
7158 (let ((ind 0) e)
7159 (goto-char b)
7160 ;; Get rightmost position
7161 (while (progn (setq e (marker-position edpos))
7162 (< (point) e))
7163 (if (verilog-re-search-forward
7164 (or (and verilog-indent-declaration-macros
7165 verilog-declaration-re-1-macro)
7166 verilog-declaration-re-1-no-macro) e 'move)
7167 (progn
7168 (goto-char (match-end 0))
7169 (verilog-backward-syntactic-ws)
7170 (if (> (current-column) ind)
7171 (setq ind (current-column)))
7172 (goto-char (match-end 0)))))
7173 (if (> ind 0)
7174 (1+ ind)
7175 ;; No lineup-string found
7176 (goto-char b)
7177 (end-of-line)
7178 (verilog-backward-syntactic-ws)
7179 ;;(skip-chars-backward " \t")
7180 (1+ (current-column))))))
7182 (defun verilog-get-lineup-indent-2 (regexp beg end)
7183 "Return the indent level that will line up several lines.
7184 The lineup string is searched using REGEXP within the region between points
7185 BEG and END."
7186 (save-excursion
7187 (let ((ind 0))
7188 (goto-char beg)
7189 ;; Get rightmost position
7190 (while (< (point) end)
7191 (when (and (verilog-re-search-forward regexp end 'move)
7192 (not (verilog-in-attribute-p))) ; skip attribute exprs
7193 (goto-char (match-beginning 2))
7194 (verilog-backward-syntactic-ws)
7195 (if (> (current-column) ind)
7196 (setq ind (current-column)))
7197 (goto-char (match-end 0))))
7198 (setq ind (if (> ind 0)
7199 (1+ ind)
7200 ;; No lineup-string found
7201 (goto-char beg)
7202 (end-of-line)
7203 (skip-chars-backward " \t")
7204 (1+ (current-column))))
7205 ind)))
7207 (defun verilog-comment-depth (type val)
7208 "A useful mode debugging aide. TYPE and VAL are comments for insertion."
7209 (save-excursion
7210 (let
7211 ((b (prog2
7212 (beginning-of-line)
7213 (point-marker)
7214 (end-of-line))))
7215 (if (re-search-backward " /\\* [#-]# [a-zA-Z]+ [0-9]+ ## \\*/" b t)
7216 (progn
7217 (replace-match " /* -# ## */")
7218 (end-of-line))
7219 (progn
7220 (end-of-line)
7221 (insert " /* ## ## */"))))
7222 (backward-char 6)
7223 (insert
7224 (format "%s %d" type val))))
7227 ;;; Completion:
7229 (defvar verilog-str nil)
7230 (defvar verilog-all nil)
7231 (defvar verilog-pred nil)
7232 (defvar verilog-buffer-to-use nil)
7233 (defvar verilog-flag nil)
7234 (defvar verilog-toggle-completions nil
7235 "True means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one.
7236 Repeated use of \\[verilog-complete-word] will show you all of them.
7237 Normally, when there is more than one possible completion,
7238 it displays a list of all possible completions.")
7239 (when (boundp 'completion-cycle-threshold)
7240 (make-obsolete-variable
7241 'verilog-toggle-completions 'completion-cycle-threshold "26.1"))
7244 (defvar verilog-type-keywords
7246 "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input"
7247 "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0"
7248 "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pulldown" "pullup"
7249 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0"
7250 "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
7251 "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor"
7253 "Keywords for types used when completing a word in a declaration or parmlist.
7254 \(integer, real, reg...)")
7256 (defvar verilog-cpp-keywords
7257 '("module" "macromodule" "primitive" "timescale" "define" "ifdef" "ifndef" "else"
7258 "endif")
7259 "Keywords to complete when at first word of a line in declarative scope.
7260 \(initial, always, begin, assign...)
7261 The procedures and variables defined within the Verilog program
7262 will be completed at runtime and should not be added to this list.")
7264 (defvar verilog-defun-keywords
7265 (append
7267 "always" "always_comb" "always_ff" "always_latch" "assign"
7268 "begin" "end" "generate" "endgenerate" "module" "endmodule"
7269 "specify" "endspecify" "function" "endfunction" "initial" "final"
7270 "task" "endtask" "primitive" "endprimitive"
7272 verilog-type-keywords)
7273 "Keywords to complete when at first word of a line in declarative scope.
7274 \(initial, always, begin, assign...)
7275 The procedures and variables defined within the Verilog program
7276 will be completed at runtime and should not be added to this list.")
7278 (defvar verilog-block-keywords
7280 "begin" "break" "case" "continue" "else" "end" "endfunction"
7281 "endgenerate" "endinterface" "endpackage" "endspecify" "endtask"
7282 "for" "fork" "if" "join" "join_any" "join_none" "repeat" "return"
7283 "while")
7284 "Keywords to complete when at first word of a line in behavioral scope.
7285 \(begin, if, then, else, for, fork...)
7286 The procedures and variables defined within the Verilog program
7287 will be completed at runtime and should not be added to this list.")
7289 (defvar verilog-tf-keywords
7290 '("begin" "break" "fork" "join" "join_any" "join_none" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat")
7291 "Keywords to complete when at first word of a line in a task or function.
7292 \(begin, if, then, else, for, fork.)
7293 The procedures and variables defined within the Verilog program
7294 will be completed at runtime and should not be added to this list.")
7296 (defvar verilog-case-keywords
7297 '("begin" "fork" "join" "join_any" "join_none" "case" "end" "endcase" "if" "else" "for" "repeat")
7298 "Keywords to complete when at first word of a line in case scope.
7299 \(begin, if, then, else, for, fork...)
7300 The procedures and variables defined within the Verilog program
7301 will be completed at runtime and should not be added to this list.")
7303 (defvar verilog-separator-keywords
7304 '("else" "then" "begin")
7305 "Keywords to complete when NOT standing at the first word of a statement.
7306 \(else, then, begin...)
7307 Variables and function names defined within the Verilog program
7308 will be completed at runtime and should not be added to this list.")
7310 (defvar verilog-gate-ios
7311 ;; All these have an implied {"input"...} at the end
7312 '(("and" "output")
7313 ("buf" "output")
7314 ("bufif0" "output")
7315 ("bufif1" "output")
7316 ("cmos" "output")
7317 ("nand" "output")
7318 ("nmos" "output")
7319 ("nor" "output")
7320 ("not" "output")
7321 ("notif0" "output")
7322 ("notif1" "output")
7323 ("or" "output")
7324 ("pmos" "output")
7325 ("pulldown" "output")
7326 ("pullup" "output")
7327 ("rcmos" "output")
7328 ("rnmos" "output")
7329 ("rpmos" "output")
7330 ("rtran" "inout" "inout")
7331 ("rtranif0" "inout" "inout")
7332 ("rtranif1" "inout" "inout")
7333 ("tran" "inout" "inout")
7334 ("tranif0" "inout" "inout")
7335 ("tranif1" "inout" "inout")
7336 ("xnor" "output")
7337 ("xor" "output"))
7338 "Map of direction for each positional argument to each gate primitive.")
7340 (defvar verilog-gate-keywords (mapcar `car verilog-gate-ios)
7341 "Keywords for gate primitives.")
7343 (defun verilog-string-diff (str1 str2)
7344 "Return index of first letter where STR1 and STR2 differs."
7345 (catch 'done
7346 (let ((diff 0))
7347 (while t
7348 (if (or (> (1+ diff) (length str1))
7349 (> (1+ diff) (length str2)))
7350 (throw 'done diff))
7351 (or (equal (aref str1 diff) (aref str2 diff))
7352 (throw 'done diff))
7353 (setq diff (1+ diff))))))
7355 ;; Calculate all possible completions for functions if argument is `function',
7356 ;; completions for procedures if argument is `procedure' or both functions and
7357 ;; procedures otherwise.
7359 (defun verilog-func-completion (type)
7360 "Build regular expression for module/task/function names.
7361 TYPE is `module', `tf' for task or function, or t if unknown."
7362 (if (string= verilog-str "")
7363 (setq verilog-str "[a-zA-Z_]"))
7364 (let ((verilog-str (concat (cond
7365 ((eq type 'module) "\\<\\(module\\)\\s +")
7366 ((eq type 'tf) "\\<\\(task\\|function\\)\\s +")
7367 (t "\\<\\(task\\|function\\|module\\)\\s +"))
7368 "\\<\\(" verilog-str "[a-zA-Z0-9_.]*\\)\\>"))
7369 match)
7371 (if (not (looking-at verilog-defun-re))
7372 (verilog-re-search-backward verilog-defun-re nil t))
7373 (forward-char 1)
7375 ;; Search through all reachable functions
7376 (goto-char (point-min))
7377 (while (verilog-re-search-forward verilog-str (point-max) t)
7378 (progn (setq match (buffer-substring (match-beginning 2)
7379 (match-end 2)))
7380 (if (or (null verilog-pred)
7381 (funcall verilog-pred match))
7382 (setq verilog-all (cons match verilog-all)))))
7383 (if (match-beginning 0)
7384 (goto-char (match-beginning 0)))))
7386 (defun verilog-get-completion-decl (end)
7387 "Macro for searching through current declaration (var, type or const)
7388 for matches of `str' and adding the occurrence tp `all' through point END."
7389 (let ((re (or (and verilog-indent-declaration-macros
7390 verilog-declaration-re-2-macro)
7391 verilog-declaration-re-2-no-macro))
7392 decl-end match)
7393 ;; Traverse lines
7394 (while (and (< (point) end)
7395 (verilog-re-search-forward re end t))
7396 ;; Traverse current line
7397 (setq decl-end (save-excursion (verilog-declaration-end)))
7398 (while (and (verilog-re-search-forward verilog-symbol-re decl-end t)
7399 (not (match-end 1)))
7400 (setq match (buffer-substring (match-beginning 0) (match-end 0)))
7401 (if (string-match (concat "\\<" verilog-str) match)
7402 (if (or (null verilog-pred)
7403 (funcall verilog-pred match))
7404 (setq verilog-all (cons match verilog-all)))))
7405 (forward-line 1)))
7406 verilog-all)
7408 (defun verilog-var-completion ()
7409 "Calculate all possible completions for variables (or constants)."
7410 (let ((start (point)))
7411 ;; Search for all reachable var declarations
7412 (verilog-beg-of-defun)
7413 (save-excursion
7414 ;; Check var declarations
7415 (verilog-get-completion-decl start))))
7417 (defun verilog-keyword-completion (keyword-list)
7418 "Give list of all possible completions of keywords in KEYWORD-LIST."
7419 (mapcar (lambda (s)
7420 (if (string-match (concat "\\<" verilog-str) s)
7421 (if (or (null verilog-pred)
7422 (funcall verilog-pred s))
7423 (setq verilog-all (cons s verilog-all)))))
7424 keyword-list))
7427 (defun verilog-completion (verilog-str verilog-pred verilog-flag)
7428 "Function passed to `completing-read', `try-completion' or `all-completions'.
7429 Called to get completion on VERILOG-STR. If VERILOG-PRED is non-nil, it
7430 must be a function to be called for every match to check if this should
7431 really be a match. If VERILOG-FLAG is t, the function returns a list of
7432 all possible completions. If VERILOG-FLAG is nil it returns a string,
7433 the longest possible completion, or t if VERILOG-STR is an exact match.
7434 If VERILOG-FLAG is `lambda', the function returns t if VERILOG-STR is an
7435 exact match, nil otherwise."
7436 (save-excursion
7437 (let ((verilog-all nil))
7438 ;; Set buffer to use for searching labels. This should be set
7439 ;; within functions which use verilog-completions
7440 (set-buffer verilog-buffer-to-use)
7442 ;; Determine what should be completed
7443 (let ((state (car (verilog-calculate-indent))))
7444 (cond ((eq state 'defun)
7445 (save-excursion (verilog-var-completion))
7446 (verilog-func-completion 'module)
7447 (verilog-keyword-completion verilog-defun-keywords))
7449 ((eq state 'behavioral)
7450 (save-excursion (verilog-var-completion))
7451 (verilog-func-completion 'module)
7452 (verilog-keyword-completion verilog-defun-keywords))
7454 ((eq state 'block)
7455 (save-excursion (verilog-var-completion))
7456 (verilog-func-completion 'tf)
7457 (verilog-keyword-completion verilog-block-keywords))
7459 ((eq state 'case)
7460 (save-excursion (verilog-var-completion))
7461 (verilog-func-completion 'tf)
7462 (verilog-keyword-completion verilog-case-keywords))
7464 ((eq state 'tf)
7465 (save-excursion (verilog-var-completion))
7466 (verilog-func-completion 'tf)
7467 (verilog-keyword-completion verilog-tf-keywords))
7469 ((eq state 'cpp)
7470 (save-excursion (verilog-var-completion))
7471 (verilog-keyword-completion verilog-cpp-keywords))
7473 ((eq state 'cparenexp)
7474 (save-excursion (verilog-var-completion)))
7476 (t;--Anywhere else
7477 (save-excursion (verilog-var-completion))
7478 (verilog-func-completion 'both)
7479 (verilog-keyword-completion verilog-separator-keywords))))
7481 ;; Now we have built a list of all matches. Give response to caller
7482 (verilog-completion-response))))
7484 (defun verilog-completion-response ()
7485 (cond ((or (equal verilog-flag 'lambda) (null verilog-flag))
7486 ;; This was not called by all-completions
7487 (if (null verilog-all)
7488 ;; Return nil if there was no matching label
7490 ;; Get longest string common in the labels
7491 ;; FIXME: Why not use `try-completion'?
7492 (let* ((elm (cdr verilog-all))
7493 (match (car verilog-all))
7494 (min (length match))
7495 tmp)
7496 (if (string= match verilog-str)
7497 ;; Return t if first match was an exact match
7498 (setq match t)
7499 (while (not (null elm))
7500 ;; Find longest common string
7501 (if (< (setq tmp (verilog-string-diff match (car elm))) min)
7502 (progn
7503 (setq min tmp)
7504 (setq match (substring match 0 min))))
7505 ;; Terminate with match=t if this is an exact match
7506 (if (string= (car elm) verilog-str)
7507 (progn
7508 (setq match t)
7509 (setq elm nil))
7510 (setq elm (cdr elm)))))
7511 ;; If this is a test just for exact match, return nil ot t
7512 (if (and (equal verilog-flag 'lambda) (not (equal match 't)))
7514 match))))
7515 ;; If flag is t, this was called by all-completions. Return
7516 ;; list of all possible completions
7517 (verilog-flag
7518 verilog-all)))
7520 (defvar verilog-last-word-numb 0)
7521 (defvar verilog-last-word-shown nil)
7522 (defvar verilog-last-completions nil)
7524 (defun verilog-completion-at-point ()
7525 "Used as an element of `completion-at-point-functions'.
7526 \(See also `verilog-type-keywords' and
7527 `verilog-separator-keywords'.)"
7528 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
7529 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
7530 (verilog-str (buffer-substring b e))
7531 ;; The following variable is used in verilog-completion
7532 (verilog-buffer-to-use (current-buffer))
7533 (allcomp (if (and verilog-toggle-completions
7534 (string= verilog-last-word-shown verilog-str))
7535 verilog-last-completions
7536 (all-completions verilog-str 'verilog-completion))))
7537 (list b e allcomp)))
7539 (defun verilog-complete-word ()
7540 "Complete word at current point.
7541 \(See also `verilog-toggle-completions', `verilog-type-keywords',
7542 and `verilog-separator-keywords'.)"
7543 ;; NOTE: This is just a fallback for Emacs versions lacking
7544 ;; `completion-at-point'.
7545 (interactive)
7546 (let* ((comp-info (verilog-completion-at-point))
7547 (b (nth 0 comp-info))
7548 (e (nth 1 comp-info))
7549 (verilog-str (buffer-substring b e))
7550 (allcomp (nth 2 comp-info))
7551 (match (if verilog-toggle-completions
7552 "" (try-completion
7553 verilog-str (mapcar (lambda (elm)
7554 (cons elm 0)) allcomp)))))
7555 ;; Delete old string
7556 (delete-region b e)
7558 ;; Toggle-completions inserts whole labels
7559 (if verilog-toggle-completions
7560 (progn
7561 ;; Update entry number in list
7562 (setq verilog-last-completions allcomp
7563 verilog-last-word-numb
7564 (if (>= verilog-last-word-numb (1- (length allcomp)))
7566 (1+ verilog-last-word-numb)))
7567 (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb))
7568 ;; Display next match or same string if no match was found
7569 (if (not (null allcomp))
7570 (insert "" verilog-last-word-shown)
7571 (insert "" verilog-str)
7572 (message "(No match)")))
7573 ;; The other form of completion does not necessarily do that.
7575 ;; Insert match if found, or the original string if no match
7576 (if (or (null match) (equal match 't))
7577 (progn (insert "" verilog-str)
7578 (message "(No match)"))
7579 (insert "" match))
7580 ;; Give message about current status of completion
7581 (cond ((equal match 't)
7582 (if (not (null (cdr allcomp)))
7583 (message "(Complete but not unique)")
7584 (message "(Sole completion)")))
7585 ;; Display buffer if the current completion didn't help
7586 ;; on completing the label.
7587 ((and (not (null (cdr allcomp))) (= (length verilog-str)
7588 (length match)))
7589 (with-output-to-temp-buffer "*Completions*"
7590 (display-completion-list allcomp))
7591 ;; Wait for a key press. Then delete *Completion* window
7592 (momentary-string-display "" (point))
7593 (delete-window (get-buffer-window (get-buffer "*Completions*")))
7594 )))))
7596 (defun verilog-show-completions ()
7597 "Show all possible completions at current point."
7598 ;; NOTE: This is just a fallback for Emacs versions lacking
7599 ;; `completion-help-at-point'.
7600 (interactive)
7601 ;; Show possible completions in a temporary buffer.
7602 (with-output-to-temp-buffer "*Completions*"
7603 (display-completion-list (nth 2 (verilog-completion-at-point))))
7604 ;; Wait for a key press. Then delete *Completion* window
7605 (momentary-string-display "" (point))
7606 (delete-window (get-buffer-window (get-buffer "*Completions*"))))
7608 (defun verilog-get-default-symbol ()
7609 "Return symbol around current point as a string."
7610 (save-excursion
7611 (buffer-substring (progn
7612 (skip-chars-backward " \t")
7613 (skip-chars-backward "a-zA-Z0-9_")
7614 (point))
7615 (progn
7616 (skip-chars-forward "a-zA-Z0-9_")
7617 (point)))))
7619 (defun verilog-build-defun-re (str &optional arg)
7620 "Return function/task/module starting with STR as regular expression.
7621 With optional second ARG non-nil, STR is the complete name of the instruction."
7622 (if arg
7623 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "\\)\\>")
7624 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>")))
7626 (defun verilog-comp-defun (verilog-str verilog-pred verilog-flag)
7627 "Function passed to `completing-read', `try-completion' or `all-completions'.
7628 Returns a completion on any function name based on VERILOG-STR prefix. If
7629 VERILOG-PRED is non-nil, it must be a function to be called for every match
7630 to check if this should really be a match. If VERILOG-FLAG is t, the
7631 function returns a list of all possible completions. If it is nil it
7632 returns a string, the longest possible completion, or t if VERILOG-STR is
7633 an exact match. If VERILOG-FLAG is `lambda', the function returns t if
7634 VERILOG-STR is an exact match, nil otherwise."
7635 (save-excursion
7636 (let ((verilog-all nil)
7637 match)
7639 ;; Set buffer to use for searching labels. This should be set
7640 ;; within functions which use verilog-completions
7641 (set-buffer verilog-buffer-to-use)
7643 (let ((verilog-str verilog-str))
7644 ;; Build regular expression for functions
7645 (if (string= verilog-str "")
7646 (setq verilog-str (verilog-build-defun-re "[a-zA-Z_]"))
7647 (setq verilog-str (verilog-build-defun-re verilog-str)))
7648 (goto-char (point-min))
7650 ;; Build a list of all possible completions
7651 (while (verilog-re-search-forward verilog-str nil t)
7652 (setq match (buffer-substring (match-beginning 2) (match-end 2)))
7653 (if (or (null verilog-pred)
7654 (funcall verilog-pred match))
7655 (setq verilog-all (cons match verilog-all)))))
7657 ;; Now we have built a list of all matches. Give response to caller
7658 (verilog-completion-response))))
7660 (defun verilog-goto-defun ()
7661 "Move to specified Verilog module/interface/task/function.
7662 The default is a name found in the buffer around point.
7663 If search fails, other files are checked based on
7664 `verilog-library-flags'."
7665 (interactive)
7666 (let* ((default (verilog-get-default-symbol))
7667 ;; The following variable is used in verilog-comp-function
7668 (verilog-buffer-to-use (current-buffer))
7669 (label (if (not (string= default ""))
7670 ;; Do completion with default
7671 (completing-read (concat "Goto-Label: (default "
7672 default ") ")
7673 'verilog-comp-defun nil nil "")
7674 ;; There is no default value. Complete without it
7675 (completing-read "Goto-Label: "
7676 'verilog-comp-defun nil nil "")))
7678 ;; Make sure library paths are correct, in case need to resolve module
7679 (verilog-auto-reeval-locals)
7680 (verilog-getopt-flags)
7681 ;; If there was no response on prompt, use default value
7682 (if (string= label "")
7683 (setq label default))
7684 ;; Goto right place in buffer if label is not an empty string
7685 (or (string= label "")
7686 (progn
7687 (save-excursion
7688 (goto-char (point-min))
7689 (setq pt
7690 (re-search-forward (verilog-build-defun-re label t) nil t)))
7691 (when pt
7692 (goto-char pt)
7693 (beginning-of-line))
7695 (verilog-goto-defun-file label))))
7697 ;; Eliminate compile warning
7698 (defvar occur-pos-list)
7700 (defun verilog-showscopes ()
7701 "List all scopes in this module."
7702 (interactive)
7703 (let ((buffer (current-buffer))
7704 (linenum 1)
7705 (nlines 0)
7706 (first 1)
7707 (prevpos (point-min))
7708 (final-context-start (make-marker))
7709 (regexp "\\(module\\s-+\\w+\\s-*(\\)\\|\\(\\w+\\s-+\\w+\\s-*(\\)"))
7710 (with-output-to-temp-buffer "*Occur*"
7711 (save-excursion
7712 (message "Searching for %s ..." regexp)
7713 ;; Find next match, but give up if prev match was at end of buffer.
7714 (while (and (not (= prevpos (point-max)))
7715 (verilog-re-search-forward regexp nil t))
7716 (goto-char (match-beginning 0))
7717 (beginning-of-line)
7718 (save-match-data
7719 (setq linenum (+ linenum (count-lines prevpos (point)))))
7720 (setq prevpos (point))
7721 (goto-char (match-end 0))
7722 (let* ((start (save-excursion
7723 (goto-char (match-beginning 0))
7724 (forward-line (if (< nlines 0) nlines (- nlines)))
7725 (point)))
7726 (end (save-excursion
7727 (goto-char (match-end 0))
7728 (if (> nlines 0)
7729 (forward-line (1+ nlines))
7730 (forward-line 1))
7731 (point)))
7732 (tag (format "%3d" linenum))
7733 (empty (make-string (length tag) ?\ ))
7734 tem)
7735 (save-excursion
7736 (setq tem (make-marker))
7737 (set-marker tem (point))
7738 (set-buffer standard-output)
7739 (setq occur-pos-list (cons tem occur-pos-list))
7740 (or first (zerop nlines)
7741 (insert "--------\n"))
7742 (setq first nil)
7743 (insert-buffer-substring buffer start end)
7744 (backward-char (- end start))
7745 (setq tem (if (< nlines 0) (- nlines) nlines))
7746 (while (> tem 0)
7747 (insert empty ?:)
7748 (forward-line 1)
7749 (setq tem (1- tem)))
7750 (let ((this-linenum linenum))
7751 (set-marker final-context-start
7752 (+ (point) (- (match-end 0) (match-beginning 0))))
7753 (while (< (point) final-context-start)
7754 (if (null tag)
7755 (setq tag (format "%3d" this-linenum)))
7756 (insert tag ?:)))))))
7757 (set-buffer-modified-p nil))))
7760 ;; Highlight helper functions
7761 (defconst verilog-directive-regexp "\\(translate\\|coverage\\|lint\\)_")
7763 (defun verilog-within-translate-off ()
7764 "Return point if within translate-off region, else nil."
7765 (and (save-excursion
7766 (re-search-backward
7767 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>")
7768 nil t))
7769 (equal "off" (match-string 2))
7770 (point)))
7772 (defun verilog-start-translate-off (limit)
7773 "Return point before translate-off directive if before LIMIT, else nil."
7774 (when (re-search-forward
7775 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
7776 limit t)
7777 (match-beginning 0)))
7779 (defun verilog-back-to-start-translate-off (limit)
7780 "Return point before translate-off directive if before LIMIT, else nil."
7781 (when (re-search-backward
7782 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
7783 limit t)
7784 (match-beginning 0)))
7786 (defun verilog-end-translate-off (limit)
7787 "Return point after translate-on directive if before LIMIT, else nil."
7789 (re-search-forward (concat
7790 "//\\s-*.*\\s-*" verilog-directive-regexp "on\\>") limit t))
7792 (defun verilog-match-translate-off (limit)
7793 "Match a translate-off block, setting `match-data' and returning t, else nil.
7794 Bound search by LIMIT."
7795 (when (< (point) limit)
7796 (let ((start (or (verilog-within-translate-off)
7797 (verilog-start-translate-off limit)))
7798 (case-fold-search t))
7799 (when start
7800 (let ((end (or (verilog-end-translate-off limit) limit)))
7801 (set-match-data (list start end))
7802 (goto-char end))))))
7804 (defun verilog-font-lock-match-item (limit)
7805 "Match, and move over, any declaration item after point.
7806 Bound search by LIMIT. Adapted from
7807 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
7808 (condition-case nil
7809 (save-restriction
7810 (narrow-to-region (point-min) limit)
7811 ;; match item
7812 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
7813 (save-match-data
7814 (goto-char (match-end 1))
7815 ;; move to next item
7816 (if (looking-at "\\(\\s-*,\\)")
7817 (goto-char (match-end 1))
7818 (end-of-line) t))))
7819 (error nil)))
7822 ;; Added by Subbu Meiyappan for Header
7824 (defun verilog-header ()
7825 "Insert a standard Verilog file header.
7826 See also `verilog-sk-header' for an alternative format."
7827 (interactive)
7828 (let ((start (point)))
7829 (insert "\
7830 //-----------------------------------------------------------------------------
7831 // Title : <title>
7832 // Project : <project>
7833 //-----------------------------------------------------------------------------
7834 // File : <filename>
7835 // Author : <author>
7836 // Created : <credate>
7837 // Last modified : <moddate>
7838 //-----------------------------------------------------------------------------
7839 // Description :
7840 // <description>
7841 //-----------------------------------------------------------------------------
7842 // Copyright (c) <copydate> by <company> This model is the confidential and
7843 // proprietary property of <company> and the possession or use of this
7844 // file requires a written license from <company>.
7845 //------------------------------------------------------------------------------
7846 // Modification history :
7847 // <modhist>
7848 //-----------------------------------------------------------------------------
7851 (goto-char start)
7852 (search-forward "<filename>")
7853 (replace-match (buffer-name) t t)
7854 (search-forward "<author>") (replace-match "" t t)
7855 (insert (user-full-name))
7856 (insert " <" (user-login-name) "@" (system-name) ">")
7857 (search-forward "<credate>") (replace-match "" t t)
7858 (verilog-insert-date)
7859 (search-forward "<moddate>") (replace-match "" t t)
7860 (verilog-insert-date)
7861 (search-forward "<copydate>") (replace-match "" t t)
7862 (verilog-insert-year)
7863 (search-forward "<modhist>") (replace-match "" t t)
7864 (verilog-insert-date)
7865 (insert " : created")
7866 (goto-char start)
7867 (let (string)
7868 (setq string (read-string "title: "))
7869 (search-forward "<title>")
7870 (replace-match string t t)
7871 (setq string (read-string "project: " verilog-project))
7872 (setq verilog-project string)
7873 (search-forward "<project>")
7874 (replace-match string t t)
7875 (setq string (read-string "Company: " verilog-company))
7876 (setq verilog-company string)
7877 (search-forward "<company>")
7878 (replace-match string t t)
7879 (search-forward "<company>")
7880 (replace-match string t t)
7881 (search-forward "<company>")
7882 (replace-match string t t)
7883 (search-backward "<description>")
7884 (replace-match "" t t))))
7886 ;; verilog-header Uses the verilog-insert-date function
7888 (defun verilog-insert-date ()
7889 "Insert date from the system."
7890 (interactive)
7891 (if verilog-date-scientific-format
7892 (insert (format-time-string "%Y/%m/%d"))
7893 (insert (format-time-string "%d.%m.%Y"))))
7895 (defun verilog-insert-year ()
7896 "Insert year from the system."
7897 (interactive)
7898 (insert (format-time-string "%Y")))
7901 ;;; Signal list parsing:
7904 ;; Elements of a signal list
7905 ;; Unfortunately we use 'assoc' on this, so can't be a vector
7906 (defsubst verilog-sig-new (name bits comment mem enum signed type multidim modport)
7907 (list name bits comment mem enum signed type multidim modport))
7908 (defsubst verilog-sig-name (sig)
7909 (car sig))
7910 (defsubst verilog-sig-bits (sig) ; First element of packed array (pre signal-name)
7911 (nth 1 sig))
7912 (defsubst verilog-sig-comment (sig)
7913 (nth 2 sig))
7914 (defsubst verilog-sig-memory (sig) ; Unpacked array (post signal-name)
7915 (nth 3 sig))
7916 (defsubst verilog-sig-enum (sig)
7917 (nth 4 sig))
7918 (defsubst verilog-sig-signed (sig)
7919 (nth 5 sig))
7920 (defsubst verilog-sig-type (sig)
7921 (nth 6 sig))
7922 (defsubst verilog-sig-type-set (sig type)
7923 (setcar (nthcdr 6 sig) type))
7924 (defsubst verilog-sig-multidim (sig) ; Second and additional elements of packed array
7925 (nth 7 sig))
7926 (defsubst verilog-sig-multidim-string (sig)
7927 (if (verilog-sig-multidim sig)
7928 (let ((str "") (args (verilog-sig-multidim sig)))
7929 (while args
7930 (setq str (concat (car args) str))
7931 (setq args (cdr args)))
7932 str)))
7933 (defsubst verilog-sig-modport (sig)
7934 (nth 8 sig))
7935 (defsubst verilog-sig-width (sig)
7936 (verilog-make-width-expression (verilog-sig-bits sig)))
7938 (defsubst verilog-alw-new (outputs-del outputs-imm temps inputs)
7939 (vector outputs-del outputs-imm temps inputs))
7940 (defsubst verilog-alw-get-outputs-delayed (sigs)
7941 (aref sigs 0))
7942 (defsubst verilog-alw-get-outputs-immediate (sigs)
7943 (aref sigs 1))
7944 (defsubst verilog-alw-get-temps (sigs)
7945 (aref sigs 2))
7946 (defsubst verilog-alw-get-inputs (sigs)
7947 (aref sigs 3))
7948 (defsubst verilog-alw-get-uses-delayed (sigs)
7949 (aref sigs 0))
7951 (defsubst verilog-modport-new (name clockings decls)
7952 (list name clockings decls))
7953 (defsubst verilog-modport-name (sig)
7954 (car sig))
7955 (defsubst verilog-modport-clockings (sig)
7956 (nth 1 sig)) ; Returns list of names
7957 (defsubst verilog-modport-clockings-add (sig val)
7958 (setcar (nthcdr 1 sig) (cons val (nth 1 sig))))
7959 (defsubst verilog-modport-decls (sig)
7960 (nth 2 sig)) ; Returns verilog-decls-* structure
7961 (defsubst verilog-modport-decls-set (sig val)
7962 (setcar (nthcdr 2 sig) val))
7964 (defsubst verilog-modi-new (name fob pt type)
7965 (vector name fob pt type))
7966 (defsubst verilog-modi-name (modi)
7967 (aref modi 0))
7968 (defsubst verilog-modi-file-or-buffer (modi)
7969 (aref modi 1))
7970 (defsubst verilog-modi-get-point (modi)
7971 (aref modi 2))
7972 (defsubst verilog-modi-get-type (modi) ; "module" or "interface"
7973 (aref modi 3))
7974 (defsubst verilog-modi-get-decls (modi)
7975 (verilog-modi-cache-results modi 'verilog-read-decls))
7976 (defsubst verilog-modi-get-sub-decls (modi)
7977 (verilog-modi-cache-results modi 'verilog-read-sub-decls))
7979 ;; Signal reading for given module
7980 ;; Note these all take modi's - as returned from verilog-modi-current
7981 (defsubst verilog-decls-new (out inout in vars modports assigns consts gparams interfaces)
7982 (vector out inout in vars modports assigns consts gparams interfaces))
7983 (defsubst verilog-decls-append (a b)
7984 (cond ((not a) b) ((not b) a)
7985 (t (vector (append (aref a 0) (aref b 0)) (append (aref a 1) (aref b 1))
7986 (append (aref a 2) (aref b 2)) (append (aref a 3) (aref b 3))
7987 (append (aref a 4) (aref b 4)) (append (aref a 5) (aref b 5))
7988 (append (aref a 6) (aref b 6)) (append (aref a 7) (aref b 7))
7989 (append (aref a 8) (aref b 8))))))
7990 (defsubst verilog-decls-get-outputs (decls)
7991 (aref decls 0))
7992 (defsubst verilog-decls-get-inouts (decls)
7993 (aref decls 1))
7994 (defsubst verilog-decls-get-inputs (decls)
7995 (aref decls 2))
7996 (defsubst verilog-decls-get-vars (decls)
7997 (aref decls 3))
7998 (defsubst verilog-decls-get-modports (decls) ; Also for clocking blocks; contains another verilog-decls struct
7999 (aref decls 4)) ; Returns verilog-modport* structure
8000 (defsubst verilog-decls-get-assigns (decls)
8001 (aref decls 5))
8002 (defsubst verilog-decls-get-consts (decls)
8003 (aref decls 6))
8004 (defsubst verilog-decls-get-gparams (decls)
8005 (aref decls 7))
8006 (defsubst verilog-decls-get-interfaces (decls)
8007 (aref decls 8))
8010 (defsubst verilog-subdecls-new (out inout in intf intfd)
8011 (vector out inout in intf intfd))
8012 (defsubst verilog-subdecls-get-outputs (subdecls)
8013 (aref subdecls 0))
8014 (defsubst verilog-subdecls-get-inouts (subdecls)
8015 (aref subdecls 1))
8016 (defsubst verilog-subdecls-get-inputs (subdecls)
8017 (aref subdecls 2))
8018 (defsubst verilog-subdecls-get-interfaces (subdecls)
8019 (aref subdecls 3))
8020 (defsubst verilog-subdecls-get-interfaced (subdecls)
8021 (aref subdecls 4))
8023 (defun verilog-signals-from-signame (signame-list)
8024 "Return signals in standard form from SIGNAME-LIST, a simple list of names."
8025 (mapcar (lambda (name) (verilog-sig-new name nil nil nil nil nil nil nil nil))
8026 signame-list))
8028 (defun verilog-signals-in (in-list not-list)
8029 "Return list of signals in IN-LIST that are also in NOT-LIST.
8030 Also remove any duplicates in IN-LIST.
8031 Signals must be in standard (base vector) form."
8032 ;; This function is hot, so implemented as O(1)
8033 (cond ((eval-when-compile (fboundp 'make-hash-table))
8034 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
8035 (ht-not (make-hash-table :test 'equal :rehash-size 4.0))
8036 out-list)
8037 (while not-list
8038 (puthash (car (car not-list)) t ht-not)
8039 (setq not-list (cdr not-list)))
8040 (while in-list
8041 (when (and (gethash (verilog-sig-name (car in-list)) ht-not)
8042 (not (gethash (verilog-sig-name (car in-list)) ht)))
8043 (setq out-list (cons (car in-list) out-list))
8044 (puthash (verilog-sig-name (car in-list)) t ht))
8045 (setq in-list (cdr in-list)))
8046 (nreverse out-list)))
8047 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
8049 (let (out-list)
8050 (while in-list
8051 (if (and (assoc (verilog-sig-name (car in-list)) not-list)
8052 (not (assoc (verilog-sig-name (car in-list)) out-list)))
8053 (setq out-list (cons (car in-list) out-list)))
8054 (setq in-list (cdr in-list)))
8055 (nreverse out-list)))))
8056 ;;(verilog-signals-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("C" "")))
8058 (defun verilog-signals-not-in (in-list not-list)
8059 "Return list of signals in IN-LIST that aren't also in NOT-LIST.
8060 Also remove any duplicates in IN-LIST.
8061 Signals must be in standard (base vector) form."
8062 ;; This function is hot, so implemented as O(1)
8063 (cond ((eval-when-compile (fboundp 'make-hash-table))
8064 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
8065 out-list)
8066 (while not-list
8067 (puthash (car (car not-list)) t ht)
8068 (setq not-list (cdr not-list)))
8069 (while in-list
8070 (when (not (gethash (verilog-sig-name (car in-list)) ht))
8071 (setq out-list (cons (car in-list) out-list))
8072 (puthash (verilog-sig-name (car in-list)) t ht))
8073 (setq in-list (cdr in-list)))
8074 (nreverse out-list)))
8075 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
8077 (let (out-list)
8078 (while in-list
8079 (if (and (not (assoc (verilog-sig-name (car in-list)) not-list))
8080 (not (assoc (verilog-sig-name (car in-list)) out-list)))
8081 (setq out-list (cons (car in-list) out-list)))
8082 (setq in-list (cdr in-list)))
8083 (nreverse out-list)))))
8084 ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" "")))
8086 (defun verilog-signals-not-in-struct (in-list not-list)
8087 "Return list of signals in IN-LIST that aren't also in NOT-LIST.
8088 Also remove any duplicates in IN-LIST.
8089 Any structure in not-list will remove all members in in-list.
8090 Signals must be in standard (base vector) form."
8091 (cond ((eval-when-compile (fboundp 'make-hash-table))
8092 (let ((ht (make-hash-table :test 'equal :rehash-size 4.0))
8093 out-list addit nm)
8094 (while not-list
8095 (puthash (car (car not-list)) t ht)
8096 (setq not-list (cdr not-list)))
8097 (while in-list
8098 (setq nm (verilog-sig-name (car in-list)))
8099 (when (not (gethash nm ht))
8100 (setq addit t)
8101 (while (string-match "^\\([^\\].*\\)\\.[^.]+$" nm)
8102 (setq nm (match-string 1 nm))
8103 (setq addit (and addit
8104 (not (gethash nm ht)))))
8105 (when addit
8106 (setq out-list (cons (car in-list) out-list))
8107 (puthash (verilog-sig-name (car in-list)) t ht)))
8108 (setq in-list (cdr in-list)))
8109 (nreverse out-list)))
8110 ;; Slower Fallback if no hash tables (pre Emacs 21.1/XEmacs 21.4)
8112 (let (out-list addit nm)
8113 (while in-list
8114 (setq nm (verilog-sig-name (car in-list)))
8115 (when (and (not (assoc nm not-list))
8116 (not (assoc nm out-list)))
8117 (setq addit t)
8118 (while (string-match "^\\([^\\].*\\)\\.[^.]+$" nm)
8119 (setq nm (match-string 1 nm))
8120 (setq addit (and addit
8121 (not (assoc nm not-list)))))
8122 (when addit
8123 (setq out-list (cons (car in-list) out-list))))
8124 (setq in-list (cdr in-list)))
8125 (nreverse out-list)))))
8126 ;;(verilog-signals-not-in-struct '(("A" "") ("B" "") ("DEL.SUB.A" "[2:3]")) '(("DEL.SUB" "") ("EXT" "")))
8128 (defun verilog-signals-memory (in-list)
8129 "Return list of signals in IN-LIST that are memorized (multidimensional)."
8130 (let (out-list)
8131 (while in-list
8132 (if (nth 3 (car in-list))
8133 (setq out-list (cons (car in-list) out-list)))
8134 (setq in-list (cdr in-list)))
8135 out-list))
8136 ;;(verilog-signals-memory '(("A" nil nil "[3:0]")) '(("B" nil nil nil)))
8138 (defun verilog-signals-sort-compare (a b)
8139 "Compare signal A and B for sorting."
8140 (string< (verilog-sig-name a) (verilog-sig-name b)))
8142 (defun verilog-signals-not-params (in-list)
8143 "Return list of signals in IN-LIST that aren't parameters or numeric constants."
8144 (let (out-list)
8145 (while in-list
8146 ;; Namespace intentionally short for AUTOs and compatibility
8147 (unless (boundp (intern (concat "vh-" (verilog-sig-name (car in-list)))))
8148 (setq out-list (cons (car in-list) out-list)))
8149 (setq in-list (cdr in-list)))
8150 (nreverse out-list)))
8152 (defun verilog-signals-with (func in-list)
8153 "Return list of signals where FUNC is true executed on each signal in IN-LIST."
8154 (let (out-list)
8155 (while in-list
8156 (when (funcall func (car in-list))
8157 (setq out-list (cons (car in-list) out-list)))
8158 (setq in-list (cdr in-list)))
8159 (nreverse out-list)))
8161 (defun verilog-signals-combine-bus (in-list)
8162 "Return a list of signals in IN-LIST, with buses combined.
8163 Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]."
8164 (let (combo
8165 buswarn
8166 out-list
8167 sig highbit lowbit ; Temp information about current signal
8168 sv-name sv-highbit sv-lowbit ; Details about signal we are forming
8169 sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring
8170 sv-modport
8171 bus)
8172 ;; Shove signals so duplicated signals will be adjacent
8173 (setq in-list (sort in-list `verilog-signals-sort-compare))
8174 (while in-list
8175 (setq sig (car in-list))
8176 ;; No current signal; form from existing details
8177 (unless sv-name
8178 (setq sv-name (verilog-sig-name sig)
8179 sv-highbit nil
8180 sv-busstring nil
8181 sv-comment (verilog-sig-comment sig)
8182 sv-memory (verilog-sig-memory sig)
8183 sv-enum (verilog-sig-enum sig)
8184 sv-signed (verilog-sig-signed sig)
8185 sv-type (verilog-sig-type sig)
8186 sv-multidim (verilog-sig-multidim sig)
8187 sv-modport (verilog-sig-modport sig)
8188 combo ""
8189 buswarn ""))
8190 ;; Extract bus details
8191 (setq bus (verilog-sig-bits sig))
8192 (setq bus (and bus (verilog-simplify-range-expression bus)))
8193 (cond ((and bus
8194 (or (and (string-match "\\[\\([0-9]+\\):\\([0-9]+\\)\\]" bus)
8195 (setq highbit (string-to-number (match-string 1 bus))
8196 lowbit (string-to-number
8197 (match-string 2 bus))))
8198 (and (string-match "\\[\\([0-9]+\\)\\]" bus)
8199 (setq highbit (string-to-number (match-string 1 bus))
8200 lowbit highbit))))
8201 ;; Combine bits in bus
8202 (if sv-highbit
8203 (setq sv-highbit (max highbit sv-highbit)
8204 sv-lowbit (min lowbit sv-lowbit))
8205 (setq sv-highbit highbit
8206 sv-lowbit lowbit)))
8207 (bus
8208 ;; String, probably something like `preproc:0
8209 (setq sv-busstring bus)))
8210 ;; Peek ahead to next signal
8211 (setq in-list (cdr in-list))
8212 (setq sig (car in-list))
8213 (cond ((and sig (equal sv-name (verilog-sig-name sig)))
8214 ;; Combine with this signal
8215 (when (and sv-busstring
8216 (not (equal sv-busstring (verilog-sig-bits sig))))
8217 (when nil ; Debugging
8218 (message (concat "Warning, can't merge into single bus `%s%s'"
8219 ", the AUTOs may be wrong")
8220 sv-name bus))
8221 (setq buswarn ", Couldn't Merge"))
8222 (if (verilog-sig-comment sig) (setq combo ", ..."))
8223 (setq sv-memory (or sv-memory (verilog-sig-memory sig))
8224 sv-enum (or sv-enum (verilog-sig-enum sig))
8225 sv-signed (or sv-signed (verilog-sig-signed sig))
8226 sv-type (or sv-type (verilog-sig-type sig))
8227 sv-multidim (or sv-multidim (verilog-sig-multidim sig))
8228 sv-modport (or sv-modport (verilog-sig-modport sig))))
8229 ;; Doesn't match next signal, add to queue, zero in prep for next
8230 ;; Note sig may also be nil for the last signal in the list
8232 (setq out-list
8233 (cons (verilog-sig-new
8234 sv-name
8235 (or sv-busstring
8236 (if sv-highbit
8237 (concat "[" (int-to-string sv-highbit) ":"
8238 (int-to-string sv-lowbit) "]")))
8239 (concat sv-comment combo buswarn)
8240 sv-memory sv-enum sv-signed sv-type sv-multidim sv-modport)
8241 out-list)
8242 sv-name nil))))
8244 out-list))
8246 (defun verilog-sig-tieoff (sig)
8247 "Return tieoff expression for given SIG, with appropriate width.
8248 Tieoff value uses `verilog-active-low-regexp' and
8249 `verilog-auto-reset-widths'."
8250 (concat
8251 (if (and verilog-active-low-regexp
8252 (verilog-string-match-fold verilog-active-low-regexp (verilog-sig-name sig)))
8253 "~" "")
8254 (cond ((not verilog-auto-reset-widths)
8255 "0")
8256 ((equal verilog-auto-reset-widths 'unbased)
8257 "'0")
8258 ;; Else presume verilog-auto-reset-widths is true
8260 (let* ((width (verilog-sig-width sig)))
8261 (cond ((not width)
8262 "`0/*NOWIDTH*/")
8263 ((string-match "^[0-9]+$" width)
8264 (concat width (if (verilog-sig-signed sig) "'sh0" "'h0")))
8266 (concat "{" width "{1'b0}}"))))))))
8269 ;; Dumping
8272 (defun verilog-decls-princ (decls &optional header prefix)
8273 "For debug, dump the `verilog-read-decls' structure DECLS.
8274 Use optional HEADER and PREFIX."
8275 (when decls
8276 (if header (princ header))
8277 (setq prefix (or prefix ""))
8278 (verilog-signals-princ (verilog-decls-get-outputs decls)
8279 (concat prefix "Outputs:\n") (concat prefix " "))
8280 (verilog-signals-princ (verilog-decls-get-inouts decls)
8281 (concat prefix "Inout:\n") (concat prefix " "))
8282 (verilog-signals-princ (verilog-decls-get-inputs decls)
8283 (concat prefix "Inputs:\n") (concat prefix " "))
8284 (verilog-signals-princ (verilog-decls-get-vars decls)
8285 (concat prefix "Vars:\n") (concat prefix " "))
8286 (verilog-signals-princ (verilog-decls-get-assigns decls)
8287 (concat prefix "Assigns:\n") (concat prefix " "))
8288 (verilog-signals-princ (verilog-decls-get-consts decls)
8289 (concat prefix "Consts:\n") (concat prefix " "))
8290 (verilog-signals-princ (verilog-decls-get-gparams decls)
8291 (concat prefix "Gparams:\n") (concat prefix " "))
8292 (verilog-signals-princ (verilog-decls-get-interfaces decls)
8293 (concat prefix "Interfaces:\n") (concat prefix " "))
8294 (verilog-modport-princ (verilog-decls-get-modports decls)
8295 (concat prefix "Modports:\n") (concat prefix " "))
8296 (princ "\n")))
8298 (defun verilog-signals-princ (signals &optional header prefix)
8299 "For debug, dump internal SIGNALS structures, with HEADER and PREFIX."
8300 (when signals
8301 (if header (princ header))
8302 (while signals
8303 (let ((sig (car signals)))
8304 (setq signals (cdr signals))
8305 (princ prefix)
8306 (princ "\"") (princ (verilog-sig-name sig)) (princ "\"")
8307 (princ " bits=") (princ (verilog-sig-bits sig))
8308 (princ " cmt=") (princ (verilog-sig-comment sig))
8309 (princ " mem=") (princ (verilog-sig-memory sig))
8310 (princ " enum=") (princ (verilog-sig-enum sig))
8311 (princ " sign=") (princ (verilog-sig-signed sig))
8312 (princ " type=") (princ (verilog-sig-type sig))
8313 (princ " dim=") (princ (verilog-sig-multidim sig))
8314 (princ " modp=") (princ (verilog-sig-modport sig))
8315 (princ "\n")))))
8317 (defun verilog-modport-princ (modports &optional header prefix)
8318 "For debug, dump internal MODPORTS structures, with HEADER and PREFIX."
8319 (when modports
8320 (if header (princ header))
8321 (while modports
8322 (let ((sig (car modports)))
8323 (setq modports (cdr modports))
8324 (princ prefix)
8325 (princ "\"") (princ (verilog-modport-name sig)) (princ "\"")
8326 (princ " clockings=") (princ (verilog-modport-clockings sig))
8327 (princ "\n")
8328 (verilog-decls-princ (verilog-modport-decls sig)
8329 (concat prefix " syms:\n")
8330 (concat prefix " "))))))
8333 ;; Port/Wire/Etc Reading
8336 (defun verilog-read-inst-backward-name ()
8337 "Internal. Move point back to beginning of inst-name."
8338 (verilog-backward-open-paren)
8339 (let (done)
8340 (while (not done)
8341 (verilog-re-search-backward-quick "\\()\\|\\b[a-zA-Z0-9`_$]\\|\\]\\)" nil nil) ; ] isn't word boundary
8342 (cond ((looking-at ")")
8343 (verilog-backward-open-paren))
8344 (t (setq done t)))))
8345 (while (looking-at "\\]")
8346 (verilog-backward-open-bracket)
8347 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_$]\\|\\]\\)" nil nil))
8348 (skip-chars-backward "a-zA-Z0-9`_$"))
8350 (defun verilog-read-inst-module-matcher ()
8351 "Set match data 0 with module_name when point is inside instantiation."
8352 (verilog-read-inst-backward-name)
8353 ;; Skip over instantiation name
8354 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_$]\\|)\\)" nil nil) ; ) isn't word boundary
8355 ;; Check for parameterized instantiations
8356 (when (looking-at ")")
8357 (verilog-backward-open-paren)
8358 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_$]" nil nil))
8359 (skip-chars-backward "a-zA-Z0-9'_$")
8360 ;; #1 is legal syntax for gate primitives
8361 (when (save-excursion
8362 (verilog-backward-syntactic-ws-quick)
8363 (eq ?# (char-before)))
8364 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_$]" nil nil)
8365 (skip-chars-backward "a-zA-Z0-9'_$"))
8366 (looking-at "[a-zA-Z0-9`_$]+")
8367 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
8368 (buffer-substring-no-properties (match-beginning 0) (match-end 0))
8369 ;; Caller assumes match-beginning/match-end is still set
8372 (defun verilog-read-inst-module ()
8373 "Return module_name when point is inside instantiation."
8374 (save-excursion
8375 (verilog-read-inst-module-matcher)))
8377 (defun verilog-read-inst-name ()
8378 "Return instance_name when point is inside instantiation."
8379 (save-excursion
8380 (verilog-read-inst-backward-name)
8381 (looking-at "[a-zA-Z0-9`_$]+")
8382 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
8383 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))
8385 (defun verilog-read-module-name ()
8386 "Return module name when after its ( or ;."
8387 (save-excursion
8388 (re-search-backward "[(;]")
8389 ;; Due to "module x import y (" we must search for declaration begin
8390 (verilog-re-search-backward-quick verilog-defun-re nil nil)
8391 (goto-char (match-end 0))
8392 (verilog-re-search-forward-quick "\\b[a-zA-Z0-9`_$]+" nil nil)
8393 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
8394 (verilog-symbol-detick
8395 (buffer-substring-no-properties (match-beginning 0) (match-end 0)) t)))
8397 (defun verilog-read-inst-param-value ()
8398 "Return list of parameters and values when point is inside instantiation."
8399 (save-excursion
8400 (verilog-read-inst-backward-name)
8401 ;; Skip over instantiation name
8402 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_$]\\|)\\)" nil nil) ; ) isn't word boundary
8403 ;; If there are parameterized instantiations
8404 (when (looking-at ")")
8405 (let ((end-pt (point))
8406 params
8407 param-name paren-beg-pt param-value)
8408 (verilog-backward-open-paren)
8409 (while (verilog-re-search-forward-quick "\\." end-pt t)
8410 (verilog-re-search-forward-quick "\\([a-zA-Z0-9`_$]\\)" nil nil)
8411 (skip-chars-backward "a-zA-Z0-9'_$")
8412 (looking-at "[a-zA-Z0-9`_$]+")
8413 (setq param-name (buffer-substring-no-properties
8414 (match-beginning 0) (match-end 0)))
8415 (verilog-re-search-forward-quick "(" nil nil)
8416 (setq paren-beg-pt (point))
8417 (verilog-forward-close-paren)
8418 (setq param-value (verilog-string-remove-spaces
8419 (buffer-substring-no-properties
8420 paren-beg-pt (1- (point)))))
8421 (setq params (cons (list param-name param-value) params)))
8422 params))))
8424 (defun verilog-read-auto-params (num-param &optional max-param)
8425 "Return parameter list inside auto.
8426 Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters."
8427 (let ((olist))
8428 (save-excursion
8429 ;; /*AUTOPUNT("parameter", "parameter")*/
8430 (backward-sexp 1)
8431 (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?")
8432 (setq olist (cons (match-string 1) olist))
8433 (goto-char (match-end 0))))
8434 (or (eq nil num-param)
8435 (<= num-param (length olist))
8436 (error "%s: Expected %d parameters" (verilog-point-text) num-param))
8437 (if (eq max-param nil) (setq max-param num-param))
8438 (or (eq nil max-param)
8439 (>= max-param (length olist))
8440 (error "%s: Expected <= %d parameters" (verilog-point-text) max-param))
8441 (nreverse olist)))
8443 (defun verilog-read-decls ()
8444 "Compute signal declaration information for the current module at point.
8445 Return an array of [outputs inouts inputs wire reg assign const]."
8446 (let ((end-mod-point (or (verilog-get-end-of-defun) (point-max)))
8447 (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t)
8448 in-modport in-clocking in-ign-to-semi ptype ign-prop
8449 sigs-in sigs-out sigs-inout sigs-var sigs-assign sigs-const
8450 sigs-gparam sigs-intf sigs-modports
8451 vec expect-signal keywd last-keywd newsig rvalue enum io
8452 signed typedefed multidim
8453 modport
8454 varstack tmp)
8455 ;;(if dbg (setq dbg (concat dbg (format "\n\nverilog-read-decls START PT %s END %s\n" (point) end-mod-point))))
8456 (save-excursion
8457 (verilog-beg-of-defun-quick)
8458 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point))
8459 (while (< (point) end-mod-point)
8460 ;;(if dbg (setq dbg (concat dbg (format "Pt %s Vec %s C%c Kwd'%s'\n" (point) vec (following-char) keywd))))
8461 (cond
8462 ((looking-at "//")
8463 (when (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
8464 (setq enum (match-string 2)))
8465 (search-forward "\n"))
8466 ((looking-at "/\\*")
8467 (forward-char 2)
8468 (when (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
8469 (setq enum (match-string 2)))
8470 (or (search-forward "*/")
8471 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8472 ((looking-at "(\\*")
8473 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
8474 (forward-char 1)
8475 (or (search-forward "*)")
8476 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
8477 ((eq ?\" (following-char))
8478 (or (re-search-forward "[^\\]\"" nil t) ; don't forward-char first, since we look for a non backslash first
8479 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
8480 ((eq ?\; (following-char))
8481 (cond (in-ign-to-semi ; Such as inside a "import ...;" in a module header
8482 (setq in-ign-to-semi nil rvalue nil))
8483 ((and in-modport (not (eq in-modport t))) ; end of a modport declaration
8484 (verilog-modport-decls-set
8485 in-modport
8486 (verilog-decls-new sigs-out sigs-inout sigs-in
8487 nil nil nil nil nil nil))
8488 ;; Pop from varstack to restore state to pre-clocking
8489 (setq tmp (car varstack)
8490 varstack (cdr varstack)
8491 sigs-out (aref tmp 0)
8492 sigs-inout (aref tmp 1)
8493 sigs-in (aref tmp 2))
8494 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
8495 v2kargs-ok nil in-modport nil ign-prop nil))
8497 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
8498 v2kargs-ok nil in-modport nil ign-prop nil)))
8499 (forward-char 1))
8500 ((eq ?= (following-char))
8501 (setq rvalue t newsig nil)
8502 (forward-char 1))
8503 ((and (eq ?, (following-char))
8504 (eq paren sig-paren))
8505 (setq rvalue nil)
8506 (forward-char 1))
8507 ;; ,'s can occur inside {} & funcs
8508 ((looking-at "[{(]")
8509 (setq paren (1+ paren))
8510 (forward-char 1))
8511 ((looking-at "[})]")
8512 (setq paren (1- paren))
8513 (forward-char 1)
8514 (when (< paren sig-paren)
8515 (setq expect-signal nil rvalue nil))) ; ) that ends variables inside v2k arg list
8516 ((looking-at "\\s-*\\(\\[[^]]+\\]\\)")
8517 (goto-char (match-end 0))
8518 (cond (newsig ; Memory, not just width. Patch last signal added's memory (nth 3)
8519 (setcar (cdr (cdr (cdr newsig)))
8520 (if (verilog-sig-memory newsig)
8521 (concat (verilog-sig-memory newsig) (match-string 1))
8522 (match-string-no-properties 1))))
8523 (vec ; Multidimensional
8524 (setq multidim (cons vec multidim))
8525 (setq vec (verilog-string-replace-matches
8526 "\\s-+" "" nil nil (match-string-no-properties 1))))
8527 (t ; Bit width
8528 (setq vec (verilog-string-replace-matches
8529 "\\s-+" "" nil nil (match-string-no-properties 1))))))
8530 ;; Normal or escaped identifier -- note we remember the \ if escaped
8531 ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
8532 (goto-char (match-end 0))
8533 (setq last-keywd keywd
8534 keywd (match-string-no-properties 1))
8535 (when (string-match "^\\\\" (match-string 1))
8536 (setq keywd (concat keywd " "))) ; Escaped ID needs space at end
8537 ;; Add any :: package names to same identifier
8538 ;; '*' here is for "import x::*"
8539 (while (looking-at "\\s-*::\\s-*\\(\\*\\|[a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
8540 (goto-char (match-end 0))
8541 (setq keywd (concat keywd "::" (match-string 1)))
8542 (when (string-match "^\\\\" (match-string 1))
8543 (setq keywd (concat keywd " ")))) ; Escaped ID needs space at end
8544 (cond ((equal keywd "input")
8545 (setq vec nil enum nil rvalue nil newsig nil signed nil
8546 typedefed nil multidim nil ptype nil modport nil
8547 expect-signal 'sigs-in io t sig-paren paren))
8548 ((equal keywd "output")
8549 (setq vec nil enum nil rvalue nil newsig nil signed nil
8550 typedefed nil multidim nil ptype nil modport nil
8551 expect-signal 'sigs-out io t sig-paren paren))
8552 ((equal keywd "inout")
8553 (setq vec nil enum nil rvalue nil newsig nil signed nil
8554 typedefed nil multidim nil ptype nil modport nil
8555 expect-signal 'sigs-inout io t sig-paren paren))
8556 ((equal keywd "parameter")
8557 (setq vec nil enum nil rvalue nil signed nil
8558 typedefed nil multidim nil ptype nil modport nil
8559 expect-signal 'sigs-gparam io t sig-paren paren))
8560 ((member keywd '("wire" "reg" ; Fast
8561 ;; net_type
8562 "tri" "tri0" "tri1" "triand" "trior" "trireg"
8563 "uwire" "wand" "wor"
8564 ;; integer_atom_type
8565 "byte" "shortint" "int" "longint" "integer" "time"
8566 "supply0" "supply1"
8567 ;; integer_vector_type - "reg" above
8568 "bit" "logic"
8569 ;; non_integer_type
8570 "shortreal" "real" "realtime"
8571 ;; data_type
8572 "string" "event" "chandle"))
8573 (cond (io
8574 (setq typedefed
8575 (if typedefed (concat typedefed " " keywd) keywd)))
8576 (t (setq vec nil enum nil rvalue nil signed nil
8577 typedefed nil multidim nil sig-paren paren
8578 expect-signal 'sigs-var modport nil))))
8579 ((equal keywd "assign")
8580 (setq vec nil enum nil rvalue nil signed nil
8581 typedefed nil multidim nil ptype nil modport nil
8582 expect-signal 'sigs-assign sig-paren paren))
8583 ((member keywd '("localparam" "genvar"))
8584 (setq vec nil enum nil rvalue nil signed nil
8585 typedefed nil multidim nil ptype nil modport nil
8586 expect-signal 'sigs-const sig-paren paren))
8587 ((member keywd '("signed" "unsigned"))
8588 (setq signed keywd))
8589 ((member keywd '("assert" "assume" "cover" "expect" "restrict"))
8590 (setq ign-prop t))
8591 ((member keywd '("class" "covergroup" "function"
8592 "property" "randsequence" "sequence" "task"))
8593 (unless ign-prop
8594 (setq functask (1+ functask))))
8595 ((member keywd '("endclass" "endgroup" "endfunction"
8596 "endproperty" "endsequence" "endtask"))
8597 (setq functask (1- functask)))
8598 ((equal keywd "modport")
8599 (setq in-modport t))
8600 ((and (equal keywd "clocking")
8601 (not (equal last-keywd "default")))
8602 (setq in-clocking t))
8603 ((equal keywd "import")
8604 (when v2kargs-ok ; import in module header, not a modport import
8605 (setq in-ign-to-semi t rvalue t)))
8606 ((equal keywd "type")
8607 (setq ptype t))
8608 ((equal keywd "var"))
8609 ;; Ifdef? Ignore name of define
8610 ((member keywd '("`ifdef" "`ifndef" "`elsif"))
8611 (setq rvalue t))
8612 ;; Type?
8613 ((unless ptype
8614 (verilog-typedef-name-p keywd))
8615 (cond (io
8616 (setq typedefed
8617 (if typedefed (concat typedefed " " keywd) keywd)))
8618 (t (setq vec nil enum nil rvalue nil signed nil
8619 typedefed keywd ; Have a type
8620 multidim nil sig-paren paren
8621 expect-signal 'sigs-var modport nil))))
8622 ;; Interface with optional modport in v2k arglist?
8623 ;; Skip over parsing modport, and take the interface name as the type
8624 ((and v2kargs-ok
8625 (eq paren 1)
8626 (not rvalue)
8627 (looking-at "\\s-*\\(\\.\\(\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*\\)\\|\\)\\s-*[a-zA-Z`_$][a-zA-Z0-9`_$]*"))
8628 (when (match-end 2) (goto-char (match-end 2)))
8629 (setq vec nil enum nil rvalue nil signed nil
8630 typedefed keywd multidim nil ptype nil modport (match-string 2)
8631 newsig nil sig-paren paren
8632 expect-signal 'sigs-intf io t ))
8633 ;; Ignore dotted LHS assignments: "assign foo.bar = z;"
8634 ((looking-at "\\s-*\\.")
8635 (goto-char (match-end 0))
8636 (when (not rvalue)
8637 (setq expect-signal nil)))
8638 ;; "modport <keywd>"
8639 ((and (eq in-modport t)
8640 (not (member keywd verilog-keywords)))
8641 (setq in-modport (verilog-modport-new keywd nil nil))
8642 (setq sigs-modports (cons in-modport sigs-modports))
8643 ;; Push old sig values to stack and point to new signal list
8644 (setq varstack (cons (vector sigs-out sigs-inout sigs-in)
8645 varstack))
8646 (setq sigs-in nil sigs-inout nil sigs-out nil))
8647 ;; "modport x (clocking <keywd>)"
8648 ((and in-modport in-clocking)
8649 (verilog-modport-clockings-add in-modport keywd)
8650 (setq in-clocking nil))
8651 ;; endclocking
8652 ((and in-clocking
8653 (equal keywd "endclocking"))
8654 (unless (eq in-clocking t)
8655 (verilog-modport-decls-set
8656 in-clocking
8657 (verilog-decls-new sigs-out sigs-inout sigs-in
8658 nil nil nil nil nil nil))
8659 ;; Pop from varstack to restore state to pre-clocking
8660 (setq tmp (car varstack)
8661 varstack (cdr varstack)
8662 sigs-out (aref tmp 0)
8663 sigs-inout (aref tmp 1)
8664 sigs-in (aref tmp 2)))
8665 (setq in-clocking nil))
8666 ;; "clocking <keywd>"
8667 ((and (eq in-clocking t)
8668 (not (member keywd verilog-keywords)))
8669 (setq in-clocking (verilog-modport-new keywd nil nil))
8670 (setq sigs-modports (cons in-clocking sigs-modports))
8671 ;; Push old sig values to stack and point to new signal list
8672 (setq varstack (cons (vector sigs-out sigs-inout sigs-in)
8673 varstack))
8674 (setq sigs-in nil sigs-inout nil sigs-out nil))
8675 ;; New signal, maybe?
8676 ((and expect-signal
8677 (not rvalue)
8678 (eq functask 0)
8679 (not (member keywd verilog-keywords)))
8680 ;; Add new signal to expect-signal's variable
8681 ;;(if dbg (setq dbg (concat dbg (format "Pt %s New sig %s'\n" (point) keywd))))
8682 (setq newsig (verilog-sig-new keywd vec nil nil enum signed typedefed multidim modport))
8683 (set expect-signal (cons newsig
8684 (symbol-value expect-signal))))))
8686 (forward-char 1)))
8687 (skip-syntax-forward " "))
8688 ;; Return arguments
8689 (setq tmp (verilog-decls-new (nreverse sigs-out)
8690 (nreverse sigs-inout)
8691 (nreverse sigs-in)
8692 (nreverse sigs-var)
8693 (nreverse sigs-modports)
8694 (nreverse sigs-assign)
8695 (nreverse sigs-const)
8696 (nreverse sigs-gparam)
8697 (nreverse sigs-intf)))
8698 ;;(if dbg (verilog-decls-princ tmp))
8699 tmp)))
8701 (defvar verilog-read-sub-decls-in-interfaced nil
8702 "For `verilog-read-sub-decls', process next signal as under interfaced block.")
8704 (defvar verilog-read-sub-decls-gate-ios nil
8705 "For `verilog-read-sub-decls', gate IO pins remaining, nil if non-primitive.")
8707 (eval-when-compile
8708 ;; Prevent compile warnings; these are let's, not globals
8709 ;; Do not remove the eval-when-compile
8710 ;; - we want an error when we are debugging this code if they are refed.
8711 (defvar sigs-in)
8712 (defvar sigs-inout)
8713 (defvar sigs-intf)
8714 (defvar sigs-intfd)
8715 (defvar sigs-out)
8716 (defvar sigs-out-d)
8717 (defvar sigs-out-i)
8718 (defvar sigs-out-unk)
8719 (defvar sigs-temp)
8720 ;; These are known to be from other packages and may not be defined
8721 (defvar diff-command)
8722 ;; There are known to be from newer versions of Emacs
8723 (defvar create-lockfiles)
8724 (defvar which-func-modes))
8726 (defun verilog-read-sub-decls-type (par-values portdata)
8727 "For `verilog-read-sub-decls-line', decode a signal type."
8728 (let* ((type (verilog-sig-type portdata))
8729 (pvassoc (assoc type par-values)))
8730 (cond ((member type '("wire" "reg")) nil)
8731 (pvassoc (nth 1 pvassoc))
8732 (t type))))
8734 (defun verilog-read-sub-decls-sig (submoddecls par-values comment port sig vec multidim mem)
8735 "For `verilog-read-sub-decls-line', add a signal."
8736 ;; sig eq t to indicate .name syntax
8737 ;;(message "vrsds: %s(%S)" port sig)
8738 (let ((dotname (eq sig t))
8739 portdata)
8740 (when sig
8741 (setq port (verilog-symbol-detick-denumber port))
8742 (setq sig (if dotname port (verilog-symbol-detick-denumber sig)))
8743 (if vec (setq vec (verilog-symbol-detick-denumber vec)))
8744 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim)))
8745 (if mem (setq mem (verilog-symbol-detick-denumber mem)))
8746 (unless (or (not sig)
8747 (equal sig "")) ; Ignore .foo(1'b1) assignments
8748 (cond ((or (setq portdata (assoc port (verilog-decls-get-inouts submoddecls)))
8749 (equal "inout" verilog-read-sub-decls-gate-ios))
8750 (setq sigs-inout
8751 (cons (verilog-sig-new
8753 (if dotname (verilog-sig-bits portdata) vec)
8754 (concat "To/From " comment)
8757 (verilog-sig-signed portdata)
8758 (verilog-read-sub-decls-type par-values portdata)
8759 multidim nil)
8760 sigs-inout)))
8761 ((or (setq portdata (assoc port (verilog-decls-get-outputs submoddecls)))
8762 (equal "output" verilog-read-sub-decls-gate-ios))
8763 (setq sigs-out
8764 (cons (verilog-sig-new
8766 (if dotname (verilog-sig-bits portdata) vec)
8767 (concat "From " comment)
8770 (verilog-sig-signed portdata)
8771 ;; Though ok in SV, in V2K code, propagating the
8772 ;; "reg" in "output reg" upwards isn't legal.
8773 ;; Also for backwards compatibility we don't propagate
8774 ;; "input wire" upwards.
8775 ;; See also `verilog-signals-edit-wire-reg'.
8776 (verilog-read-sub-decls-type par-values portdata)
8777 multidim nil)
8778 sigs-out)))
8779 ((or (setq portdata (assoc port (verilog-decls-get-inputs submoddecls)))
8780 (equal "input" verilog-read-sub-decls-gate-ios))
8781 (setq sigs-in
8782 (cons (verilog-sig-new
8784 (if dotname (verilog-sig-bits portdata) vec)
8785 (concat "To " comment)
8788 (verilog-sig-signed portdata)
8789 (verilog-read-sub-decls-type par-values portdata)
8790 multidim nil)
8791 sigs-in)))
8792 ((setq portdata (assoc port (verilog-decls-get-interfaces submoddecls)))
8793 (setq sigs-intf
8794 (cons (verilog-sig-new
8796 (if dotname (verilog-sig-bits portdata) vec)
8797 (concat "To/From " comment)
8800 (verilog-sig-signed portdata)
8801 (verilog-read-sub-decls-type par-values portdata)
8802 multidim nil)
8803 sigs-intf)))
8804 ((setq portdata (and verilog-read-sub-decls-in-interfaced
8805 (assoc port (verilog-decls-get-vars submoddecls))))
8806 (setq sigs-intfd
8807 (cons (verilog-sig-new
8809 (if dotname (verilog-sig-bits portdata) vec)
8810 (concat "To/From " comment)
8813 (verilog-sig-signed portdata)
8814 (verilog-read-sub-decls-type par-values portdata)
8815 multidim nil)
8816 sigs-intf)))
8817 ;; (t -- warning pin isn't defined.) ; Leave for lint tool
8818 )))))
8820 (defun verilog-read-sub-decls-expr (submoddecls par-values comment port expr)
8821 "For `verilog-read-sub-decls-line', parse a subexpression and add signals."
8822 ;;(message "vrsde: `%s'" expr)
8823 ;; Replace special /*[....]*/ comments inserted by verilog-auto-inst-port
8824 (setq expr (verilog-string-replace-matches "/\\*\\(\\.?\\[[^*]+\\]\\)\\*/" "\\1" nil nil expr))
8825 ;; Remove front operators
8826 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
8828 (cond
8829 ;; {..., a, b} requires us to recurse on a,b
8830 ;; To support {#{},{#{a,b}} we'll just split everything on [{},]
8831 ((string-match "^\\s-*{\\(.*\\)}\\s-*$" expr)
8832 (unless verilog-auto-ignore-concat
8833 (let ((mlst (split-string (match-string 1 expr) "[{},]"))
8834 mstr)
8835 (while (setq mstr (pop mlst))
8836 (verilog-read-sub-decls-expr submoddecls par-values comment port mstr)))))
8838 (let (sig vec multidim mem)
8839 ;; Remove leading reduction operators, etc
8840 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
8841 ;;(message "vrsde-ptop: `%s'" expr)
8842 (cond ; Find \signal. Final space is part of escaped signal name
8843 ((string-match "^\\s-*\\(\\\\[^ \t\n\f]+\\s-\\)" expr)
8844 ;;(message "vrsde-s: `%s'" (match-string 1 expr))
8845 (setq sig (match-string 1 expr)
8846 expr (substring expr (match-end 0))))
8847 ;; Find signal
8848 ((string-match "^\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" expr)
8849 ;;(message "vrsde-s: `%s'" (match-string 1 expr))
8850 (setq sig (verilog-string-remove-spaces (match-string 1 expr))
8851 expr (substring expr (match-end 0)))))
8852 ;; Find [vector] or [multi][multi][multi][vector]
8853 (while (string-match "^\\s-*\\(\\[[^]]+\\]\\)" expr)
8854 ;;(message "vrsde-v: `%s'" (match-string 1 expr))
8855 (when vec (setq multidim (cons vec multidim)))
8856 (setq vec (match-string 1 expr)
8857 expr (substring expr (match-end 0))))
8858 ;; Find .[unpacked_memory] or .[unpacked][unpacked]...
8859 (while (string-match "^\\s-*\\.\\(\\(\\[[^]]+\\]\\)+\\)" expr)
8860 ;;(message "vrsde-m: `%s'" (match-string 1 expr))
8861 (setq mem (match-string 1 expr)
8862 expr (substring expr (match-end 0))))
8863 ;; If found signal, and nothing unrecognized, add the signal
8864 ;;(message "vrsde-rem: `%s'" expr)
8865 (when (and sig (string-match "^\\s-*$" expr))
8866 (verilog-read-sub-decls-sig submoddecls par-values comment port sig vec multidim mem))))))
8868 (defun verilog-read-sub-decls-line (submoddecls par-values comment)
8869 "For `verilog-read-sub-decls', read lines of port defs until none match.
8870 Inserts the list of signals found, using submodi to look up each port."
8871 (let (done port)
8872 (save-excursion
8873 (forward-line 1)
8874 (while (not done)
8875 ;; Get port name
8876 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*")
8877 (setq port (match-string-no-properties 1))
8878 (goto-char (match-end 0)))
8879 ;; .\escaped (
8880 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*")
8881 (setq port (concat (match-string-no-properties 1) " ")) ; escaped id's need trailing space
8882 (goto-char (match-end 0)))
8883 ;; .name
8884 ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*[,)/]")
8885 (verilog-read-sub-decls-sig
8886 submoddecls par-values comment (match-string-no-properties 1) t ; sig==t for .name
8887 nil nil nil) ; vec multidim mem
8888 (setq port nil))
8889 ;; .\escaped_name
8890 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*[,)/]")
8891 (verilog-read-sub-decls-sig
8892 submoddecls par-values comment (concat (match-string-no-properties 1) " ") t ; sig==t for .name
8893 nil nil nil) ; vec multidim mem
8894 (setq port nil))
8895 ;; random
8896 ((looking-at "\\s-*\\.[^(]*(")
8897 (setq port nil) ; skip this line
8898 (goto-char (match-end 0)))
8900 (setq port nil done t))) ; Unknown, ignore rest of line
8901 ;; Get signal name. Point is at the first-non-space after (
8902 ;; We intentionally ignore (non-escaped) signals with .s in them
8903 ;; this prevents AUTOWIRE etc from noticing hierarchical sigs.
8904 (when port
8905 (cond ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*)")
8906 (verilog-read-sub-decls-sig
8907 submoddecls par-values comment port
8908 (verilog-string-remove-spaces (match-string-no-properties 1)) ; sig
8909 nil nil nil)) ; vec multidim mem
8911 ((looking-at "\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)")
8912 (verilog-read-sub-decls-sig
8913 submoddecls par-values comment port
8914 (verilog-string-remove-spaces (match-string-no-properties 1)) ; sig
8915 (match-string-no-properties 2) nil nil)) ; vec multidim mem
8916 ;; Fastpath was above looking-at's.
8917 ;; For something more complicated invoke a parser
8918 ((looking-at "[^)]+")
8919 (verilog-read-sub-decls-expr
8920 submoddecls par-values comment port
8921 (buffer-substring-no-properties
8922 (point) (1- (progn (search-backward "(") ; start at (
8923 (verilog-forward-sexp-ign-cmt 1)
8924 (point)))))))) ; expr
8926 (forward-line 1)))))
8927 ;;(verilog-read-sub-decls-line (verilog-subdecls-new nil nil nil nil nil) nil "Cmt")
8929 (defun verilog-read-sub-decls-gate (submoddecls par-values comment submod end-inst-point)
8930 "For `verilog-read-sub-decls', read lines of UDP gate decl until none match.
8931 Inserts the list of signals found."
8932 (save-excursion
8933 (let ((iolist (cdr (assoc submod verilog-gate-ios))))
8934 (while (< (point) end-inst-point)
8935 ;; Get primitive's signal name, as will never have port, and no trailing )
8936 (cond ((looking-at "//")
8937 (search-forward "\n"))
8938 ((looking-at "/\\*")
8939 (or (search-forward "*/")
8940 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
8941 ((looking-at "(\\*")
8942 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
8943 (forward-char 1)
8944 (or (search-forward "*)")
8945 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
8946 ;; On pins, parse and advance to next pin
8947 ;; Looking at pin, but *not* an // Output comment, or ) to end the inst
8948 ((looking-at "\\s-*[a-zA-Z0-9`_$({}\\\\][^,]*")
8949 (goto-char (match-end 0))
8950 (setq verilog-read-sub-decls-gate-ios (or (car iolist) "input")
8951 iolist (cdr iolist))
8952 (verilog-read-sub-decls-expr
8953 submoddecls par-values comment "primitive_port"
8954 (match-string 0)))
8956 (forward-char 1)
8957 (skip-syntax-forward " ")))))))
8959 (defun verilog-read-sub-decls ()
8960 "Internally parse signals going to modules under this module.
8961 Return an array of [ outputs inouts inputs ] signals for modules that are
8962 instantiated in this module. For example if declare A A (.B(SIG)) and SIG
8963 is an output, then SIG will be included in the list.
8965 This only works on instantiations created with /*AUTOINST*/ converted by
8966 \\[verilog-auto-inst]. Otherwise, it would have to read in the whole
8967 component library to determine connectivity of the design.
8969 One work around for this problem is to manually create // Inputs and //
8970 Outputs comments above subcell signals, for example:
8972 module ModuleName (
8973 // Outputs
8974 .out (out),
8975 // Inputs
8976 .in (in));"
8977 (save-excursion
8978 (let ((end-mod-point (verilog-get-end-of-defun))
8979 st-point end-inst-point par-values
8980 ;; below 3 modified by verilog-read-sub-decls-line
8981 sigs-out sigs-inout sigs-in sigs-intf sigs-intfd)
8982 (verilog-beg-of-defun-quick)
8983 (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t)
8984 (save-excursion
8985 (goto-char (match-beginning 0))
8986 (setq par-values (and verilog-auto-inst-param-value
8987 verilog-auto-inst-param-value-type
8988 (verilog-read-inst-param-value)))
8989 (unless (verilog-inside-comment-or-string-p)
8990 ;; Attempt to snarf a comment
8991 (let* ((submod (verilog-read-inst-module))
8992 (inst (verilog-read-inst-name))
8993 (subprim (member submod verilog-gate-keywords))
8994 (comment (concat inst " of " submod ".v"))
8995 submodi submoddecls)
8996 (cond
8997 (subprim
8998 (setq submodi `primitive
8999 submoddecls (verilog-decls-new nil nil nil nil nil nil nil nil nil)
9000 comment (concat inst " of " submod))
9001 (verilog-backward-open-paren)
9002 (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
9003 (point))
9004 st-point (point))
9005 (forward-char 1)
9006 (verilog-read-sub-decls-gate submoddecls par-values comment submod end-inst-point))
9007 ;; Non-primitive
9009 (when (setq submodi (verilog-modi-lookup submod t))
9010 (setq submoddecls (verilog-modi-get-decls submodi)
9011 verilog-read-sub-decls-gate-ios nil)
9012 (verilog-backward-open-paren)
9013 (setq end-inst-point (save-excursion (verilog-forward-sexp-ign-cmt 1)
9014 (point))
9015 st-point (point))
9016 ;; This could have used a list created by verilog-auto-inst
9017 ;; However I want it to be runnable even on user's manually added signals
9018 (let ((verilog-read-sub-decls-in-interfaced t))
9019 (while (re-search-forward "\\s *(?\\s *// Interfaced" end-inst-point t)
9020 (verilog-read-sub-decls-line submoddecls par-values comment))) ; Modifies sigs-ifd
9021 (goto-char st-point)
9022 (while (re-search-forward "\\s *(?\\s *// Interfaces" end-inst-point t)
9023 (verilog-read-sub-decls-line submoddecls par-values comment)) ; Modifies sigs-out
9024 (goto-char st-point)
9025 (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t)
9026 (verilog-read-sub-decls-line submoddecls par-values comment)) ; Modifies sigs-out
9027 (goto-char st-point)
9028 (while (re-search-forward "\\s *(?\\s *// Inouts" end-inst-point t)
9029 (verilog-read-sub-decls-line submoddecls par-values comment)) ; Modifies sigs-inout
9030 (goto-char st-point)
9031 (while (re-search-forward "\\s *(?\\s *// Inputs" end-inst-point t)
9032 (verilog-read-sub-decls-line submoddecls par-values comment)) ; Modifies sigs-in
9033 )))))))
9034 ;; Combine duplicate bits
9035 ;;(setq rr (vector sigs-out sigs-inout sigs-in))
9036 (verilog-subdecls-new
9037 (verilog-signals-combine-bus (nreverse sigs-out))
9038 (verilog-signals-combine-bus (nreverse sigs-inout))
9039 (verilog-signals-combine-bus (nreverse sigs-in))
9040 (verilog-signals-combine-bus (nreverse sigs-intf))
9041 (verilog-signals-combine-bus (nreverse sigs-intfd))))))
9043 (defun verilog-read-inst-pins ()
9044 "Return an array of [ pins ] for the current instantiation at point.
9045 For example if declare A A (.B(SIG)) then B will be included in the list."
9046 (save-excursion
9047 (let ((end-mod-point (point)) ; presume at /*AUTOINST*/ point
9048 pins pin)
9049 (verilog-backward-open-paren)
9050 (while (re-search-forward "\\.\\([^(,) \t\n\f]*\\)\\s-*" end-mod-point t)
9051 (setq pin (match-string 1))
9052 (unless (verilog-inside-comment-or-string-p)
9053 (setq pins (cons (list pin) pins))
9054 (when (looking-at "(")
9055 (verilog-forward-sexp-ign-cmt 1))))
9056 (vector pins))))
9058 (defun verilog-read-arg-pins ()
9059 "Return an array of [ pins ] for the current argument declaration at point."
9060 (save-excursion
9061 (let ((end-mod-point (point)) ; presume at /*AUTOARG*/ point
9062 pins pin)
9063 (verilog-backward-open-paren)
9064 (while (re-search-forward "\\([a-zA-Z0-9$_.%`]+\\)" end-mod-point t)
9065 (setq pin (match-string 1))
9066 (unless (verilog-inside-comment-or-string-p)
9067 (setq pins (cons (list pin) pins))))
9068 (vector pins))))
9070 (defun verilog-read-auto-constants (beg end-mod-point)
9071 "Return a list of AUTO_CONSTANTs used in the region from BEG to END-MOD-POINT."
9072 ;; Insert new
9073 (save-excursion
9074 (let (sig-list tpl-end-pt)
9075 (goto-char beg)
9076 (while (re-search-forward "\\<AUTO_CONSTANT" end-mod-point t)
9077 (if (not (looking-at "\\s *("))
9078 (error "%s: Missing () after AUTO_CONSTANT" (verilog-point-text)))
9079 (search-forward "(" end-mod-point)
9080 (setq tpl-end-pt (save-excursion
9081 (backward-char 1)
9082 (verilog-forward-sexp-cmt 1) ; Moves to paren that closes argdecl's
9083 (backward-char 1)
9084 (point)))
9085 (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t)
9086 (setq sig-list (cons (list (match-string 1) nil nil) sig-list))))
9087 sig-list)))
9089 (defvar verilog-cache-has-lisp nil "True if any AUTO_LISP in buffer.")
9090 (make-variable-buffer-local 'verilog-cache-has-lisp)
9092 (defun verilog-read-auto-lisp-present ()
9093 "Set `verilog-cache-has-lisp' if any AUTO_LISP in this buffer."
9094 (save-excursion
9095 (goto-char (point-min))
9096 (setq verilog-cache-has-lisp (re-search-forward "\\<AUTO_LISP(" nil t))))
9098 (defun verilog-read-auto-lisp (start end)
9099 "Look for and evaluate an AUTO_LISP between START and END.
9100 Must call `verilog-read-auto-lisp-present' before this function."
9101 ;; This function is expensive for large buffers, so we cache if any AUTO_LISP exists
9102 (when verilog-cache-has-lisp
9103 (save-excursion
9104 (goto-char start)
9105 (while (re-search-forward "\\<AUTO_LISP(" end t)
9106 (backward-char)
9107 (let* ((beg-pt (prog1 (point)
9108 (verilog-forward-sexp-cmt 1))) ; Closing paren
9109 (end-pt (point))
9110 (verilog-in-hooks t))
9111 (eval-region beg-pt end-pt nil))))))
9113 (defun verilog-read-always-signals-recurse
9114 (exit-keywd rvalue temp-next)
9115 "Recursive routine for parentheses/bracket matching.
9116 EXIT-KEYWD is expression to stop at, nil if top level.
9117 RVALUE is true if at right hand side of equal.
9118 IGNORE-NEXT is true to ignore next token, fake from inside case statement."
9119 (let* ((semi-rvalue (equal "endcase" exit-keywd)) ; true if after a ; we are looking for rvalue
9120 keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-list end-else-check
9121 ignore-next)
9122 ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue temp-next))))
9123 (while (not (or (eobp) gotend))
9124 (cond
9125 ((looking-at "//")
9126 (search-forward "\n"))
9127 ((looking-at "/\\*")
9128 (or (search-forward "*/")
9129 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
9130 ((looking-at "(\\*")
9131 ;; To advance past either "(*)" or "(* ... *)" don't forward past first *
9132 (forward-char 1)
9133 (or (search-forward "*)")
9134 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
9135 (t (setq keywd (buffer-substring-no-properties
9136 (point)
9137 (save-excursion (when (eq 0 (skip-chars-forward "a-zA-Z0-9$_.%`"))
9138 (forward-char 1))
9139 (point)))
9140 sig-last-tolk sig-tolk
9141 sig-tolk nil)
9142 ;;(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))))
9143 (cond
9144 ((equal keywd "\"")
9145 (or (re-search-forward "[^\\]\"" nil t)
9146 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
9147 ;; else at top level loop, keep parsing
9148 ((and end-else-check (equal keywd "else"))
9149 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else %s\n" keywd))))
9150 ;; no forward movement, want to see else in lower loop
9151 (setq end-else-check nil))
9152 ;; End at top level loop
9153 ((and end-else-check (looking-at "[^ \t\n\f]"))
9154 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else-other %s\n" keywd))))
9155 (setq gotend t))
9156 ;; Final statement?
9157 ((and exit-keywd (and (equal keywd exit-keywd)
9158 (not (looking-at "::"))))
9159 (setq gotend t)
9160 (forward-char (length keywd)))
9161 ;; Standard tokens...
9162 ((equal keywd ";")
9163 (setq ignore-next nil rvalue semi-rvalue)
9164 ;; Final statement at top level loop?
9165 (when (not exit-keywd)
9166 ;;(if dbg (setq dbg (concat dbg (format "\ttop-end-check %s\n" keywd))))
9167 (setq end-else-check t))
9168 (forward-char 1))
9169 ((equal keywd "'")
9170 (if (looking-at "'[sS]?[hdxboHDXBO]?[ \t]*[0-9a-fA-F_xzXZ?]+")
9171 (goto-char (match-end 0))
9172 (forward-char 1)))
9173 ((equal keywd ":") ; Case statement, begin/end label, x?y:z
9174 (cond ((looking-at "::")
9175 (forward-char 1)) ; Another forward-char below
9176 ((equal "endcase" exit-keywd) ; case x: y=z; statement next
9177 (setq ignore-next nil rvalue nil))
9178 ((equal "?" exit-keywd) ; x?y:z rvalue
9179 ) ; NOP
9180 ((equal "]" exit-keywd) ; [x:y] rvalue
9181 ) ; NOP
9182 (got-sig ; label: statement
9183 (setq ignore-next nil rvalue semi-rvalue got-sig nil))
9184 ((not rvalue) ; begin label
9185 (setq ignore-next t rvalue nil)))
9186 (forward-char 1))
9187 ((equal keywd "=")
9188 (when got-sig
9189 ;;(if dbg (setq dbg (concat dbg (format "\t\tequal got-sig=%S got-list=%s\n" got-sig got-list))))
9190 (set got-list (cons got-sig (symbol-value got-list)))
9191 (setq got-sig nil))
9192 (when (not rvalue)
9193 (if (eq (char-before) ?< )
9194 (setq sigs-out-d (append sigs-out-d sigs-out-unk)
9195 sigs-out-unk nil)
9196 (setq sigs-out-i (append sigs-out-i sigs-out-unk)
9197 sigs-out-unk nil)))
9198 (setq ignore-next nil rvalue t)
9199 (forward-char 1))
9200 ((equal keywd "?")
9201 (forward-char 1)
9202 (verilog-read-always-signals-recurse ":" rvalue nil))
9203 ((equal keywd "[")
9204 (forward-char 1)
9205 (verilog-read-always-signals-recurse "]" t nil))
9206 ((equal keywd "(")
9207 (forward-char 1)
9208 (cond (sig-last-tolk ; Function call; zap last signal
9209 (setq got-sig nil)))
9210 (cond ((equal last-keywd "for")
9211 ;; temp-next: Variables on LHS are lvalues, but generally we want
9212 ;; to ignore them, assuming they are loop increments
9213 (verilog-read-always-signals-recurse ";" nil t)
9214 (verilog-read-always-signals-recurse ";" t nil)
9215 (verilog-read-always-signals-recurse ")" nil nil))
9216 (t (verilog-read-always-signals-recurse ")" t nil))))
9217 ((equal keywd "begin")
9218 (skip-syntax-forward "w_")
9219 (verilog-read-always-signals-recurse "end" nil nil)
9220 ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd))))
9221 (setq ignore-next nil rvalue semi-rvalue)
9222 (if (not exit-keywd) (setq end-else-check t)))
9223 ((member keywd '("case" "casex" "casez" "randcase"))
9224 (skip-syntax-forward "w_")
9225 (verilog-read-always-signals-recurse "endcase" t nil)
9226 (setq ignore-next nil rvalue semi-rvalue)
9227 (if (not exit-keywd) (setq gotend t))) ; top level begin/end
9228 ((string-match "^[$`a-zA-Z_]" keywd) ; not exactly word constituent
9229 (cond ((member keywd '("`ifdef" "`ifndef" "`elsif"))
9230 (setq ignore-next t))
9231 ((or ignore-next
9232 (member keywd verilog-keywords)
9233 (string-match "^\\$" keywd)) ; PLI task
9234 (setq ignore-next nil))
9236 (setq keywd (verilog-symbol-detick-denumber keywd))
9237 (when got-sig
9238 (set got-list (cons got-sig (symbol-value got-list)))
9239 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S got-list=%S\n" got-sig got-list))))
9241 (setq got-list (cond (temp-next 'sigs-temp)
9242 (rvalue 'sigs-in)
9243 (t 'sigs-out-unk))
9244 got-sig (if (or (not keywd)
9245 (assoc keywd (symbol-value got-list)))
9246 nil (list keywd nil nil))
9247 temp-next nil
9248 sig-tolk t)))
9249 (skip-chars-forward "a-zA-Z0-9$_.%`"))
9251 (forward-char 1)))
9252 ;; End of non-comment token
9253 (setq last-keywd keywd)))
9254 (skip-syntax-forward " "))
9255 ;; Append the final pending signal
9256 (when got-sig
9257 ;;(if dbg (setq dbg (concat dbg (format "\t\tfinal got-sig=%S got-list=%s\n" got-sig got-list))))
9258 (set got-list (cons got-sig (symbol-value got-list)))
9259 (setq got-sig nil))
9260 ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd))))
9263 (defun verilog-read-always-signals ()
9264 "Parse always block at point and return list of (outputs inout inputs)."
9265 (save-excursion
9266 (let* (;(dbg "")
9267 sigs-out-d sigs-out-i sigs-out-unk sigs-temp sigs-in)
9268 (verilog-read-always-signals-recurse nil nil nil)
9269 (setq sigs-out-i (append sigs-out-i sigs-out-unk)
9270 sigs-out-unk nil)
9271 ;;(if dbg (with-current-buffer (get-buffer-create "*vl-dbg*") (delete-region (point-min) (point-max)) (insert dbg) (setq dbg "")))
9272 ;; Return what was found
9273 (verilog-alw-new sigs-out-d sigs-out-i sigs-temp sigs-in))))
9275 (defun verilog-read-instants ()
9276 "Parse module at point and return list of ( ( file instance ) ... )."
9277 (verilog-beg-of-defun-quick)
9278 (let* ((end-mod-point (verilog-get-end-of-defun))
9279 (state nil)
9280 (instants-list nil))
9281 (save-excursion
9282 (while (< (point) end-mod-point)
9283 ;; Stay at level 0, no comments
9284 (while (progn
9285 (setq state (parse-partial-sexp (point) end-mod-point 0 t nil))
9286 (or (> (car state) 0) ; in parens
9287 (nth 5 state) ; comment
9289 (forward-line 1))
9290 (beginning-of-line)
9291 (if (looking-at "^\\s-*\\([a-zA-Z0-9`_$]+\\)\\s-+\\([a-zA-Z0-9`_$]+\\)\\s-*(")
9292 ;;(if (looking-at "^\\(.+\\)$")
9293 (let ((module (match-string 1))
9294 (instant (match-string 2)))
9295 (if (not (member module verilog-keywords))
9296 (setq instants-list (cons (list module instant) instants-list)))))
9297 (forward-line 1)))
9298 instants-list))
9301 (defun verilog-read-auto-template-middle ()
9302 "With point in middle of an AUTO_TEMPLATE, parse it.
9303 Returns REGEXP and list of ( (signal_name connection_name)... )."
9304 (save-excursion
9305 ;; Find beginning
9306 (let ((tpl-regexp "\\([0-9]+\\)")
9307 (lineno -1) ; -1 to offset for the AUTO_TEMPLATE's newline
9308 (templateno 0)
9309 tpl-sig-list tpl-wild-list tpl-end-pt rep)
9310 ;; Parse "REGEXP"
9311 ;; We reserve @"..." for future lisp expressions that evaluate
9312 ;; once-per-AUTOINST
9313 (when (looking-at "\\s-*\"\\([^\"]*\\)\"")
9314 (setq tpl-regexp (match-string 1))
9315 (goto-char (match-end 0)))
9316 (search-forward "(")
9317 ;; Parse lines in the template
9318 (when (or verilog-auto-inst-template-numbers
9319 verilog-auto-template-warn-unused)
9320 (save-excursion
9321 (let ((pre-pt (point)))
9322 (goto-char (point-min))
9323 (while (search-forward "AUTO_TEMPLATE" pre-pt t)
9324 (setq templateno (1+ templateno)))
9325 (while (< (point) pre-pt)
9326 (forward-line 1)
9327 (setq lineno (1+ lineno))))))
9328 (setq tpl-end-pt (save-excursion
9329 (backward-char 1)
9330 (verilog-forward-sexp-cmt 1) ; Moves to paren that closes argdecl's
9331 (backward-char 1)
9332 (point)))
9334 (while (< (point) tpl-end-pt)
9335 (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
9336 (setq tpl-sig-list
9337 (cons (list
9338 (match-string-no-properties 1)
9339 (match-string-no-properties 2)
9340 templateno lineno)
9341 tpl-sig-list))
9342 (goto-char (match-end 0)))
9343 ;; Regexp form??
9344 ((looking-at
9345 ;; Regexp bug in XEmacs disallows ][ inside [], and wants + last
9346 "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
9347 (setq rep (match-string-no-properties 3))
9348 (goto-char (match-end 0))
9349 (setq tpl-wild-list
9350 (cons (list
9351 (concat "^"
9352 (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil
9353 (match-string 1))
9354 "$")
9356 templateno lineno)
9357 tpl-wild-list)))
9358 ((looking-at "[ \t\f]+")
9359 (goto-char (match-end 0)))
9360 ((looking-at "\n")
9361 (setq lineno (1+ lineno))
9362 (goto-char (match-end 0)))
9363 ((looking-at "//")
9364 (search-forward "\n")
9365 (setq lineno (1+ lineno)))
9366 ((looking-at "/\\*")
9367 (forward-char 2)
9368 (or (search-forward "*/")
9369 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
9371 (error "%s: AUTO_TEMPLATE parsing error: %s"
9372 (verilog-point-text)
9373 (progn (looking-at ".*$") (match-string 0))))))
9374 ;; Return
9375 (vector tpl-regexp
9376 (list tpl-sig-list tpl-wild-list)))))
9378 (defun verilog-read-auto-template (module)
9379 "Look for an auto_template for the instantiation of the given MODULE.
9380 If found returns `verilog-read-auto-template-inside' structure."
9381 (save-excursion
9382 ;; Find beginning
9383 (let ((pt (point)))
9384 ;; Note this search is expensive, as we hunt from mod-begin to point
9385 ;; for every instantiation. Likewise in verilog-read-auto-lisp.
9386 ;; So, we look first for an exact string rather than a slow regexp.
9387 ;; Someday we may keep a cache of every template, but this would also
9388 ;; need to record the relative position of each AUTOINST, as multiple
9389 ;; templates exist for each module, and we're inserting lines.
9390 (cond ((or
9391 ;; See also regexp in `verilog-auto-template-lint'
9392 (verilog-re-search-backward-substr
9393 "AUTO_TEMPLATE"
9394 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)
9395 ;; Also try forward of this AUTOINST
9396 ;; This is for historical support; this isn't speced as working
9397 (progn
9398 (goto-char pt)
9399 (verilog-re-search-forward-substr
9400 "AUTO_TEMPLATE"
9401 (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)))
9402 (goto-char (match-end 0))
9403 (verilog-read-auto-template-middle))
9404 ;; If no template found
9405 (t (vector "" nil))))))
9406 ;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry"))
9408 (defvar verilog-auto-template-hits nil "Successful lookups with `verilog-read-auto-template-hit'.")
9409 (make-variable-buffer-local 'verilog-auto-template-hits)
9411 (defun verilog-read-auto-template-init ()
9412 "Initialize `verilog-read-auto-template'."
9413 (when (eval-when-compile (fboundp 'make-hash-table)) ; else feature not allowed
9414 (when verilog-auto-template-warn-unused
9415 (setq verilog-auto-template-hits
9416 (make-hash-table :test 'equal :rehash-size 4.0)))))
9418 (defun verilog-read-auto-template-hit (tpl-ass)
9419 "Record that TPL-ASS template from `verilog-read-auto-template' was used."
9420 (when (eval-when-compile (fboundp 'make-hash-table)) ; else feature not allowed
9421 (when verilog-auto-template-warn-unused
9422 (unless verilog-auto-template-hits
9423 (verilog-read-auto-template-init))
9424 (puthash (vector (nth 2 tpl-ass) (nth 3 tpl-ass)) t
9425 verilog-auto-template-hits))))
9427 (defun verilog-set-define (defname defvalue &optional buffer enumname)
9428 "Set the definition DEFNAME to the DEFVALUE in the given BUFFER.
9429 Optionally associate it with the specified enumeration ENUMNAME."
9430 (with-current-buffer (or buffer (current-buffer))
9431 ;; Namespace intentionally short for AUTOs and compatibility
9432 (let ((mac (intern (concat "vh-" defname))))
9433 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
9434 ;; Need to define to a constant if no value given
9435 (set (make-local-variable mac)
9436 (if (equal defvalue "") "1" defvalue)))
9437 (if enumname
9438 ;; Namespace intentionally short for AUTOs and compatibility
9439 (let ((enumvar (intern (concat "venum-" enumname))))
9440 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
9441 (unless (boundp enumvar) (set enumvar nil))
9442 (add-to-list (make-local-variable enumvar) defname)))))
9444 (defun verilog-read-defines (&optional filename recurse subcall)
9445 "Read \\=`defines and parameters for the current file, or optional FILENAME.
9446 If the filename is provided, `verilog-library-flags' will be used to
9447 resolve it. If optional RECURSE is non-nil, recurse through \\=`includes.
9449 Localparams must be simple assignments to constants, or have their own
9450 \"localparam\" label rather than a list of localparams. Thus:
9452 localparam X = 5, Y = 10; // Ok
9453 localparam X = {1\\='b1, 2\\='h2}; // Ok
9454 localparam X = {1\\='b1, 2\\='h2}, Y = 10; // Bad, make into 2 localparam lines
9456 Defines must be simple text substitutions, one on a line, starting
9457 at the beginning of the line. Any ifdefs or multiline comments around the
9458 define are ignored.
9460 Defines are stored inside Emacs variables using the name
9461 vh-{definename}.
9463 Localparams define what symbols are constants so that AUTOSENSE
9464 will not include them in sensitivity lists. However any
9465 parameters in the include file are not considered ports in the
9466 including file, thus will not appear in AUTOINSTPARAM lists for a
9467 parent module..
9469 The file variables feature can be used to set defines that
9470 `verilog-mode' can see; put at the *END* of your file something
9471 like:
9473 // Local Variables:
9474 // vh-macro:\"macro_definition\"
9475 // End:
9477 If macros are defined earlier in the same file and you want their values,
9478 you can read them automatically with:
9480 // Local Variables:
9481 // verilog-auto-read-includes:t
9482 // End:
9484 Or a more specific alternative example, which requires having
9485 `enable-local-eval' non-nil:
9487 // Local Variables:
9488 // eval:(verilog-read-defines)
9489 // eval:(verilog-read-defines \"group_standard_includes.v\")
9490 // End:
9492 Note these are only read when the file is first visited, you must use
9493 \\[find-alternate-file] RET to have these take effect after editing them!
9495 If you want to disable the \"Process `eval' or hook local variables\"
9496 warning message, you need to add to your init file:
9498 (setq enable-local-eval t)"
9499 (let ((origbuf (current-buffer)))
9500 (save-excursion
9501 (unless subcall (verilog-getopt-flags))
9502 (when filename
9503 (let ((fns (verilog-library-filenames filename (buffer-file-name))))
9504 (if fns
9505 (set-buffer (find-file-noselect (car fns)))
9506 (error "%s: Can't find verilog-read-defines file: %s"
9507 (verilog-point-text) filename))))
9508 (when recurse
9509 (goto-char (point-min))
9510 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
9511 (let ((inc (verilog-string-replace-matches
9512 "\"" "" nil nil (match-string-no-properties 1))))
9513 (unless (verilog-inside-comment-or-string-p)
9514 (verilog-read-defines inc recurse t)))))
9515 ;; Read `defines
9516 ;; note we don't use verilog-re... it's faster this way, and that
9517 ;; function has problems when comments are at the end of the define
9518 (goto-char (point-min))
9519 (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t)
9520 (let ((defname (match-string-no-properties 1))
9521 (defvalue (match-string-no-properties 2)))
9522 (unless (verilog-inside-comment-or-string-p (match-beginning 0))
9523 (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue))
9524 (verilog-set-define defname defvalue origbuf))))
9525 ;; Hack: Read parameters
9526 (goto-char (point-min))
9527 (while (re-search-forward
9528 "^\\s-*\\(parameter\\|localparam\\)\\(\\s-*\\[[^]]*\\]\\)?\\s-*" nil t)
9529 (let (enumname)
9530 ;; The primary way of getting defines is verilog-read-decls
9531 ;; However, that isn't called yet for included files, so we'll add another scheme
9532 (if (looking-at "[^\n]*\\(auto\\|synopsys\\)\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
9533 (setq enumname (match-string-no-properties 2)))
9534 (forward-comment 99999)
9535 (while (looking-at (concat "\\s-*,?\\s-*\\(?:/[/*].*?$\\)?\\s-*\\([a-zA-Z0-9_$]+\\)"
9536 "\\s-*=\\s-*\\([^;,]*\\),?\\s-*\\(/[/*].*?$\\)?\\s-*"))
9537 (unless (verilog-inside-comment-or-string-p (match-beginning 0))
9538 (verilog-set-define (match-string-no-properties 1)
9539 (match-string-no-properties 2) origbuf enumname))
9540 (goto-char (match-end 0))
9541 (forward-comment 99999)))))))
9543 (defun verilog-read-includes ()
9544 "Read \\=`includes for the current file.
9545 This will find all of the \\=`includes which are at the beginning of lines,
9546 ignoring any ifdefs or multiline comments around them.
9547 `verilog-read-defines' is then performed on the current and each included
9548 file.
9550 It is often useful put at the *END* of your file something like:
9552 // Local Variables:
9553 // verilog-auto-read-includes:t
9554 // End:
9556 Or the equivalent longer version, which requires having
9557 `enable-local-eval' non-nil:
9559 // Local Variables:
9560 // eval:(verilog-read-defines)
9561 // eval:(verilog-read-includes)
9562 // End:
9564 Note includes are only read when the file is first visited, you must use
9565 \\[find-alternate-file] RET to have these take effect after editing them!
9567 It is good to get in the habit of including all needed files in each .v
9568 file that needs it, rather than waiting for compile time. This will aid
9569 this process, Verilint, and readability. To prevent defining the same
9570 variable over and over when many modules are compiled together, put a test
9571 around the inside each include file:
9573 foo.v (an include file):
9574 \\=`ifdef _FOO_V // include if not already included
9575 \\=`else
9576 \\=`define _FOO_V
9577 ... contents of file
9578 \\=`endif // _FOO_V"
9579 ;;slow: (verilog-read-defines nil t)
9580 (save-excursion
9581 (verilog-getopt-flags)
9582 (goto-char (point-min))
9583 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
9584 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string 1))))
9585 (verilog-read-defines inc nil t)))))
9587 (defun verilog-read-signals (&optional start end)
9588 "Return a simple list of all possible signals in the file.
9589 Bounded by optional region from START to END. Overly aggressive but fast.
9590 Some macros and such are also found and included. For dinotrace.el."
9591 (let (sigs-all keywd)
9592 (progn;save-excursion
9593 (goto-char (or start (point-min)))
9594 (setq end (or end (point-max)))
9595 (while (re-search-forward "[\"/a-zA-Z_.%`]" end t)
9596 (forward-char -1)
9597 (cond
9598 ((looking-at "//")
9599 (search-forward "\n"))
9600 ((looking-at "/\\*")
9601 (search-forward "*/"))
9602 ((looking-at "(\\*")
9603 (or (looking-at "(\\*\\s-*)") ; It's an "always @ (*)"
9604 (search-forward "*)")))
9605 ((eq ?\" (following-char))
9606 (re-search-forward "[^\\]\"")) ; don't forward-char first, since we look for a non backslash first
9607 ((looking-at "\\s-*\\([a-zA-Z0-9$_.%`]+\\)")
9608 (goto-char (match-end 0))
9609 (setq keywd (match-string-no-properties 1))
9610 (or (member keywd verilog-keywords)
9611 (member keywd sigs-all)
9612 (setq sigs-all (cons keywd sigs-all))))
9613 (t (forward-char 1))))
9614 ;; Return list
9615 sigs-all)))
9618 ;; Argument file parsing
9621 (defun verilog-getopt (arglist &optional default-dir)
9622 "Parse -f, -v etc arguments in ARGLIST list or string.
9623 Use DEFAULT-DIR to anchor paths if non-nil."
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 "-f")
9644 (setq next-param arg))
9645 ((equal arg "-v")
9646 (setq next-param arg))
9647 ((equal arg "-y")
9648 (setq next-param arg))
9649 ;; +libext+(ext1)+(ext2)...
9650 ((string-match "^\\+libext\\+\\(.*\\)" arg)
9651 (setq arg (match-string 1 arg))
9652 (while (string-match "\\([^+]+\\)\\+?\\(.*\\)" arg)
9653 (verilog-add-list-unique `verilog-library-extensions
9654 (match-string 1 arg))
9655 (setq arg (match-string 2 arg))))
9657 ((or (string-match "^-D\\([^+=]*\\)[+=]\\(.*\\)" arg) ; -Ddefine=val
9658 (string-match "^-D\\([^+=]*\\)\\(\\)" arg) ; -Ddefine
9659 (string-match "^\\+define\\([^+=]*\\)[+=]\\(.*\\)" arg) ; +define+val
9660 (string-match "^\\+define\\([^+=]*\\)\\(\\)" arg)) ; +define+define
9661 (verilog-set-define (match-string 1 arg) (match-string 2 arg)))
9663 ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ; +incdir+dir
9664 (string-match "^-I\\(.*\\)" arg)) ; -Idir
9665 (verilog-add-list-unique `verilog-library-directories
9666 (substitute-in-file-name (match-string 1 arg))))
9667 ;; Ignore
9668 ((equal "+librescan" arg))
9669 ((string-match "^-U\\(.*\\)" arg)) ; -Udefine
9670 ;; Second parameters
9671 ((equal next-param "-F")
9672 (setq next-param nil)
9673 (verilog-getopt-file (verilog-substitute-file-name-path arg default-dir)
9674 (file-name-directory (verilog-substitute-file-name-path arg default-dir))))
9675 ((equal next-param "-f")
9676 (setq next-param nil)
9677 (verilog-getopt-file (verilog-substitute-file-name-path arg default-dir) nil))
9678 ((equal next-param "-v")
9679 (setq next-param nil)
9680 (verilog-add-list-unique `verilog-library-files
9681 (verilog-substitute-file-name-path arg default-dir)))
9682 ((equal next-param "-y")
9683 (setq next-param nil)
9684 (verilog-add-list-unique `verilog-library-directories
9685 (verilog-substitute-file-name-path arg default-dir)))
9686 ;; Filename
9687 ((string-match "^[^-+]" arg)
9688 (verilog-add-list-unique `verilog-library-files
9689 (verilog-substitute-file-name-path arg default-dir)))
9690 ;; Default - ignore; no warning
9691 ))))
9692 ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir"))
9694 (defun verilog-getopt-file (filename &optional default-dir)
9695 "Read Verilog options from the specified FILENAME.
9696 Use DEFAULT-DIR to anchor paths if non-nil."
9697 (save-excursion
9698 (let ((fns (verilog-library-filenames filename (buffer-file-name)))
9699 (orig-buffer (current-buffer))
9700 line)
9701 (if fns
9702 (set-buffer (find-file-noselect (car fns)))
9703 (error "%s: Can't find verilog-getopt-file -f file: %s"
9704 (verilog-point-text) filename))
9705 (goto-char (point-min))
9706 (while (not (eobp))
9707 (setq line (buffer-substring (point) (point-at-eol)))
9708 (forward-line 1)
9709 (when (string-match "//" line)
9710 (setq line (substring line 0 (match-beginning 0))))
9711 (with-current-buffer orig-buffer ; Variables are buffer-local, so need right context.
9712 (verilog-getopt line default-dir))))))
9714 (defun verilog-getopt-flags ()
9715 "Convert `verilog-library-flags' into standard library variables."
9716 ;; If the flags are local, then all the outputs should be local also
9717 (when (local-variable-p `verilog-library-flags (current-buffer))
9718 (mapc 'make-local-variable '(verilog-library-extensions
9719 verilog-library-directories
9720 verilog-library-files
9721 verilog-library-flags)))
9722 ;; Allow user to customize
9723 (verilog-run-hooks 'verilog-before-getopt-flags-hook)
9724 ;; Process arguments
9725 (verilog-getopt verilog-library-flags)
9726 ;; Allow user to customize
9727 (verilog-run-hooks 'verilog-getopt-flags-hook))
9729 (defun verilog-substitute-file-name-path (filename default-dir)
9730 "Return FILENAME with environment variables substituted.
9731 Use DEFAULT-DIR to anchor paths if non-nil."
9732 (if default-dir
9733 (expand-file-name (substitute-in-file-name filename) default-dir)
9734 (substitute-in-file-name filename)))
9736 (defun verilog-add-list-unique (varref object)
9737 "Append to VARREF list the given OBJECT,
9738 unless it is already a member of the variable's list."
9739 (unless (member object (symbol-value varref))
9740 (set varref (append (symbol-value varref) (list object))))
9741 varref)
9742 ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l)
9744 (defun verilog-current-flags ()
9745 "Convert `verilog-library-flags' and similar variables to command line.
9746 Used for __FLAGS__ in `verilog-expand-command'."
9747 (let ((cmd (mapconcat `concat verilog-library-flags " ")))
9748 (when (equal cmd "")
9749 (setq cmd (concat
9750 "+libext+" (mapconcat `concat verilog-library-extensions "+")
9751 (mapconcat (lambda (i) (concat " -y " i " +incdir+" i))
9752 verilog-library-directories "")
9753 (mapconcat (lambda (i) (concat " -v " i))
9754 verilog-library-files ""))))
9755 cmd))
9756 ;;(verilog-current-flags)
9759 ;;; Cached directory support:
9762 (defvar verilog-dir-cache-preserving nil
9763 "If true, the directory cache is enabled, and file system changes are ignored.
9764 See `verilog-dir-exists-p' and `verilog-dir-files'.")
9766 ;; If adding new cached variable, add also to verilog-preserve-dir-cache
9767 (defvar verilog-dir-cache-list nil
9768 "Alist of (((Cwd Dirname) Results)...) for caching `verilog-dir-files'.")
9769 (defvar verilog-dir-cache-lib-filenames nil
9770 "Cached data for `verilog-library-filenames'.")
9772 (defmacro verilog-preserve-dir-cache (&rest body)
9773 "Execute the BODY forms, allowing directory cache preservation within BODY.
9774 This means that changes inside BODY made to the file system will not be
9775 seen by the `verilog-dir-files' and related functions."
9776 `(let ((verilog-dir-cache-preserving (current-buffer))
9777 verilog-dir-cache-list
9778 verilog-dir-cache-lib-filenames)
9779 (progn ,@body)))
9781 (defun verilog-dir-files (dirname)
9782 "Return all filenames in the DIRNAME directory.
9783 Relative paths depend on the `default-directory'.
9784 Results are cached if inside `verilog-preserve-dir-cache'."
9785 (unless verilog-dir-cache-preserving
9786 (setq verilog-dir-cache-list nil)) ; Cache disabled
9787 ;; We don't use expand-file-name on the dirname to make key, as it's slow
9788 (let* ((cache-key (list dirname default-directory))
9789 (fass (assoc cache-key verilog-dir-cache-list))
9790 exp-dirname data)
9791 (cond (fass ; Return data from cache hit
9792 (nth 1 fass))
9794 (setq exp-dirname (expand-file-name dirname)
9795 data (and (file-directory-p exp-dirname)
9796 (directory-files exp-dirname nil nil nil)))
9797 ;; Note we also encache nil for non-existing dirs.
9798 (setq verilog-dir-cache-list (cons (list cache-key data)
9799 verilog-dir-cache-list))
9800 data))))
9801 ;; Miss-and-hit test:
9802 ;;(verilog-preserve-dir-cache (prin1 (verilog-dir-files "."))
9803 ;; (prin1 (verilog-dir-files ".")) nil)
9805 (defun verilog-dir-file-exists-p (filename)
9806 "Return true if FILENAME exists.
9807 Like `file-exists-p' but results are cached if inside
9808 `verilog-preserve-dir-cache'."
9809 (let* ((dirname (file-name-directory filename))
9810 ;; Correct for file-name-nondirectory returning same if no slash.
9811 (dirnamed (if (or (not dirname) (equal dirname filename))
9812 default-directory dirname))
9813 (flist (verilog-dir-files dirnamed)))
9814 (and flist
9815 (member (file-name-nondirectory filename) flist)
9816 t)))
9817 ;;(verilog-dir-file-exists-p "verilog-mode.el")
9818 ;;(verilog-dir-file-exists-p "../verilog-mode/verilog-mode.el")
9821 ;;; Module name lookup:
9824 (defun verilog-module-inside-filename-p (module filename)
9825 "Return modi if MODULE is specified inside FILENAME, else nil.
9826 Allows version control to check out the file if need be."
9827 (and (or (file-exists-p filename)
9828 (and (fboundp 'vc-backend)
9829 (vc-backend filename)))
9830 (let (modi type)
9831 (with-current-buffer (find-file-noselect filename)
9832 (save-excursion
9833 (goto-char (point-min))
9834 (while (and
9835 ;; It may be tempting to look for verilog-defun-re,
9836 ;; don't, it slows things down a lot!
9837 (verilog-re-search-forward-quick "\\<\\(module\\|interface\\|program\\)\\>" nil t)
9838 (setq type (match-string-no-properties 0))
9839 (verilog-re-search-forward-quick "[(;]" nil t))
9840 (if (equal module (verilog-read-module-name))
9841 (setq modi (verilog-modi-new module filename (point) type))))
9842 modi)))))
9844 (defun verilog-is-number (symbol)
9845 "Return true if SYMBOL is number-like."
9846 (or (string-match "^[0-9 \t:]+$" symbol)
9847 (string-match "^[---]*[0-9]+$" symbol)
9848 (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol)))
9850 (defun verilog-symbol-detick (symbol wing-it)
9851 "Return an expanded SYMBOL name without any defines.
9852 If the variable vh-{symbol} is defined, return that value.
9853 If undefined, and WING-IT, return just SYMBOL without the tick, else nil."
9854 (while (and symbol (string-match "^`" symbol))
9855 (setq symbol (substring symbol 1))
9856 (setq symbol
9857 ;; Namespace intentionally short for AUTOs and compatibility
9858 (if (boundp (intern (concat "vh-" symbol)))
9859 ;; Emacs has a bug where boundp on a buffer-local
9860 ;; variable in only one buffer returns t in another.
9861 ;; This can confuse, so check for nil.
9862 ;; Namespace intentionally short for AUTOs and compatibility
9863 (let ((val (eval (intern (concat "vh-" symbol)))))
9864 (if (eq val nil)
9865 (if wing-it symbol nil)
9866 val))
9867 (if wing-it symbol nil))))
9868 symbol)
9869 ;;(verilog-symbol-detick "`mod" nil)
9871 (defun verilog-symbol-detick-denumber (symbol)
9872 "Return SYMBOL with defines converted and any numbers dropped to nil."
9873 (when (string-match "^`" symbol)
9874 ;; This only will work if the define is a simple signal, not
9875 ;; something like a[b]. Sorry, it should be substituted into the parser
9876 (setq symbol
9877 (verilog-string-replace-matches
9878 "\\[[^0-9: \t]+\\]" "" nil nil
9879 (or (verilog-symbol-detick symbol nil)
9880 (if verilog-auto-sense-defines-constant
9882 symbol)))))
9883 (if (verilog-is-number symbol)
9885 symbol))
9887 (defun verilog-symbol-detick-text (text)
9888 "Return TEXT without any known defines.
9889 If the variable vh-{symbol} is defined, substitute that value."
9890 (let ((ok t) symbol val)
9891 (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text))
9892 (setq symbol (match-string 1 text))
9893 ;;(message symbol)
9894 (cond ((and
9895 ;; Namespace intentionally short for AUTOs and compatibility
9896 (boundp (intern (concat "vh-" symbol)))
9897 ;; Emacs has a bug where boundp on a buffer-local
9898 ;; variable in only one buffer returns t in another.
9899 ;; This can confuse, so check for nil.
9900 ;; Namespace intentionally short for AUTOs and compatibility
9901 (setq val (eval (intern (concat "vh-" symbol)))))
9902 (setq text (replace-match val nil nil text)))
9903 (t (setq ok nil)))))
9904 text)
9905 ;;(progn (setq vh-mod "`foo" vh-foo "bar") (verilog-symbol-detick-text "bar `mod `undefed"))
9907 (defun verilog-expand-dirnames (&optional dirnames)
9908 "Return a list of existing directories given a list of wildcarded DIRNAMES.
9909 Or, just the existing dirnames themselves if there are no wildcards."
9910 ;; Note this function is performance critical.
9911 ;; Do not call anything that requires disk access that cannot be cached.
9912 (interactive)
9913 (unless dirnames
9914 (error "`verilog-library-directories' should include at least `.'"))
9915 (save-match-data
9916 (setq dirnames (reverse dirnames)) ; not nreverse
9917 (let ((dirlist nil)
9918 pattern dirfile dirfiles dirname root filename rest basefile)
9919 (setq dirnames (mapcar 'substitute-in-file-name dirnames))
9920 (while dirnames
9921 (setq dirname (car dirnames)
9922 dirnames (cdr dirnames))
9923 (cond ((string-match (concat "^\\(\\|[/\\]*[^*?]*[/\\]\\)" ; root
9924 "\\([^/\\]*[*?][^/\\]*\\)" ; filename with *?
9925 "\\(.*\\)") ; rest
9926 dirname)
9927 (setq root (match-string 1 dirname)
9928 filename (match-string 2 dirname)
9929 rest (match-string 3 dirname)
9930 pattern filename)
9931 ;; now replace those * and ? with .+ and .
9932 ;; use ^ and /> to get only whole file names
9933 (setq pattern (verilog-string-replace-matches "[*]" ".+" nil nil pattern)
9934 pattern (verilog-string-replace-matches "[?]" "." nil nil pattern)
9935 pattern (concat "^" pattern "$")
9936 dirfiles (verilog-dir-files root))
9937 (while dirfiles
9938 (setq basefile (car dirfiles)
9939 dirfile (expand-file-name (concat root basefile rest))
9940 dirfiles (cdr dirfiles))
9941 (when (and (string-match pattern basefile)
9942 ;; Don't allow abc/*/rtl to match abc/rtl via ..
9943 (not (equal basefile "."))
9944 (not (equal basefile "..")))
9945 ;; Might have more wildcards, so process again
9946 (setq dirnames (cons dirfile dirnames)))))
9947 ;; Defaults
9949 (if (file-directory-p dirname)
9950 (setq dirlist (cons dirname dirlist))))))
9951 dirlist)))
9952 ;;(verilog-expand-dirnames (list "." ".." "nonexist" "../*" "/home/wsnyder/*/v" "../*/*"))
9954 (defun verilog-library-filenames (filename &optional current check-ext)
9955 "Return a search path to find the given FILENAME or module name.
9956 Uses the optional CURRENT filename or variable `buffer-file-name', plus
9957 `verilog-library-directories' and `verilog-library-extensions'
9958 variables to build the path. With optional CHECK-EXT also check
9959 `verilog-library-extensions'."
9960 (unless current (setq current (buffer-file-name)))
9961 (unless verilog-dir-cache-preserving
9962 (setq verilog-dir-cache-lib-filenames nil))
9963 (let* ((cache-key (list filename current check-ext))
9964 (fass (assoc cache-key verilog-dir-cache-lib-filenames))
9965 chkdirs chkdir chkexts fn outlist)
9966 (cond (fass ; Return data from cache hit
9967 (nth 1 fass))
9969 ;; Note this expand can't be easily cached, as we need to
9970 ;; pick up buffer-local variables for newly read sub-module files
9971 (setq chkdirs (verilog-expand-dirnames verilog-library-directories))
9972 (while chkdirs
9973 (setq chkdir (expand-file-name (car chkdirs)
9974 (file-name-directory current))
9975 chkexts (if check-ext verilog-library-extensions `("")))
9976 (while chkexts
9977 (setq fn (expand-file-name (concat filename (car chkexts))
9978 chkdir))
9979 ;;(message "Check for %s" fn)
9980 (if (verilog-dir-file-exists-p fn)
9981 (setq outlist (cons (expand-file-name
9982 fn (file-name-directory current))
9983 outlist)))
9984 (setq chkexts (cdr chkexts)))
9985 (setq chkdirs (cdr chkdirs)))
9986 (setq outlist (nreverse outlist))
9987 (setq verilog-dir-cache-lib-filenames
9988 (cons (list cache-key outlist)
9989 verilog-dir-cache-lib-filenames))
9990 outlist))))
9992 (defun verilog-module-filenames (module current)
9993 "Return a search path to find the given MODULE name.
9994 Uses the CURRENT filename, `verilog-library-extensions',
9995 `verilog-library-directories' and `verilog-library-files'
9996 variables to build the path."
9997 ;; Return search locations for it
9998 (append (list current) ; first, current buffer
9999 (verilog-library-filenames module current t)
10000 ;; Finally any libraries; fixed up if using e.g. tramp
10001 (mapcar (lambda (fname)
10002 (if (file-name-absolute-p fname)
10003 (concat (file-remote-p current) fname)
10004 fname))
10005 verilog-library-files)))
10008 ;; Module Information
10010 ;; Many of these functions work on "modi" a module information structure
10011 ;; A modi is: [module-name-string file-name begin-point]
10013 (defvar verilog-cache-enabled t
10014 "Non-nil enables caching of signals, etc. Set to nil for debugging to make things SLOW!")
10016 (defvar verilog-modi-cache-list nil
10017 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)...
10018 For speeding up verilog-modi-get-* commands.
10019 Buffer-local.")
10020 (make-variable-buffer-local 'verilog-modi-cache-list)
10022 (defvar verilog-modi-cache-preserve-tick nil
10023 "Modification tick after which the cache is still considered valid.
10024 Use `verilog-preserve-modi-cache' to set it.")
10025 (defvar verilog-modi-cache-preserve-buffer nil
10026 "Modification tick after which the cache is still considered valid.
10027 Use `verilog-preserve-modi-cache' to set it.")
10028 (defvar verilog-modi-cache-current-enable nil
10029 "Non-nil means allow caching `verilog-modi-current', set by let().")
10030 (defvar verilog-modi-cache-current nil
10031 "Currently active `verilog-modi-current', if any, set by let().")
10032 (defvar verilog-modi-cache-current-max nil
10033 "Current endmodule point for `verilog-modi-cache-current', if any.")
10035 (defun verilog-modi-current ()
10036 "Return the modi structure for the module currently at point, possibly cached."
10037 (cond ((and verilog-modi-cache-current
10038 (>= (point) (verilog-modi-get-point verilog-modi-cache-current))
10039 (<= (point) verilog-modi-cache-current-max))
10040 ;; Slow assertion, for debugging the cache:
10041 ;;(or (equal verilog-modi-cache-current (verilog-modi-current-get)) (debug))
10042 verilog-modi-cache-current)
10043 (verilog-modi-cache-current-enable
10044 (setq verilog-modi-cache-current (verilog-modi-current-get)
10045 verilog-modi-cache-current-max
10046 ;; The cache expires when we pass "endmodule" as then the
10047 ;; current modi may change to the next module
10048 ;; This relies on the AUTOs generally inserting, not deleting text
10049 (save-excursion
10050 (verilog-re-search-forward-quick verilog-end-defun-re nil nil)))
10051 verilog-modi-cache-current)
10053 (verilog-modi-current-get))))
10055 (defun verilog-modi-current-get ()
10056 "Return the modi structure for the module currently at point."
10057 (let* (name type pt)
10058 ;; read current module's name
10059 (save-excursion
10060 (verilog-re-search-backward-quick verilog-defun-re nil nil)
10061 (setq type (match-string-no-properties 0))
10062 (verilog-re-search-forward-quick "(" nil nil)
10063 (setq name (verilog-read-module-name))
10064 (setq pt (point)))
10065 ;; return modi - note this vector built two places
10066 (verilog-modi-new name (or (buffer-file-name) (current-buffer)) pt type)))
10068 (defvar verilog-modi-lookup-cache nil "Hash of (modulename modi).")
10069 (make-variable-buffer-local 'verilog-modi-lookup-cache)
10070 (defvar verilog-modi-lookup-last-current nil "Cache of `current-buffer' at last lookup.")
10071 (defvar verilog-modi-lookup-last-tick nil "Cache of `buffer-chars-modified-tick' at last lookup.")
10073 (defun verilog-modi-lookup (module allow-cache &optional ignore-error)
10074 "Find the file and point at which MODULE is defined.
10075 If ALLOW-CACHE is set, check and remember cache of previous lookups.
10076 Return modi if successful, else print message unless IGNORE-ERROR is true."
10077 (let* ((current (or (buffer-file-name) (current-buffer)))
10078 modi)
10079 ;; Check cache
10080 ;;(message "verilog-modi-lookup: %s" module)
10081 (cond ((and verilog-modi-lookup-cache
10082 verilog-cache-enabled
10083 allow-cache
10084 (setq modi (gethash module verilog-modi-lookup-cache))
10085 (equal verilog-modi-lookup-last-current current)
10086 ;; If hit is in current buffer, then tick must match
10087 (or (equal verilog-modi-lookup-last-tick (buffer-chars-modified-tick))
10088 (not (equal current (verilog-modi-file-or-buffer modi)))))
10089 ;;(message "verilog-modi-lookup: HIT %S" modi)
10090 modi)
10091 ;; Miss
10092 (t (let* ((realname (verilog-symbol-detick module t))
10093 (orig-filenames (verilog-module-filenames realname current))
10094 (filenames orig-filenames)
10095 mif)
10096 (while (and filenames (not mif))
10097 (if (not (setq mif (verilog-module-inside-filename-p realname (car filenames))))
10098 (setq filenames (cdr filenames))))
10099 ;; mif has correct form to become later elements of modi
10100 (setq modi mif)
10101 (or mif ignore-error
10102 (error
10103 (concat
10104 "%s: Can't locate `%s' module definition%s"
10105 "\n Check the verilog-library-directories variable."
10106 "\n I looked in (if not listed, doesn't exist):\n\t%s")
10107 (verilog-point-text) module
10108 (if (not (equal module realname))
10109 (concat " (Expanded macro to " realname ")")
10111 (mapconcat 'concat orig-filenames "\n\t")))
10112 (when (eval-when-compile (fboundp 'make-hash-table))
10113 (unless verilog-modi-lookup-cache
10114 (setq verilog-modi-lookup-cache
10115 (make-hash-table :test 'equal :rehash-size 4.0)))
10116 (puthash module modi verilog-modi-lookup-cache))
10117 (setq verilog-modi-lookup-last-current current
10118 verilog-modi-lookup-last-tick (buffer-chars-modified-tick)))))
10119 modi))
10121 (defun verilog-modi-filename (modi)
10122 "Filename of MODI, or name of buffer if it's never been saved."
10123 (if (bufferp (verilog-modi-file-or-buffer modi))
10124 (or (buffer-file-name (verilog-modi-file-or-buffer modi))
10125 (buffer-name (verilog-modi-file-or-buffer modi)))
10126 (verilog-modi-file-or-buffer modi)))
10128 (defun verilog-modi-goto (modi)
10129 "Move point/buffer to specified MODI."
10130 (or modi (error "Passed unfound modi to goto, check earlier"))
10131 (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi))
10132 (verilog-modi-file-or-buffer modi)
10133 (find-file-noselect (verilog-modi-file-or-buffer modi))))
10134 (or (equal major-mode `verilog-mode) ; Put into Verilog mode to get syntax
10135 (verilog-mode))
10136 (goto-char (verilog-modi-get-point modi)))
10138 (defun verilog-goto-defun-file (module)
10139 "Move point to the file at which a given MODULE is defined."
10140 (interactive "sGoto File for Module: ")
10141 (let* ((modi (verilog-modi-lookup module nil)))
10142 (when modi
10143 (verilog-modi-goto modi)
10144 (switch-to-buffer (current-buffer)))))
10146 (defun verilog-modi-cache-results (modi function)
10147 "Run on MODI the given FUNCTION. Locate the module in a file.
10148 Cache the output of function so next call may have faster access."
10149 (let (fass)
10150 (save-excursion ; Cache is buffer-local so can't avoid this.
10151 (verilog-modi-goto modi)
10152 (if (and (setq fass (assoc (list modi function)
10153 verilog-modi-cache-list))
10154 ;; Destroy caching when incorrect; Modified or file changed
10155 (not (and verilog-cache-enabled
10156 (or (equal (buffer-chars-modified-tick) (nth 1 fass))
10157 (and verilog-modi-cache-preserve-tick
10158 (<= verilog-modi-cache-preserve-tick (nth 1 fass))
10159 (equal verilog-modi-cache-preserve-buffer (current-buffer))))
10160 (equal (visited-file-modtime) (nth 2 fass)))))
10161 (setq verilog-modi-cache-list nil
10162 fass nil))
10163 (cond (fass
10164 ;; Return data from cache hit
10165 (nth 3 fass))
10167 ;; Read from file
10168 ;; Clear then restore any highlighting to make emacs19 happy
10169 (let ((func-returns
10170 (verilog-save-font-no-change-functions
10171 (funcall function))))
10172 ;; Cache for next time
10173 (setq verilog-modi-cache-list
10174 (cons (list (list modi function)
10175 (buffer-chars-modified-tick)
10176 (visited-file-modtime)
10177 func-returns)
10178 verilog-modi-cache-list))
10179 func-returns))))))
10181 (defun verilog-modi-cache-add (modi function element sig-list)
10182 "Add function return results to the module cache.
10183 Update MODI's cache for given FUNCTION so that the return ELEMENT of that
10184 function now contains the additional SIG-LIST parameters."
10185 (let (fass)
10186 (save-excursion
10187 (verilog-modi-goto modi)
10188 (if (setq fass (assoc (list modi function)
10189 verilog-modi-cache-list))
10190 (let ((func-returns (nth 3 fass)))
10191 (aset func-returns element
10192 (append sig-list (aref func-returns element))))))))
10194 (defmacro verilog-preserve-modi-cache (&rest body)
10195 "Execute the BODY forms, allowing cache preservation within BODY.
10196 This means that changes to the buffer will not result in the cache being
10197 flushed. If the changes affect the modsig state, they must call the
10198 modsig-cache-add-* function, else the results of later calls may be
10199 incorrect. Without this, changes are assumed to be adding/removing signals
10200 and invalidating the cache."
10201 `(let ((verilog-modi-cache-preserve-tick (buffer-chars-modified-tick))
10202 (verilog-modi-cache-preserve-buffer (current-buffer)))
10203 (progn ,@body)))
10206 (defun verilog-modi-modport-lookup-one (modi name &optional ignore-error)
10207 "Given a MODI, return the declarations related to the given modport NAME.
10208 Report errors unless optional IGNORE-ERROR."
10209 ;; Recursive routine - see below
10210 (let* ((realname (verilog-symbol-detick name t))
10211 (modport (assoc name (verilog-decls-get-modports (verilog-modi-get-decls modi)))))
10212 (or modport ignore-error
10213 (error "%s: Can't locate `%s' modport definition%s"
10214 (verilog-point-text) name
10215 (if (not (equal name realname))
10216 (concat " (Expanded macro to " realname ")")
10217 "")))
10218 (let* ((decls (verilog-modport-decls modport))
10219 (clks (verilog-modport-clockings modport)))
10220 ;; Now expand any clocking's
10221 (while clks
10222 (setq decls (verilog-decls-append
10223 decls
10224 (verilog-modi-modport-lookup-one modi (car clks) ignore-error)))
10225 (setq clks (cdr clks)))
10226 decls)))
10228 (defun verilog-modi-modport-lookup (modi name-re &optional ignore-error)
10229 "Given a MODI, return the declarations related to the given modport NAME-RE.
10230 If the modport points to any clocking blocks, expand the signals to include
10231 those clocking block's signals."
10232 ;; Recursive routine - see below
10233 (let* ((mod-decls (verilog-modi-get-decls modi))
10234 (clks (verilog-decls-get-modports mod-decls))
10235 (name-re (concat "^" name-re "$"))
10236 (decls (verilog-decls-new nil nil nil nil nil nil nil nil nil)))
10237 ;; Pull in all modports
10238 (while clks
10239 (when (string-match name-re (verilog-modport-name (car clks)))
10240 (setq decls (verilog-decls-append
10241 decls
10242 (verilog-modi-modport-lookup-one modi (verilog-modport-name (car clks)) ignore-error))))
10243 (setq clks (cdr clks)))
10244 decls))
10246 (defun verilog-signals-matching-enum (in-list enum)
10247 "Return all signals in IN-LIST matching the given ENUM."
10248 (let (out-list)
10249 (while in-list
10250 (if (equal (verilog-sig-enum (car in-list)) enum)
10251 (setq out-list (cons (car in-list) out-list)))
10252 (setq in-list (cdr in-list)))
10253 ;; New scheme
10254 ;; Namespace intentionally short for AUTOs and compatibility
10255 (let* ((enumvar (intern (concat "venum-" enum)))
10256 (enumlist (and (boundp enumvar) (eval enumvar))))
10257 (while enumlist
10258 (add-to-list 'out-list (list (car enumlist)))
10259 (setq enumlist (cdr enumlist))))
10260 (nreverse out-list)))
10262 (defun verilog-signals-matching-regexp (in-list regexp)
10263 "Return all signals in IN-LIST matching the given REGEXP, if non-nil."
10264 (if (or (not regexp) (equal regexp ""))
10265 in-list
10266 (let ((case-fold-search verilog-case-fold)
10267 out-list)
10268 (while in-list
10269 (if (string-match regexp (verilog-sig-name (car in-list)))
10270 (setq out-list (cons (car in-list) out-list)))
10271 (setq in-list (cdr in-list)))
10272 (nreverse out-list))))
10274 (defun verilog-signals-not-matching-regexp (in-list regexp)
10275 "Return all signals in IN-LIST not matching the given REGEXP, if non-nil."
10276 (if (or (not regexp) (equal regexp ""))
10277 in-list
10278 (let ((case-fold-search verilog-case-fold)
10279 out-list)
10280 (while in-list
10281 (if (not (string-match regexp (verilog-sig-name (car in-list))))
10282 (setq out-list (cons (car in-list) out-list)))
10283 (setq in-list (cdr in-list)))
10284 (nreverse out-list))))
10286 (defun verilog-signals-matching-dir-re (in-list decl-type regexp)
10287 "Return all signals in IN-LIST matching the given DECL-TYPE and REGEXP,
10288 if non-nil."
10289 (if (or (not regexp) (equal regexp ""))
10290 in-list
10291 (let (out-list to-match)
10292 (while in-list
10293 ;; Note verilog-insert-one-definition matches on this order
10294 (setq to-match (concat
10295 decl-type
10296 " " (verilog-sig-signed (car in-list))
10297 " " (verilog-sig-multidim (car in-list))
10298 (verilog-sig-bits (car in-list))))
10299 (if (string-match regexp to-match)
10300 (setq out-list (cons (car in-list) out-list)))
10301 (setq in-list (cdr in-list)))
10302 (nreverse out-list))))
10304 (defun verilog-signals-edit-wire-reg (in-list)
10305 "Return all signals in IN-LIST with wire/reg data types made blank."
10306 (mapcar (lambda (sig)
10307 (when (member (verilog-sig-type sig) '("wire" "reg"))
10308 (verilog-sig-type-set sig nil))
10309 sig) in-list))
10311 ;; Combined
10312 (defun verilog-decls-get-signals (decls)
10313 "Return all declared signals in DECLS, excluding `assign' statements."
10314 (append
10315 (verilog-decls-get-outputs decls)
10316 (verilog-decls-get-inouts decls)
10317 (verilog-decls-get-inputs decls)
10318 (verilog-decls-get-vars decls)
10319 (verilog-decls-get-consts decls)
10320 (verilog-decls-get-gparams decls)))
10322 (defun verilog-decls-get-ports (decls)
10323 (append
10324 (verilog-decls-get-outputs decls)
10325 (verilog-decls-get-inouts decls)
10326 (verilog-decls-get-inputs decls)))
10328 (defun verilog-decls-get-iovars (decls)
10329 (append
10330 (verilog-decls-get-vars decls)
10331 (verilog-decls-get-outputs decls)
10332 (verilog-decls-get-inouts decls)
10333 (verilog-decls-get-inputs decls)))
10335 (defsubst verilog-modi-cache-add-outputs (modi sig-list)
10336 (verilog-modi-cache-add modi 'verilog-read-decls 0 sig-list))
10337 (defsubst verilog-modi-cache-add-inouts (modi sig-list)
10338 (verilog-modi-cache-add modi 'verilog-read-decls 1 sig-list))
10339 (defsubst verilog-modi-cache-add-inputs (modi sig-list)
10340 (verilog-modi-cache-add modi 'verilog-read-decls 2 sig-list))
10341 (defsubst verilog-modi-cache-add-vars (modi sig-list)
10342 (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list))
10343 (defsubst verilog-modi-cache-add-gparams (modi sig-list)
10344 (verilog-modi-cache-add modi 'verilog-read-decls 7 sig-list))
10347 ;;; Auto creation utilities:
10350 (defun verilog-auto-re-search-do (search-for func)
10351 "Search for the given auto text regexp SEARCH-FOR, and perform FUNC where it occurs."
10352 (goto-char (point-min))
10353 (while (verilog-re-search-forward-quick search-for nil t)
10354 (funcall func)))
10356 (defun verilog-insert-one-definition (sig type indent-pt)
10357 "Print out a definition for SIG of the given TYPE,
10358 with appropriate INDENT-PT indentation."
10359 (indent-to indent-pt)
10360 ;; Note verilog-signals-matching-dir-re matches on this order
10361 (insert type)
10362 (when (verilog-sig-modport sig)
10363 (insert "." (verilog-sig-modport sig)))
10364 (when (verilog-sig-signed sig)
10365 (insert " " (verilog-sig-signed sig)))
10366 (when (verilog-sig-multidim sig)
10367 (insert " " (verilog-sig-multidim-string sig)))
10368 (when (verilog-sig-bits sig)
10369 (insert " " (verilog-sig-bits sig)))
10370 (indent-to (max 24 (+ indent-pt 16)))
10371 (unless (= (char-syntax (preceding-char)) ?\ )
10372 (insert " ")) ; Need space between "]name" if indent-to did nothing
10373 (insert (verilog-sig-name sig))
10374 (when (verilog-sig-memory sig)
10375 (insert " " (verilog-sig-memory sig))))
10377 (defun verilog-insert-definition (modi sigs direction indent-pt v2k &optional dont-sort)
10378 "Print out a definition for MODI's list of SIGS of the given DIRECTION,
10379 with appropriate INDENT-PT indentation. If V2K, use Verilog 2001 I/O
10380 format. Sort unless DONT-SORT. DIRECTION is normally wire/reg/output.
10381 When MODI is non-null, also add to modi-cache, for tracking."
10382 (when modi
10383 (cond ((equal direction "wire")
10384 (verilog-modi-cache-add-vars modi sigs))
10385 ((equal direction "reg")
10386 (verilog-modi-cache-add-vars modi sigs))
10387 ((equal direction "output")
10388 (verilog-modi-cache-add-outputs modi sigs)
10389 (when verilog-auto-declare-nettype
10390 (verilog-modi-cache-add-vars modi sigs)))
10391 ((equal direction "input")
10392 (verilog-modi-cache-add-inputs modi sigs)
10393 (when verilog-auto-declare-nettype
10394 (verilog-modi-cache-add-vars modi sigs)))
10395 ((equal direction "inout")
10396 (verilog-modi-cache-add-inouts modi sigs)
10397 (when verilog-auto-declare-nettype
10398 (verilog-modi-cache-add-vars modi sigs)))
10399 ((equal direction "interface"))
10400 ((equal direction "parameter")
10401 (verilog-modi-cache-add-gparams modi sigs))
10403 (error "Unsupported verilog-insert-definition direction: `%s'" direction))))
10404 (or dont-sort
10405 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
10406 (while sigs
10407 (let ((sig (car sigs)))
10408 (verilog-insert-one-definition
10410 ;; Want "type x" or "output type x", not "wire type x"
10411 (cond ((and (equal "wire" verilog-auto-wire-type)
10412 (or (not (verilog-sig-type sig))
10413 (equal "logic" (verilog-sig-type sig))))
10414 (if (member direction '("input" "output" "inout"))
10415 direction
10416 "wire"))
10418 ((or (verilog-sig-type sig)
10419 verilog-auto-wire-type)
10420 (concat
10421 (when (member direction '("input" "output" "inout"))
10422 (concat direction " "))
10423 (or (verilog-sig-type sig)
10424 verilog-auto-wire-type)))
10426 ((and verilog-auto-declare-nettype
10427 (member direction '("input" "output" "inout")))
10428 (concat direction " " verilog-auto-declare-nettype))
10430 direction))
10431 indent-pt)
10432 (insert (if v2k "," ";"))
10433 (if (or (not verilog-auto-wire-comment)
10434 (not (verilog-sig-comment sig))
10435 (equal "" (verilog-sig-comment sig)))
10436 (insert "\n")
10437 (indent-to (max 48 (+ indent-pt 40)))
10438 (verilog-insert "// " (verilog-sig-comment sig) "\n"))
10439 (setq sigs (cdr sigs)))))
10441 (eval-when-compile
10442 (if (not (boundp 'indent-pt))
10443 (defvar indent-pt nil "Local used by `verilog-insert-indent'.")))
10445 (defun verilog-insert-indent (&rest stuff)
10446 "Indent to position stored in local `indent-pt' variable, then insert STUFF.
10447 Presumes that any newlines end a list element."
10448 (let ((need-indent t))
10449 (while stuff
10450 (if need-indent (indent-to indent-pt))
10451 (setq need-indent nil)
10452 (verilog-insert (car stuff))
10453 (setq need-indent (string-match "\n$" (car stuff))
10454 stuff (cdr stuff)))))
10455 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n"))
10457 (defun verilog-forward-or-insert-line ()
10458 "Move forward a line, unless at EOB, then insert a newline."
10459 (if (eobp) (insert "\n")
10460 (forward-line)))
10462 (defun verilog-repair-open-comma ()
10463 "Insert comma if previous argument is other than an open parenthesis or endif."
10464 ;; We can't just search backward for ) as it might be inside another expression.
10465 ;; Also want "`ifdef X input foo `endif" to just leave things to the human to deal with
10466 (save-excursion
10467 (verilog-backward-syntactic-ws-quick)
10468 (when (and (not (save-excursion ; Not beginning (, or existing ,
10469 (backward-char 1)
10470 (looking-at "[(,]")))
10471 (not (save-excursion ; Not `endif, or user define
10472 (backward-char 1)
10473 (skip-chars-backward "[a-zA-Z0-9_`]")
10474 (looking-at "`"))))
10475 (insert ","))))
10477 (defun verilog-repair-close-comma ()
10478 "If point is at a comma followed by a close parenthesis, fix it.
10479 This repairs those mis-inserted by an AUTOARG."
10480 ;; It would be much nicer if Verilog allowed extra commas like Perl does!
10481 (save-excursion
10482 (verilog-forward-close-paren)
10483 (backward-char 1)
10484 (verilog-backward-syntactic-ws-quick)
10485 (backward-char 1)
10486 (when (looking-at ",")
10487 (delete-char 1))))
10489 (defun verilog-make-width-expression (range-exp)
10490 "Return an expression calculating the length of a range [x:y] in RANGE-EXP."
10491 ;; strip off the []
10492 (cond ((not range-exp)
10493 "1")
10495 (if (string-match "^\\[\\(.*\\)\\]$" range-exp)
10496 (setq range-exp (match-string 1 range-exp)))
10497 (cond ((not range-exp)
10498 "1")
10499 ;; [#:#] We can compute a numeric result
10500 ((string-match "^\\s *\\([0-9]+\\)\\s *:\\s *\\([0-9]+\\)\\s *$"
10501 range-exp)
10502 (int-to-string
10503 (1+ (abs (- (string-to-number (match-string 1 range-exp))
10504 (string-to-number (match-string 2 range-exp)))))))
10505 ;; [PARAM-1:0] can just return PARAM
10506 ((string-match "^\\s *\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s *-\\s *1\\s *:\\s *0\\s *$" range-exp)
10507 (match-string 1 range-exp))
10508 ;; [arbitrary] need math
10509 ((string-match "^\\(.*\\)\\s *:\\s *\\(.*\\)\\s *$" range-exp)
10510 (concat "(1+(" (match-string 1 range-exp) ")"
10511 (if (equal "0" (match-string 2 range-exp))
10512 "" ; Don't bother with -(0)
10513 (concat "-(" (match-string 2 range-exp) ")"))
10514 ")"))
10515 (t nil)))))
10516 ;;(verilog-make-width-expression "`A:`B")
10518 (defun verilog-simplify-range-expression (expr)
10519 "Return a simplified range expression with constants eliminated from EXPR."
10520 ;; Note this is always called with brackets; ie [z] or [z:z]
10521 (if (not (string-match "[---+*()]" expr))
10522 expr ; short-circuit
10523 (let ((out expr)
10524 (last-pass ""))
10525 (while (not (equal last-pass out))
10526 (setq last-pass out)
10527 ;; Prefix regexp needs beginning of match, or some symbol of
10528 ;; lesser or equal precedence. We assume the [:]'s exist in expr.
10529 ;; Ditto the end.
10530 (while (string-match
10531 (concat "\\([[({:*+-]\\)" ; - must be last
10532 "(\\<\\([0-9A-Za-z_]+\\))"
10533 "\\([])}:*+-]\\)")
10534 out)
10535 (setq out (replace-match "\\1\\2\\3" nil nil out)))
10536 (while (string-match
10537 (concat "\\([[({:*+-]\\)" ; - must be last
10538 "\\$clog2\\s *(\\<\\([0-9]+\\))"
10539 "\\([])}:*+-]\\)")
10540 out)
10541 (setq out (replace-match
10542 (concat
10543 (match-string 1 out)
10544 (int-to-string (verilog-clog2 (string-to-number (match-string 2 out))))
10545 (match-string 3 out))
10546 nil nil out)))
10547 ;; For precedence do * before +/-
10548 (while (string-match
10549 (concat "\\([[({:*+-]\\)"
10550 "\\([0-9]+\\)\\s *\\([*]\\)\\s *\\([0-9]+\\)"
10551 "\\([])}:*+-]\\)")
10552 out)
10553 (setq out (replace-match
10554 (concat (match-string 1 out)
10555 (int-to-string (* (string-to-number (match-string 2 out))
10556 (string-to-number (match-string 4 out))))
10557 (match-string 5 out))
10558 nil nil out)))
10559 (while (string-match
10560 (concat "\\([[({:+-]\\)" ; No * here as higher prec
10561 "\\([0-9]+\\)\\s *\\([---+]\\)\\s *\\([0-9]+\\)"
10562 "\\([])}:+-]\\)")
10563 out)
10564 (let ((pre (match-string 1 out))
10565 (lhs (string-to-number (match-string 2 out)))
10566 (rhs (string-to-number (match-string 4 out)))
10567 (post (match-string 5 out))
10568 val)
10569 (when (equal pre "-")
10570 (setq lhs (- lhs)))
10571 (setq val (if (equal (match-string 3 out) "-")
10572 (- lhs rhs)
10573 (+ lhs rhs))
10574 out (replace-match
10575 (concat (if (and (equal pre "-")
10576 (< val 0))
10577 "" ; Not "--20" but just "-20"
10578 pre)
10579 (int-to-string val)
10580 post)
10581 nil nil out)) )))
10582 out)))
10584 ;;(verilog-simplify-range-expression "[1:3]") ; 1
10585 ;;(verilog-simplify-range-expression "[(1):3]") ; 1
10586 ;;(verilog-simplify-range-expression "[(((16)+1)+1+(1+1))]") ; 20
10587 ;;(verilog-simplify-range-expression "[(2*3+6*7)]") ; 48
10588 ;;(verilog-simplify-range-expression "[(FOO*4-1*2)]") ; FOO*4-2
10589 ;;(verilog-simplify-range-expression "[(FOO*4+1-1)]") ; FOO*4+0
10590 ;;(verilog-simplify-range-expression "[(func(BAR))]") ; func(BAR)
10591 ;;(verilog-simplify-range-expression "[FOO-1+1-1+1]") ; FOO-0
10592 ;;(verilog-simplify-range-expression "[$clog2(2)]") ; 1
10593 ;;(verilog-simplify-range-expression "[$clog2(7)]") ; 3
10595 (defun verilog-clog2 (value)
10596 "Compute $clog2 - ceiling log2 of VALUE."
10597 (if (< value 1)
10599 (ceiling (/ (log value) (log 2)))))
10601 (defun verilog-typedef-name-p (variable-name)
10602 "Return true if the VARIABLE-NAME is a type definition."
10603 (when verilog-typedef-regexp
10604 (verilog-string-match-fold verilog-typedef-regexp variable-name)))
10606 ;;; Auto deletion:
10609 (defun verilog-delete-autos-lined ()
10610 "Delete autos that occupy multiple lines, between begin and end comments."
10611 ;; The newline must not have a comment property, so we must
10612 ;; delete the end auto's newline, not the first newline
10613 (forward-line 1)
10614 (let ((pt (point)))
10615 (when (and
10616 (looking-at "\\s-*// Beginning")
10617 (search-forward "// End of automatic" nil t))
10618 ;; End exists
10619 (end-of-line)
10620 (forward-line 1)
10621 (delete-region pt (point)))))
10623 (defun verilog-delete-empty-auto-pair ()
10624 "Delete begin/end auto pair at point, if empty."
10625 (forward-line 0)
10626 (when (looking-at (concat "\\s-*// Beginning of automatic.*\n"
10627 "\\s-*// End of automatics\n"))
10628 (delete-region (point) (save-excursion (forward-line 2) (point)))))
10630 (defun verilog-forward-close-paren ()
10631 "Find the close parenthesis that match the current point.
10632 Ignore other close parenthesis with matching open parens."
10633 (let ((parens 1))
10634 (while (> parens 0)
10635 (unless (verilog-re-search-forward-quick "[()]" nil t)
10636 (error "%s: Mismatching ()" (verilog-point-text)))
10637 (cond ((= (preceding-char) ?\( )
10638 (setq parens (1+ parens)))
10639 ((= (preceding-char) ?\) )
10640 (setq parens (1- parens)))))))
10642 (defun verilog-backward-open-paren ()
10643 "Find the open parenthesis that match the current point.
10644 Ignore other open parenthesis with matching close parens."
10645 (let ((parens 1))
10646 (while (> parens 0)
10647 (unless (verilog-re-search-backward-quick "[()]" nil t)
10648 (error "%s: Mismatching ()" (verilog-point-text)))
10649 (cond ((= (following-char) ?\) )
10650 (setq parens (1+ parens)))
10651 ((= (following-char) ?\( )
10652 (setq parens (1- parens)))))))
10654 (defun verilog-backward-open-bracket ()
10655 "Find the open bracket that match the current point.
10656 Ignore other open bracket with matching close bracket."
10657 (let ((parens 1))
10658 (while (> parens 0)
10659 (unless (verilog-re-search-backward-quick "[][]" nil t)
10660 (error "%s: Mismatching []" (verilog-point-text)))
10661 (cond ((= (following-char) ?\] )
10662 (setq parens (1+ parens)))
10663 ((= (following-char) ?\[ )
10664 (setq parens (1- parens)))))))
10666 (defun verilog-delete-to-paren ()
10667 "Delete the automatic inst/sense/arg created by autos.
10668 Deletion stops at the matching end parenthesis, outside comments."
10669 (delete-region (point)
10670 (save-excursion
10671 (verilog-backward-open-paren)
10672 (verilog-forward-sexp-ign-cmt 1) ; Moves to paren that closes argdecl's
10673 (backward-char 1)
10674 (point))))
10676 (defun verilog-auto-star-safe ()
10677 "Return if a .* AUTOINST is safe to delete or expand.
10678 It was created by the AUTOS themselves, or by the user."
10679 (and verilog-auto-star-expand
10680 (looking-at
10681 (concat "[ \t\n\f,]*\\([)]\\|// " verilog-inst-comment-re "\\)"))))
10683 (defun verilog-delete-auto-star-all ()
10684 "Delete a .* AUTOINST, if it is safe."
10685 (when (verilog-auto-star-safe)
10686 (verilog-delete-to-paren)))
10688 (defun verilog-delete-auto-star-implicit ()
10689 "Delete all .* implicit connections created by `verilog-auto-star'.
10690 This function will be called automatically at save unless
10691 `verilog-auto-star-save' is set, any non-templated expanded pins will be
10692 removed."
10693 (interactive)
10694 (let (paren-pt indent have-close-paren)
10695 (save-excursion
10696 (goto-char (point-min))
10697 ;; We need to match these even outside of comments.
10698 ;; For reasonable performance, we don't check if inside comments, sorry.
10699 (while (re-search-forward "// Implicit \\.\\*" nil t)
10700 (setq paren-pt (point))
10701 (beginning-of-line)
10702 (setq have-close-paren
10703 (save-excursion
10704 (when (search-forward ");" paren-pt t)
10705 (setq indent (current-indentation))
10706 t)))
10707 (delete-region (point) (+ 1 paren-pt)) ; Nuke line incl CR
10708 (when have-close-paren
10709 ;; Delete extra commentary
10710 (save-excursion
10711 (while (progn
10712 (forward-line -1)
10713 (looking-at (concat "\\s *//\\s *" verilog-inst-comment-re "\n")))
10714 (delete-region (match-beginning 0) (match-end 0))))
10715 ;; If it is simple, we can put the ); on the same line as the last text
10716 (let ((rtn-pt (point)))
10717 (save-excursion
10718 (while (progn (backward-char 1)
10719 (looking-at "[ \t\n\f]")))
10720 (when (looking-at ",")
10721 (delete-region (+ 1 (point)) rtn-pt))))
10722 (when (bolp)
10723 (indent-to indent))
10724 (insert ");\n")
10725 ;; Still need to kill final comma - always is one as we put one after the .*
10726 (re-search-backward ",")
10727 (delete-char 1))))))
10729 (defun verilog-delete-auto-buffer ()
10730 "Perform `verilog-delete-auto' on the current buffer.
10731 Intended for internal use inside a `verilog-save-font-no-change-functions' block."
10732 ;; Allow user to customize
10733 (verilog-run-hooks 'verilog-before-delete-auto-hook)
10735 ;; Remove those that have multi-line insertions, possibly with parameters
10736 ;; We allow anything beginning with AUTO, so that users can add their own
10737 ;; patterns
10738 (verilog-auto-re-search-do
10739 (concat "/\\*AUTO[A-Za-z0-9_]+"
10740 ;; Optional parens or quoted parameter or .* for (((...)))
10741 "\\(\\|([^)]*)\\|(\"[^\"]*\")\\).*?"
10742 "\\*/")
10743 'verilog-delete-autos-lined)
10744 ;; Remove those that are in parenthesis
10745 (verilog-auto-re-search-do
10746 (concat "/\\*"
10747 (eval-when-compile
10748 (verilog-regexp-words
10749 `("AS" "AUTOARG" "AUTOCONCATWIDTH" "AUTOINST" "AUTOINSTPARAM"
10750 "AUTOSENSE")))
10751 "\\*/")
10752 'verilog-delete-to-paren)
10753 ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments
10754 (verilog-auto-re-search-do "\\.\\*"
10755 'verilog-delete-auto-star-all)
10756 ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed
10757 (goto-char (point-min))
10758 (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)\\([ \tLT0-9]*\\| LHS: .*\\)?$" nil t)
10759 (replace-match ""))
10761 ;; Final customize
10762 (verilog-run-hooks 'verilog-delete-auto-hook))
10764 (defun verilog-delete-auto ()
10765 "Delete the automatic outputs, regs, and wires created by \\[verilog-auto].
10766 Use \\[verilog-auto] to re-insert the updated AUTOs.
10768 The hooks `verilog-before-delete-auto-hook' and `verilog-delete-auto-hook' are
10769 called before and after this function, respectively."
10770 (interactive)
10771 (save-excursion
10772 (if (buffer-file-name)
10773 (find-file-noselect (buffer-file-name))) ; To check we have latest version
10774 (verilog-save-font-no-change-functions
10775 (verilog-save-scan-cache
10776 (verilog-delete-auto-buffer)))))
10779 ;;; Auto inject:
10782 (defun verilog-inject-auto ()
10783 "Examine legacy non-AUTO code and insert AUTOs in appropriate places.
10785 Any always @ blocks with sensitivity lists that match computed lists will
10786 be replaced with /*AS*/ comments.
10788 Any cells will get /*AUTOINST*/ added to the end of the pin list.
10789 Pins with have identical names will be deleted.
10791 Argument lists will not be deleted, /*AUTOARG*/ will only be inserted to
10792 support adding new ports. You may wish to delete older ports yourself.
10794 For example:
10796 module ExampInject (i, o);
10797 input i;
10798 input j;
10799 output o;
10800 always @ (i or j)
10801 o = i | j;
10802 InstModule instName
10803 (.foobar(baz),
10804 j(j));
10805 endmodule
10807 Typing \\[verilog-inject-auto] will make this into:
10809 module ExampInject (i, o/*AUTOARG*/
10810 // Inputs
10812 input i;
10813 output o;
10814 always @ (/*AS*/i or j)
10815 o = i | j;
10816 InstModule instName
10817 (.foobar(baz),
10818 /*AUTOINST*/
10819 // Outputs
10820 j(j));
10821 endmodule"
10822 (interactive)
10823 (verilog-auto t))
10825 (defun verilog-inject-arg ()
10826 "Inject AUTOARG into new code. See `verilog-inject-auto'."
10827 ;; Presume one module per file.
10828 (save-excursion
10829 (goto-char (point-min))
10830 (while (verilog-re-search-forward-quick "\\<module\\>" nil t)
10831 (let ((endmodp (save-excursion
10832 (verilog-re-search-forward-quick "\\<endmodule\\>" nil t)
10833 (point))))
10834 ;; See if there's already a comment .. inside a comment so not verilog-re-search
10835 (when (not (re-search-forward "/\\*AUTOARG\\*/" endmodp t))
10836 (verilog-re-search-forward-quick ";" nil t)
10837 (backward-char 1)
10838 (verilog-backward-syntactic-ws-quick)
10839 (backward-char 1) ; Moves to paren that closes argdecl's
10840 (when (looking-at ")")
10841 (verilog-insert "/*AUTOARG*/")))))))
10843 (defun verilog-inject-sense ()
10844 "Inject AUTOSENSE into new code. See `verilog-inject-auto'."
10845 (save-excursion
10846 (goto-char (point-min))
10847 (while (verilog-re-search-forward-quick "\\<always\\s *@\\s *(" nil t)
10848 (let* ((start-pt (point))
10849 (modi (verilog-modi-current))
10850 (moddecls (verilog-modi-get-decls modi))
10851 pre-sigs
10852 got-sigs)
10853 (backward-char 1)
10854 (verilog-forward-sexp-ign-cmt 1)
10855 (backward-char 1) ; End )
10856 (when (not (verilog-re-search-backward-quick "/\\*\\(AUTOSENSE\\|AS\\)\\*/" start-pt t))
10857 (setq pre-sigs (verilog-signals-from-signame
10858 (verilog-read-signals start-pt (point)))
10859 got-sigs (verilog-auto-sense-sigs moddecls nil))
10860 (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal?
10861 (verilog-signals-not-in got-sigs pre-sigs)))
10862 (delete-region start-pt (point))
10863 (verilog-insert "/*AS*/")))))))
10865 (defun verilog-inject-inst ()
10866 "Inject AUTOINST into new code. See `verilog-inject-auto'."
10867 (save-excursion
10868 (goto-char (point-min))
10869 ;; It's hard to distinguish modules; we'll instead search for pins.
10870 (while (verilog-re-search-forward-quick "\\.\\s *[a-zA-Z0-9`_$]+\\s *(\\s *[a-zA-Z0-9`_$]+\\s *)" nil t)
10871 (verilog-backward-open-paren) ; Inst start
10872 (cond
10873 ((= (preceding-char) ?\#) ; #(...) parameter section, not pin. Skip.
10874 (forward-char 1)
10875 (verilog-forward-close-paren)) ; Parameters done
10877 (forward-char 1)
10878 (let ((indent-pt (+ (current-column)))
10879 (end-pt (save-excursion (verilog-forward-close-paren) (point))))
10880 (cond ((verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-pt t)
10881 (goto-char end-pt)) ; Already there, continue search with next instance
10883 ;; Delete identical interconnect
10884 (let ((case-fold-search nil)) ; So we don't convert upper-to-lower, etc
10885 (while (verilog-re-search-forward-quick "\\.\\s *\\([a-zA-Z0-9`_$]+\\)*\\s *(\\s *\\1\\s *)\\s *" end-pt t)
10886 (delete-region (match-beginning 0) (match-end 0))
10887 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))) ; Keep it correct
10888 (while (or (looking-at "[ \t\n\f,]+")
10889 (looking-at "//[^\n]*"))
10890 (delete-region (match-beginning 0) (match-end 0))
10891 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))))))
10892 (verilog-forward-close-paren)
10893 (backward-char 1)
10894 ;; Not verilog-re-search, as we don't want to strip comments
10895 (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t)
10896 (delete-region (match-beginning 0) (match-end 0)))
10897 (verilog-insert "\n")
10898 (verilog-insert-indent "/*AUTOINST*/")))))))))
10901 ;; Auto diff:
10904 (defun verilog-diff-buffers-p (b1 b2 &optional whitespace regexp)
10905 "Return nil if buffers B1 and B2 have same contents.
10906 Else, return point in B1 that first mismatches.
10907 If optional WHITESPACE true, ignore whitespace.
10908 If optional REGEXP, ignore differences matching it."
10909 (save-excursion
10910 (let* ((case-fold-search nil) ; compare-buffer-substrings cares
10911 (p1 (with-current-buffer b1 (goto-char (point-min))))
10912 (p2 (with-current-buffer b2 (goto-char (point-min))))
10913 (maxp1 (with-current-buffer b1 (point-max)))
10914 (maxp2 (with-current-buffer b2 (point-max)))
10915 (op1 -1) (op2 -1)
10916 progress size)
10917 (while (not (and (eq p1 op1) (eq p2 op2)))
10918 ;; If both windows have whitespace optionally skip over it.
10919 (when whitespace
10920 ;; skip-syntax-* doesn't count \n
10921 (with-current-buffer b1
10922 (goto-char p1)
10923 (skip-chars-forward " \t\n\r\f\v")
10924 (setq p1 (point)))
10925 (with-current-buffer b2
10926 (goto-char p2)
10927 (skip-chars-forward " \t\n\r\f\v")
10928 (setq p2 (point))))
10929 (when regexp
10930 (with-current-buffer b1
10931 (goto-char p1)
10932 (when (looking-at regexp)
10933 (setq p1 (match-end 0))))
10934 (with-current-buffer b2
10935 (goto-char p2)
10936 (when (looking-at regexp)
10937 (setq p2 (match-end 0)))))
10938 (setq size (min (- maxp1 p1) (- maxp2 p2)))
10939 (setq progress (compare-buffer-substrings b2 p2 (+ size p2)
10940 b1 p1 (+ size p1)))
10941 (setq progress (if (zerop progress) size (1- (abs progress))))
10942 (setq op1 p1 op2 p2
10943 p1 (+ p1 progress)
10944 p2 (+ p2 progress)))
10945 ;; Return value
10946 (if (and (eq p1 maxp1) (eq p2 maxp2))
10947 nil p1))))
10949 (defun verilog-diff-file-with-buffer (f1 b2 &optional whitespace show)
10950 "View the differences between file F1 and buffer B2.
10951 This requires the external program `diff-command' to be in your `exec-path',
10952 and uses `diff-switches' in which you may want to have \"-u\" flag.
10953 Ignores WHITESPACE if t, and writes output to stdout if SHOW."
10954 ;; Similar to `diff-buffer-with-file' but works on XEmacs, and doesn't
10955 ;; call `diff' as `diff' has different calling semantics on different
10956 ;; versions of Emacs.
10957 (if (not (file-exists-p f1))
10958 (message "Buffer `%s' has no associated file on disk" (buffer-name b2))
10959 (with-temp-buffer "*Verilog-Diff*"
10960 (let ((outbuf (current-buffer))
10961 (f2 (make-temp-file "vm-diff-auto-")))
10962 (unwind-protect
10963 (progn
10964 (with-current-buffer b2
10965 (save-restriction
10966 (widen)
10967 (write-region (point-min) (point-max) f2 nil 'nomessage)))
10968 (call-process diff-command nil outbuf t
10969 diff-switches ; User may want -u in diff-switches
10970 (if whitespace "-b" "")
10971 f1 f2)
10972 ;; Print out results. Alternatively we could have call-processed
10973 ;; ourself, but this way we can reuse diff switches
10974 (when show
10975 (with-current-buffer outbuf (message "%s" (buffer-string))))))
10976 (sit-for 0)
10977 (when (file-exists-p f2)
10978 (delete-file f2))))))
10980 (defun verilog-diff-report (b1 b2 diffpt)
10981 "Report differences detected with `verilog-diff-auto'.
10982 Differences are between buffers B1 and B2, starting at point
10983 DIFFPT. This function is called via `verilog-diff-function'."
10984 (let ((name1 (with-current-buffer b1 (buffer-file-name))))
10985 (verilog-warn-error "%s:%d: Difference in AUTO expansion found"
10986 name1 (with-current-buffer b1
10987 (count-lines (point-min) diffpt)))
10988 (cond (noninteractive
10989 (verilog-diff-file-with-buffer name1 b2 t t))
10991 (ediff-buffers b1 b2)))))
10993 (defun verilog-diff-auto ()
10994 "Expand AUTOs in a temporary buffer and indicate any change.
10995 Whitespace is ignored when detecting differences, but once a
10996 difference is detected, whitespace differences may be shown.
10998 To call this from the command line, see \\[verilog-batch-diff-auto].
11000 The action on differences is selected with
11001 `verilog-diff-function'. The default is `verilog-diff-report'
11002 which will report an error and run `ediff' in interactive mode,
11003 or `diff' in batch mode."
11004 (interactive)
11005 (let ((b1 (current-buffer)) b2 diffpt
11006 (name1 (buffer-file-name))
11007 (newname "*Verilog-Diff*"))
11008 (save-excursion
11009 (when (get-buffer newname)
11010 (kill-buffer newname))
11011 (setq b2 (let (buffer-file-name) ; Else clone is upset
11012 (clone-buffer newname)))
11013 (with-current-buffer b2
11014 ;; auto requires the filename, but can't have same filename in two
11015 ;; buffers; so override both b1 and b2's names
11016 (let ((buffer-file-name name1))
11017 (unwind-protect
11018 (progn
11019 (with-current-buffer b1 (setq buffer-file-name nil))
11020 (verilog-auto)
11021 (when (not verilog-auto-star-save)
11022 (verilog-delete-auto-star-implicit)))
11023 ;; Restore name if unwind
11024 (with-current-buffer b1 (setq buffer-file-name name1)))))
11026 (setq diffpt (verilog-diff-buffers-p b1 b2 t verilog-diff-ignore-regexp))
11027 (cond ((not diffpt)
11028 (unless noninteractive (message "AUTO expansion identical"))
11029 (kill-buffer newname)) ; Nice to cleanup after oneself
11031 (funcall verilog-diff-function b1 b2 diffpt)))
11032 ;; Return result of compare
11033 diffpt)))
11036 ;; Auto save
11039 (defun verilog-auto-save-check ()
11040 "On saving see if we need auto update."
11041 (cond ((not verilog-auto-save-policy)) ; disabled
11042 ((not (save-excursion
11043 (save-match-data
11044 (let ((case-fold-search nil))
11045 (goto-char (point-min))
11046 (re-search-forward "AUTO" nil t))))))
11047 ((eq verilog-auto-save-policy 'force)
11048 (verilog-auto))
11049 ((not (buffer-modified-p)))
11050 ((eq verilog-auto-update-tick (buffer-chars-modified-tick))) ; up-to-date
11051 ((eq verilog-auto-save-policy 'detect)
11052 (verilog-auto))
11054 (when (yes-or-no-p "AUTO statements not recomputed, do it now? ")
11055 (verilog-auto))
11056 ;; Don't ask again if didn't update
11057 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))))
11058 (when (not verilog-auto-star-save)
11059 (verilog-delete-auto-star-implicit))
11060 nil) ; Always return nil -- we don't write the file ourselves
11062 (defun verilog-auto-read-locals ()
11063 "Return file local variable segment at bottom of file."
11064 (save-excursion
11065 (goto-char (point-max))
11066 (if (re-search-backward "Local Variables:" nil t)
11067 (buffer-substring-no-properties (point) (point-max))
11068 "")))
11070 (defun verilog-auto-reeval-locals (&optional force)
11071 "Read file local variable segment at bottom of file if it has changed.
11072 If FORCE, always reread it."
11073 (let ((curlocal (verilog-auto-read-locals)))
11074 (when (or force (not (equal verilog-auto-last-file-locals curlocal)))
11075 (set (make-local-variable 'verilog-auto-last-file-locals) curlocal)
11076 ;; Note this may cause this function to be recursively invoked,
11077 ;; because hack-local-variables may call (verilog-mode)
11078 ;; The above when statement will prevent it from recursing forever.
11079 (hack-local-variables)
11080 t)))
11082 ;;; Auto creation:
11085 (defun verilog-auto-arg-ports (sigs message indent-pt)
11086 "Print a list of ports for AUTOARG.
11087 Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT."
11088 (when sigs
11089 (when verilog-auto-arg-sort
11090 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
11091 (insert "\n")
11092 (indent-to indent-pt)
11093 (insert message)
11094 (insert "\n")
11095 (let ((space ""))
11096 (indent-to indent-pt)
11097 (while sigs
11098 (cond ((equal verilog-auto-arg-format 'single)
11099 (insert space)
11100 (indent-to indent-pt)
11101 (setq space "\n"))
11102 ;; verilog-auto-arg-format 'packed
11103 ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column)
11104 (insert "\n")
11105 (indent-to indent-pt)
11106 (setq space " "))
11108 (insert space)
11109 (setq space " ")))
11110 (insert (verilog-sig-name (car sigs)) ",")
11111 (setq sigs (cdr sigs))))))
11113 (defun verilog-auto-arg ()
11114 "Expand AUTOARG statements.
11115 Replace the argument declarations at the beginning of the
11116 module with ones automatically derived from input and output
11117 statements. This can be dangerous if the module is instantiated
11118 using position-based connections, so use only name-based when
11119 instantiating the resulting module. Long lines are split based
11120 on the `fill-column', see \\[set-fill-column].
11122 Limitations:
11123 Concatenation and outputting partial buses is not supported.
11125 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11127 For example:
11129 module ExampArg (/*AUTOARG*/);
11130 input i;
11131 output o;
11132 endmodule
11134 Typing \\[verilog-auto] will make this into:
11136 module ExampArg (/*AUTOARG*/
11137 // Outputs
11139 // Inputs
11142 input i;
11143 output o;
11144 endmodule
11146 The argument declarations may be printed in declaration order to
11147 best suit order based instantiations, or alphabetically, based on
11148 the `verilog-auto-arg-sort' variable.
11150 Formatting is controlled with `verilog-auto-arg-format' variable.
11152 Any ports declared between the ( and /*AUTOARG*/ are presumed to be
11153 predeclared and are not redeclared by AUTOARG. AUTOARG will make a
11154 conservative guess on adding a comma for the first signal, if you have
11155 any ifdefs or complicated expressions before the AUTOARG you will need
11156 to choose the comma yourself.
11158 Avoid declaring ports manually, as it makes code harder to maintain."
11159 (save-excursion
11160 (let* ((modi (verilog-modi-current))
11161 (moddecls (verilog-modi-get-decls modi))
11162 (skip-pins (aref (verilog-read-arg-pins) 0)))
11163 (verilog-repair-open-comma)
11164 (verilog-auto-arg-ports (verilog-signals-not-in
11165 (verilog-decls-get-outputs moddecls)
11166 skip-pins)
11167 "// Outputs"
11168 verilog-indent-level-declaration)
11169 (verilog-auto-arg-ports (verilog-signals-not-in
11170 (verilog-decls-get-inouts moddecls)
11171 skip-pins)
11172 "// Inouts"
11173 verilog-indent-level-declaration)
11174 (verilog-auto-arg-ports (verilog-signals-not-in
11175 (verilog-decls-get-inputs moddecls)
11176 skip-pins)
11177 "// Inputs"
11178 verilog-indent-level-declaration)
11179 (verilog-repair-close-comma)
11180 (unless (eq (char-before) ?/ )
11181 (insert "\n"))
11182 (indent-to verilog-indent-level-declaration))))
11184 (defun verilog-auto-assign-modport ()
11185 "Expand AUTOASSIGNMODPORT statements, as part of \\[verilog-auto].
11186 Take input/output/inout statements from the specified interface
11187 and modport and use to build assignments into the modport, for
11188 making verification modules that connect to UVM interfaces.
11190 The first parameter is the name of an interface.
11192 The second parameter is a regexp of modports to read from in
11193 that interface.
11195 The third parameter is the instance name to use to dot reference into.
11197 The optional fourth parameter is a regular expression, and only
11198 signals matching the regular expression will be included.
11200 Limitations:
11202 Interface names must be resolvable to filenames. See `verilog-auto-inst'.
11204 Inouts are not supported, as assignments must be unidirectional.
11206 If a signal is part of the interface header and in both a
11207 modport and the interface itself, it will not be listed. (As
11208 this would result in a syntax error when the connections are
11209 made.)
11211 See the example in `verilog-auto-inout-modport'."
11212 (save-excursion
11213 (let* ((params (verilog-read-auto-params 3 4))
11214 (submod (nth 0 params))
11215 (modport-re (nth 1 params))
11216 (inst-name (nth 2 params))
11217 (regexp (nth 3 params))
11218 direction-re submodi) ; direction argument not supported until requested
11219 ;; Lookup position, etc of co-module
11220 ;; Note this may raise an error
11221 (when (setq submodi (verilog-modi-lookup submod t))
11222 (let* ((indent-pt (current-indentation))
11223 (submoddecls (verilog-modi-get-decls submodi))
11224 (submodportdecls (verilog-modi-modport-lookup submodi modport-re))
11225 (sig-list-i (verilog-signals-in ; Decls doesn't have data types, must resolve
11226 (verilog-decls-get-vars submoddecls)
11227 (verilog-signals-not-in
11228 (verilog-decls-get-inputs submodportdecls)
11229 (verilog-decls-get-ports submoddecls))))
11230 (sig-list-o (verilog-signals-in ; Decls doesn't have data types, must resolve
11231 (verilog-decls-get-vars submoddecls)
11232 (verilog-signals-not-in
11233 (verilog-decls-get-outputs submodportdecls)
11234 (verilog-decls-get-ports submoddecls)))))
11235 (forward-line 1)
11236 (setq sig-list-i (verilog-signals-edit-wire-reg
11237 (verilog-signals-matching-dir-re
11238 (verilog-signals-matching-regexp sig-list-i regexp)
11239 "input" direction-re))
11240 sig-list-o (verilog-signals-edit-wire-reg
11241 (verilog-signals-matching-dir-re
11242 (verilog-signals-matching-regexp sig-list-o regexp)
11243 "output" direction-re)))
11244 (setq sig-list-i (sort (copy-alist sig-list-i) `verilog-signals-sort-compare))
11245 (setq sig-list-o (sort (copy-alist sig-list-o) `verilog-signals-sort-compare))
11246 (when (or sig-list-i sig-list-o)
11247 (verilog-insert-indent "// Beginning of automatic assignments from modport\n")
11248 ;; Don't sort them so an upper AUTOINST will match the main module
11249 (let ((sigs sig-list-o))
11250 (while sigs
11251 (verilog-insert-indent "assign " (verilog-sig-name (car sigs))
11252 " = " inst-name
11253 "." (verilog-sig-name (car sigs)) ";\n")
11254 (setq sigs (cdr sigs))))
11255 (let ((sigs sig-list-i))
11256 (while sigs
11257 (verilog-insert-indent "assign " inst-name
11258 "." (verilog-sig-name (car sigs))
11259 " = " (verilog-sig-name (car sigs)) ";\n")
11260 (setq sigs (cdr sigs))))
11261 (verilog-insert-indent "// End of automatics\n")))))))
11263 (defun verilog-auto-inst-port-map (_port-st)
11264 nil)
11266 (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning
11267 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
11268 (defvar vl-modport nil "See `verilog-auto-inst'.") ; Prevent compile warning
11269 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
11270 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning
11271 (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning
11272 (defvar vl-bits nil "See `verilog-auto-inst'.") ; Prevent compile warning
11273 (defvar vl-mbits nil "See `verilog-auto-inst'.") ; Prevent compile warning
11275 (defun verilog-auto-inst-port (port-st indent-pt moddecls tpl-list tpl-num for-star par-values)
11276 "Print out an instantiation connection for this PORT-ST.
11277 Insert to INDENT-PT, use template TPL-LIST.
11278 @ are instantiation numbers, replaced with TPL-NUM.
11279 @\"(expression @)\" are evaluated, with @ as a variable.
11280 If FOR-STAR add comment it is a .* expansion.
11281 If PAR-VALUES replace final strings with these parameter values."
11282 (let* ((port (verilog-sig-name port-st))
11283 (tpl-ass (or (assoc port (car tpl-list))
11284 (verilog-auto-inst-port-map port-st)))
11285 ;; vl-* are documented for user use
11286 (vl-name (verilog-sig-name port-st))
11287 (vl-width (verilog-sig-width port-st))
11288 (vl-modport (verilog-sig-modport port-st))
11289 (vl-memory (verilog-sig-memory port-st))
11290 (vl-mbits (if (verilog-sig-multidim port-st)
11291 (verilog-sig-multidim-string port-st) ""))
11292 (vl-bits (if (or verilog-auto-inst-vector
11293 (not (assoc port (verilog-decls-get-signals moddecls)))
11294 (not (equal (verilog-sig-bits port-st)
11295 (verilog-sig-bits
11296 (assoc port (verilog-decls-get-signals moddecls))))))
11297 (or (verilog-sig-bits port-st) "")
11298 ""))
11299 (case-fold-search nil)
11300 (check-values par-values)
11301 tpl-net dflt-bits)
11302 ;; Replace parameters in bit-width
11303 (when (and check-values
11304 (not (equal vl-bits "")))
11305 (while check-values
11306 (setq vl-bits (verilog-string-replace-matches
11307 (concat "\\<" (nth 0 (car check-values)) "\\>")
11308 (concat "(" (nth 1 (car check-values)) ")")
11309 t t vl-bits)
11310 vl-mbits (verilog-string-replace-matches
11311 (concat "\\<" (nth 0 (car check-values)) "\\>")
11312 (concat "(" (nth 1 (car check-values)) ")")
11313 t t vl-mbits)
11314 vl-memory (when vl-memory
11315 (verilog-string-replace-matches
11316 (concat "\\<" (nth 0 (car check-values)) "\\>")
11317 (concat "(" (nth 1 (car check-values)) ")")
11318 t t vl-memory))
11319 check-values (cdr check-values)))
11320 (setq vl-bits (verilog-simplify-range-expression vl-bits)
11321 vl-mbits (verilog-simplify-range-expression vl-mbits)
11322 vl-memory (when vl-memory (verilog-simplify-range-expression vl-memory))
11323 vl-width (verilog-make-width-expression vl-bits))) ; Not in the loop for speed
11324 ;; Default net value if not found
11325 (setq dflt-bits (if (or (and (verilog-sig-bits port-st)
11326 (verilog-sig-multidim port-st))
11327 (verilog-sig-memory port-st))
11328 (concat "/*" vl-mbits vl-bits
11329 ;; .[ used to separate packed from unpacked
11330 (if vl-memory "." "")
11331 (if vl-memory vl-memory "")
11332 "*/")
11333 (concat vl-bits))
11334 tpl-net (concat port
11335 (if (and vl-modport
11336 ;; .modport cannot be added if attachment is
11337 ;; already declared as modport, VCS croaks
11338 (let ((sig (assoc port (verilog-decls-get-interfaces moddecls))))
11339 (not (and sig (verilog-sig-modport sig)))))
11340 (concat "." vl-modport) "")
11341 dflt-bits))
11342 ;; Find template
11343 (cond (tpl-ass ; Template of exact port name
11344 (setq tpl-net (nth 1 tpl-ass)))
11345 ((nth 1 tpl-list) ; Wildcards in template, search them
11346 (let ((wildcards (nth 1 tpl-list)))
11347 (while wildcards
11348 (when (string-match (nth 0 (car wildcards)) port)
11349 (setq tpl-ass (car wildcards) ; so allow @ parsing
11350 tpl-net (replace-match (nth 1 (car wildcards))
11351 t nil port)))
11352 (setq wildcards (cdr wildcards))))))
11353 ;; Parse Templated variable
11354 (when tpl-ass
11355 ;; Evaluate @"(lispcode)"
11356 (when (string-match "@\".*[^\\]\"" tpl-net)
11357 (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net)
11358 (setq tpl-net
11359 (concat
11360 (substring tpl-net 0 (match-beginning 0))
11361 (save-match-data
11362 (let* ((expr (match-string 1 tpl-net))
11363 (value
11364 (progn
11365 (setq expr (verilog-string-replace-matches "\\\\\"" "\"" nil nil expr))
11366 (setq expr (verilog-string-replace-matches "@" tpl-num nil nil expr))
11367 (prin1 (eval (car (read-from-string expr)))
11368 (lambda (_ch) ())))))
11369 (if (numberp value) (setq value (number-to-string value)))
11370 value))
11371 (substring tpl-net (match-end 0))))))
11372 ;; Replace @ and [] magic variables in final output
11373 (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net))
11374 (setq tpl-net (verilog-string-replace-matches "\\[\\]\\[\\]" dflt-bits nil nil tpl-net))
11375 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)))
11376 ;; Insert it
11377 (indent-to indent-pt)
11378 (insert "." port)
11379 (unless (and verilog-auto-inst-dot-name
11380 (equal port tpl-net))
11381 (indent-to verilog-auto-inst-column)
11382 (insert "(" tpl-net ")"))
11383 (insert ",")
11384 (cond (tpl-ass
11385 (verilog-read-auto-template-hit tpl-ass)
11386 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
11387 verilog-auto-inst-column))
11388 ;; verilog-insert requires the complete comment in one call - including the newline
11389 (cond ((equal verilog-auto-inst-template-numbers `lhs)
11390 (verilog-insert " // Templated"
11391 " LHS: " (nth 0 tpl-ass)
11392 "\n"))
11393 (verilog-auto-inst-template-numbers
11394 (verilog-insert " // Templated"
11395 " T" (int-to-string (nth 2 tpl-ass))
11396 " L" (int-to-string (nth 3 tpl-ass))
11397 "\n"))
11399 (verilog-insert " // Templated\n"))))
11400 (for-star
11401 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
11402 verilog-auto-inst-column))
11403 (verilog-insert " // Implicit .*\n"))
11405 (insert "\n")))))
11406 ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3")
11407 ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]")
11408 ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));")
11410 (defun verilog-auto-inst-port-list (sig-list indent-pt moddecls tpl-list tpl-num for-star par-values)
11411 "For `verilog-auto-inst' print a list of ports using `verilog-auto-inst-port'."
11412 (when verilog-auto-inst-sort
11413 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)))
11414 (mapc (lambda (port)
11415 (verilog-auto-inst-port port indent-pt moddecls
11416 tpl-list tpl-num for-star par-values))
11417 sig-list))
11419 (defun verilog-auto-inst-first ()
11420 "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]."
11421 ;; Do we need a trailing comma?
11422 ;; There maybe an ifdef or something similar before us. What a mess. Thus
11423 ;; to avoid trouble we only insert on preceding ) or *.
11424 ;; Insert first port on new line
11425 (insert "\n") ; Must insert before search, so point will move forward if insert comma
11426 (save-excursion
11427 (verilog-re-search-backward-quick "[^ \t\n\f]" nil nil)
11428 (when (looking-at ")\\|\\*") ; Generally don't insert, unless we are fairly sure
11429 (forward-char 1)
11430 (insert ","))))
11432 (defun verilog-auto-star ()
11433 "Expand SystemVerilog .* pins, as part of \\[verilog-auto].
11435 If `verilog-auto-star-expand' is set, .* pins are treated if they were
11436 AUTOINST statements, otherwise they are ignored. For safety, Verilog mode
11437 will also ignore any .* that are not last in your pin list (this prevents
11438 it from deleting pins following the .* when it expands the AUTOINST.)
11440 On writing your file, unless `verilog-auto-star-save' is set, any
11441 non-templated expanded pins will be removed. You may do this at any time
11442 with \\[verilog-delete-auto-star-implicit].
11444 If you are converting a module to use .* for the first time, you may wish
11445 to use \\[verilog-inject-auto] and then replace the created AUTOINST with .*.
11447 See `verilog-auto-inst' for examples, templates, and more information."
11448 (when (verilog-auto-star-safe)
11449 (verilog-auto-inst)))
11451 (defun verilog-auto-inst ()
11452 "Expand AUTOINST statements, as part of \\[verilog-auto].
11453 Replace the pin connections to an instantiation or interface
11454 declaration with ones automatically derived from the module or
11455 interface header of the instantiated item.
11457 If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports,
11458 and delete them before saving unless `verilog-auto-star-save' is set.
11459 See `verilog-auto-star' for more information.
11461 The pins are printed in declaration order or alphabetically,
11462 based on the `verilog-auto-inst-sort' variable.
11464 Limitations:
11465 Module names must be resolvable to filenames by adding a
11466 `verilog-library-extensions', and being found in the same directory, or
11467 by changing the variable `verilog-library-flags' or
11468 `verilog-library-directories'. Macros `modname are translated through the
11469 vh-{name} Emacs variable, if that is not found, it just ignores the \\=`.
11471 In templates you must have one signal per line, ending in a ), or ));,
11472 and have proper () nesting, including a final ); to end the template.
11474 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
11476 SystemVerilog multidimensional input/output has only experimental support.
11478 SystemVerilog .name syntax is used if `verilog-auto-inst-dot-name' is set.
11480 Parameters referenced by the instantiation will remain symbolic, unless
11481 `verilog-auto-inst-param-value' is set.
11483 Gate primitives (and/or) may have AUTOINST for the purpose of
11484 AUTOWIRE declarations, etc. Gates are the only case when
11485 position based connections are passed.
11487 The array part of arrayed instances are ignored; this may
11488 result in undesirable default AUTOINST connections; use a
11489 template instead.
11491 For example, first take the submodule InstModule.v:
11493 module InstModule (o,i);
11494 output [31:0] o;
11495 input i;
11496 wire [31:0] o = {32{i}};
11497 endmodule
11499 This is then used in an upper level module:
11501 module ExampInst (o,i);
11502 output o;
11503 input i;
11504 InstModule instName
11505 (/*AUTOINST*/);
11506 endmodule
11508 Typing \\[verilog-auto] will make this into:
11510 module ExampInst (o,i);
11511 output o;
11512 input i;
11513 InstModule instName
11514 (/*AUTOINST*/
11515 // Outputs
11516 .ov (ov[31:0]),
11517 // Inputs
11518 .i (i));
11519 endmodule
11521 Where the list of inputs and outputs came from the inst module.
11523 Exceptions:
11525 Unless you are instantiating a module multiple times, or the module is
11526 something trivial like an adder, DO NOT CHANGE SIGNAL NAMES ACROSS HIERARCHY.
11527 It just makes for unmaintainable code. To sanitize signal names, try
11528 vrename from URL `http://www.veripool.org'.
11530 When you need to violate this suggestion there are two ways to list
11531 exceptions, placing them before the AUTOINST, or using templates.
11533 Any ports defined before the /*AUTOINST*/ are not included in the list of
11534 automatics. This is similar to making a template as described below, but
11535 is restricted to simple connections just like you normally make. Also note
11536 that any signals before the AUTOINST will only be picked up by AUTOWIRE if
11537 you have the appropriate // Input or // Output comment, and exactly the
11538 same line formatting as AUTOINST itself uses.
11540 InstModule instName
11541 (// Inputs
11542 .i (my_i_dont_mess_with_it),
11543 /*AUTOINST*/
11544 // Outputs
11545 .ov (ov[31:0]));
11548 Templates:
11550 For multiple instantiations based upon a single template, create a
11551 commented out template:
11553 /* InstModule AUTO_TEMPLATE (
11554 .sig3 (sigz[]),
11558 Templates go ABOVE the instantiation(s). When an instantiation is
11559 expanded `verilog-mode' simply searches up for the closest template.
11560 Thus you can have multiple templates for the same module, just alternate
11561 between the template for an instantiation and the instantiation itself.
11562 (For backward compatibility if no template is found above, it
11563 will also look below, but do not use this behavior in new designs.)
11565 The module name must be the same as the name of the module in the
11566 instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact
11567 words and capitalized. Only signals that must be different for each
11568 instantiation need to be listed.
11570 Inside a template, a [] in a connection name (with nothing else
11571 inside the brackets) will be replaced by the same bus subscript
11572 as it is being connected to, or the [] will be removed if it is
11573 a single bit signal.
11575 Inside a template, a [][] in a connection name will behave
11576 similarly to a [] for scalar or single-dimensional connection;
11577 for a multidimensional connection it will print a comment
11578 similar to that printed when a template is not used. Generally
11579 it is a good idea to do this for all connections in a template,
11580 as then they will work for any width signal, and with AUTOWIRE.
11581 See PTL_BUS becoming PTL_BUSNEW below.
11583 Inside a template, a [] in a connection name (with nothing else inside
11584 the brackets) will be replaced by the same bus subscript as it is being
11585 connected to, or the [] will be removed if it is a single bit signal.
11586 Generally it is a good idea to do this for all connections in a template,
11587 as then they will work for any width signal, and with AUTOWIRE. See
11588 PTL_BUS becoming PTL_BUSNEW below.
11590 If you have a complicated template, set `verilog-auto-inst-template-numbers'
11591 to see which regexps are matching. Don't leave that mode set after
11592 debugging is completed though, it will result in lots of extra differences
11593 and merge conflicts.
11595 Setting `verilog-auto-template-warn-unused' will report errors
11596 if any template lines are unused.
11598 For example:
11600 /* InstModule AUTO_TEMPLATE (
11601 .ptl_bus (ptl_busnew[]),
11604 InstModule ms2m (/*AUTOINST*/);
11606 Typing \\[verilog-auto] will make this into:
11608 InstModule ms2m (/*AUTOINST*/
11609 // Outputs
11610 .NotInTemplate (NotInTemplate),
11611 .ptl_bus (ptl_busnew[3:0]), // Templated
11612 ....
11615 Multiple Module Templates:
11617 The same template lines can be applied to multiple modules with
11618 the syntax as follows:
11620 /* InstModuleA AUTO_TEMPLATE
11621 InstModuleB AUTO_TEMPLATE
11622 InstModuleC AUTO_TEMPLATE
11623 InstModuleD AUTO_TEMPLATE (
11624 .ptl_bus (ptl_busnew[]),
11628 Note there is only one AUTO_TEMPLATE opening parenthesis.
11630 @ Templates:
11632 It is common to instantiate a cell multiple times, so templates make it
11633 trivial to substitute part of the cell name into the connection name.
11635 /* InstName AUTO_TEMPLATE <optional \"REGEXP\"> (
11636 .sig1 (sigx[@]),
11637 .sig2 (sigy[@\"(% (+ 1 @) 4)\"]),
11641 If no regular expression is provided immediately after the AUTO_TEMPLATE
11642 keyword, then the @ character in any connection names will be replaced
11643 with the instantiation number; the first digits found in the cell's
11644 instantiation name.
11646 If a regular expression is provided, the @ character will be replaced
11647 with the first () grouping that matches against the cell name. Using a
11648 regexp of `\\([0-9]+\\)' provides identical values for @ as when no
11649 regexp is provided. If you use multiple layers of parenthesis,
11650 `test\\([^0-9]+\\)_\\([0-9]+\\)' would replace @ with non-number
11651 characters after test and before _, whereas
11652 `\\(test\\([a-z]+\\)_\\([0-9]+\\)\\)' would replace @ with the entire
11653 match.
11655 For example:
11657 /* InstModule AUTO_TEMPLATE (
11658 .ptl_mapvalidx (ptl_mapvalid[@]),
11659 .ptl_mapvalidp1x (ptl_mapvalid[@\"(% (+ 1 @) 4)\"]),
11662 InstModule ms2m (/*AUTOINST*/);
11664 Typing \\[verilog-auto] will make this into:
11666 InstModule ms2m (/*AUTOINST*/
11667 // Outputs
11668 .ptl_mapvalidx (ptl_mapvalid[2]),
11669 .ptl_mapvalidp1x (ptl_mapvalid[3]));
11671 Note the @ character was replaced with the 2 from \"ms2m\".
11673 Alternatively, using a regular expression for @:
11675 /* InstModule AUTO_TEMPLATE \"_\\([a-z]+\\)\" (
11676 .ptl_mapvalidx (@_ptl_mapvalid),
11677 .ptl_mapvalidp1x (ptl_mapvalid_@),
11680 InstModule ms2_FOO (/*AUTOINST*/);
11681 InstModule ms2_BAR (/*AUTOINST*/);
11683 Typing \\[verilog-auto] will make this into:
11685 InstModule ms2_FOO (/*AUTOINST*/
11686 // Outputs
11687 .ptl_mapvalidx (FOO_ptl_mapvalid),
11688 .ptl_mapvalidp1x (ptl_mapvalid_FOO));
11689 InstModule ms2_BAR (/*AUTOINST*/
11690 // Outputs
11691 .ptl_mapvalidx (BAR_ptl_mapvalid),
11692 .ptl_mapvalidp1x (ptl_mapvalid_BAR));
11695 Regexp Templates:
11697 A template entry of the form
11699 .pci_req\\([0-9]+\\)_l (pci_req_jtag_[\\1]),
11701 will apply an Emacs style regular expression search for any port beginning
11702 in pci_req followed by numbers and ending in _l and connecting that to
11703 the pci_req_jtag_[] net, with the bus subscript coming from what matches
11704 inside the first set of \\( \\). Thus pci_req2_l becomes pci_req_jtag_[2].
11706 Since \\([0-9]+\\) is so common and ugly to read, a @ in the port name
11707 does the same thing. (Note a @ in the connection/replacement text is
11708 completely different -- still use \\1 there!) Thus this is the same as
11709 the above template:
11711 .pci_req@_l (pci_req_jtag_[\\1]),
11713 Here's another example to remove the _l, useful when naming conventions
11714 specify _ alone to mean active low. Note the use of [] to keep the bus
11715 subscript:
11717 .\\(.*\\)_l (\\1_[]),
11719 Lisp Templates:
11721 First any regular expression template is expanded.
11723 If the syntax @\"( ... )\" is found in a connection, the expression in
11724 quotes will be evaluated as a Lisp expression, with @ replaced by the
11725 instantiation number. The MAPVALIDP1X example above would put @+1 modulo
11726 4 into the brackets. Quote all double-quotes inside the expression with
11727 a leading backslash (\\\"...\\\"); or if the Lisp template is also a
11728 regexp template backslash the backslash quote (\\\\\"...\\\\\").
11730 There are special variables defined that are useful in these
11731 Lisp functions:
11733 vl-name Name portion of the input/output port.
11734 vl-bits Bus bits portion of the input/output port (`[2:0]').
11735 vl-mbits Multidimensional array bits for port (`[2:0][3:0]').
11736 vl-width Width of the input/output port (`3' for [2:0]).
11737 May be a (...) expression if bits isn't a constant.
11738 vl-dir Direction of the pin input/output/inout/interface.
11739 vl-modport The modport, if an interface with a modport.
11740 vl-cell-type Module name/type of the cell (`InstModule').
11741 vl-cell-name Instance name of the cell (`instName').
11743 Normal Lisp variables may be used in expressions. See
11744 `verilog-read-defines' which can set vh-{definename} variables for use
11745 here. Also, any comments of the form:
11747 /*AUTO_LISP(setq foo 1)*/
11749 will evaluate any Lisp expression inside the parenthesis between the
11750 beginning of the buffer and the point of the AUTOINST. This allows
11751 functions to be defined or variables to be changed between instantiations.
11752 (See also `verilog-auto-insert-lisp' if you want the output from your
11753 lisp function to be inserted.)
11755 Note that when using lisp expressions errors may occur when @ is not a
11756 number; you may need to use the standard Emacs Lisp functions
11757 `number-to-string' and `string-to-number'.
11759 After the evaluation is completed, @ substitution and [] substitution
11760 occur.
11762 For more information see the \\[verilog-faq] and forums at URL
11763 `http://www.veripool.org'."
11764 (save-excursion
11765 ;; Find beginning
11766 (let* ((pt (point))
11767 (for-star (save-excursion (backward-char 2) (looking-at "\\.\\*")))
11768 (indent-pt (save-excursion (verilog-backward-open-paren)
11769 (1+ (current-column))))
11770 (verilog-auto-inst-column (max verilog-auto-inst-column
11771 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
11772 (modi (verilog-modi-current))
11773 (moddecls (verilog-modi-get-decls modi))
11774 submod submodi submoddecls
11775 inst skip-pins tpl-list tpl-num did-first par-values)
11777 ;; Find module name that is instantiated
11778 (setq submod (verilog-read-inst-module)
11779 inst (verilog-read-inst-name)
11780 vl-cell-type submod
11781 vl-cell-name inst
11782 skip-pins (aref (verilog-read-inst-pins) 0))
11784 ;; Parse any AUTO_LISP() before here
11785 (verilog-read-auto-lisp (point-min) pt)
11787 ;; Read parameters (after AUTO_LISP)
11788 (setq par-values (and verilog-auto-inst-param-value
11789 (verilog-read-inst-param-value)))
11791 ;; Lookup position, etc of submodule
11792 ;; Note this may raise an error
11793 (when (and (not (member submod verilog-gate-keywords))
11794 (setq submodi (verilog-modi-lookup submod t)))
11795 (setq submoddecls (verilog-modi-get-decls submodi))
11796 ;; If there's a number in the instantiation, it may be an argument to the
11797 ;; automatic variable instantiation program.
11798 (let* ((tpl-info (verilog-read-auto-template submod))
11799 (tpl-regexp (aref tpl-info 0)))
11800 (setq tpl-num (if (verilog-string-match-fold tpl-regexp inst)
11801 (match-string 1 inst)
11803 tpl-list (aref tpl-info 1)))
11804 ;; Find submodule's signals and dump
11805 (let ((sig-list (and (equal (verilog-modi-get-type submodi) "interface")
11806 (verilog-signals-not-in
11807 (verilog-decls-get-vars submoddecls)
11808 skip-pins)))
11809 (vl-dir "interfaced"))
11810 (when (and sig-list
11811 verilog-auto-inst-interfaced-ports)
11812 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11813 ;; Note these are searched for in verilog-read-sub-decls.
11814 (verilog-insert-indent "// Interfaced\n")
11815 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11816 tpl-list tpl-num for-star par-values)))
11817 (let ((sig-list (verilog-signals-not-in
11818 (verilog-decls-get-interfaces submoddecls)
11819 skip-pins))
11820 (vl-dir "interface"))
11821 (when sig-list
11822 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11823 ;; Note these are searched for in verilog-read-sub-decls.
11824 (verilog-insert-indent "// Interfaces\n")
11825 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11826 tpl-list tpl-num for-star par-values)))
11827 (let ((sig-list (verilog-signals-not-in
11828 (verilog-decls-get-outputs submoddecls)
11829 skip-pins))
11830 (vl-dir "output"))
11831 (when sig-list
11832 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11833 (verilog-insert-indent "// Outputs\n")
11834 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11835 tpl-list tpl-num for-star par-values)))
11836 (let ((sig-list (verilog-signals-not-in
11837 (verilog-decls-get-inouts submoddecls)
11838 skip-pins))
11839 (vl-dir "inout"))
11840 (when sig-list
11841 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11842 (verilog-insert-indent "// Inouts\n")
11843 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11844 tpl-list tpl-num for-star par-values)))
11845 (let ((sig-list (verilog-signals-not-in
11846 (verilog-decls-get-inputs submoddecls)
11847 skip-pins))
11848 (vl-dir "input"))
11849 (when sig-list
11850 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11851 (verilog-insert-indent "// Inputs\n")
11852 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11853 tpl-list tpl-num for-star par-values)))
11854 ;; Kill extra semi
11855 (save-excursion
11856 (cond (did-first
11857 (re-search-backward "," pt t)
11858 (delete-char 1)
11859 (insert ");")
11860 (search-forward "\n") ; Added by inst-port
11861 (delete-char -1)
11862 (if (search-forward ")" nil t) ; From user, moved up a line
11863 (delete-char -1))
11864 (if (search-forward ";" nil t) ; Don't error if user had syntax error and forgot it
11865 (delete-char -1)))))))))
11867 (defun verilog-auto-inst-param ()
11868 "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto].
11869 Replace the parameter connections to an instantiation with ones
11870 automatically derived from the module header of the instantiated netlist.
11872 See \\[verilog-auto-inst] for limitations, and templates to customize the
11873 output.
11875 For example, first take the submodule InstModule.v:
11877 module InstModule (o,i);
11878 parameter PAR;
11879 endmodule
11881 This is then used in an upper level module:
11883 module ExampInst (o,i);
11884 parameter PAR;
11885 InstModule #(/*AUTOINSTPARAM*/)
11886 instName (/*AUTOINST*/);
11887 endmodule
11889 Typing \\[verilog-auto] will make this into:
11891 module ExampInst (o,i);
11892 output o;
11893 input i;
11894 InstModule #(/*AUTOINSTPARAM*/
11895 // Parameters
11896 .PAR (PAR));
11897 instName (/*AUTOINST*/);
11898 endmodule
11900 Where the list of parameter connections come from the inst module.
11902 Templates:
11904 You can customize the parameter connections using AUTO_TEMPLATEs,
11905 just as you would with \\[verilog-auto-inst]."
11906 (save-excursion
11907 ;; Find beginning
11908 (let* ((pt (point))
11909 (indent-pt (save-excursion (verilog-backward-open-paren)
11910 (1+ (current-column))))
11911 (verilog-auto-inst-column (max verilog-auto-inst-column
11912 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
11913 (modi (verilog-modi-current))
11914 (moddecls (verilog-modi-get-decls modi))
11915 submod submodi submoddecls
11916 inst skip-pins tpl-list tpl-num did-first)
11917 ;; Find module name that is instantiated
11918 (setq submod (save-excursion
11919 ;; Get to the point where AUTOINST normally is to read the module
11920 (verilog-re-search-forward-quick "[(;]" nil nil)
11921 (verilog-read-inst-module))
11922 inst (save-excursion
11923 ;; Get to the point where AUTOINST normally is to read the module
11924 (verilog-re-search-forward-quick "[(;]" nil nil)
11925 (verilog-read-inst-name))
11926 vl-cell-type submod
11927 vl-cell-name inst
11928 skip-pins (aref (verilog-read-inst-pins) 0))
11930 ;; Parse any AUTO_LISP() before here
11931 (verilog-read-auto-lisp (point-min) pt)
11933 ;; Lookup position, etc of submodule
11934 ;; Note this may raise an error
11935 (when (setq submodi (verilog-modi-lookup submod t))
11936 (setq submoddecls (verilog-modi-get-decls submodi))
11937 ;; If there's a number in the instantiation, it may be an argument to the
11938 ;; automatic variable instantiation program.
11939 (let* ((tpl-info (verilog-read-auto-template submod))
11940 (tpl-regexp (aref tpl-info 0)))
11941 (setq tpl-num (if (verilog-string-match-fold tpl-regexp inst)
11942 (match-string 1 inst)
11944 tpl-list (aref tpl-info 1)))
11945 ;; Find submodule's signals and dump
11946 (let ((sig-list (verilog-signals-not-in
11947 (verilog-decls-get-gparams submoddecls)
11948 skip-pins))
11949 (vl-dir "parameter"))
11950 (when sig-list
11951 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
11952 ;; Note these are searched for in verilog-read-sub-decls.
11953 (verilog-insert-indent "// Parameters\n")
11954 (verilog-auto-inst-port-list sig-list indent-pt moddecls
11955 tpl-list tpl-num nil nil)))
11956 ;; Kill extra semi
11957 (save-excursion
11958 (cond (did-first
11959 (re-search-backward "," pt t)
11960 (delete-char 1)
11961 (insert ")")
11962 (search-forward "\n") ; Added by inst-port
11963 (delete-char -1)
11964 (if (search-forward ")" nil t) ; From user, moved up a line
11965 (delete-char -1)))))))))
11967 (defun verilog-auto-reg ()
11968 "Expand AUTOREG statements, as part of \\[verilog-auto].
11969 Make reg statements for any output that isn't already declared,
11970 and isn't a wire output from a block. `verilog-auto-wire-type'
11971 may be used to change the datatype of the declarations.
11973 Limitations:
11974 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
11976 This does NOT work on memories, declare those yourself.
11978 An example:
11980 module ExampReg (o,i);
11981 output o;
11982 input i;
11983 /*AUTOREG*/
11984 always o = i;
11985 endmodule
11987 Typing \\[verilog-auto] will make this into:
11989 module ExampReg (o,i);
11990 output o;
11991 input i;
11992 /*AUTOREG*/
11993 // Beginning of automatic regs (for this module's undeclared outputs)
11994 reg o;
11995 // End of automatics
11996 always o = i;
11997 endmodule"
11998 (save-excursion
11999 ;; Point must be at insertion point.
12000 (let* ((indent-pt (current-indentation))
12001 (modi (verilog-modi-current))
12002 (moddecls (verilog-modi-get-decls modi))
12003 (modsubdecls (verilog-modi-get-sub-decls modi))
12004 (sig-list (verilog-signals-not-in
12005 (verilog-decls-get-outputs moddecls)
12006 (append (verilog-signals-with ; ignore typed signals
12007 'verilog-sig-type
12008 (verilog-decls-get-outputs moddecls))
12009 (verilog-decls-get-vars moddecls)
12010 (verilog-decls-get-assigns moddecls)
12011 (verilog-decls-get-consts moddecls)
12012 (verilog-decls-get-gparams moddecls)
12013 (verilog-subdecls-get-interfaced modsubdecls)
12014 (verilog-subdecls-get-outputs modsubdecls)
12015 (verilog-subdecls-get-inouts modsubdecls)))))
12016 (when sig-list
12017 (verilog-forward-or-insert-line)
12018 (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n")
12019 (verilog-insert-definition modi sig-list "reg" indent-pt nil)
12020 (verilog-insert-indent "// End of automatics\n")))))
12022 (defun verilog-auto-reg-input ()
12023 "Expand AUTOREGINPUT statements, as part of \\[verilog-auto].
12024 Make reg statements instantiation inputs that aren't already declared.
12025 This is useful for making a top level shell for testing the module that is
12026 to be instantiated.
12028 Limitations:
12029 This ONLY detects inputs of AUTOINSTants (see `verilog-read-sub-decls').
12031 This does NOT work on memories, declare those yourself.
12033 An example (see `verilog-auto-inst' for what else is going on here):
12035 module ExampRegInput (o,i);
12036 output o;
12037 input i;
12038 /*AUTOREGINPUT*/
12039 InstModule instName
12040 (/*AUTOINST*/);
12041 endmodule
12043 Typing \\[verilog-auto] will make this into:
12045 module ExampRegInput (o,i);
12046 output o;
12047 input i;
12048 /*AUTOREGINPUT*/
12049 // Beginning of automatic reg inputs (for undeclared ...
12050 reg [31:0] iv; // From inst of inst.v
12051 // End of automatics
12052 InstModule instName
12053 (/*AUTOINST*/
12054 // Outputs
12055 .o (o[31:0]),
12056 // Inputs
12057 .iv (iv));
12058 endmodule"
12059 (save-excursion
12060 ;; Point must be at insertion point.
12061 (let* ((indent-pt (current-indentation))
12062 (modi (verilog-modi-current))
12063 (moddecls (verilog-modi-get-decls modi))
12064 (modsubdecls (verilog-modi-get-sub-decls modi))
12065 (sig-list (verilog-signals-combine-bus
12066 (verilog-signals-not-in
12067 (append (verilog-subdecls-get-inputs modsubdecls)
12068 (verilog-subdecls-get-inouts modsubdecls))
12069 (append (verilog-decls-get-signals moddecls)
12070 (verilog-decls-get-assigns moddecls))))))
12071 (when sig-list
12072 (verilog-forward-or-insert-line)
12073 (verilog-insert-indent "// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)\n")
12074 (verilog-insert-definition modi sig-list "reg" indent-pt nil)
12075 (verilog-insert-indent "// End of automatics\n")))))
12077 (defun verilog-auto-logic-setup ()
12078 "Prepare variables due to AUTOLOGIC."
12079 (unless verilog-auto-wire-type
12080 (set (make-local-variable 'verilog-auto-wire-type)
12081 "logic")))
12083 (defun verilog-auto-logic ()
12084 "Expand AUTOLOGIC statements, as part of \\[verilog-auto].
12085 Make wire statements using the SystemVerilog logic keyword.
12086 This is currently equivalent to:
12088 /*AUTOWIRE*/
12090 with the below at the bottom of the file
12092 // Local Variables:
12093 // verilog-auto-wire-type:\"logic\"
12094 // End:
12096 In the future AUTOLOGIC may declare additional identifiers,
12097 while AUTOWIRE will not."
12098 (save-excursion
12099 (verilog-auto-logic-setup)
12100 (verilog-auto-wire)))
12102 (defun verilog-auto-wire ()
12103 "Expand AUTOWIRE statements, as part of \\[verilog-auto].
12104 Make wire statements for instantiations outputs that aren't
12105 already declared. `verilog-auto-wire-type' may be used to change
12106 the datatype of the declarations.
12108 Limitations:
12109 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'),
12110 and all buses must have widths, such as those from AUTOINST, or using []
12111 in AUTO_TEMPLATEs.
12113 This does NOT work on memories or SystemVerilog .name connections,
12114 declare those yourself.
12116 Verilog mode will add \"Couldn't Merge\" comments to signals it cannot
12117 determine how to bus together. This occurs when you have ports with
12118 non-numeric or non-sequential bus subscripts. If Verilog mode
12119 mis-guessed, you'll have to declare them yourself.
12121 An example (see `verilog-auto-inst' for what else is going on here):
12123 module ExampWire (o,i);
12124 output o;
12125 input i;
12126 /*AUTOWIRE*/
12127 InstModule instName
12128 (/*AUTOINST*/);
12129 endmodule
12131 Typing \\[verilog-auto] will make this into:
12133 module ExampWire (o,i);
12134 output o;
12135 input i;
12136 /*AUTOWIRE*/
12137 // Beginning of automatic wires
12138 wire [31:0] ov; // From inst of inst.v
12139 // End of automatics
12140 InstModule instName
12141 (/*AUTOINST*/
12142 // Outputs
12143 .ov (ov[31:0]),
12144 // Inputs
12145 .i (i));
12146 wire o = | ov;
12147 endmodule"
12148 (save-excursion
12149 ;; Point must be at insertion point.
12150 (let* ((indent-pt (current-indentation))
12151 (modi (verilog-modi-current))
12152 (moddecls (verilog-modi-get-decls modi))
12153 (modsubdecls (verilog-modi-get-sub-decls modi))
12154 (sig-list (verilog-signals-combine-bus
12155 (verilog-signals-not-in
12156 (append (verilog-subdecls-get-outputs modsubdecls)
12157 (verilog-subdecls-get-inouts modsubdecls))
12158 (verilog-decls-get-signals moddecls)))))
12159 (when sig-list
12160 (verilog-forward-or-insert-line)
12161 (verilog-insert-indent "// Beginning of automatic wires (for undeclared instantiated-module outputs)\n")
12162 (verilog-insert-definition modi sig-list "wire" indent-pt nil)
12163 (verilog-insert-indent "// End of automatics\n")
12164 ;; We used to optionally call verilog-pretty-declarations and
12165 ;; verilog-pretty-expr here, but it's too slow on huge modules,
12166 ;; plus makes everyone's module change. Finally those call
12167 ;; syntax-ppss which is broken when change hooks are disabled.
12168 ))))
12170 (defun verilog-auto-output ()
12171 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto].
12172 Make output statements for any output signal from an /*AUTOINST*/ that
12173 isn't an input to another AUTOINST. This is useful for modules which
12174 only instantiate other modules.
12176 Limitations:
12177 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
12179 If placed inside the parenthesis of a module declaration, it creates
12180 Verilog 2001 style, else uses Verilog 1995 style.
12182 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
12183 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
12185 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
12187 Types are added to declarations if an AUTOLOGIC or
12188 `verilog-auto-wire-type' is set to logic.
12190 Signals matching `verilog-auto-output-ignore-regexp' are not included.
12192 An example (see `verilog-auto-inst' for what else is going on here):
12194 module ExampOutput (ov,i);
12195 input i;
12196 /*AUTOOUTPUT*/
12197 InstModule instName
12198 (/*AUTOINST*/);
12199 endmodule
12201 Typing \\[verilog-auto] will make this into:
12203 module ExampOutput (ov,i);
12204 input i;
12205 /*AUTOOUTPUT*/
12206 // Beginning of automatic outputs (from unused autoinst outputs)
12207 output [31:0] ov; // From inst of inst.v
12208 // End of automatics
12209 InstModule instName
12210 (/*AUTOINST*/
12211 // Outputs
12212 .ov (ov[31:0]),
12213 // Inputs
12214 .i (i));
12215 endmodule
12217 You may also provide an optional regular expression, in which case only
12218 signals matching the regular expression will be included. For example the
12219 same expansion will result from only extracting outputs starting with ov:
12221 /*AUTOOUTPUT(\"^ov\")*/"
12222 (save-excursion
12223 ;; Point must be at insertion point.
12224 (let* ((indent-pt (current-indentation))
12225 (params (verilog-read-auto-params 0 1))
12226 (regexp (nth 0 params))
12227 (v2k (verilog-in-paren-quick))
12228 (modi (verilog-modi-current))
12229 (moddecls (verilog-modi-get-decls modi))
12230 (modsubdecls (verilog-modi-get-sub-decls modi))
12231 (sig-list (verilog-signals-not-in
12232 (verilog-subdecls-get-outputs modsubdecls)
12233 (append (verilog-decls-get-outputs moddecls)
12234 (verilog-decls-get-inouts moddecls)
12235 (verilog-decls-get-inputs moddecls)
12236 (verilog-subdecls-get-inputs modsubdecls)
12237 (verilog-subdecls-get-inouts modsubdecls)))))
12238 (when regexp
12239 (setq sig-list (verilog-signals-matching-regexp
12240 sig-list regexp)))
12241 (setq sig-list (verilog-signals-not-matching-regexp
12242 sig-list verilog-auto-output-ignore-regexp))
12243 (verilog-forward-or-insert-line)
12244 (when v2k (verilog-repair-open-comma))
12245 (when sig-list
12246 (verilog-insert-indent "// Beginning of automatic outputs (from unused autoinst outputs)\n")
12247 (verilog-insert-definition modi sig-list "output" indent-pt v2k)
12248 (verilog-insert-indent "// End of automatics\n"))
12249 (when v2k (verilog-repair-close-comma)))))
12251 (defun verilog-auto-output-every ()
12252 "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto].
12253 Make output statements for any signals that aren't primary inputs or
12254 outputs already. This makes every signal in the design an output. This is
12255 useful to get Synopsys to preserve every signal in the design, since it
12256 won't optimize away the outputs.
12258 An example:
12260 module ExampOutputEvery (o,i,tempa,tempb);
12261 output o;
12262 input i;
12263 /*AUTOOUTPUTEVERY*/
12264 wire tempa = i;
12265 wire tempb = tempa;
12266 wire o = tempb;
12267 endmodule
12269 Typing \\[verilog-auto] will make this into:
12271 module ExampOutputEvery (o,i,tempa,tempb);
12272 output o;
12273 input i;
12274 /*AUTOOUTPUTEVERY*/
12275 // Beginning of automatic outputs (every signal)
12276 output tempb;
12277 output tempa;
12278 // End of automatics
12279 wire tempa = i;
12280 wire tempb = tempa;
12281 wire o = tempb;
12282 endmodule
12284 You may also provide an optional regular expression, in which case only
12285 signals matching the regular expression will be included. For example the
12286 same expansion will result from only extracting outputs starting with ov:
12288 /*AUTOOUTPUTEVERY(\"^ov\")*/"
12289 (save-excursion
12290 ;;Point must be at insertion point
12291 (let* ((indent-pt (current-indentation))
12292 (params (verilog-read-auto-params 0 1))
12293 (regexp (nth 0 params))
12294 (v2k (verilog-in-paren-quick))
12295 (modi (verilog-modi-current))
12296 (moddecls (verilog-modi-get-decls modi))
12297 (sig-list (verilog-signals-combine-bus
12298 (verilog-signals-not-in
12299 (verilog-decls-get-signals moddecls)
12300 (verilog-decls-get-ports moddecls)))))
12301 (when regexp
12302 (setq sig-list (verilog-signals-matching-regexp
12303 sig-list regexp)))
12304 (setq sig-list (verilog-signals-not-matching-regexp
12305 sig-list verilog-auto-output-ignore-regexp))
12306 (verilog-forward-or-insert-line)
12307 (when v2k (verilog-repair-open-comma))
12308 (when sig-list
12309 (verilog-insert-indent "// Beginning of automatic outputs (every signal)\n")
12310 (verilog-insert-definition modi sig-list "output" indent-pt v2k)
12311 (verilog-insert-indent "// End of automatics\n"))
12312 (when v2k (verilog-repair-close-comma)))))
12314 (defun verilog-auto-input ()
12315 "Expand AUTOINPUT statements, as part of \\[verilog-auto].
12316 Make input statements for any input signal into an /*AUTOINST*/ that
12317 isn't declared elsewhere inside the module. This is useful for modules which
12318 only instantiate other modules.
12320 Limitations:
12321 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
12323 If placed inside the parenthesis of a module declaration, it creates
12324 Verilog 2001 style, else uses Verilog 1995 style.
12326 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
12327 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
12329 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
12331 Types are added to declarations if an AUTOLOGIC or
12332 `verilog-auto-wire-type' is set to logic.
12334 Signals matching `verilog-auto-input-ignore-regexp' are not included.
12336 An example (see `verilog-auto-inst' for what else is going on here):
12338 module ExampInput (ov,i);
12339 output [31:0] ov;
12340 /*AUTOINPUT*/
12341 InstModule instName
12342 (/*AUTOINST*/);
12343 endmodule
12345 Typing \\[verilog-auto] will make this into:
12347 module ExampInput (ov,i);
12348 output [31:0] ov;
12349 /*AUTOINPUT*/
12350 // Beginning of automatic inputs (from unused autoinst inputs)
12351 input i; // From inst of inst.v
12352 // End of automatics
12353 InstModule instName
12354 (/*AUTOINST*/
12355 // Outputs
12356 .ov (ov[31:0]),
12357 // Inputs
12358 .i (i));
12359 endmodule
12361 You may also provide an optional regular expression, in which case only
12362 signals matching the regular expression will be included. For example the
12363 same expansion will result from only extracting inputs starting with i:
12365 /*AUTOINPUT(\"^i\")*/"
12366 (save-excursion
12367 (let* ((indent-pt (current-indentation))
12368 (params (verilog-read-auto-params 0 1))
12369 (regexp (nth 0 params))
12370 (v2k (verilog-in-paren-quick))
12371 (modi (verilog-modi-current))
12372 (moddecls (verilog-modi-get-decls modi))
12373 (modsubdecls (verilog-modi-get-sub-decls modi))
12374 (sig-list (verilog-signals-not-in
12375 (verilog-subdecls-get-inputs modsubdecls)
12376 (append (verilog-decls-get-inputs moddecls)
12377 (verilog-decls-get-inouts moddecls)
12378 (verilog-decls-get-outputs moddecls)
12379 (verilog-decls-get-vars moddecls)
12380 (verilog-decls-get-consts moddecls)
12381 (verilog-decls-get-gparams moddecls)
12382 (verilog-subdecls-get-interfaced modsubdecls)
12383 (verilog-subdecls-get-outputs modsubdecls)
12384 (verilog-subdecls-get-inouts modsubdecls)))))
12385 (when regexp
12386 (setq sig-list (verilog-signals-matching-regexp
12387 sig-list regexp)))
12388 (setq sig-list (verilog-signals-not-matching-regexp
12389 sig-list verilog-auto-input-ignore-regexp))
12390 (verilog-forward-or-insert-line)
12391 (when v2k (verilog-repair-open-comma))
12392 (when sig-list
12393 (verilog-insert-indent "// Beginning of automatic inputs (from unused autoinst inputs)\n")
12394 (verilog-insert-definition modi sig-list "input" indent-pt v2k)
12395 (verilog-insert-indent "// End of automatics\n"))
12396 (when v2k (verilog-repair-close-comma)))))
12398 (defun verilog-auto-inout ()
12399 "Expand AUTOINOUT statements, as part of \\[verilog-auto].
12400 Make inout statements for any inout signal in an /*AUTOINST*/ that
12401 isn't declared elsewhere inside the module.
12403 Limitations:
12404 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
12406 If placed inside the parenthesis of a module declaration, it creates
12407 Verilog 2001 style, else uses Verilog 1995 style.
12409 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
12410 instantiation, all bets are off. (For example due to an AUTO_TEMPLATE).
12412 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
12414 Types are added to declarations if an AUTOLOGIC or
12415 `verilog-auto-wire-type' is set to logic.
12417 Signals matching `verilog-auto-inout-ignore-regexp' are not included.
12419 An example (see `verilog-auto-inst' for what else is going on here):
12421 module ExampInout (ov,i);
12422 input i;
12423 /*AUTOINOUT*/
12424 InstModule instName
12425 (/*AUTOINST*/);
12426 endmodule
12428 Typing \\[verilog-auto] will make this into:
12430 module ExampInout (ov,i);
12431 input i;
12432 /*AUTOINOUT*/
12433 // Beginning of automatic inouts (from unused autoinst inouts)
12434 inout [31:0] ov; // From inst of inst.v
12435 // End of automatics
12436 InstModule instName
12437 (/*AUTOINST*/
12438 // Inouts
12439 .ov (ov[31:0]),
12440 // Inputs
12441 .i (i));
12442 endmodule
12444 You may also provide an optional regular expression, in which case only
12445 signals matching the regular expression will be included. For example the
12446 same expansion will result from only extracting inouts starting with i:
12448 /*AUTOINOUT(\"^i\")*/"
12449 (save-excursion
12450 ;; Point must be at insertion point.
12451 (let* ((indent-pt (current-indentation))
12452 (params (verilog-read-auto-params 0 1))
12453 (regexp (nth 0 params))
12454 (v2k (verilog-in-paren-quick))
12455 (modi (verilog-modi-current))
12456 (moddecls (verilog-modi-get-decls modi))
12457 (modsubdecls (verilog-modi-get-sub-decls modi))
12458 (sig-list (verilog-signals-not-in
12459 (verilog-subdecls-get-inouts modsubdecls)
12460 (append (verilog-decls-get-outputs moddecls)
12461 (verilog-decls-get-inouts moddecls)
12462 (verilog-decls-get-inputs moddecls)
12463 (verilog-subdecls-get-inputs modsubdecls)
12464 (verilog-subdecls-get-outputs modsubdecls)))))
12465 (when regexp
12466 (setq sig-list (verilog-signals-matching-regexp
12467 sig-list regexp)))
12468 (setq sig-list (verilog-signals-not-matching-regexp
12469 sig-list verilog-auto-inout-ignore-regexp))
12470 (verilog-forward-or-insert-line)
12471 (when v2k (verilog-repair-open-comma))
12472 (when sig-list
12473 (verilog-insert-indent "// Beginning of automatic inouts (from unused autoinst inouts)\n")
12474 (verilog-insert-definition modi sig-list "inout" indent-pt v2k)
12475 (verilog-insert-indent "// End of automatics\n"))
12476 (when v2k (verilog-repair-close-comma)))))
12478 (defun verilog-auto-inout-module (&optional complement all-in)
12479 "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto].
12480 Take input/output/inout statements from the specified module and insert
12481 into the current module. This is useful for making null templates and
12482 shell modules which need to have identical I/O with another module.
12483 Any I/O which are already defined in this module will not be redefined.
12484 For the complement of this function, see `verilog-auto-inout-comp',
12485 and to make monitors with all inputs, see `verilog-auto-inout-in'.
12487 Limitations:
12488 If placed inside the parenthesis of a module declaration, it creates
12489 Verilog 2001 style, else uses Verilog 1995 style.
12491 Concatenation and outputting partial buses is not supported.
12493 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12495 Signals are not inserted in the same order as in the original module,
12496 though they will appear to be in the same order to an AUTOINST
12497 instantiating either module.
12499 Signals declared as \"output reg\" or \"output wire\" etc will
12500 lose the wire/reg declaration so that shell modules may
12501 generate those outputs differently. However, \"output logic\"
12502 is propagated.
12504 An example:
12506 module ExampShell (/*AUTOARG*/);
12507 /*AUTOINOUTMODULE(\"ExampMain\")*/
12508 endmodule
12510 module ExampMain (i,o,io);
12511 input i;
12512 output o;
12513 inout io;
12514 endmodule
12516 Typing \\[verilog-auto] will make this into:
12518 module ExampShell (/*AUTOARG*/i,o,io);
12519 /*AUTOINOUTMODULE(\"ExampMain\")*/
12520 // Beginning of automatic in/out/inouts (from specific module)
12521 output o;
12522 inout io;
12523 input i;
12524 // End of automatics
12525 endmodule
12527 You may also provide an optional regular expression, in which case only
12528 signals matching the regular expression will be included. For example the
12529 same expansion will result from only extracting signals starting with i:
12531 /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/
12533 You may also provide an optional third argument regular
12534 expression, in which case only signals which have that pin
12535 direction and data type matching that regular expression will be
12536 included. This matches against everything before the signal name
12537 in the declaration, for example against \"input\" (single
12538 bit), \"output logic\" (direction and type) or
12539 \"output [1:0]\" (direction and implicit type). You also
12540 probably want to skip spaces in your regexp.
12542 For example, the below will result in matching the output \"o\"
12543 against the previous example's module:
12545 /*AUTOINOUTMODULE(\"ExampMain\",\"\",\"^output.*\")*/
12547 You may also provide an optional fourth argument regular
12548 expression, which if not \"\" only signals which do NOT match
12549 that expression are included."
12550 ;; Beware spacing of quotes in above as can mess up Emacs indenter
12551 (save-excursion
12552 (let* ((params (verilog-read-auto-params 1 4))
12553 (submod (nth 0 params))
12554 (regexp (nth 1 params))
12555 (direction-re (nth 2 params))
12556 (not-re (nth 3 params))
12557 submodi)
12558 ;; Lookup position, etc of co-module
12559 ;; Note this may raise an error
12560 (when (setq submodi (verilog-modi-lookup submod t))
12561 (let* ((indent-pt (current-indentation))
12562 (v2k (verilog-in-paren-quick))
12563 (modi (verilog-modi-current))
12564 (moddecls (verilog-modi-get-decls modi))
12565 (submoddecls (verilog-modi-get-decls submodi))
12566 (sig-list-i (verilog-signals-not-in
12567 (cond (all-in
12568 (append
12569 (verilog-decls-get-inputs submoddecls)
12570 (verilog-decls-get-inouts submoddecls)
12571 (verilog-decls-get-outputs submoddecls)))
12572 (complement
12573 (verilog-decls-get-outputs submoddecls))
12574 (t (verilog-decls-get-inputs submoddecls)))
12575 (append (verilog-decls-get-inputs moddecls))))
12576 (sig-list-o (verilog-signals-not-in
12577 (cond (all-in nil)
12578 (complement
12579 (verilog-decls-get-inputs submoddecls))
12580 (t (verilog-decls-get-outputs submoddecls)))
12581 (append (verilog-decls-get-outputs moddecls))))
12582 (sig-list-io (verilog-signals-not-in
12583 (cond (all-in nil)
12584 (t (verilog-decls-get-inouts submoddecls)))
12585 (append (verilog-decls-get-inouts moddecls))))
12586 (sig-list-if (verilog-signals-not-in
12587 (verilog-decls-get-interfaces submoddecls)
12588 (append (verilog-decls-get-interfaces moddecls)))))
12589 (forward-line 1)
12590 (setq sig-list-i (verilog-signals-edit-wire-reg
12591 (verilog-signals-not-matching-regexp
12592 (verilog-signals-matching-dir-re
12593 (verilog-signals-matching-regexp sig-list-i regexp)
12594 "input" direction-re) not-re))
12595 sig-list-o (verilog-signals-edit-wire-reg
12596 (verilog-signals-not-matching-regexp
12597 (verilog-signals-matching-dir-re
12598 (verilog-signals-matching-regexp sig-list-o regexp)
12599 "output" direction-re) not-re))
12600 sig-list-io (verilog-signals-edit-wire-reg
12601 (verilog-signals-not-matching-regexp
12602 (verilog-signals-matching-dir-re
12603 (verilog-signals-matching-regexp sig-list-io regexp)
12604 "inout" direction-re) not-re))
12605 sig-list-if (verilog-signals-not-matching-regexp
12606 (verilog-signals-matching-dir-re
12607 (verilog-signals-matching-regexp sig-list-if regexp)
12608 "interface" direction-re) not-re))
12609 (when v2k (verilog-repair-open-comma))
12610 (when (or sig-list-i sig-list-o sig-list-io sig-list-if)
12611 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n")
12612 ;; Don't sort them so an upper AUTOINST will match the main module
12613 (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
12614 (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
12615 (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
12616 (verilog-insert-definition modi sig-list-if "interface" indent-pt v2k t)
12617 (verilog-insert-indent "// End of automatics\n"))
12618 (when v2k (verilog-repair-close-comma)))))))
12620 (defun verilog-auto-inout-comp ()
12621 "Expand AUTOINOUTCOMP statements, as part of \\[verilog-auto].
12622 Take input/output/inout statements from the specified module and
12623 insert the inverse into the current module (inputs become outputs
12624 and vice-versa.) This is useful for making test and stimulus
12625 modules which need to have complementing I/O with another module.
12626 Any I/O which are already defined in this module will not be
12627 redefined. For the complement of this function, see
12628 `verilog-auto-inout-module'.
12630 Limitations:
12631 If placed inside the parenthesis of a module declaration, it creates
12632 Verilog 2001 style, else uses Verilog 1995 style.
12634 Concatenation and outputting partial buses is not supported.
12636 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12638 Signals are not inserted in the same order as in the original module,
12639 though they will appear to be in the same order to an AUTOINST
12640 instantiating either module.
12642 An example:
12644 module ExampShell (/*AUTOARG*/);
12645 /*AUTOINOUTCOMP(\"ExampMain\")*/
12646 endmodule
12648 module ExampMain (i,o,io);
12649 input i;
12650 output o;
12651 inout io;
12652 endmodule
12654 Typing \\[verilog-auto] will make this into:
12656 module ExampShell (/*AUTOARG*/i,o,io);
12657 /*AUTOINOUTCOMP(\"ExampMain\")*/
12658 // Beginning of automatic in/out/inouts (from specific module)
12659 output i;
12660 inout io;
12661 input o;
12662 // End of automatics
12663 endmodule
12665 You may also provide an optional regular expression, in which case only
12666 signals matching the regular expression will be included. For example the
12667 same expansion will result from only extracting signals starting with i:
12669 /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/
12671 You may also provide an optional third argument regular
12672 expression, in which case only signals which have that pin
12673 direction and data type matching that regular expression will be
12674 included. This matches against everything before the signal name
12675 in the declaration, for example against \"input\" (single
12676 bit), \"output logic\" (direction and type)
12677 or \"output [1:0]\" (direction and implicit type). You also
12678 probably want to skip spaces in your regexp.
12680 For example, the below will result in matching the output \"o\"
12681 against the previous example's module:
12683 /*AUTOINOUTCOMP(\"ExampMain\",\"\",\"^output.*\")*/
12685 You may also provide an optional fourth argument regular
12686 expression, which if not \"\" only signals which do NOT match
12687 that expression are included."
12688 ;; Beware spacing of quotes in above as can mess up Emacs indenter
12689 (verilog-auto-inout-module t nil))
12691 (defun verilog-auto-inout-in ()
12692 "Expand AUTOINOUTIN statements, as part of \\[verilog-auto].
12693 Take input/output/inout statements from the specified module and
12694 insert them as all inputs into the current module. This is
12695 useful for making monitor modules which need to see all signals
12696 as inputs based on another module. Any I/O which are already
12697 defined in this module will not be redefined. See also
12698 `verilog-auto-inout-module'.
12700 Limitations:
12701 If placed inside the parenthesis of a module declaration, it creates
12702 Verilog 2001 style, else uses Verilog 1995 style.
12704 Concatenation and outputting partial buses is not supported.
12706 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12708 Signals are not inserted in the same order as in the original module,
12709 though they will appear to be in the same order to an AUTOINST
12710 instantiating either module.
12712 An example:
12714 module ExampShell (/*AUTOARG*/);
12715 /*AUTOINOUTIN(\"ExampMain\")*/
12716 endmodule
12718 module ExampMain (i,o,io);
12719 input i;
12720 output o;
12721 inout io;
12722 endmodule
12724 Typing \\[verilog-auto] will make this into:
12726 module ExampShell (/*AUTOARG*/i,o,io);
12727 /*AUTOINOUTIN(\"ExampMain\")*/
12728 // Beginning of automatic in/out/inouts (from specific module)
12729 input i;
12730 input io;
12731 input o;
12732 // End of automatics
12733 endmodule
12735 You may also provide an optional regular expression, in which case only
12736 signals matching the regular expression will be included. For example the
12737 same expansion will result from only extracting signals starting with i:
12739 /*AUTOINOUTIN(\"ExampMain\",\"^i\")*/"
12740 (verilog-auto-inout-module nil t))
12742 (defun verilog-auto-inout-param ()
12743 "Expand AUTOINOUTPARAM statements, as part of \\[verilog-auto].
12744 Take input/output/inout statements from the specified module and insert
12745 into the current module. This is useful for making null templates and
12746 shell modules which need to have identical I/O with another module.
12747 Any I/O which are already defined in this module will not be redefined.
12748 For the complement of this function, see `verilog-auto-inout-comp',
12749 and to make monitors with all inputs, see `verilog-auto-inout-in'.
12751 Limitations:
12752 If placed inside the parenthesis of a module declaration, it creates
12753 Verilog 2001 style, else uses Verilog 1995 style.
12755 Module names must be resolvable to filenames. See `verilog-auto-inst'.
12757 Parameters are inserted in the same order as in the original module.
12759 Parameters do not have values, which is SystemVerilog 2009 syntax.
12761 An example:
12763 module ExampShell ();
12764 /*AUTOINOUTPARAM(\"ExampMain\")*/
12765 endmodule
12767 module ExampMain ();
12768 parameter PARAM = 22;
12769 endmodule
12771 Typing \\[verilog-auto] will make this into:
12773 module ExampShell (/*AUTOARG*/i,o,io);
12774 /*AUTOINOUTPARAM(\"ExampMain\")*/
12775 // Beginning of automatic parameters (from specific module)
12776 parameter PARAM;
12777 // End of automatics
12778 endmodule
12780 You may also provide an optional regular expression, in which case only
12781 parameters matching the regular expression will be included. For example the
12782 same expansion will result from only extracting parameters starting with i:
12784 /*AUTOINOUTPARAM(\"ExampMain\",\"^i\")*/"
12785 (save-excursion
12786 (let* ((params (verilog-read-auto-params 1 2))
12787 (submod (nth 0 params))
12788 (regexp (nth 1 params))
12789 submodi)
12790 ;; Lookup position, etc of co-module
12791 ;; Note this may raise an error
12792 (when (setq submodi (verilog-modi-lookup submod t))
12793 (let* ((indent-pt (current-indentation))
12794 (v2k (verilog-in-paren-quick))
12795 (modi (verilog-modi-current))
12796 (moddecls (verilog-modi-get-decls modi))
12797 (submoddecls (verilog-modi-get-decls submodi))
12798 (sig-list-p (verilog-signals-not-in
12799 (verilog-decls-get-gparams submoddecls)
12800 (append (verilog-decls-get-gparams moddecls)))))
12801 (forward-line 1)
12802 (setq sig-list-p (verilog-signals-matching-regexp sig-list-p regexp))
12803 (when v2k (verilog-repair-open-comma))
12804 (when sig-list-p
12805 (verilog-insert-indent "// Beginning of automatic parameters (from specific module)\n")
12806 ;; Don't sort them so an upper AUTOINST will match the main module
12807 (verilog-insert-definition modi sig-list-p "parameter" indent-pt v2k t)
12808 (verilog-insert-indent "// End of automatics\n"))
12809 (when v2k (verilog-repair-close-comma)))))))
12811 (defun verilog-auto-inout-modport ()
12812 "Expand AUTOINOUTMODPORT statements, as part of \\[verilog-auto].
12813 Take input/output/inout statements from the specified interface
12814 and modport and insert into the current module. This is useful
12815 for making verification modules that connect to UVM interfaces.
12817 The first parameter is the name of an interface.
12819 The second parameter is a regexp of modports to read from in
12820 that interface.
12822 The optional third parameter is a regular expression, and only
12823 signals matching the regular expression will be included.
12825 Limitations:
12826 If placed inside the parenthesis of a module declaration, it creates
12827 Verilog 2001 style, else uses Verilog 1995 style.
12829 Interface names must be resolvable to filenames. See `verilog-auto-inst'.
12831 As with other autos, any inputs/outputs declared in the module
12832 will suppress the AUTO from redeclaring an inputs/outputs by
12833 the same name.
12835 An example:
12837 interface ExampIf
12838 ( input logic clk );
12839 logic req_val;
12840 logic [7:0] req_dat;
12841 clocking mon_clkblk @(posedge clk);
12842 input req_val;
12843 input req_dat;
12844 endclocking
12845 modport mp(clocking mon_clkblk);
12846 endinterface
12848 module ExampMain
12849 ( input clk,
12850 /*AUTOINOUTMODPORT(\"ExampIf\" \"mp\")*/
12851 // Beginning of automatic in/out/inouts (from modport)
12852 input [7:0] req_dat,
12853 input req_val
12854 // End of automatics
12856 /*AUTOASSIGNMODPORT(\"ExampIf\" \"mp\")*/
12857 endmodule
12859 Typing \\[verilog-auto] will make this into:
12862 module ExampMain
12863 ( input clk,
12864 /*AUTOINOUTMODPORT(\"ExampIf\" \"mp\")*/
12865 // Beginning of automatic in/out/inouts (from modport)
12866 input req_dat,
12867 input req_val
12868 // End of automatics
12871 If the modport is part of a UVM monitor/driver class, this
12872 creates a wrapper module that may be used to instantiate the
12873 driver/monitor using AUTOINST in the testbench."
12874 (save-excursion
12875 (let* ((params (verilog-read-auto-params 2 3))
12876 (submod (nth 0 params))
12877 (modport-re (nth 1 params))
12878 (regexp (nth 2 params))
12879 direction-re submodi) ; direction argument not supported until requested
12880 ;; Lookup position, etc of co-module
12881 ;; Note this may raise an error
12882 (when (setq submodi (verilog-modi-lookup submod t))
12883 (let* ((indent-pt (current-indentation))
12884 (v2k (verilog-in-paren-quick))
12885 (modi (verilog-modi-current))
12886 (moddecls (verilog-modi-get-decls modi))
12887 (submoddecls (verilog-modi-get-decls submodi))
12888 (submodportdecls (verilog-modi-modport-lookup submodi modport-re))
12889 (sig-list-i (verilog-signals-in ; Decls doesn't have data types, must resolve
12890 (verilog-decls-get-vars submoddecls)
12891 (verilog-signals-not-in
12892 (verilog-decls-get-inputs submodportdecls)
12893 (append (verilog-decls-get-ports submoddecls)
12894 (verilog-decls-get-ports moddecls)))))
12895 (sig-list-o (verilog-signals-in ; Decls doesn't have data types, must resolve
12896 (verilog-decls-get-vars submoddecls)
12897 (verilog-signals-not-in
12898 (verilog-decls-get-outputs submodportdecls)
12899 (append (verilog-decls-get-ports submoddecls)
12900 (verilog-decls-get-ports moddecls)))))
12901 (sig-list-io (verilog-signals-in ; Decls doesn't have data types, must resolve
12902 (verilog-decls-get-vars submoddecls)
12903 (verilog-signals-not-in
12904 (verilog-decls-get-inouts submodportdecls)
12905 (append (verilog-decls-get-ports submoddecls)
12906 (verilog-decls-get-ports moddecls))))))
12907 (forward-line 1)
12908 (setq sig-list-i (verilog-signals-edit-wire-reg
12909 (verilog-signals-matching-dir-re
12910 (verilog-signals-matching-regexp sig-list-i regexp)
12911 "input" direction-re))
12912 sig-list-o (verilog-signals-edit-wire-reg
12913 (verilog-signals-matching-dir-re
12914 (verilog-signals-matching-regexp sig-list-o regexp)
12915 "output" direction-re))
12916 sig-list-io (verilog-signals-edit-wire-reg
12917 (verilog-signals-matching-dir-re
12918 (verilog-signals-matching-regexp sig-list-io regexp)
12919 "inout" direction-re)))
12920 (when v2k (verilog-repair-open-comma))
12921 (when (or sig-list-i sig-list-o sig-list-io)
12922 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from modport)\n")
12923 ;; Don't sort them so an upper AUTOINST will match the main module
12924 (verilog-insert-definition modi sig-list-o "output" indent-pt v2k t)
12925 (verilog-insert-definition modi sig-list-io "inout" indent-pt v2k t)
12926 (verilog-insert-definition modi sig-list-i "input" indent-pt v2k t)
12927 (verilog-insert-indent "// End of automatics\n"))
12928 (when v2k (verilog-repair-close-comma)))))))
12930 (defun verilog-auto-insert-lisp ()
12931 "Expand AUTOINSERTLISP statements, as part of \\[verilog-auto].
12932 The Lisp code provided is called before other AUTOS are expanded,
12933 and the Lisp code generally will call `insert' to insert text
12934 into the current file beginning on the line after the
12935 AUTOINSERTLISP.
12937 See also AUTOINSERTLAST and `verilog-auto-insert-last' which
12938 executes after (as opposed to before) other AUTOs.
12940 See also AUTO_LISP, which takes a Lisp expression and evaluates
12941 it during `verilog-auto-inst' but does not insert any text.
12943 An example:
12945 module ExampInsertLisp;
12946 /*AUTOINSERTLISP(my-verilog-insert-hello \"world\")*/
12947 endmodule
12949 // For this example we declare the function in the
12950 // module's file itself. Often you'd define it instead
12951 // in a site-start.el or init file.
12953 Local Variables:
12954 eval:
12955 (defun my-verilog-insert-hello (who)
12956 (insert (concat \"initial $write(\\\"hello \" who \"\\\");\\n\")))
12957 End:
12960 Typing \\[verilog-auto] will call my-verilog-insert-hello and
12961 expand the above into:
12963 // Beginning of automatic insert lisp
12964 initial $write(\"hello world\");
12965 // End of automatics
12967 You can also call an external program and insert the returned
12968 text:
12970 /*AUTOINSERTLISP(insert (shell-command-to-string \"echo //hello\"))*/
12971 // Beginning of automatic insert lisp
12972 //hello
12973 // End of automatics"
12974 (save-excursion
12975 ;; Point is at end of /*AUTO...*/
12976 (let* ((indent-pt (current-indentation))
12977 (cmd-end-pt (save-excursion (search-backward ")")
12978 (forward-char)
12979 (point))) ; Closing paren
12980 (cmd-beg-pt (save-excursion (goto-char cmd-end-pt)
12981 (backward-sexp 1) ; Inside comment
12982 (point))) ; Beginning paren
12983 (cmd (buffer-substring-no-properties cmd-beg-pt cmd-end-pt)))
12984 (verilog-forward-or-insert-line)
12985 ;; Some commands don't move point (like insert-file) so we always
12986 ;; add the begin/end comments, then delete it if not needed
12987 (verilog-insert-indent "// Beginning of automatic insert lisp\n")
12988 (verilog-insert-indent "// End of automatics\n")
12989 (forward-line -1)
12990 (eval (read cmd))
12991 (forward-line -1)
12992 (setq verilog-scan-cache-tick nil) ; Clear cache; inserted unknown text
12993 (verilog-delete-empty-auto-pair))))
12995 (defun verilog-auto-insert-last ()
12996 "Expand AUTOINSERTLAST statements, as part of \\[verilog-auto].
12997 The Lisp code provided is called after all other AUTOS have been
12998 expanded, and the Lisp code generally will call `insert' to
12999 insert text into the current file beginning on the line after the
13000 AUTOINSERTLAST.
13002 Other than when called (after AUTOs are expanded), the functionality
13003 is otherwise identical to AUTOINSERTLISP and `verilog-auto-insert-lisp' which
13004 executes before (as opposed to after) other AUTOs.
13006 See `verilog-auto-insert-lisp' for examples."
13007 (verilog-auto-insert-lisp))
13009 (defun verilog-auto-sense-sigs (moddecls presense-sigs)
13010 "Return list of signals for current AUTOSENSE block."
13011 (let* ((sigss (save-excursion
13012 (search-forward ")")
13013 (verilog-read-always-signals)))
13014 (sig-list (verilog-signals-not-params
13015 (verilog-signals-not-in (verilog-alw-get-inputs sigss)
13016 (append (and (not verilog-auto-sense-include-inputs)
13017 (verilog-alw-get-outputs-delayed sigss))
13018 (and (not verilog-auto-sense-include-inputs)
13019 (verilog-alw-get-outputs-immediate sigss))
13020 (verilog-alw-get-temps sigss)
13021 (verilog-decls-get-consts moddecls)
13022 (verilog-decls-get-gparams moddecls)
13023 presense-sigs)))))
13024 sig-list))
13026 (defun verilog-auto-sense ()
13027 "Expand AUTOSENSE statements, as part of \\[verilog-auto].
13028 Replace the always (/*AUTOSENSE*/) sensitivity list (/*AS*/ for short)
13029 with one automatically derived from all inputs declared in the always
13030 statement. Signals that are generated within the same always block are NOT
13031 placed into the sensitivity list (see `verilog-auto-sense-include-inputs').
13032 Long lines are split based on the `fill-column', see \\[set-fill-column].
13034 Limitations:
13035 Verilog does not allow memories (multidimensional arrays) in sensitivity
13036 lists. AUTOSENSE will thus exclude them, and add a /*memory or*/ comment.
13038 Constant signals:
13039 AUTOSENSE cannot always determine if a \\=`define is a constant or a signal
13040 (it could be in an include file for example). If a \\=`define or other signal
13041 is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT
13042 declaration anywhere in the module (parenthesis are required):
13044 /* AUTO_CONSTANT ( \\=`this_is_really_constant_dont_autosense_it ) */
13046 Better yet, use a parameter, which will be understood to be constant
13047 automatically.
13049 OOps!
13050 If AUTOSENSE makes a mistake, please report it. (First try putting
13051 a begin/end after your always!) As a workaround, if a signal that
13052 shouldn't be in the sensitivity list was, use the AUTO_CONSTANT above.
13053 If a signal should be in the sensitivity list wasn't, placing it before
13054 the /*AUTOSENSE*/ comment will prevent it from being deleted when the
13055 autos are updated (or added if it occurs there already).
13057 An example:
13059 always @ (/*AS*/) begin
13060 /* AUTO_CONSTANT (\\=`constant) */
13061 outin = ina | inb | \\=`constant;
13062 out = outin;
13065 Typing \\[verilog-auto] will make this into:
13067 always @ (/*AS*/ina or inb) begin
13068 /* AUTO_CONSTANT (\\=`constant) */
13069 outin = ina | inb | \\=`constant;
13070 out = outin;
13073 Note in Verilog 2001, you can often get the same result from the new @*
13074 operator. (This was added to the language in part due to AUTOSENSE!)
13076 always @* begin
13077 outin = ina | inb | \\=`constant;
13078 out = outin;
13079 end"
13080 (save-excursion
13081 ;; Find beginning
13082 (let* ((start-pt (save-excursion
13083 (verilog-re-search-backward-quick "(" nil t)
13084 (point)))
13085 (indent-pt (save-excursion
13086 (or (and (goto-char start-pt) (1+ (current-column)))
13087 (current-indentation))))
13088 (modi (verilog-modi-current))
13089 (moddecls (verilog-modi-get-decls modi))
13090 (sig-memories (verilog-signals-memory
13091 (verilog-decls-get-vars moddecls)))
13092 sig-list not-first presense-sigs)
13093 ;; Read signals in always, eliminate outputs from sense list
13094 (setq presense-sigs (verilog-signals-from-signame
13095 (save-excursion
13096 (verilog-read-signals start-pt (point)))))
13097 (setq sig-list (verilog-auto-sense-sigs moddecls presense-sigs))
13098 (when sig-memories
13099 (let ((tlen (length sig-list)))
13100 (setq sig-list (verilog-signals-not-in sig-list sig-memories))
13101 (if (not (eq tlen (length sig-list))) (verilog-insert " /*memory or*/ "))))
13102 (if (and presense-sigs ; Add a "or" if not "(.... or /*AUTOSENSE*/"
13103 (save-excursion (goto-char (point))
13104 (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
13105 (verilog-re-search-backward-quick "\\s-" start-pt t)
13106 (while (looking-at "\\s-`endif")
13107 (verilog-re-search-backward-quick "[a-zA-Z0-9$_.%`]+" start-pt t)
13108 (verilog-re-search-backward-quick "\\s-" start-pt t))
13109 (not (looking-at "\\s-or\\b"))))
13110 (setq not-first t))
13111 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
13112 (while sig-list
13113 (cond ((> (+ 4 (current-column) (length (verilog-sig-name (car sig-list)))) fill-column) ;+4 for width of or
13114 (insert "\n")
13115 (indent-to indent-pt)
13116 (if not-first (insert "or ")))
13117 (not-first (insert " or ")))
13118 (insert (verilog-sig-name (car sig-list)))
13119 (setq sig-list (cdr sig-list)
13120 not-first t)))))
13122 (defun verilog-auto-reset ()
13123 "Expand AUTORESET statements, as part of \\[verilog-auto].
13124 Replace the /*AUTORESET*/ comment with code to initialize all
13125 registers set elsewhere in the always block.
13127 Limitations:
13128 AUTORESET will not clear memories.
13130 AUTORESET uses <= if the signal has a <= assignment in the block,
13131 else it uses =.
13133 If <= is used, all = assigned variables are ignored if
13134 `verilog-auto-reset-blocking-in-non' is nil; they are presumed
13135 to be temporaries.
13137 /*AUTORESET*/ presumes that any signals mentioned between the previous
13138 begin/case/if statement and the AUTORESET comment are being reset manually
13139 and should not be automatically reset. This includes omitting any signals
13140 used on the right hand side of assignments.
13142 By default, AUTORESET will include the width of the signal in the
13143 autos, SystemVerilog designs may want to change this. To control
13144 this behavior, see `verilog-auto-reset-widths'. In some cases
13145 AUTORESET must use a \\='0 assignment and it will print NOWIDTH; use
13146 `verilog-auto-reset-widths' unbased to prevent this.
13148 AUTORESET ties signals to deasserted, which is presumed to be zero.
13149 Signals that match `verilog-active-low-regexp' will be deasserted by tying
13150 them to a one.
13152 AUTORESET may try to reset arrays or structures that cannot be
13153 reset by a simple assignment, resulting in compile errors. This
13154 is a feature to be taken as a hint that you need to reset these
13155 signals manually (or put them into a \"\\=`ifdef NEVER signal<=\\=`0;
13156 \\=`endif\" so Verilog-Mode ignores them.)
13158 An example:
13160 always @(posedge clk or negedge reset_l) begin
13161 if (!reset_l) begin
13162 c <= 1;
13163 /*AUTORESET*/
13165 else begin
13166 a <= in_a;
13167 b <= in_b;
13168 c <= in_c;
13172 Typing \\[verilog-auto] will make this into:
13174 always @(posedge core_clk or negedge reset_l) begin
13175 if (!reset_l) begin
13176 c <= 1;
13177 /*AUTORESET*/
13178 // Beginning of autoreset for uninitialized flops
13179 a <= 0;
13180 b = 0; // if `verilog-auto-reset-blocking-in-non' true
13181 // End of automatics
13183 else begin
13184 a <= in_a;
13185 b = in_b;
13186 c <= in_c;
13188 end"
13190 (interactive)
13191 (save-excursion
13192 ;; Find beginning
13193 (let* ((indent-pt (current-indentation))
13194 (modi (verilog-modi-current))
13195 (moddecls (verilog-modi-get-decls modi))
13196 (all-list (verilog-decls-get-signals moddecls))
13197 sigss sig-list dly-list prereset-sigs)
13198 ;; Read signals in always, eliminate outputs from reset list
13199 (setq prereset-sigs (verilog-signals-from-signame
13200 (save-excursion
13201 (verilog-read-signals
13202 (save-excursion
13203 (verilog-re-search-backward-quick
13204 "\\(@\\|\\<\\(begin\\|if\\|case[xz]?\\|always\\(_latch\\|_ff\\|_comb\\)?\\)\\>\\)" nil t)
13205 (point))
13206 (point)))))
13207 (save-excursion
13208 (verilog-re-search-backward-quick "\\(@\\|\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\)\\>\\)" nil t)
13209 (setq sigss (verilog-read-always-signals)))
13210 (setq dly-list (verilog-alw-get-outputs-delayed sigss))
13211 (setq sig-list (verilog-signals-not-in-struct
13212 (append
13213 (verilog-alw-get-outputs-delayed sigss)
13214 (when (or (not (verilog-alw-get-uses-delayed sigss))
13215 verilog-auto-reset-blocking-in-non)
13216 (verilog-alw-get-outputs-immediate sigss)))
13217 (append
13218 (verilog-alw-get-temps sigss)
13219 prereset-sigs)))
13220 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
13221 (when sig-list
13222 (insert "\n");
13223 (verilog-insert-indent "// Beginning of autoreset for uninitialized flops\n");
13224 (while sig-list
13225 (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ; As sig-list has no widths
13226 (car sig-list))))
13227 (indent-to indent-pt)
13228 (insert (verilog-sig-name sig)
13229 (if (assoc (verilog-sig-name sig) dly-list)
13230 (concat " <= " verilog-assignment-delay)
13231 " = ")
13232 (verilog-sig-tieoff sig)
13233 ";\n")
13234 (setq sig-list (cdr sig-list))))
13235 (verilog-insert-indent "// End of automatics")))))
13237 (defun verilog-auto-tieoff ()
13238 "Expand AUTOTIEOFF statements, as part of \\[verilog-auto].
13239 Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output
13240 signals to deasserted.
13242 /*AUTOTIEOFF*/ is used to make stub modules; modules that have
13243 the same input/output list as another module, but no internals.
13244 Specifically, it finds all outputs in the module, and if that
13245 input is not otherwise declared as a register or wire, nor comes
13246 from a AUTOINST submodule's output, creates a tieoff. AUTOTIEOFF
13247 does not examine assignments to determine what is already driven.
13249 AUTORESET ties signals to deasserted, which is presumed to be zero.
13250 Signals that match `verilog-active-low-regexp' will be deasserted by tying
13251 them to a one.
13253 You can add signals you do not want included in AUTOTIEOFF with
13254 `verilog-auto-tieoff-ignore-regexp'.
13256 `verilog-auto-wire-type' may be used to change the datatype of
13257 the declarations.
13259 `verilog-auto-reset-widths' may be used to change how the tieoff
13260 value's width is generated.
13262 An example of making a stub for another module:
13264 module ExampStub (/*AUTOINST*/);
13265 /*AUTOINOUTPARAM(\"Foo\")*/
13266 /*AUTOINOUTMODULE(\"Foo\")*/
13267 /*AUTOTIEOFF*/
13268 // verilator lint_off UNUSED
13269 wire _unused_ok = &{1\\='b0,
13270 /*AUTOUNUSED*/
13271 1\\='b0};
13272 // verilator lint_on UNUSED
13273 endmodule
13275 Typing \\[verilog-auto] will make this into:
13277 module ExampStub (/*AUTOINST*/...);
13278 /*AUTOINOUTPARAM(\"Foo\")*/
13279 /*AUTOINOUTMODULE(\"Foo\")*/
13280 // Beginning of autotieoff
13281 output [2:0] foo;
13282 // End of automatics
13284 /*AUTOTIEOFF*/
13285 // Beginning of autotieoff
13286 wire [2:0] foo = 3\\='b0;
13287 // End of automatics
13289 endmodule"
13290 (interactive)
13291 (save-excursion
13292 ;; Find beginning
13293 (let* ((indent-pt (current-indentation))
13294 (modi (verilog-modi-current))
13295 (moddecls (verilog-modi-get-decls modi))
13296 (modsubdecls (verilog-modi-get-sub-decls modi))
13297 (sig-list (verilog-signals-not-in
13298 (verilog-decls-get-outputs moddecls)
13299 (append (verilog-decls-get-vars moddecls)
13300 (verilog-decls-get-assigns moddecls)
13301 (verilog-decls-get-consts moddecls)
13302 (verilog-decls-get-gparams moddecls)
13303 (verilog-subdecls-get-interfaced modsubdecls)
13304 (verilog-subdecls-get-outputs modsubdecls)
13305 (verilog-subdecls-get-inouts modsubdecls)))))
13306 (setq sig-list (verilog-signals-not-matching-regexp
13307 sig-list verilog-auto-tieoff-ignore-regexp))
13308 (when sig-list
13309 (verilog-forward-or-insert-line)
13310 (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n")
13311 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
13312 (verilog-modi-cache-add-vars modi sig-list) ; Before we trash list
13313 (while sig-list
13314 (let ((sig (car sig-list)))
13315 (cond ((equal verilog-auto-tieoff-declaration "assign")
13316 (indent-to indent-pt)
13317 (insert "assign " (verilog-sig-name sig)))
13319 (verilog-insert-one-definition sig verilog-auto-tieoff-declaration indent-pt)))
13320 (indent-to (max 48 (+ indent-pt 40)))
13321 (insert "= " (verilog-sig-tieoff sig)
13322 ";\n")
13323 (setq sig-list (cdr sig-list))))
13324 (verilog-insert-indent "// End of automatics\n")))))
13326 (defun verilog-auto-undef ()
13327 "Expand AUTOUNDEF statements, as part of \\[verilog-auto].
13328 Take any \\=`defines since the last AUTOUNDEF in the current file
13329 and create \\=`undefs for them. This is used to insure that
13330 file-local defines do not pollute the global \\=`define name space.
13332 Limitations:
13333 AUTOUNDEF presumes any identifier following \\=`define is the
13334 name of a define. Any \\=`ifdefs are ignored.
13336 AUTOUNDEF suppresses creating an \\=`undef for any define that was
13337 \\=`undefed before the AUTOUNDEF. This may be used to work around
13338 the ignoring of \\=`ifdefs as shown below.
13340 An example:
13342 \\=`define XX_FOO
13343 \\=`define M_BAR(x)
13344 \\=`define M_BAZ
13346 \\=`ifdef NEVER
13347 \\=`undef M_BAZ // Emacs will see this and not \\=`undef M_BAZ
13348 \\=`endif
13350 /*AUTOUNDEF*/
13352 Typing \\[verilog-auto] will make this into:
13355 /*AUTOUNDEF*/
13356 // Beginning of automatic undefs
13357 \\=`undef XX_FOO
13358 \\=`undef M_BAR
13359 // End of automatics
13361 You may also provide an optional regular expression, in which case only
13362 defines the regular expression will be undefed."
13363 (save-excursion
13364 (let* ((params (verilog-read-auto-params 0 1))
13365 (regexp (nth 0 params))
13366 (indent-pt (current-indentation))
13367 (end-pt (point))
13368 defs def)
13369 (save-excursion
13370 ;; Scan from start of file, or last AUTOUNDEF
13371 (or (verilog-re-search-backward-quick "/\\*AUTOUNDEF\\>" end-pt t)
13372 (goto-char (point-min)))
13373 (while (verilog-re-search-forward-quick
13374 "`\\(define\\|undef\\)\\s-*\\([a-zA-Z_][a-zA-Z_0-9]*\\)" end-pt t)
13375 (cond ((equal (match-string-no-properties 1) "define")
13376 (setq def (match-string-no-properties 2))
13377 (when (and (or (not regexp)
13378 (string-match regexp def))
13379 (not (member def defs))) ; delete-dups not in 21.1
13380 (setq defs (cons def defs))))
13382 (setq defs (delete (match-string-no-properties 2) defs))))))
13383 ;; Insert
13384 (setq defs (sort defs 'string<))
13385 (when defs
13386 (verilog-forward-or-insert-line)
13387 (verilog-insert-indent "// Beginning of automatic undefs\n")
13388 (while defs
13389 (verilog-insert-indent "`undef " (car defs) "\n")
13390 (setq defs (cdr defs)))
13391 (verilog-insert-indent "// End of automatics\n")))))
13393 (defun verilog-auto-unused ()
13394 "Expand AUTOUNUSED statements, as part of \\[verilog-auto].
13395 Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused
13396 input and inout signals.
13398 /*AUTOUNUSED*/ is used to make stub modules; modules that have the same
13399 input/output list as another module, but no internals. Specifically, it
13400 finds all inputs and inouts in the module, and if that input is not otherwise
13401 used, adds it to a comma separated list.
13403 The comma separated list is intended to be used to create a _unused_ok
13404 signal. Using the exact name \"_unused_ok\" for name of the temporary
13405 signal is recommended as it will insure maximum forward compatibility, it
13406 also makes lint warnings easy to understand; ignore any unused warnings
13407 with \"unused\" in the signal name.
13409 To reduce simulation time, the _unused_ok signal should be forced to a
13410 constant to prevent wiggling. The easiest thing to do is use a
13411 reduction-and with 1\\='b0 as shown.
13413 This way all unused signals are in one place, making it convenient to add
13414 your tool's specific pragmas around the assignment to disable any unused
13415 warnings.
13417 You can add signals you do not want included in AUTOUNUSED with
13418 `verilog-auto-unused-ignore-regexp'.
13420 An example of making a stub for another module:
13422 module ExampStub (/*AUTOINST*/);
13423 /*AUTOINOUTPARAM(\"Examp\")*/
13424 /*AUTOINOUTMODULE(\"Examp\")*/
13425 /*AUTOTIEOFF*/
13426 // verilator lint_off UNUSED
13427 wire _unused_ok = &{1\\='b0,
13428 /*AUTOUNUSED*/
13429 1\\='b0};
13430 // verilator lint_on UNUSED
13431 endmodule
13433 Typing \\[verilog-auto] will make this into:
13436 // verilator lint_off UNUSED
13437 wire _unused_ok = &{1\\='b0,
13438 /*AUTOUNUSED*/
13439 // Beginning of automatics
13440 unused_input_a,
13441 unused_input_b,
13442 unused_input_c,
13443 // End of automatics
13444 1\\='b0};
13445 // verilator lint_on UNUSED
13446 endmodule"
13447 (interactive)
13448 (save-excursion
13449 ;; Find beginning
13450 (let* ((indent-pt (progn (search-backward "/*") (current-column)))
13451 (modi (verilog-modi-current))
13452 (moddecls (verilog-modi-get-decls modi))
13453 (modsubdecls (verilog-modi-get-sub-decls modi))
13454 (sig-list (verilog-signals-not-in
13455 (append (verilog-decls-get-inputs moddecls)
13456 (verilog-decls-get-inouts moddecls))
13457 (append (verilog-subdecls-get-inputs modsubdecls)
13458 (verilog-subdecls-get-inouts modsubdecls)))))
13459 (setq sig-list (verilog-signals-not-matching-regexp
13460 sig-list verilog-auto-unused-ignore-regexp))
13461 (when sig-list
13462 (verilog-forward-or-insert-line)
13463 (verilog-insert-indent "// Beginning of automatic unused inputs\n")
13464 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
13465 (while sig-list
13466 (let ((sig (car sig-list)))
13467 (indent-to indent-pt)
13468 (insert (verilog-sig-name sig) ",\n")
13469 (setq sig-list (cdr sig-list))))
13470 (verilog-insert-indent "// End of automatics\n")))))
13472 (defun verilog-enum-ascii (signm elim-regexp)
13473 "Convert an enum name SIGNM to an ascii string for insertion.
13474 Remove user provided prefix ELIM-REGEXP."
13475 (or elim-regexp (setq elim-regexp "_ DONT MATCH IT_"))
13476 (let ((case-fold-search t))
13477 ;; All upper becomes all lower for readability
13478 (downcase (verilog-string-replace-matches elim-regexp "" nil nil signm))))
13480 (defun verilog-auto-ascii-enum ()
13481 "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto].
13482 Create a register to contain the ASCII decode of an enumerated signal type.
13483 This will allow trace viewers to show the ASCII name of states.
13485 First, parameters are built into an enumeration using the synopsys enum
13486 comment. The comment must be between the keyword and the symbol.
13487 \(Annoying, but that's what Synopsys's dc_shell FSM reader requires.)
13489 Next, registers which that enum applies to are also tagged with the same
13490 enum.
13492 Finally, an AUTOASCIIENUM command is used.
13494 The first parameter is the name of the signal to be decoded.
13496 The second parameter is the name to store the ASCII code into. For the
13497 signal foo, I suggest the name _foo__ascii, where the leading _ indicates
13498 a signal that is just for simulation, and the magic characters _ascii
13499 tell viewers like Dinotrace to display in ASCII format.
13501 The third optional parameter is a string which will be removed
13502 from the state names. It defaults to \"\" which removes nothing.
13504 The fourth optional parameter is \"onehot\" to force one-hot
13505 decoding. If unspecified, if and only if the first parameter
13506 width is 2^(number of states in enum) and does NOT match the
13507 width of the enum, the signal is assumed to be a one-hot
13508 decode. Otherwise, it's a normal encoded state vector.
13510 `verilog-auto-wire-type' may be used to change the datatype of
13511 the declarations.
13513 \"auto enum\" may be used in place of \"synopsys enum\".
13515 An example:
13517 //== State enumeration
13518 parameter [2:0] // synopsys enum state_info
13519 SM_IDLE = 3\\='b000,
13520 SM_SEND = 3\\='b001,
13521 SM_WAIT1 = 3\\='b010;
13522 //== State variables
13523 reg [2:0] /* synopsys enum state_info */
13524 state_r; /* synopsys state_vector state_r */
13525 reg [2:0] /* synopsys enum state_info */
13526 state_e1;
13528 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
13530 Typing \\[verilog-auto] will make this into:
13532 ... same front matter ...
13534 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
13535 // Beginning of automatic ASCII enum decoding
13536 reg [39:0] state_ascii_r; // Decode of state_r
13537 always @(state_r) begin
13538 case ({state_r})
13539 SM_IDLE: state_ascii_r = \"idle \";
13540 SM_SEND: state_ascii_r = \"send \";
13541 SM_WAIT1: state_ascii_r = \"wait1\";
13542 default: state_ascii_r = \"%Erro\";
13543 endcase
13545 // End of automatics"
13546 (save-excursion
13547 (let* ((params (verilog-read-auto-params 2 4))
13548 (undecode-name (nth 0 params))
13549 (ascii-name (nth 1 params))
13550 (elim-regexp (and (nth 2 params)
13551 (not (equal (nth 2 params) ""))
13552 (nth 2 params)))
13553 (one-hot-flag (nth 3 params))
13555 (indent-pt (current-indentation))
13556 (modi (verilog-modi-current))
13557 (moddecls (verilog-modi-get-decls modi))
13559 (sig-list-consts (append (verilog-decls-get-consts moddecls)
13560 (verilog-decls-get-gparams moddecls)))
13561 (sig-list-all (verilog-decls-get-iovars moddecls))
13563 (undecode-sig (or (assoc undecode-name sig-list-all)
13564 (error "%s: Signal `%s' not found in design"
13565 (verilog-point-text) undecode-name)))
13566 (undecode-enum (or (verilog-sig-enum undecode-sig)
13567 (error "%s: Signal `%s' does not have an enum tag"
13568 (verilog-point-text) undecode-name)))
13570 (enum-sigs (verilog-signals-not-in
13571 (or (verilog-signals-matching-enum sig-list-consts undecode-enum)
13572 (error "%s: No state definitions for `%s'"
13573 (verilog-point-text) undecode-enum))
13574 nil))
13576 (one-hot (or
13577 (string-match "onehot" (or one-hot-flag ""))
13578 (and ; width(enum) != width(sig)
13579 (or (not (verilog-sig-bits (car enum-sigs)))
13580 (not (equal (verilog-sig-width (car enum-sigs))
13581 (verilog-sig-width undecode-sig))))
13582 ;; count(enums) == width(sig)
13583 (equal (number-to-string (length enum-sigs))
13584 (verilog-sig-width undecode-sig)))))
13585 (enum-chars 0)
13586 (ascii-chars 0))
13588 ;; Find number of ascii chars needed
13589 (let ((tmp-sigs enum-sigs))
13590 (while tmp-sigs
13591 (setq enum-chars (max enum-chars (length (verilog-sig-name (car tmp-sigs))))
13592 ascii-chars (max ascii-chars (length (verilog-enum-ascii
13593 (verilog-sig-name (car tmp-sigs))
13594 elim-regexp)))
13595 tmp-sigs (cdr tmp-sigs))))
13597 (verilog-forward-or-insert-line)
13598 (verilog-insert-indent "// Beginning of automatic ASCII enum decoding\n")
13599 (let ((decode-sig-list (list (list ascii-name (format "[%d:0]" (- (* ascii-chars 8) 1))
13600 (concat "Decode of " undecode-name) nil nil))))
13601 (verilog-insert-definition modi decode-sig-list "reg" indent-pt nil))
13603 (verilog-insert-indent "always @(" undecode-name ") begin\n")
13604 (setq indent-pt (+ indent-pt verilog-indent-level))
13605 (verilog-insert-indent "case ({" undecode-name "})\n")
13606 (setq indent-pt (+ indent-pt verilog-case-indent))
13608 (let ((tmp-sigs enum-sigs)
13609 (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n"
13610 (+ (if one-hot 9 1) (max 8 enum-chars))
13611 ascii-name ascii-chars))
13612 (errname (substring "%Error" 0 (min 6 ascii-chars))))
13613 (while tmp-sigs
13614 (verilog-insert-indent
13615 (concat
13616 (format chrfmt
13617 (concat (if one-hot "(")
13618 ;; Use enum-sigs length as that's numeric
13619 ;; verilog-sig-width undecode-sig might not be.
13620 (if one-hot (number-to-string (length enum-sigs)))
13621 ;; We use a shift instead of var[index]
13622 ;; so that a non-one hot value will show as error.
13623 (if one-hot "'b1<<")
13624 (verilog-sig-name (car tmp-sigs))
13625 (if one-hot ")") ":")
13626 (verilog-enum-ascii (verilog-sig-name (car tmp-sigs))
13627 elim-regexp))))
13628 (setq tmp-sigs (cdr tmp-sigs)))
13629 (verilog-insert-indent (format chrfmt "default:" errname)))
13631 (setq indent-pt (- indent-pt verilog-case-indent))
13632 (verilog-insert-indent "endcase\n")
13633 (setq indent-pt (- indent-pt verilog-indent-level))
13634 (verilog-insert-indent "end\n"
13635 "// End of automatics\n"))))
13637 (defun verilog-auto-templated-rel ()
13638 "Replace Templated relative line numbers with absolute line numbers.
13639 Internal use only. This hacks around the line numbers in AUTOINST Templates
13640 being different from the final output's line numbering."
13641 (let ((templateno 0) (template-line (list 0)) (buf-line 1))
13642 ;; Find line number each template is on
13643 ;; Count lines as we go, as otherwise it's O(n^2) to use count-lines
13644 (goto-char (point-min))
13645 (while (not (eobp))
13646 (when (looking-at ".*AUTO_TEMPLATE")
13647 (setq templateno (1+ templateno))
13648 (setq template-line (cons buf-line template-line)))
13649 (setq buf-line (1+ buf-line))
13650 (forward-line 1))
13651 (setq template-line (nreverse template-line))
13652 ;; Replace T# L# with absolute line number
13653 (goto-char (point-min))
13654 (while (re-search-forward " Templated T\\([0-9]+\\) L\\([0-9]+\\)" nil t)
13655 (replace-match
13656 (concat " Templated "
13657 (int-to-string (+ (nth (string-to-number (match-string 1))
13658 template-line)
13659 (string-to-number (match-string 2)))))
13660 t t))))
13662 (defun verilog-auto-template-lint ()
13663 "Check AUTO_TEMPLATEs for unused lines.
13664 Enable with `verilog-auto-template-warn-unused'."
13665 (let ((name1 (or (buffer-file-name) (buffer-name))))
13666 (save-excursion
13667 (goto-char (point-min))
13668 (while (re-search-forward
13669 "^\\s-*/?\\*?\\s-*[a-zA-Z0-9`_$]+\\s-+AUTO_TEMPLATE" nil t)
13670 (let* ((tpl-info (verilog-read-auto-template-middle))
13671 (tpl-list (aref tpl-info 1))
13672 (tlines (append (nth 0 tpl-list) (nth 1 tpl-list)))
13673 tpl-ass)
13674 (while tlines
13675 (setq tpl-ass (car tlines)
13676 tlines (cdr tlines))
13678 (unless (or (not (eval-when-compile (fboundp 'make-hash-table))) ; Not supported, no warning
13679 (not verilog-auto-template-hits)
13680 (gethash (vector (nth 2 tpl-ass) (nth 3 tpl-ass))
13681 verilog-auto-template-hits))
13682 (verilog-warn-error "%s:%d: AUTO_TEMPLATE line unused: \".%s (%s)\""
13683 name1
13684 (+ (elt tpl-ass 3) ; Template line number
13685 (count-lines (point-min) (point)))
13686 (elt tpl-ass 0) (elt tpl-ass 1))
13687 )))))))
13690 ;;; Auto top level:
13693 (defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing an arg
13694 "Expand AUTO statements.
13695 Look for any /*AUTO...*/ commands in the code, as used in
13696 instantiations or argument headers. Update the list of signals
13697 following the /*AUTO...*/ command.
13699 Use \\[verilog-delete-auto] to remove the AUTOs.
13701 Use \\[verilog-diff-auto] to see differences in AUTO expansion.
13703 Use \\[verilog-inject-auto] to insert AUTOs for the first time.
13705 Use \\[verilog-faq] for a pointer to frequently asked questions.
13707 For new users, we recommend setting `verilog-case-fold' to nil
13708 and `verilog-auto-arg-sort' to t.
13710 The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are
13711 called before and after this function, respectively.
13713 For example:
13714 module ModuleName (/*AUTOARG*/);
13715 /*AUTOINPUT*/
13716 /*AUTOOUTPUT*/
13717 /*AUTOWIRE*/
13718 /*AUTOREG*/
13719 InstMod instName #(/*AUTOINSTPARAM*/) (/*AUTOINST*/);
13721 You can also update the AUTOs from the shell using:
13722 emacs --batch <filenames.v> -f verilog-batch-auto
13723 Or fix indentation with:
13724 emacs --batch <filenames.v> -f verilog-batch-indent
13725 Likewise, you can delete or inject AUTOs with:
13726 emacs --batch <filenames.v> -f verilog-batch-delete-auto
13727 emacs --batch <filenames.v> -f verilog-batch-inject-auto
13728 Or check if AUTOs have the same expansion
13729 emacs --batch <filenames.v> -f verilog-batch-diff-auto
13731 Using \\[describe-function], see also:
13732 `verilog-auto-arg' for AUTOARG module instantiations
13733 `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding
13734 `verilog-auto-assign-modport' for AUTOASSIGNMODPORT assignment to/from modport
13735 `verilog-auto-inout' for AUTOINOUT making hierarchy inouts
13736 `verilog-auto-inout-comp' for AUTOINOUTCOMP copy complemented i/o
13737 `verilog-auto-inout-in' for AUTOINOUTIN inputs for all i/o
13738 `verilog-auto-inout-modport' for AUTOINOUTMODPORT i/o from an interface modport
13739 `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere
13740 `verilog-auto-inout-param' for AUTOINOUTPARAM copying params from elsewhere
13741 `verilog-auto-input' for AUTOINPUT making hierarchy inputs
13742 `verilog-auto-insert-lisp' for AUTOINSERTLISP insert code from lisp function
13743 `verilog-auto-insert-last' for AUTOINSERTLAST insert code from lisp function
13744 `verilog-auto-inst' for AUTOINST instantiation pins
13745 `verilog-auto-star' for AUTOINST .* SystemVerilog pins
13746 `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params
13747 `verilog-auto-logic' for AUTOLOGIC declaring logic signals
13748 `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs
13749 `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs
13750 `verilog-auto-reg' for AUTOREG registers
13751 `verilog-auto-reg-input' for AUTOREGINPUT instantiation registers
13752 `verilog-auto-reset' for AUTORESET flop resets
13753 `verilog-auto-sense' for AUTOSENSE or AS always sensitivity lists
13754 `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs
13755 `verilog-auto-undef' for AUTOUNDEF \\=`undef of local \\=`defines
13756 `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts
13757 `verilog-auto-wire' for AUTOWIRE instantiation wires
13759 `verilog-read-defines' for reading \\=`define values
13760 `verilog-read-includes' for reading \\=`includes
13762 If you have bugs with these autos, please file an issue at
13763 URL `http://www.veripool.org/verilog-mode' or contact the AUTOAUTHOR
13764 Wilson Snyder (wsnyder@wsnyder.org)."
13765 (interactive)
13766 (unless noninteractive (message "Updating AUTOs..."))
13767 (if (fboundp 'dinotrace-unannotate-all)
13768 (dinotrace-unannotate-all))
13769 ;; Disable change hooks for speed
13770 ;; This let can't be part of above let; must restore
13771 ;; after-change-functions before font-lock resumes
13772 (verilog-save-font-no-change-functions
13773 (let ((oldbuf (if (not (buffer-modified-p))
13774 (buffer-string)))
13775 (case-fold-search verilog-case-fold)
13776 ;; Cache directories; we don't write new files, so can't change
13777 (verilog-dir-cache-preserving t)
13778 ;; Cache current module
13779 (verilog-modi-cache-current-enable t)
13780 (verilog-modi-cache-current-max (point-min)) ; IE it's invalid
13781 verilog-modi-cache-current)
13782 (verilog-save-scan-cache
13783 (save-excursion
13784 ;; Wipe cache; otherwise if we AUTOed a block above this one,
13785 ;; we'll misremember we have generated IOs, confusing AUTOOUTPUT
13786 (setq verilog-modi-cache-list nil)
13787 ;; Local state
13788 (verilog-read-auto-template-init)
13789 ;; If we're not in verilog-mode, change syntax table so parsing works right
13790 (unless (eq major-mode `verilog-mode) (verilog-mode))
13791 ;; Allow user to customize
13792 (verilog-run-hooks 'verilog-before-auto-hook)
13793 ;; Try to save the user from needing to revert-file to reread file local-variables
13794 (verilog-auto-reeval-locals)
13795 (verilog-read-auto-lisp-present)
13796 (verilog-read-auto-lisp (point-min) (point-max))
13797 (verilog-getopt-flags)
13798 ;; From here on out, we can cache anything we read from disk
13799 (verilog-preserve-dir-cache
13800 ;; These two may seem obvious to do always, but on large includes it can be way too slow
13801 (when verilog-auto-read-includes
13802 (verilog-read-includes)
13803 (verilog-read-defines nil nil t))
13804 ;; Setup variables due to SystemVerilog expansion
13805 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic-setup)
13806 ;; This particular ordering is important
13807 ;; INST: Lower modules correct, no internal dependencies, FIRST
13808 (verilog-preserve-modi-cache
13809 ;; Clear existing autos else we'll be screwed by existing ones
13810 (verilog-delete-auto-buffer)
13811 ;; Injection if appropriate
13812 (when inject
13813 (verilog-inject-inst)
13814 (verilog-inject-sense)
13815 (verilog-inject-arg))
13817 ;; Do user inserts first, so their code can insert AUTOs
13818 (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/"
13819 'verilog-auto-insert-lisp)
13820 ;; Expand instances before need the signals the instances input/output
13821 (verilog-auto-re-search-do "/\\*AUTOINSTPARAM\\*/" 'verilog-auto-inst-param)
13822 (verilog-auto-re-search-do "/\\*AUTOINST\\*/" 'verilog-auto-inst)
13823 (verilog-auto-re-search-do "\\.\\*" 'verilog-auto-star)
13824 ;; Must be done before autoin/out as creates a reg
13825 (verilog-auto-re-search-do "/\\*AUTOASCIIENUM(.*?)\\*/" 'verilog-auto-ascii-enum)
13827 ;; first in/outs from other files
13828 (verilog-auto-re-search-do "/\\*AUTOINOUTMODPORT(.*?)\\*/" 'verilog-auto-inout-modport)
13829 (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE(.*?)\\*/" 'verilog-auto-inout-module)
13830 (verilog-auto-re-search-do "/\\*AUTOINOUTCOMP(.*?)\\*/" 'verilog-auto-inout-comp)
13831 (verilog-auto-re-search-do "/\\*AUTOINOUTIN(.*?)\\*/" 'verilog-auto-inout-in)
13832 (verilog-auto-re-search-do "/\\*AUTOINOUTPARAM(.*?)\\*/" 'verilog-auto-inout-param)
13833 ;; next in/outs which need previous sucked inputs first
13834 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\((.*?)\\)?\\*/" 'verilog-auto-output)
13835 (verilog-auto-re-search-do "/\\*AUTOINPUT\\((.*?)\\)?\\*/" 'verilog-auto-input)
13836 (verilog-auto-re-search-do "/\\*AUTOINOUT\\((.*?)\\)?\\*/" 'verilog-auto-inout)
13837 ;; Then tie off those in/outs
13838 (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff)
13839 ;; These can be anywhere after AUTOINSERTLISP
13840 (verilog-auto-re-search-do "/\\*AUTOUNDEF\\((.*?)\\)?\\*/" 'verilog-auto-undef)
13841 ;; Wires/regs must be after inputs/outputs
13842 (verilog-auto-re-search-do "/\\*AUTOASSIGNMODPORT(.*?)\\*/" 'verilog-auto-assign-modport)
13843 (verilog-auto-re-search-do "/\\*AUTOLOGIC\\*/" 'verilog-auto-logic)
13844 (verilog-auto-re-search-do "/\\*AUTOWIRE\\*/" 'verilog-auto-wire)
13845 (verilog-auto-re-search-do "/\\*AUTOREG\\*/" 'verilog-auto-reg)
13846 (verilog-auto-re-search-do "/\\*AUTOREGINPUT\\*/" 'verilog-auto-reg-input)
13847 ;; outputevery needs AUTOOUTPUTs done first
13848 (verilog-auto-re-search-do "/\\*AUTOOUTPUTEVERY\\((.*?)\\)?\\*/" 'verilog-auto-output-every)
13849 ;; Doesn't matter when done, but combine it with a common changer
13850 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense)
13851 ;; After AUTOREG*, as they may have set signal widths
13852 (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset)
13853 ;; After we've created all new variables
13854 (verilog-auto-re-search-do "/\\*AUTOUNUSED\\*/" 'verilog-auto-unused)
13855 ;; Must be after all inputs outputs are generated
13856 (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg)
13857 ;; User inserts
13858 (verilog-auto-re-search-do "/\\*AUTOINSERTLAST(.*?)\\*/" 'verilog-auto-insert-last)
13859 ;; Fix line numbers (comments only)
13860 (when verilog-auto-inst-template-numbers
13861 (verilog-auto-templated-rel))
13862 (when verilog-auto-template-warn-unused
13863 (verilog-auto-template-lint))))
13865 (verilog-run-hooks 'verilog-auto-hook)
13867 (when verilog-auto-delete-trailing-whitespace
13868 (verilog-delete-trailing-whitespace))
13870 (set (make-local-variable 'verilog-auto-update-tick) (buffer-chars-modified-tick))
13872 ;; If end result is same as when started, clear modified flag
13873 (cond ((and oldbuf (equal oldbuf (buffer-string)))
13874 (verilog-restore-buffer-modified-p nil)
13875 (unless noninteractive (message "Updating AUTOs...done (no changes)")))
13876 (t (unless noninteractive (message "Updating AUTOs...done"))))
13877 ;; End of save-cache
13878 )))))
13880 ;;; Skeletons:
13883 (defvar verilog-template-map
13884 (let ((map (make-sparse-keymap)))
13885 (define-key map "a" 'verilog-sk-always)
13886 (define-key map "b" 'verilog-sk-begin)
13887 (define-key map "c" 'verilog-sk-case)
13888 (define-key map "f" 'verilog-sk-for)
13889 (define-key map "g" 'verilog-sk-generate)
13890 (define-key map "h" 'verilog-sk-header)
13891 (define-key map "i" 'verilog-sk-initial)
13892 (define-key map "j" 'verilog-sk-fork)
13893 (define-key map "m" 'verilog-sk-module)
13894 (define-key map "o" 'verilog-sk-ovm-class)
13895 (define-key map "p" 'verilog-sk-primitive)
13896 (define-key map "r" 'verilog-sk-repeat)
13897 (define-key map "s" 'verilog-sk-specify)
13898 (define-key map "t" 'verilog-sk-task)
13899 (define-key map "u" 'verilog-sk-uvm-object)
13900 (define-key map "w" 'verilog-sk-while)
13901 (define-key map "x" 'verilog-sk-casex)
13902 (define-key map "z" 'verilog-sk-casez)
13903 (define-key map "?" 'verilog-sk-if)
13904 (define-key map ":" 'verilog-sk-else-if)
13905 (define-key map "/" 'verilog-sk-comment)
13906 (define-key map "A" 'verilog-sk-assign)
13907 (define-key map "F" 'verilog-sk-function)
13908 (define-key map "I" 'verilog-sk-input)
13909 (define-key map "O" 'verilog-sk-output)
13910 (define-key map "S" 'verilog-sk-state-machine)
13911 (define-key map "=" 'verilog-sk-inout)
13912 (define-key map "U" 'verilog-sk-uvm-component)
13913 (define-key map "W" 'verilog-sk-wire)
13914 (define-key map "R" 'verilog-sk-reg)
13915 (define-key map "D" 'verilog-sk-define-signal)
13916 map)
13917 "Keymap used in Verilog mode for smart template operations.")
13921 ;; Place the templates into Verilog Mode. They may be inserted under any key.
13922 ;; C-c C-t will be the default. If you use templates a lot, you
13923 ;; may want to consider moving the binding to another key in your init
13924 ;; file.
13926 ;; Note \C-c and letter are reserved for users
13927 (define-key verilog-mode-map "\C-c\C-t" verilog-template-map)
13929 ;; ---- statement skeletons ------------------------------------------
13931 (define-skeleton verilog-sk-prompt-condition
13932 "Prompt for the loop condition."
13933 "[condition]: " str )
13935 (define-skeleton verilog-sk-prompt-init
13936 "Prompt for the loop init statement."
13937 "[initial statement]: " str )
13939 (define-skeleton verilog-sk-prompt-inc
13940 "Prompt for the loop increment statement."
13941 "[increment statement]: " str )
13943 (define-skeleton verilog-sk-prompt-name
13944 "Prompt for the name of something."
13945 "[name]: " str)
13947 (define-skeleton verilog-sk-prompt-clock
13948 "Prompt for the name of something."
13949 "name and edge of clock(s): " str)
13951 (defvar verilog-sk-reset nil)
13952 (defun verilog-sk-prompt-reset ()
13953 "Prompt for the name of a state machine reset."
13954 (setq verilog-sk-reset (read-string "name of reset: " "rst")))
13957 (define-skeleton verilog-sk-prompt-state-selector
13958 "Prompt for the name of a state machine selector."
13959 "name of selector (eg {a,b,c,d}): " str )
13961 (define-skeleton verilog-sk-prompt-output
13962 "Prompt for the name of something."
13963 "output: " str)
13965 (define-skeleton verilog-sk-prompt-msb
13966 "Prompt for most significant bit specification."
13967 "msb:" str & ?: & '(verilog-sk-prompt-lsb) | -1 )
13969 (define-skeleton verilog-sk-prompt-lsb
13970 "Prompt for least significant bit specification."
13971 "lsb:" str )
13973 (defvar verilog-sk-p nil)
13974 (define-skeleton verilog-sk-prompt-width
13975 "Prompt for a width specification."
13977 (progn
13978 (setq verilog-sk-p (point))
13979 (verilog-sk-prompt-msb)
13980 (if (> (point) verilog-sk-p) "] " " ")))
13982 (defun verilog-sk-header ()
13983 "Insert a descriptive header at the top of the file.
13984 See also `verilog-header' for an alternative format."
13985 (interactive "*")
13986 (save-excursion
13987 (goto-char (point-min))
13988 (verilog-sk-header-tmpl)))
13990 (define-skeleton verilog-sk-header-tmpl
13991 "Insert a comment block containing the module title, author, etc."
13992 "[Description]: "
13993 "// -*- Mode: Verilog -*-"
13994 "\n// Filename : " (buffer-name)
13995 "\n// Description : " str
13996 "\n// Author : " (user-full-name)
13997 "\n// Created On : " (current-time-string)
13998 "\n// Last Modified By: " (user-full-name)
13999 "\n// Last Modified On: " (current-time-string)
14000 "\n// Update Count : 0"
14001 "\n// Status : Unknown, Use with caution!"
14002 "\n")
14004 (define-skeleton verilog-sk-module
14005 "Insert a module definition."
14007 > "module " '(verilog-sk-prompt-name) " (/*AUTOARG*/ ) ;" \n
14008 > _ \n
14009 > (- verilog-indent-level-behavioral) "endmodule" (progn (electric-verilog-terminate-line) nil))
14011 ;; ------------------------------------------------------------------------
14012 ;; Define a default OVM class, with macros and new()
14013 ;; ------------------------------------------------------------------------
14015 (define-skeleton verilog-sk-ovm-class
14016 "Insert a class definition"
14018 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
14019 > _ \n
14020 > "`ovm_object_utils_begin(" name ")" \n
14021 > (- verilog-indent-level) " `ovm_object_utils_end" \n
14022 > _ \n
14023 > "function new(string name=\"" name "\");" \n
14024 > "super.new(name);" \n
14025 > (- verilog-indent-level) "endfunction" \n
14026 > _ \n
14027 > "endclass" (progn (electric-verilog-terminate-line) nil))
14029 (define-skeleton verilog-sk-uvm-object
14030 "Insert a class definition"
14032 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
14033 > _ \n
14034 > "`uvm_object_utils_begin(" name ")" \n
14035 > (- verilog-indent-level) "`uvm_object_utils_end" \n
14036 > _ \n
14037 > "function new(string name=\"" name "\");" \n
14038 > "super.new(name);" \n
14039 > (- verilog-indent-level) "endfunction" \n
14040 > _ \n
14041 > "endclass" (progn (electric-verilog-terminate-line) nil))
14043 (define-skeleton verilog-sk-uvm-component
14044 "Insert a class definition"
14046 > "class " (setq name (skeleton-read "Name: ")) " extends " (skeleton-read "Extends: ") ";" \n
14047 > _ \n
14048 > "`uvm_component_utils_begin(" name ")" \n
14049 > (- verilog-indent-level) "`uvm_component_utils_end" \n
14050 > _ \n
14051 > "function new(string name=\"\", uvm_component parent);" \n
14052 > "super.new(name, parent);" \n
14053 > (- verilog-indent-level) "endfunction" \n
14054 > _ \n
14055 > "endclass" (progn (electric-verilog-terminate-line) nil))
14057 (define-skeleton verilog-sk-primitive
14058 "Insert a task definition."
14060 > "primitive " '(verilog-sk-prompt-name) " ( " '(verilog-sk-prompt-output) ("input:" ", " str ) " );"\n
14061 > _ \n
14062 > (- verilog-indent-level-behavioral) "endprimitive" (progn (electric-verilog-terminate-line) nil))
14064 (define-skeleton verilog-sk-task
14065 "Insert a task definition."
14067 > "task " '(verilog-sk-prompt-name) & ?\; \n
14068 > _ \n
14069 > "begin" \n
14070 > \n
14071 > (- verilog-indent-level-behavioral) "end" \n
14072 > (- verilog-indent-level-behavioral) "endtask" (progn (electric-verilog-terminate-line) nil))
14074 (define-skeleton verilog-sk-function
14075 "Insert a function definition."
14077 > "function [" '(verilog-sk-prompt-width) | -1 '(verilog-sk-prompt-name) ?\; \n
14078 > _ \n
14079 > "begin" \n
14080 > \n
14081 > (- verilog-indent-level-behavioral) "end" \n
14082 > (- verilog-indent-level-behavioral) "endfunction" (progn (electric-verilog-terminate-line) nil))
14084 (define-skeleton verilog-sk-always
14085 "Insert always block. Uses the minibuffer to prompt
14086 for sensitivity list."
14088 > "always @ ( /*AUTOSENSE*/ ) begin\n"
14089 > _ \n
14090 > (- verilog-indent-level-behavioral) "end" \n >
14093 (define-skeleton verilog-sk-initial
14094 "Insert an initial block."
14096 > "initial begin\n"
14097 > _ \n
14098 > (- verilog-indent-level-behavioral) "end" \n > )
14100 (define-skeleton verilog-sk-specify
14101 "Insert specify block. "
14103 > "specify\n"
14104 > _ \n
14105 > (- verilog-indent-level-behavioral) "endspecify" \n > )
14107 (define-skeleton verilog-sk-generate
14108 "Insert generate block. "
14110 > "generate\n"
14111 > _ \n
14112 > (- verilog-indent-level-behavioral) "endgenerate" \n > )
14114 (define-skeleton verilog-sk-begin
14115 "Insert begin end block. Uses the minibuffer to prompt for name."
14117 > "begin" '(verilog-sk-prompt-name) \n
14118 > _ \n
14119 > (- verilog-indent-level-behavioral) "end" )
14121 (define-skeleton verilog-sk-fork
14122 "Insert a fork join block."
14124 > "fork\n"
14125 > "begin" \n
14126 > _ \n
14127 > (- verilog-indent-level-behavioral) "end" \n
14128 > "begin" \n
14129 > \n
14130 > (- verilog-indent-level-behavioral) "end" \n
14131 > (- verilog-indent-level-behavioral) "join" \n
14135 (define-skeleton verilog-sk-case
14136 "Build skeleton case statement, prompting for the selector expression,
14137 and the case items."
14138 "[selector expression]: "
14139 > "case (" str ") " \n
14140 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
14141 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
14143 (define-skeleton verilog-sk-casex
14144 "Build skeleton casex statement, prompting for the selector expression,
14145 and the case items."
14146 "[selector expression]: "
14147 > "casex (" str ") " \n
14148 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
14149 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
14151 (define-skeleton verilog-sk-casez
14152 "Build skeleton casez statement, prompting for the selector expression,
14153 and the case items."
14154 "[selector expression]: "
14155 > "casez (" str ") " \n
14156 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
14157 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
14159 (define-skeleton verilog-sk-if
14160 "Insert a skeleton if statement."
14161 > "if (" '(verilog-sk-prompt-condition) & ")" " begin" \n
14162 > _ \n
14163 > (- verilog-indent-level-behavioral) "end " \n )
14165 (define-skeleton verilog-sk-else-if
14166 "Insert a skeleton else if statement."
14167 > (verilog-indent-line) "else if ("
14168 (progn (setq verilog-sk-p (point)) nil) '(verilog-sk-prompt-condition) (if (> (point) verilog-sk-p) ") " -1 ) & " begin" \n
14169 > _ \n
14170 > "end" (progn (electric-verilog-terminate-line) nil))
14172 (define-skeleton verilog-sk-datadef
14173 "Common routine to get data definition."
14175 '(verilog-sk-prompt-width) | -1 ("name (RET to end):" str ", ") -2 ";" \n)
14177 (define-skeleton verilog-sk-input
14178 "Insert an input definition."
14180 > "input [" '(verilog-sk-datadef))
14182 (define-skeleton verilog-sk-output
14183 "Insert an output definition."
14185 > "output [" '(verilog-sk-datadef))
14187 (define-skeleton verilog-sk-inout
14188 "Insert an inout definition."
14190 > "inout [" '(verilog-sk-datadef))
14192 (defvar verilog-sk-signal nil)
14193 (define-skeleton verilog-sk-def-reg
14194 "Insert a reg definition."
14196 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations-auto) )
14198 (defun verilog-sk-define-signal ()
14199 "Insert a definition of signal under point at top of module."
14200 (interactive "*")
14201 (let* ((sig-re "[a-zA-Z0-9_]*")
14202 (v1 (buffer-substring
14203 (save-excursion
14204 (skip-chars-backward sig-re)
14205 (point))
14206 (save-excursion
14207 (skip-chars-forward sig-re)
14208 (point)))))
14209 (if (not (member v1 verilog-keywords))
14210 (save-excursion
14211 (setq verilog-sk-signal v1)
14212 (verilog-beg-of-defun)
14213 (verilog-end-of-statement)
14214 (verilog-forward-syntactic-ws)
14215 (verilog-sk-def-reg)
14216 (message "signal at point is %s" v1))
14217 (message "object at point (%s) is a keyword" v1))))
14219 (define-skeleton verilog-sk-wire
14220 "Insert a wire definition."
14222 > "wire [" '(verilog-sk-datadef))
14224 (define-skeleton verilog-sk-reg
14225 "Insert a reg definition."
14227 > "reg [" '(verilog-sk-datadef))
14229 (define-skeleton verilog-sk-assign
14230 "Insert a skeleton assign statement."
14232 > "assign " '(verilog-sk-prompt-name) " = " _ ";" \n)
14234 (define-skeleton verilog-sk-while
14235 "Insert a skeleton while loop statement."
14237 > "while (" '(verilog-sk-prompt-condition) ") begin" \n
14238 > _ \n
14239 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
14241 (define-skeleton verilog-sk-repeat
14242 "Insert a skeleton repeat loop statement."
14244 > "repeat (" '(verilog-sk-prompt-condition) ") begin" \n
14245 > _ \n
14246 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
14248 (define-skeleton verilog-sk-for
14249 "Insert a skeleton while loop statement."
14251 > "for ("
14252 '(verilog-sk-prompt-init) "; "
14253 '(verilog-sk-prompt-condition) "; "
14254 '(verilog-sk-prompt-inc)
14255 ") begin" \n
14256 > _ \n
14257 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
14259 (define-skeleton verilog-sk-comment
14260 "Inserts three comment lines, making a display comment."
14262 > "/*\n"
14263 > "* " _ \n
14264 > "*/")
14266 (define-skeleton verilog-sk-state-machine
14267 "Insert a state machine definition."
14268 "Name of state variable: "
14269 '(setq input "state")
14270 > "// State registers for " str | -23 \n
14271 '(setq verilog-sk-state str)
14272 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-state ", next_" verilog-sk-state ?\; \n
14273 '(setq input nil)
14274 > \n
14275 > "// State FF for " verilog-sk-state \n
14276 > "always @ ( " (read-string "clock:" "posedge clk") " or " (verilog-sk-prompt-reset) " ) begin" \n
14277 > "if ( " verilog-sk-reset " ) " verilog-sk-state " = 0; else" \n
14278 > verilog-sk-state " = next_" verilog-sk-state ?\; \n
14279 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil)
14280 > \n
14281 > "// Next State Logic for " verilog-sk-state \n
14282 > "always @ ( /*AUTOSENSE*/ ) begin\n"
14283 > "case (" '(verilog-sk-prompt-state-selector) ") " \n
14284 > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n )
14285 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)
14286 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil))
14288 ;;; Mouse Events:
14290 ;; Include file loading with mouse/return event
14292 ;; idea & first impl.: M. Rouat (eldo-mode.el)
14293 ;; second (emacs/xemacs) impl.: G. Van der Plas (spice-mode.el)
14295 (if (featurep 'xemacs)
14296 (require 'overlay))
14298 (defconst verilog-include-file-regexp
14299 "^`include\\s-+\"\\([^\n\"]*\\)\""
14300 "Regexp that matches the include file.")
14302 (defvar verilog-mode-mouse-map
14303 (let ((map (make-sparse-keymap))) ; as described in info pages, make a map
14304 (set-keymap-parent map verilog-mode-map)
14305 ;; mouse button bindings
14306 (define-key map "\r" 'verilog-load-file-at-point)
14307 (if (featurep 'xemacs)
14308 (define-key map 'button2 'verilog-load-file-at-mouse);ffap-at-mouse ?
14309 (define-key map [mouse-2] 'verilog-load-file-at-mouse))
14310 (if (featurep 'xemacs)
14311 (define-key map 'Sh-button2 'mouse-yank) ; you wanna paste don't you ?
14312 (define-key map [S-mouse-2] 'mouse-yank-at-click))
14313 map)
14314 "Map containing mouse bindings for `verilog-mode'.")
14317 (defun verilog-highlight-region (beg end _old-len)
14318 "Colorize included files and modules in the (changed?) region.
14319 Clicking on the middle-mouse button loads them in a buffer (as in dired)."
14320 (when (or verilog-highlight-includes
14321 verilog-highlight-modules)
14322 (save-excursion
14323 (save-match-data ; A query-replace may call this function - do not disturb
14324 (verilog-save-buffer-state
14325 (verilog-save-scan-cache
14326 (let (end-point)
14327 (goto-char end)
14328 (setq end-point (point-at-eol))
14329 (goto-char beg)
14330 (beginning-of-line) ; scan entire line
14331 ;; delete overlays existing on this line
14332 (let ((overlays (overlays-in (point) end-point)))
14333 (while overlays
14334 (if (and
14335 (overlay-get (car overlays) 'detachable)
14336 (or (overlay-get (car overlays) 'verilog-include-file)
14337 (overlay-get (car overlays) 'verilog-inst-module)))
14338 (delete-overlay (car overlays)))
14339 (setq overlays (cdr overlays))))
14341 ;; make new include overlays
14342 (when verilog-highlight-includes
14343 (while (search-forward-regexp verilog-include-file-regexp end-point t)
14344 (goto-char (match-beginning 1))
14345 (let ((ov (make-overlay (match-beginning 1) (match-end 1))))
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-include-file 't)
14350 (overlay-put ov 'mouse-face 'highlight)
14351 (overlay-put ov 'local-map verilog-mode-mouse-map))))
14353 ;; make new module overlays
14354 (goto-char beg)
14355 ;; This scanner is syntax-fragile, so don't get bent
14356 (when verilog-highlight-modules
14357 (condition-case nil
14358 (while (verilog-re-search-forward-quick "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-point t)
14359 (save-excursion
14360 (goto-char (match-beginning 0))
14361 (unless (verilog-inside-comment-or-string-p)
14362 (verilog-read-inst-module-matcher) ; sets match 0
14363 (let* ((ov (make-overlay (match-beginning 0) (match-end 0))))
14364 (overlay-put ov 'start-closed 't)
14365 (overlay-put ov 'end-closed 't)
14366 (overlay-put ov 'evaporate 't)
14367 (overlay-put ov 'verilog-inst-module 't)
14368 (overlay-put ov 'mouse-face 'highlight)
14369 (overlay-put ov 'local-map verilog-mode-mouse-map)))))
14370 (error nil)))
14372 ;; Future highlights:
14373 ;; variables - make an Occur buffer of where referenced
14374 ;; pins - make an Occur buffer of the sig in the declaration module
14375 )))))))
14377 (defun verilog-highlight-buffer ()
14378 "Colorize included files and modules across the whole buffer."
14379 ;; Invoked via verilog-mode calling font-lock then `font-lock-mode-hook'
14380 (interactive)
14381 ;; delete and remake overlays
14382 (verilog-highlight-region (point-min) (point-max) nil))
14384 ;; Deprecated, but was interactive, so we'll keep it around
14385 (defalias 'verilog-colorize-include-files-buffer 'verilog-highlight-buffer)
14387 ;; ffap-at-mouse isn't useful for Verilog mode. It uses library paths.
14388 ;; so define this function to do more or less the same as ffap-at-mouse
14389 ;; but first resolve filename...
14390 (defun verilog-load-file-at-mouse (event)
14391 "Load file under button 2 click's EVENT.
14392 Files are checked based on `verilog-library-flags'."
14393 (interactive "@e")
14394 (save-excursion ; implement a Verilog specific ffap-at-mouse
14395 (mouse-set-point event)
14396 (verilog-load-file-at-point t)))
14398 ;; ffap isn't usable for Verilog mode. It uses library paths.
14399 ;; so define this function to do more or less the same as ffap
14400 ;; but first resolve filename...
14401 (defun verilog-load-file-at-point (&optional warn)
14402 "Load file under point.
14403 If WARN, throw warning if not found.
14404 Files are checked based on `verilog-library-flags'."
14405 (interactive)
14406 (save-excursion ; implement a Verilog specific ffap
14407 (let ((overlays (overlays-in (point) (point)))
14408 hit)
14409 (while (and overlays (not hit))
14410 (when (overlay-get (car overlays) 'verilog-inst-module)
14411 (verilog-goto-defun-file (buffer-substring
14412 (overlay-start (car overlays))
14413 (overlay-end (car overlays))))
14414 (setq hit t))
14415 (setq overlays (cdr overlays)))
14416 ;; Include?
14417 (beginning-of-line)
14418 (when (and (not hit)
14419 (looking-at verilog-include-file-regexp))
14420 (if (and (car (verilog-library-filenames
14421 (match-string 1) (buffer-file-name)))
14422 (file-readable-p (car (verilog-library-filenames
14423 (match-string 1) (buffer-file-name)))))
14424 (find-file (car (verilog-library-filenames
14425 (match-string 1) (buffer-file-name))))
14426 (when warn
14427 (message
14428 "File `%s' isn't readable, use shift-mouse2 to paste in this field"
14429 (match-string 1))))))))
14432 ;;; Bug reporting:
14435 (defun verilog-faq ()
14436 "Tell the user their current version, and where to get the FAQ etc."
14437 (interactive)
14438 (with-output-to-temp-buffer "*verilog-mode help*"
14439 (princ (format "You are using verilog-mode %s\n" verilog-mode-version))
14440 (princ "\n")
14441 (princ "For new releases, see http://www.veripool.com/verilog-mode\n")
14442 (princ "\n")
14443 (princ "For frequently asked questions, see http://www.veripool.org/verilog-mode-faq.html\n")
14444 (princ "\n")
14445 (princ "To submit a bug, use M-x verilog-submit-bug-report\n")
14446 (princ "\n")))
14448 (autoload 'reporter-submit-bug-report "reporter")
14449 (defvar reporter-prompt-for-summary-p)
14451 (defun verilog-submit-bug-report ()
14452 "Submit via mail a bug report on verilog-mode.el."
14453 (interactive)
14454 (let ((reporter-prompt-for-summary-p t))
14455 (reporter-submit-bug-report
14456 "mac@verilog.com, wsnyder@wsnyder.org"
14457 (concat "verilog-mode v" verilog-mode-version)
14459 verilog-active-low-regexp
14460 verilog-after-save-font-hook
14461 verilog-align-ifelse
14462 verilog-assignment-delay
14463 verilog-auto-arg-sort
14464 verilog-auto-declare-nettype
14465 verilog-auto-delete-trailing-whitespace
14466 verilog-auto-endcomments
14467 verilog-auto-hook
14468 verilog-auto-ignore-concat
14469 verilog-auto-indent-on-newline
14470 verilog-auto-inout-ignore-regexp
14471 verilog-auto-input-ignore-regexp
14472 verilog-auto-inst-column
14473 verilog-auto-inst-dot-name
14474 verilog-auto-inst-interfaced-ports
14475 verilog-auto-inst-param-value
14476 verilog-auto-inst-sort
14477 verilog-auto-inst-template-numbers
14478 verilog-auto-inst-vector
14479 verilog-auto-lineup
14480 verilog-auto-newline
14481 verilog-auto-output-ignore-regexp
14482 verilog-auto-read-includes
14483 verilog-auto-reset-blocking-in-non
14484 verilog-auto-reset-widths
14485 verilog-auto-save-policy
14486 verilog-auto-sense-defines-constant
14487 verilog-auto-sense-include-inputs
14488 verilog-auto-star-expand
14489 verilog-auto-star-save
14490 verilog-auto-template-warn-unused
14491 verilog-auto-tieoff-declaration
14492 verilog-auto-tieoff-ignore-regexp
14493 verilog-auto-unused-ignore-regexp
14494 verilog-auto-wire-type
14495 verilog-before-auto-hook
14496 verilog-before-delete-auto-hook
14497 verilog-before-getopt-flags-hook
14498 verilog-before-save-font-hook
14499 verilog-cache-enabled
14500 verilog-case-fold
14501 verilog-case-indent
14502 verilog-cexp-indent
14503 verilog-compiler
14504 verilog-coverage
14505 verilog-delete-auto-hook
14506 verilog-getopt-flags-hook
14507 verilog-highlight-grouping-keywords
14508 verilog-highlight-includes
14509 verilog-highlight-modules
14510 verilog-highlight-p1800-keywords
14511 verilog-highlight-translate-off
14512 verilog-indent-begin-after-if
14513 verilog-indent-declaration-macros
14514 verilog-indent-level
14515 verilog-indent-level-behavioral
14516 verilog-indent-level-declaration
14517 verilog-indent-level-directive
14518 verilog-indent-level-module
14519 verilog-indent-lists
14520 verilog-library-directories
14521 verilog-library-extensions
14522 verilog-library-files
14523 verilog-library-flags
14524 verilog-linter
14525 verilog-minimum-comment-distance
14526 verilog-mode-hook
14527 verilog-mode-release-emacs
14528 verilog-mode-version
14529 verilog-preprocessor
14530 verilog-simulator
14531 verilog-tab-always-indent
14532 verilog-tab-to-comment
14533 verilog-typedef-regexp
14534 verilog-warn-fatal
14536 nil nil
14537 (concat "Hi Mac,
14539 I want to report a bug.
14541 Before I go further, I want to say that Verilog mode has changed my life.
14542 I save so much time, my files are colored nicely, my co workers respect
14543 my coding ability... until now. I'd really appreciate anything you
14544 could do to help me out with this minor deficiency in the product.
14546 I've taken a look at the Verilog-Mode FAQ at
14547 http://www.veripool.org/verilog-mode-faq.html.
14549 And, I've considered filing the bug on the issue tracker at
14550 http://www.veripool.org/verilog-mode-bugs
14551 since I realize that public bugs are easier for you to track,
14552 and for others to search, but would prefer to email.
14554 So, to reproduce the bug, start a fresh Emacs via " invocation-name "
14555 -no-init-file -no-site-file'. In a new buffer, in Verilog mode, type
14556 the code included below.
14558 Given those lines, I expected [[Fill in here]] to happen;
14559 but instead, [[Fill in here]] happens!.
14561 == The code: =="))))
14563 (provide 'verilog-mode)
14565 ;; Local Variables:
14566 ;; checkdoc-permit-comma-termination-flag:t
14567 ;; checkdoc-force-docstrings-flag:nil
14568 ;; indent-tabs-mode:nil
14569 ;; End:
14571 ;;; verilog-mode.el ends here