Replace last-command-char with last-command-event.
[bpt/emacs.git] / lisp / progmodes / verilog-mode.el
1 ;; verilog-mode.el --- major mode for editing verilog source in Emacs
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
5
6 ;; Author: Michael McNamara (mac@verilog.com)
7 ;; http://www.verilog.com
8 ;;
9 ;; AUTO features, signal, modsig; by: Wilson Snyder
10 ;; (wsnyder@wsnyder.org)
11 ;; http://www.veripool.org
12 ;; Keywords: languages
13
14 ;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
15 ;; file on 19/3/2008, and the maintainer agreed that when a bug is
16 ;; filed in the Emacs bug reporting system against this file, a copy
17 ;; of the bug report be sent to the maintainer's email address.
18
19 ;; This code supports Emacs 21.1 and later
20 ;; And XEmacs 21.1 and later
21 ;; Please do not make changes that break Emacs 21. Thanks!
22 ;;
23 ;;
24
25 ;; This file is part of GNU Emacs.
26
27 ;; GNU Emacs is free software: you can redistribute it and/or modify
28 ;; it under the terms of the GNU General Public License as published by
29 ;; the Free Software Foundation, either version 3 of the License, or
30 ;; (at your option) any later version.
31
32 ;; GNU Emacs is distributed in the hope that it will be useful,
33 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
34 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 ;; GNU General Public License for more details.
36
37 ;; You should have received a copy of the GNU General Public License
38 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
39
40 ;;; Commentary:
41
42 ;; This mode borrows heavily from the Pascal-mode and the cc-mode of Emacs
43
44 ;; USAGE
45 ;; =====
46
47 ;; A major mode for editing Verilog HDL source code. When you have
48 ;; entered Verilog mode, you may get more info by pressing C-h m. You
49 ;; may also get online help describing various functions by: C-h f
50 ;; <Name of function you want described>
51
52 ;; KNOWN BUGS / BUG REPORTS
53 ;; =======================
54
55 ;; Verilog is a rapidly evolving language, and hence this mode is
56 ;; under continuous development. Hence this is beta code, and likely
57 ;; has bugs. Please report any and all bugs to me at mac@verilog.com.
58 ;; Please use verilog-submit-bug-report to submit a report; type C-c
59 ;; C-b to invoke this and as a result I will have a much easier time
60 ;; of reproducing the bug you find, and hence fixing it.
61
62 ;; INSTALLING THE MODE
63 ;; ===================
64
65 ;; An older version of this mode may be already installed as a part of
66 ;; your environment, and one method of updating would be to update
67 ;; your Emacs environment. Sometimes this is difficult for local
68 ;; political/control reasons, and hence you can always install a
69 ;; private copy (or even a shared copy) which overrides the system
70 ;; default.
71
72 ;; You can get step by step help in installing this file by going to
73 ;; <http://www.verilog.com/emacs_install.html>
74
75 ;; The short list of installation instructions are: To set up
76 ;; automatic Verilog mode, put this file in your load path, and put
77 ;; the following in code (please un comment it first!) in your
78 ;; .emacs, or in your site's site-load.el
79
80 ; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
81 ; (add-to-list 'auto-mode-alist '("\\.[ds]?v\\'" . verilog-mode))
82
83 ;; If you want to customize Verilog mode to fit your needs better,
84 ;; you may add these lines (the values of the variables presented
85 ;; here are the defaults). Note also that if you use an Emacs that
86 ;; supports custom, it's probably better to use the custom menu to
87 ;; edit these.
88 ;;
89 ;; Be sure to examine at the help for verilog-auto, and the other
90 ;; verilog-auto-* functions for some major coding time savers.
91 ;;
92 ; ;; User customization for Verilog mode
93 ; (setq verilog-indent-level 3
94 ; verilog-indent-level-module 3
95 ; verilog-indent-level-declaration 3
96 ; verilog-indent-level-behavioral 3
97 ; verilog-indent-level-directive 1
98 ; verilog-case-indent 2
99 ; verilog-auto-newline t
100 ; verilog-auto-indent-on-newline t
101 ; verilog-tab-always-indent t
102 ; verilog-auto-endcomments t
103 ; verilog-minimum-comment-distance 40
104 ; verilog-indent-begin-after-if t
105 ; verilog-auto-lineup '(all)
106 ; verilog-highlight-p1800-keywords nil
107 ; verilog-linter "my_lint_shell_command"
108 ; )
109
110 ;; \f
111
112 ;;; History:
113 ;;
114 ;; See commit history at http://www.veripool.org/verilog-mode.html
115 ;; (This section is required to appease checkdoc.)
116
117 ;;; Code:
118
119 ;; This variable will always hold the version number of the mode
120 (defconst verilog-mode-version "436"
121 "Version of this Verilog mode.")
122 (defconst verilog-mode-release-date "2008-09-02-GNU"
123 "Release date of this Verilog mode.")
124 (defconst verilog-mode-release-emacs t
125 "If non-nil, this version of Verilog mode was released with Emacs itself.")
126
127 (defun verilog-version ()
128 "Inform caller of the version of this file."
129 (interactive)
130 (message "Using verilog-mode version %s" verilog-mode-version))
131
132 ;; Insure we have certain packages, and deal with it if we don't
133 ;; Be sure to note which Emacs flavor and version added each feature.
134 (eval-when-compile
135 ;; Provide stuff if we are XEmacs
136 (when (featurep 'xemacs)
137 (condition-case nil
138 (require 'easymenu)
139 (error nil))
140 (condition-case nil
141 (require 'regexp-opt)
142 (error nil))
143 ;; Bug in 19.28 through 19.30 skeleton.el, not provided.
144 (condition-case nil
145 (load "skeleton")
146 (error nil))
147 (condition-case nil
148 (if (fboundp 'when)
149 nil ;; fab
150 (defmacro when (cond &rest body)
151 (list 'if cond (cons 'progn body))))
152 (error nil))
153 (condition-case nil
154 (if (fboundp 'unless)
155 nil ;; fab
156 (defmacro unless (cond &rest body)
157 (cons 'if (cons cond (cons nil body)))))
158 (error nil))
159 (condition-case nil
160 (if (fboundp 'store-match-data)
161 nil ;; fab
162 (defmacro store-match-data (&rest args) nil))
163 (error nil))
164 (condition-case nil
165 (if (fboundp 'char-before)
166 nil ;; great
167 (defmacro char-before (&rest body)
168 (char-after (1- (point)))))
169 (error nil))
170 (condition-case nil
171 (require 'custom)
172 (error nil))
173 (condition-case nil
174 (if (fboundp 'match-string-no-properties)
175 nil ;; great
176 (defsubst match-string-no-properties (num &optional string)
177 "Return string of text matched by last search, without text properties.
178 NUM specifies which parenthesized expression in the last regexp.
179 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
180 Zero means the entire text matched by the whole regexp or whole string.
181 STRING should be given if the last search was by `string-match' on STRING."
182 (if (match-beginning num)
183 (if string
184 (let ((result
185 (substring string
186 (match-beginning num) (match-end num))))
187 (set-text-properties 0 (length result) nil result)
188 result)
189 (buffer-substring-no-properties (match-beginning num)
190 (match-end num)
191 (current-buffer)))))
192 )
193 (error nil))
194 (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
195 nil ;; We've got what we needed
196 ;; We have the old custom-library, hack around it!
197 (defmacro defgroup (&rest args) nil)
198 (defmacro customize (&rest args)
199 (message
200 "Sorry, Customize is not available with this version of Emacs"))
201 (defmacro defcustom (var value doc &rest args)
202 `(defvar ,var ,value ,doc))
203 )
204 (if (fboundp 'defface)
205 nil ; great!
206 (defmacro defface (var values doc &rest args)
207 `(make-face ,var))
208 )
209
210 (if (and (featurep 'custom) (fboundp 'customize-group))
211 nil ;; We've got what we needed
212 ;; We have an intermediate custom-library, hack around it!
213 (defmacro customize-group (var &rest args)
214 `(customize ,var))
215 ))
216 ;; OK, do this stuff if we are NOT XEmacs:
217 (unless (featurep 'xemacs)
218 (unless (fboundp 'region-active-p)
219 (defmacro region-active-p ()
220 `(and transient-mark-mode mark-active))))
221 )
222
223 ;; Provide a regular expression optimization routine, using regexp-opt
224 ;; if provided by the user's elisp libraries
225 (eval-and-compile
226 ;; The below were disabled when GNU Emacs 22 was released;
227 ;; perhaps some still need to be there to support Emacs 21.
228 (if (featurep 'xemacs)
229 (if (fboundp 'regexp-opt)
230 ;; regexp-opt is defined, does it take 3 or 2 arguments?
231 (if (fboundp 'function-max-args)
232 (let ((args (function-max-args `regexp-opt)))
233 (cond
234 ((eq args 3) ;; It takes 3
235 (condition-case nil ; Hide this defun from emacses
236 ;with just a two input regexp
237 (defun verilog-regexp-opt (a b)
238 "Deal with differing number of required arguments for `regexp-opt'.
239 Call 'regexp-opt' on A and B."
240 (regexp-opt a b 't))
241 (error nil))
242 )
243 ((eq args 2) ;; It takes 2
244 (defun verilog-regexp-opt (a b)
245 "Call 'regexp-opt' on A and B."
246 (regexp-opt a b))
247 )
248 (t nil)))
249 ;; We can't tell; assume it takes 2
250 (defun verilog-regexp-opt (a b)
251 "Call 'regexp-opt' on A and B."
252 (regexp-opt a b))
253 )
254 ;; There is no regexp-opt, provide our own
255 (defun verilog-regexp-opt (strings &optional paren shy)
256 (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
257 (concat open (mapconcat 'regexp-quote strings "\\|") close)))
258 )
259 ;; Emacs.
260 (defalias 'verilog-regexp-opt 'regexp-opt)))
261
262 (eval-when-compile
263 (defun verilog-regexp-words (a)
264 "Call 'regexp-opt' with word delimiters for the words A."
265 (concat "\\<" (verilog-regexp-opt a t) "\\>")))
266
267 (defun verilog-easy-menu-filter (menu)
268 "Filter a easy-menu-define to support new features."
269 (cond ((not (featurep 'xemacs))
270 menu) ;; GNU Emacs - passthru
271 ;; Xemacs doesn't support :help. Strip it.
272 ;; Recursively filter the a submenu
273 ((listp menu)
274 (mapcar 'verilog-easy-menu-filter menu))
275 ;; Look for [:help "blah"] and remove
276 ((vectorp menu)
277 (let ((i 0) (out []))
278 (while (< i (length menu))
279 (if (equal `:help (aref menu i))
280 (setq i (+ 2 i))
281 (setq out (vconcat out (vector (aref menu i)))
282 i (1+ i))))
283 out))
284 (t menu))) ;; Default - ok
285 ;;(verilog-easy-menu-filter
286 ;; `("Verilog" ("MA" ["SAA" nil :help "Help SAA"] ["SAB" nil :help "Help SAA"])
287 ;; "----" ["MB" nil :help "Help MB"]))
288
289 (defun verilog-customize ()
290 "Customize variables and other settings used by Verilog-Mode."
291 (interactive)
292 (customize-group 'verilog-mode))
293
294 (defun verilog-font-customize ()
295 "Customize fonts used by Verilog-Mode."
296 (interactive)
297 (if (fboundp 'customize-apropos)
298 (customize-apropos "font-lock-*" 'faces)))
299
300 (defun verilog-booleanp (value)
301 "Return t if VALUE is boolean.
302 This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs.
303 This function may be removed when Emacs 21 is no longer supported."
304 (or (equal value t) (equal value nil)))
305
306 (defalias 'verilog-syntax-ppss
307 (if (fboundp 'syntax-ppss) 'syntax-ppss
308 (lambda (&optional pos) (parse-partial-sexp (point-min) (or pos (point))))))
309
310 (defgroup verilog-mode nil
311 "Facilitates easy editing of Verilog source text."
312 :version "22.2"
313 :group 'languages)
314
315 ; (defgroup verilog-mode-fonts nil
316 ; "Facilitates easy customization fonts used in Verilog source text"
317 ; :link '(customize-apropos "font-lock-*" 'faces)
318 ; :group 'verilog-mode)
319
320 (defgroup verilog-mode-indent nil
321 "Customize indentation and highlighting of Verilog source text."
322 :group 'verilog-mode)
323
324 (defgroup verilog-mode-actions nil
325 "Customize actions on Verilog source text."
326 :group 'verilog-mode)
327
328 (defgroup verilog-mode-auto nil
329 "Customize AUTO actions when expanding Verilog source text."
330 :group 'verilog-mode)
331
332 (defcustom verilog-linter
333 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
334 "*Unix program and arguments to call to run a lint checker on Verilog source.
335 Depending on the `verilog-set-compile-command', this may be invoked when
336 you type \\[compile]. When the compile completes, \\[next-error] will take
337 you to the next lint error."
338 :type 'string
339 :group 'verilog-mode-actions)
340 ;; We don't mark it safe, as it's used as a shell command
341
342 (defcustom verilog-coverage
343 "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'"
344 "*Program and arguments to use to annotate for coverage Verilog source.
345 Depending on the `verilog-set-compile-command', this may be invoked when
346 you type \\[compile]. When the compile completes, \\[next-error] will take
347 you to the next lint error."
348 :type 'string
349 :group 'verilog-mode-actions)
350 ;; We don't mark it safe, as it's used as a shell command
351
352 (defcustom verilog-simulator
353 "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'"
354 "*Program and arguments to use to interpret Verilog source.
355 Depending on the `verilog-set-compile-command', this may be invoked when
356 you type \\[compile]. When the compile completes, \\[next-error] will take
357 you to the next lint error."
358 :type 'string
359 :group 'verilog-mode-actions)
360 ;; We don't mark it safe, as it's used as a shell command
361
362 (defcustom verilog-compiler
363 "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'"
364 "*Program and arguments to use to compile Verilog source.
365 Depending on the `verilog-set-compile-command', this may be invoked when
366 you type \\[compile]. When the compile completes, \\[next-error] will take
367 you to the next lint error."
368 :type 'string
369 :group 'verilog-mode-actions)
370 ;; We don't mark it safe, as it's used as a shell command
371
372 (defvar verilog-tool 'verilog-linter
373 "Which tool to use for building compiler-command.
374 Either nil, `verilog-linter, `verilog-coverage, `verilog-simulator, or
375 `verilog-compiler. Alternatively use the \"Choose Compilation Action\"
376 menu. See `verilog-set-compile-command' for more information.")
377
378 (defcustom verilog-highlight-translate-off nil
379 "*Non-nil means background-highlight code excluded from translation.
380 That is, all code between \"// synopsys translate_off\" and
381 \"// synopsys translate_on\" is highlighted using a different background color
382 \(face `verilog-font-lock-translate-off-face').
383
384 Note: This will slow down on-the-fly fontification (and thus editing).
385
386 Note: Activate the new setting in a Verilog buffer by re-fontifying it (menu
387 entry \"Fontify Buffer\"). XEmacs: turn off and on font locking."
388 :type 'boolean
389 :group 'verilog-mode-indent)
390 ;; Note we don't use :safe, as that would break on Emacsen before 22.0.
391 (put 'verilog-highlight-translate-off 'safe-local-variable 'verilog-booleanp)
392
393 (defcustom verilog-indent-level 3
394 "*Indentation of Verilog statements with respect to containing block."
395 :group 'verilog-mode-indent
396 :type 'integer)
397 (put 'verilog-indent-level 'safe-local-variable 'integerp)
398
399 (defcustom verilog-indent-level-module 3
400 "*Indentation of Module level Verilog statements (eg always, initial).
401 Set to 0 to get initial and always statements lined up on the left side of
402 your screen."
403 :group 'verilog-mode-indent
404 :type 'integer)
405 (put 'verilog-indent-level-module 'safe-local-variable 'integerp)
406
407 (defcustom verilog-indent-level-declaration 3
408 "*Indentation of declarations with respect to containing block.
409 Set to 0 to get them list right under containing block."
410 :group 'verilog-mode-indent
411 :type 'integer)
412 (put 'verilog-indent-level-declaration 'safe-local-variable 'integerp)
413
414 (defcustom verilog-indent-declaration-macros nil
415 "*How to treat macro expansions in a declaration.
416 If nil, indent as:
417 input [31:0] a;
418 input `CP;
419 output c;
420 If non nil, treat as:
421 input [31:0] a;
422 input `CP ;
423 output c;"
424 :group 'verilog-mode-indent
425 :type 'boolean)
426 (put 'verilog-indent-declaration-macros 'safe-local-variable 'verilog-booleanp)
427
428 (defcustom verilog-indent-lists t
429 "*How to treat indenting items in a list.
430 If t (the default), indent as:
431 always @( posedge a or
432 reset ) begin
433
434 If nil, treat as:
435 always @( posedge a or
436 reset ) begin"
437 :group 'verilog-mode-indent
438 :type 'boolean)
439 (put 'verilog-indent-lists 'safe-local-variable 'verilog-booleanp)
440
441 (defcustom verilog-indent-level-behavioral 3
442 "*Absolute indentation of first begin in a task or function block.
443 Set to 0 to get such code to start at the left side of the screen."
444 :group 'verilog-mode-indent
445 :type 'integer)
446 (put 'verilog-indent-level-behavioral 'safe-local-variable 'integerp)
447
448 (defcustom verilog-indent-level-directive 1
449 "*Indentation to add to each level of `ifdef declarations.
450 Set to 0 to have all directives start at the left side of the screen."
451 :group 'verilog-mode-indent
452 :type 'integer)
453 (put 'verilog-indent-level-directive 'safe-local-variable 'integerp)
454
455 (defcustom verilog-cexp-indent 2
456 "*Indentation of Verilog statements split across lines."
457 :group 'verilog-mode-indent
458 :type 'integer)
459 (put 'verilog-cexp-indent 'safe-local-variable 'integerp)
460
461 (defcustom verilog-case-indent 2
462 "*Indentation for case statements."
463 :group 'verilog-mode-indent
464 :type 'integer)
465 (put 'verilog-case-indent 'safe-local-variable 'integerp)
466
467 (defcustom verilog-auto-newline t
468 "*True means automatically newline after semicolons."
469 :group 'verilog-mode-indent
470 :type 'boolean)
471 (put 'verilog-auto-newline 'safe-local-variable 'verilog-booleanp)
472
473 (defcustom verilog-auto-indent-on-newline t
474 "*True means automatically indent line after newline."
475 :group 'verilog-mode-indent
476 :type 'boolean)
477 (put 'verilog-auto-indent-on-newline 'safe-local-variable 'verilog-booleanp)
478
479 (defcustom verilog-tab-always-indent t
480 "*True means TAB should always re-indent the current line.
481 A nil value means TAB will only reindent when at the beginning of the line."
482 :group 'verilog-mode-indent
483 :type 'boolean)
484 (put 'verilog-tab-always-indent 'safe-local-variable 'verilog-booleanp)
485
486 (defcustom verilog-tab-to-comment nil
487 "*True means TAB moves to the right hand column in preparation for a comment."
488 :group 'verilog-mode-actions
489 :type 'boolean)
490 (put 'verilog-tab-to-comment 'safe-local-variable 'verilog-booleanp)
491
492 (defcustom verilog-indent-begin-after-if t
493 "*If true, indent begin statements following if, else, while, for and repeat.
494 Otherwise, line them up."
495 :group 'verilog-mode-indent
496 :type 'boolean)
497 (put 'verilog-indent-begin-after-if 'safe-local-variable 'verilog-booleanp)
498
499
500 (defcustom verilog-align-ifelse nil
501 "*If true, align `else' under matching `if'.
502 Otherwise else is lined up with first character on line holding matching if."
503 :group 'verilog-mode-indent
504 :type 'boolean)
505 (put 'verilog-align-ifelse 'safe-local-variable 'verilog-booleanp)
506
507 (defcustom verilog-minimum-comment-distance 10
508 "*Minimum distance (in lines) between begin and end required before a comment.
509 Setting this variable to zero results in every end acquiring a comment; the
510 default avoids too many redundant comments in tight quarters."
511 :group 'verilog-mode-indent
512 :type 'integer)
513 (put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp)
514
515 (defcustom verilog-auto-lineup '(declaration)
516 "*Algorithm for lining up statements on multiple lines.
517
518 If this list contains the symbol 'all', then all line ups described below
519 are done.
520
521 If this list contains the symbol 'declaration', then declarations are lined up
522 with any preceding declarations, taking into account widths and the like, so
523 for example the code:
524 reg [31:0] a;
525 reg b;
526 would become
527 reg [31:0] a;
528 reg b;
529
530 If this list contains the symbol 'assignment', then assignments are lined up
531 with any preceding assignments, so for example the code
532 a_long_variable = b + c;
533 d = e + f;
534 would become
535 a_long_variable = b + c;
536 d = e + f;"
537
538 ;; The following is not implemented:
539 ;If this list contains the symbol 'case', then case items are lined up
540 ;with any preceding case items, so for example the code
541 ; case (a) begin
542 ; a_long_state : a = 3;
543 ; b: a = 4;
544 ; endcase
545 ;would become
546 ; case (a) begin
547 ; a_long_state : a = 3;
548 ; b : a = 4;
549 ; endcase
550 ;
551
552 :group 'verilog-mode-indent
553 :type 'list)
554 (put 'verilog-auto-lineup 'safe-local-variable 'listp)
555
556 (defcustom verilog-highlight-p1800-keywords nil
557 "*True means highlight words newly reserved by IEEE-1800.
558 These will appear in `verilog-font-lock-p1800-face' in order to gently
559 suggest changing where these words are used as variables to something else.
560 A nil value means highlight these words as appropriate for the SystemVerilog
561 IEEE-1800 standard. Note that changing this will require restarting Emacs
562 to see the effect as font color choices are cached by Emacs."
563 :group 'verilog-mode-indent
564 :type 'boolean)
565 (put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp)
566
567 (defcustom verilog-highlight-grouping-keywords nil
568 "*True means highlight grouping keywords 'begin' and 'end' more dramatically.
569 If false, these words are in the font-lock-type-face; if True then they are in
570 `verilog-font-lock-ams-face'. Some find that special highlighting on these
571 grouping constructs allow the structure of the code to be understood at a glance."
572 :group 'verilog-mode-indent
573 :type 'boolean)
574 (put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp)
575
576 (defcustom verilog-auto-endcomments t
577 "*True means insert a comment /* ... */ after 'end's.
578 The name of the function or case will be set between the braces."
579 :group 'verilog-mode-actions
580 :type 'boolean)
581 (put 'verilog-auto-endcomments 'safe-local-variable 'verilog-booleanp)
582
583 (defcustom verilog-auto-read-includes nil
584 "*True means to automatically read includes before AUTOs.
585 This will do a `verilog-read-defines' and `verilog-read-includes' before
586 each AUTO expansion. This makes it easier to embed defines and includes,
587 but can result in very slow reading times if there are many or large
588 include files."
589 :group 'verilog-mode-actions
590 :type 'boolean)
591 (put 'verilog-auto-read-includes 'safe-local-variable 'verilog-booleanp)
592
593 (defcustom verilog-auto-save-policy nil
594 "*Non-nil indicates action to take when saving a Verilog buffer with AUTOs.
595 A value of `force' will always do a \\[verilog-auto] automatically if
596 needed on every save. A value of `detect' will do \\[verilog-auto]
597 automatically when it thinks necessary. A value of `ask' will query the
598 user when it thinks updating is needed.
599
600 You should not rely on the 'ask or 'detect policies, they are safeguards
601 only. They do not detect when AUTOINSTs need to be updated because a
602 sub-module's port list has changed."
603 :group 'verilog-mode-actions
604 :type '(choice (const nil) (const ask) (const detect) (const force)))
605
606 (defcustom verilog-auto-star-expand t
607 "*Non-nil indicates to expand a SystemVerilog .* instance ports.
608 They will be expanded in the same way as if there was a AUTOINST in the
609 instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'."
610 :group 'verilog-mode-actions
611 :type 'boolean)
612 (put 'verilog-auto-star-expand 'safe-local-variable 'verilog-booleanp)
613
614 (defcustom verilog-auto-star-save nil
615 "*Non-nil indicates to save to disk SystemVerilog .* instance expansions.
616 A nil value indicates direct connections will be removed before saving.
617 Only meaningful to those created due to `verilog-auto-star-expand' being set.
618
619 Instead of setting this, you may want to use /*AUTOINST*/, which will
620 always be saved."
621 :group 'verilog-mode-actions
622 :type 'boolean)
623 (put 'verilog-auto-star-save 'safe-local-variable 'verilog-booleanp)
624
625 (defvar verilog-auto-update-tick nil
626 "Modification tick at which autos were last performed.")
627
628 (defvar verilog-auto-last-file-locals nil
629 "Text from file-local-variables during last evaluation.")
630
631 (defvar verilog-error-regexp-add-didit nil)
632 (defvar verilog-error-regexp nil)
633 (setq verilog-error-regexp-add-didit nil
634 verilog-error-regexp
635 '(
636 ; SureLint
637 ;; ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2)
638 ; Most SureFire tools
639 ("\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\), \\(line \\|\\)\\([0-9]+\\):" 2 4 )
640 ("\
641 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
642 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
643 ; xsim
644 ; Error! in file /homes/mac/Axis/Xsim/test.v at line 13 [OBJ_NOT_DECLARED]
645 ("\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3)
646 ; vcs
647 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3)
648 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2)
649 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3)
650 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
651 ; Verilator
652 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
653 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
654 ; vxl
655 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
656 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 1 2) ; vxl
657 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 1 2)
658 ; nc-verilog
659 (".*\\*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 1 2)
660 ; Leda
661 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 1 2)
662 )
663 ; "*List of regexps for Verilog compilers, like verilint. See compilation-error-regexp-alist for the formatting."
664 )
665
666 (defvar verilog-error-font-lock-keywords
667 '(
668 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t)
669 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t)
670
671 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t)
672 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t)
673
674 ("\
675 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
676 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
677 ("\
678 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
679 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
680
681 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t)
682 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t)
683
684 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t)
685 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t)
686
687 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
688 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
689
690 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
691 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t)
692
693 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t)
694 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
695 ; vxl
696 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
697 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
698
699 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 1 bold t)
700 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 2 bold t)
701
702 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 1 bold t)
703 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 2 bold t)
704 ; nc-verilog
705 (".*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 1 bold t)
706 (".*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t)
707 ; Leda
708 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 1 bold t)
709 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 2 bold t)
710 )
711 "*Keywords to also highlight in Verilog *compilation* buffers.")
712
713 (defcustom verilog-library-flags '("")
714 "*List of standard Verilog arguments to use for /*AUTOINST*/.
715 These arguments are used to find files for `verilog-auto', and match
716 the flags accepted by a standard Verilog-XL simulator.
717
718 -f filename Reads more `verilog-library-flags' from the filename.
719 +incdir+dir Adds the directory to `verilog-library-directories'.
720 -Idir Adds the directory to `verilog-library-directories'.
721 -y dir Adds the directory to `verilog-library-directories'.
722 +libext+.v Adds the extensions to `verilog-library-extensions'.
723 -v filename Adds the filename to `verilog-library-files'.
724
725 filename Adds the filename to `verilog-library-files'.
726 This is not recommended, -v is a better choice.
727
728 You might want these defined in each file; put at the *END* of your file
729 something like:
730
731 // Local Variables:
732 // verilog-library-flags:(\"-y dir -y otherdir\")
733 // End:
734
735 Verilog-mode attempts to detect changes to this local variable, but they
736 are only insured to be correct when the file is first visited. Thus if you
737 have problems, use \\[find-alternate-file] RET to have these take effect.
738
739 See also the variables mentioned above."
740 :group 'verilog-mode-auto
741 :type '(repeat string))
742 (put 'verilog-library-flags 'safe-local-variable 'listp)
743
744 (defcustom verilog-library-directories '(".")
745 "*List of directories when looking for files for /*AUTOINST*/.
746 The directory may be relative to the current file, or absolute.
747 Environment variables are also expanded in the directory names.
748 Having at least the current directory is a good idea.
749
750 You might want these defined in each file; put at the *END* of your file
751 something like:
752
753 // Local Variables:
754 // verilog-library-directories:(\".\" \"subdir\" \"subdir2\")
755 // End:
756
757 Verilog-mode attempts to detect changes to this local variable, but they
758 are only insured to be correct when the file is first visited. Thus if you
759 have problems, use \\[find-alternate-file] RET to have these take effect.
760
761 See also `verilog-library-flags', `verilog-library-files'
762 and `verilog-library-extensions'."
763 :group 'verilog-mode-auto
764 :type '(repeat file))
765 (put 'verilog-library-directories 'safe-local-variable 'listp)
766
767 (defcustom verilog-library-files '()
768 "*List of files to search for modules.
769 AUTOINST will use this when it needs to resolve a module name.
770 This is a complete path, usually to a technology file with many standard
771 cells defined in it.
772
773 You might want these defined in each file; put at the *END* of your file
774 something like:
775
776 // Local Variables:
777 // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\")
778 // End:
779
780 Verilog-mode attempts to detect changes to this local variable, but they
781 are only insured to be correct when the file is first visited. Thus if you
782 have problems, use \\[find-alternate-file] RET to have these take effect.
783
784 See also `verilog-library-flags', `verilog-library-directories'."
785 :group 'verilog-mode-auto
786 :type '(repeat directory))
787 (put 'verilog-library-files 'safe-local-variable 'listp)
788
789 (defcustom verilog-library-extensions '(".v" ".sv")
790 "*List of extensions to use when looking for files for /*AUTOINST*/.
791 See also `verilog-library-flags', `verilog-library-directories'."
792 :type '(repeat string)
793 :group 'verilog-mode-auto)
794 (put 'verilog-library-extensions 'safe-local-variable 'listp)
795
796 (defcustom verilog-active-low-regexp nil
797 "*If set, treat signals matching this regexp as active low.
798 This is used for AUTORESET and AUTOTIEOFF. For proper behavior,
799 you will probably also need `verilog-auto-reset-widths' set."
800 :group 'verilog-mode-auto
801 :type 'string)
802 (put 'verilog-active-low-regexp 'safe-local-variable 'stringp)
803
804 (defcustom verilog-auto-sense-include-inputs nil
805 "*If true, AUTOSENSE should include all inputs.
806 If nil, only inputs that are NOT output signals in the same block are
807 included."
808 :group 'verilog-mode-auto
809 :type 'boolean)
810 (put 'verilog-auto-sense-include-inputs 'safe-local-variable 'verilog-booleanp)
811
812 (defcustom verilog-auto-sense-defines-constant nil
813 "*If true, AUTOSENSE should assume all defines represent constants.
814 When true, the defines will not be included in sensitivity lists. To
815 maintain compatibility with other sites, this should be set at the bottom
816 of each Verilog file that requires it, rather than being set globally."
817 :group 'verilog-mode-auto
818 :type 'boolean)
819 (put 'verilog-auto-sense-defines-constant 'safe-local-variable 'verilog-booleanp)
820
821 (defcustom verilog-auto-reset-widths t
822 "*If true, AUTORESET should determine the width of signals.
823 This is then used to set the width of the zero (32'h0 for example). This
824 is required by some lint tools that aren't smart enough to ignore widths of
825 the constant zero. This may result in ugly code when parameters determine
826 the MSB or LSB of a signal inside an AUTORESET."
827 :type 'boolean
828 :group 'verilog-mode-auto)
829 (put 'verilog-auto-reset-widths 'safe-local-variable 'verilog-booleanp)
830
831 (defcustom verilog-assignment-delay ""
832 "*Text used for delays in delayed assignments. Add a trailing space if set."
833 :group 'verilog-mode-auto
834 :type 'string)
835 (put 'verilog-assignment-delay 'safe-local-variable 'stringp)
836
837 (defcustom verilog-auto-inst-param-value nil
838 "*If set, AUTOINST will replace parameters with the parameter value.
839 If nil, leave parameters as symbolic names.
840
841 Parameters must be in Verilog 2001 format #(...), and if a parameter is not
842 listed as such there (as when the default value is acceptable), it will not
843 be replaced, and will remain symbolic.
844
845 For example, imagine a submodule uses parameters to declare the size of its
846 inputs. This is then used by a upper module:
847
848 module InstModule (o,i)
849 parameter WIDTH;
850 input [WIDTH-1:0] i;
851 endmodule
852
853 module ExampInst;
854 InstModule
855 #(PARAM(10))
856 instName
857 (/*AUTOINST*/
858 .i (i[PARAM-1:0]));
859
860 Note even though PARAM=10, the AUTOINST has left the parameter as a
861 symbolic name. If `verilog-auto-inst-param-value' is set, this will
862 instead expand to:
863
864 module ExampInst;
865 InstModule
866 #(PARAM(10))
867 instName
868 (/*AUTOINST*/
869 .i (i[9:0]));"
870 :group 'verilog-mode-auto
871 :type 'boolean)
872 (put 'verilog-auto-inst-param-value 'safe-local-variable 'verilog-booleanp)
873
874 (defcustom verilog-auto-inst-vector t
875 "*If true, when creating default ports with AUTOINST, use bus subscripts.
876 If nil, skip the subscript when it matches the entire bus as declared in
877 the module (AUTOWIRE signals always are subscripted, you must manually
878 declare the wire to have the subscripts removed.) Setting this to nil may
879 speed up some simulators, but is less general and harder to read, so avoid."
880 :group 'verilog-mode-auto
881 :type 'boolean)
882 (put 'verilog-auto-inst-vector 'safe-local-variable 'verilog-booleanp)
883
884 (defcustom verilog-auto-inst-template-numbers nil
885 "*If true, when creating templated ports with AUTOINST, add a comment.
886 The comment will add the line number of the template that was used for that
887 port declaration. Setting this aids in debugging, but nil is suggested for
888 regular use to prevent large numbers of merge conflicts."
889 :group 'verilog-mode-auto
890 :type 'boolean)
891 (put 'verilog-auto-inst-template-numbers 'safe-local-variable 'verilog-booleanp)
892
893 (defcustom verilog-auto-inst-column 40
894 "*Indent-to column number for net name part of AUTOINST created pin."
895 :group 'verilog-mode-indent
896 :type 'integer)
897 (put 'verilog-auto-inst-column 'safe-local-variable 'integerp)
898
899 (defcustom verilog-auto-input-ignore-regexp nil
900 "*If set, when creating AUTOINPUT list, ignore signals matching this regexp.
901 See the \\[verilog-faq] for examples on using this."
902 :group 'verilog-mode-auto
903 :type 'string)
904 (put 'verilog-auto-input-ignore-regexp 'safe-local-variable 'stringp)
905
906 (defcustom verilog-auto-inout-ignore-regexp nil
907 "*If set, when creating AUTOINOUT list, ignore signals matching this regexp.
908 See the \\[verilog-faq] for examples on using this."
909 :group 'verilog-mode-auto
910 :type 'string)
911 (put 'verilog-auto-inout-ignore-regexp 'safe-local-variable 'stringp)
912
913 (defcustom verilog-auto-output-ignore-regexp nil
914 "*If set, when creating AUTOOUTPUT list, ignore signals matching this regexp.
915 See the \\[verilog-faq] for examples on using this."
916 :group 'verilog-mode-auto
917 :type 'string)
918 (put 'verilog-auto-output-ignore-regexp 'safe-local-variable 'stringp)
919
920 (defcustom verilog-auto-unused-ignore-regexp nil
921 "*If set, when creating AUTOUNUSED list, ignore signals matching this regexp.
922 See the \\[verilog-faq] for examples on using this."
923 :group 'verilog-mode-auto
924 :type 'string)
925 (put 'verilog-auto-unused-ignore-regexp 'safe-local-variable 'stringp)
926
927 (defcustom verilog-typedef-regexp nil
928 "*If non-nil, regular expression that matches Verilog-2001 typedef names.
929 For example, \"_t$\" matches typedefs named with _t, as in the C language."
930 :group 'verilog-mode-auto
931 :type 'string)
932 (put 'verilog-typedef-regexp 'safe-local-variable 'stringp)
933
934 (defcustom verilog-mode-hook 'verilog-set-compile-command
935 "*Hook run after Verilog mode is loaded."
936 :type 'hook
937 :group 'verilog-mode)
938
939 (defcustom verilog-auto-hook nil
940 "*Hook run after `verilog-mode' updates AUTOs."
941 :group 'verilog-mode-auto
942 :type 'hook)
943
944 (defcustom verilog-before-auto-hook nil
945 "*Hook run before `verilog-mode' updates AUTOs."
946 :group 'verilog-mode-auto
947 :type 'hook)
948
949 (defcustom verilog-delete-auto-hook nil
950 "*Hook run after `verilog-mode' deletes AUTOs."
951 :group 'verilog-mode-auto
952 :type 'hook)
953
954 (defcustom verilog-before-delete-auto-hook nil
955 "*Hook run before `verilog-mode' deletes AUTOs."
956 :group 'verilog-mode-auto
957 :type 'hook)
958
959 (defcustom verilog-getopt-flags-hook nil
960 "*Hook run after `verilog-getopt-flags' determines the Verilog option lists."
961 :group 'verilog-mode-auto
962 :type 'hook)
963
964 (defcustom verilog-before-getopt-flags-hook nil
965 "*Hook run before `verilog-getopt-flags' determines the Verilog option lists."
966 :group 'verilog-mode-auto
967 :type 'hook)
968
969 (defvar verilog-imenu-generic-expression
970 '((nil "^\\s-*\\(\\(m\\(odule\\|acromodule\\)\\)\\|primitive\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 4)
971 ("*Vars*" "^\\s-*\\(reg\\|wire\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3))
972 "Imenu expression for Verilog mode. See `imenu-generic-expression'.")
973
974 ;;
975 ;; provide a verilog-header function.
976 ;; Customization variables:
977 ;;
978 (defvar verilog-date-scientific-format nil
979 "*If non-nil, dates are written in scientific format (e.g. 1997/09/17).
980 If nil, in European format (e.g. 17.09.1997). The brain-dead American
981 format (e.g. 09/17/1997) is not supported.")
982
983 (defvar verilog-company nil
984 "*Default name of Company for Verilog header.
985 If set will become buffer local.")
986 (make-variable-buffer-local 'verilog-company)
987
988 (defvar verilog-project nil
989 "*Default name of Project for Verilog header.
990 If set will become buffer local.")
991 (make-variable-buffer-local 'verilog-project)
992
993 (defvar verilog-mode-map
994 (let ((map (make-sparse-keymap)))
995 (define-key map ";" 'electric-verilog-semi)
996 (define-key map [(control 59)] 'electric-verilog-semi-with-comment)
997 (define-key map ":" 'electric-verilog-colon)
998 ;;(define-key map "=" 'electric-verilog-equal)
999 (define-key map "\`" 'electric-verilog-tick)
1000 (define-key map "\t" 'electric-verilog-tab)
1001 (define-key map "\r" 'electric-verilog-terminate-line)
1002 ;; backspace/delete key bindings
1003 (define-key map [backspace] 'backward-delete-char-untabify)
1004 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
1005 (define-key map [delete] 'delete-char)
1006 (define-key map [(meta delete)] 'kill-word))
1007 (define-key map "\M-\C-b" 'electric-verilog-backward-sexp)
1008 (define-key map "\M-\C-f" 'electric-verilog-forward-sexp)
1009 (define-key map "\M-\r" `electric-verilog-terminate-and-indent)
1010 (define-key map "\M-\t" 'verilog-complete-word)
1011 (define-key map "\M-?" 'verilog-show-completions)
1012 (define-key map "\C-c\`" 'verilog-lint-off)
1013 (define-key map "\C-c\*" 'verilog-delete-auto-star-implicit)
1014 (define-key map "\C-c\C-r" 'verilog-label-be)
1015 (define-key map "\C-c\C-i" 'verilog-pretty-declarations)
1016 (define-key map "\C-c=" 'verilog-pretty-expr)
1017 (define-key map "\C-c\C-b" 'verilog-submit-bug-report)
1018 (define-key map "\M-*" 'verilog-star-comment)
1019 (define-key map "\C-c\C-c" 'verilog-comment-region)
1020 (define-key map "\C-c\C-u" 'verilog-uncomment-region)
1021 (when (featurep 'xemacs)
1022 (define-key map [(meta control h)] 'verilog-mark-defun)
1023 (define-key map "\M-\C-a" 'verilog-beg-of-defun)
1024 (define-key map "\M-\C-e" 'verilog-end-of-defun))
1025 (define-key map "\C-c\C-d" 'verilog-goto-defun)
1026 (define-key map "\C-c\C-k" 'verilog-delete-auto)
1027 (define-key map "\C-c\C-a" 'verilog-auto)
1028 (define-key map "\C-c\C-s" 'verilog-auto-save-compile)
1029 (define-key map "\C-c\C-z" 'verilog-inject-auto)
1030 (define-key map "\C-c\C-e" 'verilog-expand-vector)
1031 (define-key map "\C-c\C-h" 'verilog-header)
1032 map)
1033 "Keymap used in Verilog mode.")
1034
1035 ;; menus
1036 (easy-menu-define
1037 verilog-menu verilog-mode-map "Menu for Verilog mode"
1038 (verilog-easy-menu-filter
1039 '("Verilog"
1040 ("Choose Compilation Action"
1041 ["None"
1042 (progn
1043 (setq verilog-tool nil)
1044 (verilog-set-compile-command))
1045 :style radio
1046 :selected (equal verilog-tool nil)
1047 :help "When invoking compilation, use compile-command"]
1048 ["Lint"
1049 (progn
1050 (setq verilog-tool 'verilog-linter)
1051 (verilog-set-compile-command))
1052 :style radio
1053 :selected (equal verilog-tool `verilog-linter)
1054 :help "When invoking compilation, use lint checker"]
1055 ["Coverage"
1056 (progn
1057 (setq verilog-tool 'verilog-coverage)
1058 (verilog-set-compile-command))
1059 :style radio
1060 :selected (equal verilog-tool `verilog-coverage)
1061 :help "When invoking compilation, annotate for coverage"]
1062 ["Simulator"
1063 (progn
1064 (setq verilog-tool 'verilog-simulator)
1065 (verilog-set-compile-command))
1066 :style radio
1067 :selected (equal verilog-tool `verilog-simulator)
1068 :help "When invoking compilation, interpret Verilog source"]
1069 ["Compiler"
1070 (progn
1071 (setq verilog-tool 'verilog-compiler)
1072 (verilog-set-compile-command))
1073 :style radio
1074 :selected (equal verilog-tool `verilog-compiler)
1075 :help "When invoking compilation, compile Verilog source"]
1076 )
1077 ("Move"
1078 ["Beginning of function" verilog-beg-of-defun
1079 :keys "C-M-a"
1080 :help "Move backward to the beginning of the current function or procedure"]
1081 ["End of function" verilog-end-of-defun
1082 :keys "C-M-e"
1083 :help "Move forward to the end of the current function or procedure"]
1084 ["Mark function" verilog-mark-defun
1085 :keys "C-M-h"
1086 :help "Mark the current Verilog function or procedure"]
1087 ["Goto function/module" verilog-goto-defun
1088 :help "Move to specified Verilog module/task/function"]
1089 ["Move to beginning of block" electric-verilog-backward-sexp
1090 :help "Move backward over one balanced expression"]
1091 ["Move to end of block" electric-verilog-forward-sexp
1092 :help "Move forward over one balanced expression"]
1093 )
1094 ("Comments"
1095 ["Comment Region" verilog-comment-region
1096 :help "Put marked area into a comment"]
1097 ["UnComment Region" verilog-uncomment-region
1098 :help "Uncomment an area commented with Comment Region"]
1099 ["Multi-line comment insert" verilog-star-comment
1100 :help "Insert Verilog /* */ comment at point"]
1101 ["Lint error to comment" verilog-lint-off
1102 :help "Convert a Verilog linter warning line into a disable statement"]
1103 )
1104 "----"
1105 ["Compile" compile
1106 :help "Perform compilation-action (above) on the current buffer"]
1107 ["AUTO, Save, Compile" verilog-auto-save-compile
1108 :help "Recompute AUTOs, save buffer, and compile"]
1109 ["Next Compile Error" next-error
1110 :help "Visit next compilation error message and corresponding source code"]
1111 ["Ignore Lint Warning at point" verilog-lint-off
1112 :help "Convert a Verilog linter warning line into a disable statement"]
1113 "----"
1114 ["Line up declarations around point" verilog-pretty-declarations
1115 :help "Line up declarations around point"]
1116 ["Line up equations around point" verilog-pretty-expr
1117 :help "Line up expressions around point"]
1118 ["Redo/insert comments on every end" verilog-label-be
1119 :help "Label matching begin ... end statements"]
1120 ["Expand [x:y] vector line" verilog-expand-vector
1121 :help "Take a signal vector on the current line and expand it to multiple lines"]
1122 ["Insert begin-end block" verilog-insert-block
1123 :help "Insert begin ... end"]
1124 ["Complete word" verilog-complete-word
1125 :help "Complete word at point"]
1126 "----"
1127 ["Recompute AUTOs" verilog-auto
1128 :help "Expand AUTO meta-comment statements"]
1129 ["Kill AUTOs" verilog-delete-auto
1130 :help "Remove AUTO expansions"]
1131 ["Inject AUTOs" verilog-inject-auto
1132 :help "Inject AUTOs into legacy non-AUTO buffer"]
1133 ("AUTO Help..."
1134 ["AUTO General" (describe-function 'verilog-auto)
1135 :help "Help introduction on AUTOs"]
1136 ["AUTO Library Flags" (describe-variable 'verilog-library-flags)
1137 :help "Help on verilog-library-flags"]
1138 ["AUTO Library Path" (describe-variable 'verilog-library-directories)
1139 :help "Help on verilog-library-directories"]
1140 ["AUTO Library Files" (describe-variable 'verilog-library-files)
1141 :help "Help on verilog-library-files"]
1142 ["AUTO Library Extensions" (describe-variable 'verilog-library-extensions)
1143 :help "Help on verilog-library-extensions"]
1144 ["AUTO `define Reading" (describe-function 'verilog-read-defines)
1145 :help "Help on reading `defines"]
1146 ["AUTO `include Reading" (describe-function 'verilog-read-includes)
1147 :help "Help on parsing `includes"]
1148 ["AUTOARG" (describe-function 'verilog-auto-arg)
1149 :help "Help on AUTOARG - declaring module port list"]
1150 ["AUTOASCIIENUM" (describe-function 'verilog-auto-ascii-enum)
1151 :help "Help on AUTOASCIIENUM - creating ASCII for enumerations"]
1152 ["AUTOINOUTCOMP" (describe-function 'verilog-auto-inout-complement)
1153 :help "Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
1154 ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module)
1155 :help "Help on AUTOINOUTMODULE - copying i/o from another file"]
1156 ["AUTOINOUT" (describe-function 'verilog-auto-inout)
1157 :help "Help on AUTOINOUT - adding inouts from cells"]
1158 ["AUTOINPUT" (describe-function 'verilog-auto-input)
1159 :help "Help on AUTOINPUT - adding inputs from cells"]
1160 ["AUTOINST" (describe-function 'verilog-auto-inst)
1161 :help "Help on AUTOINST - adding pins for cells"]
1162 ["AUTOINST (.*)" (describe-function 'verilog-auto-star)
1163 :help "Help on expanding Verilog-2001 .* pins"]
1164 ["AUTOINSTPARAM" (describe-function 'verilog-auto-inst-param)
1165 :help "Help on AUTOINSTPARAM - adding parameter pins to cells"]
1166 ["AUTOOUTPUT" (describe-function 'verilog-auto-output)
1167 :help "Help on AUTOOUTPUT - adding outputs from cells"]
1168 ["AUTOOUTPUTEVERY" (describe-function 'verilog-auto-output-every)
1169 :help "Help on AUTOOUTPUTEVERY - adding outputs of all signals"]
1170 ["AUTOREG" (describe-function 'verilog-auto-reg)
1171 :help "Help on AUTOREG - declaring registers for non-wires"]
1172 ["AUTOREGINPUT" (describe-function 'verilog-auto-reg-input)
1173 :help "Help on AUTOREGINPUT - declaring inputs for non-wires"]
1174 ["AUTORESET" (describe-function 'verilog-auto-reset)
1175 :help "Help on AUTORESET - resetting always blocks"]
1176 ["AUTOSENSE" (describe-function 'verilog-auto-sense)
1177 :help "Help on AUTOSENSE - sensitivity lists for always blocks"]
1178 ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff)
1179 :help "Help on AUTOTIEOFF - tieing off unused outputs"]
1180 ["AUTOUNUSED" (describe-function 'verilog-auto-unused)
1181 :help "Help on AUTOUNUSED - terminating unused inputs"]
1182 ["AUTOWIRE" (describe-function 'verilog-auto-wire)
1183 :help "Help on AUTOWIRE - declaring wires for cells"]
1184 )
1185 "----"
1186 ["Submit bug report" verilog-submit-bug-report
1187 :help "Submit via mail a bug report on verilog-mode.el"]
1188 ["Version and FAQ" verilog-faq
1189 :help "Show the current version, and where to get the FAQ etc"]
1190 ["Customize Verilog Mode..." verilog-customize
1191 :help "Customize variables and other settings used by Verilog-Mode"]
1192 ["Customize Verilog Fonts & Colors" verilog-font-customize
1193 :help "Customize fonts used by Verilog-Mode."])))
1194
1195 (easy-menu-define
1196 verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog."
1197 (verilog-easy-menu-filter
1198 '("Statements"
1199 ["Header" verilog-sk-header
1200 :help "Insert a header block at the top of file"]
1201 ["Comment" verilog-sk-comment
1202 :help "Insert a comment block"]
1203 "----"
1204 ["Module" verilog-sk-module
1205 :help "Insert a module .. (/*AUTOARG*/);.. endmodule block"]
1206 ["Primitive" verilog-sk-primitive
1207 :help "Insert a primitive .. (.. );.. endprimitive block"]
1208 "----"
1209 ["Input" verilog-sk-input
1210 :help "Insert an input declaration"]
1211 ["Output" verilog-sk-output
1212 :help "Insert an output declaration"]
1213 ["Inout" verilog-sk-inout
1214 :help "Insert an inout declaration"]
1215 ["Wire" verilog-sk-wire
1216 :help "Insert a wire declaration"]
1217 ["Reg" verilog-sk-reg
1218 :help "Insert a register declaration"]
1219 ["Define thing under point as a register" verilog-sk-define-signal
1220 :help "Define signal under point as a register at the top of the module"]
1221 "----"
1222 ["Initial" verilog-sk-initial
1223 :help "Insert an initial begin .. end block"]
1224 ["Always" verilog-sk-always
1225 :help "Insert an always @(AS) begin .. end block"]
1226 ["Function" verilog-sk-function
1227 :help "Insert a function .. begin .. end endfunction block"]
1228 ["Task" verilog-sk-task
1229 :help "Insert a task .. begin .. end endtask block"]
1230 ["Specify" verilog-sk-specify
1231 :help "Insert a specify .. endspecify block"]
1232 ["Generate" verilog-sk-generate
1233 :help "Insert a generate .. endgenerate block"]
1234 "----"
1235 ["Begin" verilog-sk-begin
1236 :help "Insert a begin .. end block"]
1237 ["If" verilog-sk-if
1238 :help "Insert an if (..) begin .. end block"]
1239 ["(if) else" verilog-sk-else-if
1240 :help "Insert an else if (..) begin .. end block"]
1241 ["For" verilog-sk-for
1242 :help "Insert a for (...) begin .. end block"]
1243 ["While" verilog-sk-while
1244 :help "Insert a while (...) begin .. end block"]
1245 ["Fork" verilog-sk-fork
1246 :help "Insert a fork begin .. end .. join block"]
1247 ["Repeat" verilog-sk-repeat
1248 :help "Insert a repeat (..) begin .. end block"]
1249 ["Case" verilog-sk-case
1250 :help "Insert a case block, prompting for details"]
1251 ["Casex" verilog-sk-casex
1252 :help "Insert a casex (...) item: begin.. end endcase block"]
1253 ["Casez" verilog-sk-casez
1254 :help "Insert a casez (...) item: begin.. end endcase block"])))
1255
1256 (defvar verilog-mode-abbrev-table nil
1257 "Abbrev table in use in Verilog-mode buffers.")
1258
1259 (define-abbrev-table 'verilog-mode-abbrev-table ())
1260
1261 ;;
1262 ;; Macros
1263 ;;
1264
1265 (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string)
1266 "Replace occurrences of FROM-STRING with TO-STRING.
1267 FIXEDCASE and LITERAL as in `replace-match`. STRING is what to replace.
1268 The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\")
1269 will break, as the o's continuously replace. xa -> x works ok though."
1270 ;; Hopefully soon to a emacs built-in
1271 (let ((start 0))
1272 (while (string-match from-string string start)
1273 (setq string (replace-match to-string fixedcase literal string)
1274 start (min (length string) (+ (match-beginning 0) (length to-string)))))
1275 string))
1276
1277 (defsubst verilog-string-remove-spaces (string)
1278 "Remove spaces surrounding STRING."
1279 (save-match-data
1280 (setq string (verilog-string-replace-matches "^\\s-+" "" nil nil string))
1281 (setq string (verilog-string-replace-matches "\\s-+$" "" nil nil string))
1282 string))
1283
1284 (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR)
1285 ; checkdoc-params: (REGEXP BOUND NOERROR)
1286 "Like `re-search-forward', but skips over match in comments or strings."
1287 (let ((mdata '(nil nil))) ;; So match-end will return nil if no matches found
1288 (while (and
1289 (re-search-forward REGEXP BOUND NOERROR)
1290 (setq mdata (match-data))
1291 (and (verilog-skip-forward-comment-or-string)
1292 (progn
1293 (setq mdata '(nil nil))
1294 (if BOUND
1295 (< (point) BOUND)
1296 t)))))
1297 (store-match-data mdata)
1298 (match-end 0)))
1299
1300 (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR)
1301 ; checkdoc-params: (REGEXP BOUND NOERROR)
1302 "Like `re-search-backward', but skips over match in comments or strings."
1303 (let ((mdata '(nil nil))) ;; So match-end will return nil if no matches found
1304 (while (and
1305 (re-search-backward REGEXP BOUND NOERROR)
1306 (setq mdata (match-data))
1307 (and (verilog-skip-backward-comment-or-string)
1308 (progn
1309 (setq mdata '(nil nil))
1310 (if BOUND
1311 (> (point) BOUND)
1312 t)))))
1313 (store-match-data mdata)
1314 (match-end 0)))
1315
1316 (defsubst verilog-re-search-forward-quick (regexp bound noerror)
1317 "Like `verilog-re-search-forward', including use of REGEXP BOUND and NOERROR,
1318 but trashes match data and is faster for REGEXP that doesn't match often.
1319 This may at some point use text properties to ignore comments,
1320 so there may be a large up front penalty for the first search."
1321 (let (pt)
1322 (while (and (not pt)
1323 (re-search-forward regexp bound noerror))
1324 (if (not (verilog-inside-comment-p))
1325 (setq pt (match-end 0))))
1326 pt))
1327
1328 (defsubst verilog-re-search-backward-quick (regexp bound noerror)
1329 ; checkdoc-params: (REGEXP BOUND NOERROR)
1330 "Like `verilog-re-search-backward', including use of REGEXP BOUND and NOERROR,
1331 but trashes match data and is faster for REGEXP that doesn't match often.
1332 This may at some point use text properties to ignore comments,
1333 so there may be a large up front penalty for the first search."
1334 (let (pt)
1335 (while (and (not pt)
1336 (re-search-backward regexp bound noerror))
1337 (if (not (verilog-inside-comment-p))
1338 (setq pt (match-end 0))))
1339 pt))
1340
1341 (defsubst verilog-get-beg-of-line (&optional arg)
1342 (save-excursion
1343 (beginning-of-line arg)
1344 (point)))
1345
1346 (defsubst verilog-get-end-of-line (&optional arg)
1347 (save-excursion
1348 (end-of-line arg)
1349 (point)))
1350
1351 (defsubst verilog-within-string ()
1352 (save-excursion
1353 (nth 3 (parse-partial-sexp (verilog-get-beg-of-line) (point)))))
1354
1355 (defvar compile-command)
1356
1357 ;; compilation program
1358 (defun verilog-set-compile-command ()
1359 "Function to compute shell command to compile Verilog.
1360
1361 This reads `verilog-tool' and sets `compile-command'. This specifies the
1362 program that executes when you type \\[compile] or
1363 \\[verilog-auto-save-compile].
1364
1365 By default `verilog-tool' uses a Makefile if one exists in the current
1366 directory. If not, it is set to the `verilog-linter', `verilog-coverage',
1367 `verilog-simulator', or `verilog-compiler' variables, as selected with the
1368 Verilog -> \"Choose Compilation Action\" menu.
1369
1370 You should set `verilog-tool' or the other variables to the path and
1371 arguments for your Verilog simulator. For example:
1372 \"vcs -p123 -O\"
1373 or a string like:
1374 \"(cd /tmp; surecov %s)\".
1375
1376 In the former case, the path to the current buffer is concat'ed to the
1377 value of `verilog-tool'; in the later, the path to the current buffer is
1378 substituted for the %s.
1379
1380 Where __FILE__ appears in the string, the `buffer-file-name' of the
1381 current buffer, without the directory portion, will be substituted."
1382 (interactive)
1383 (cond
1384 ((or (file-exists-p "makefile") ;If there is a makefile, use it
1385 (file-exists-p "Makefile"))
1386 (make-local-variable 'compile-command)
1387 (setq compile-command "make "))
1388 (t
1389 (make-local-variable 'compile-command)
1390 (setq compile-command
1391 (if verilog-tool
1392 (if (string-match "%s" (eval verilog-tool))
1393 (format (eval verilog-tool) (or buffer-file-name ""))
1394 (concat (eval verilog-tool) " " (or buffer-file-name "")))
1395 ""))))
1396 (verilog-modify-compile-command))
1397
1398 (defun verilog-modify-compile-command ()
1399 "Replace meta-information in `compile-command'.
1400 Where __FILE__ appears in the string, the current buffer's file-name,
1401 without the directory portion, will be substituted."
1402 (when (and
1403 (stringp compile-command)
1404 (string-match "\\b__FILE__\\b" compile-command))
1405 (make-local-variable 'compile-command)
1406 (setq compile-command
1407 (verilog-string-replace-matches
1408 "\\b__FILE__\\b" (file-name-nondirectory (buffer-file-name))
1409 t t compile-command))))
1410
1411 ;; Following code only gets called from compilation-mode-hook.
1412 (defvar compilation-error-regexp-alist)
1413
1414 (defun verilog-error-regexp-add ()
1415 "Add the messages to the `compilation-error-regexp-alist'.
1416 Called by `compilation-mode-hook'. This allows \\[next-error] to
1417 find the errors."
1418 (if (not verilog-error-regexp-add-didit)
1419 (progn
1420 (setq verilog-error-regexp-add-didit t)
1421 (setq-default compilation-error-regexp-alist
1422 (append verilog-error-regexp
1423 (default-value 'compilation-error-regexp-alist)))
1424 ;; Could be buffer local at this point; maybe also in let; change all three
1425 (setq compilation-error-regexp-alist
1426 (default-value 'compilation-error-regexp-alist))
1427 (set (make-local-variable 'compilation-error-regexp-alist)
1428 (default-value 'compilation-error-regexp-alist)))))
1429
1430 (add-hook 'compilation-mode-hook 'verilog-error-regexp-add)
1431
1432 (defconst verilog-directive-re
1433 ;; "`case" "`default" "`define" "`define" "`else" "`endfor" "`endif"
1434 ;; "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
1435 ;; "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
1436 ;; "`time_scale" "`undef" "`while"
1437 "\\<`\\(case\\|def\\(ault\\|ine\\(\\)?\\)\\|e\\(lse\\|nd\\(for\\|if\\|protect\\|switch\\|while\\)\\)\\|for\\(mat\\)?\\|i\\(f\\(def\\|ndef\\)?\\|nclude\\)\\|let\\|protect\\|switch\\|time\\(_scale\\|scale\\)\\|undef\\|while\\)\\>")
1438
1439 (defconst verilog-directive-begin
1440 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>")
1441
1442 (defconst verilog-directive-middle
1443 "\\<`\\(else\\|default\\|case\\)\\>")
1444
1445 (defconst verilog-directive-end
1446 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>")
1447
1448 (defconst verilog-directive-re-1
1449 (concat "[ \t]*" verilog-directive-re))
1450
1451 ;;
1452 ;; Regular expressions used to calculate indent, etc.
1453 ;;
1454 (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
1455 (defconst verilog-case-re "\\(\\<case[xz]?\\>\\|\\<randcase\\>\\)")
1456 ;; Want to match
1457 ;; aa :
1458 ;; aa,bb :
1459 ;; a[34:32] :
1460 ;; a,
1461 ;; b :
1462
1463 (defconst verilog-no-indent-begin-re
1464 "\\<\\(if\\|else\\|while\\|for\\|repeat\\|always\\|always_comb\\|always_ff\\|always_latch\\)\\>")
1465
1466 (defconst verilog-ends-re
1467 ;; Parenthesis indicate type of keyword found
1468 (concat
1469 "\\(\\<else\\>\\)\\|" ; 1
1470 "\\(\\<if\\>\\)\\|" ; 2
1471 "\\(\\<end\\>\\)\\|" ; 3
1472 "\\(\\<endcase\\>\\)\\|" ; 4
1473 "\\(\\<endfunction\\>\\)\\|" ; 5
1474 "\\(\\<endtask\\>\\)\\|" ; 6
1475 "\\(\\<endspecify\\>\\)\\|" ; 7
1476 "\\(\\<endtable\\>\\)\\|" ; 8
1477 "\\(\\<endgenerate\\>\\)\\|" ; 9
1478 "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10
1479 "\\(\\<endclass\\>\\)\\|" ; 11
1480 "\\(\\<endgroup\\>\\)" ; 12
1481 ))
1482
1483 (defconst verilog-auto-end-comment-lines-re
1484 ;; Matches to names in this list cause auto-end-commentation
1485 (concat "\\("
1486 verilog-directive-re "\\)\\|\\("
1487 (eval-when-compile
1488 (verilog-regexp-words
1489 `( "begin"
1490 "else"
1491 "end"
1492 "endcase"
1493 "endclass"
1494 "endclocking"
1495 "endgroup"
1496 "endfunction"
1497 "endmodule"
1498 "endprogram"
1499 "endprimitive"
1500 "endinterface"
1501 "endpackage"
1502 "endsequence"
1503 "endspecify"
1504 "endtable"
1505 "endtask"
1506 "join"
1507 "join_any"
1508 "join_none"
1509 "module"
1510 "macromodule"
1511 "primitive"
1512 "interface"
1513 "package")))
1514 "\\)"))
1515
1516 ;;; NOTE: verilog-leap-to-head expects that verilog-end-block-re and
1517 ;;; verilog-end-block-ordered-re matches exactly the same strings.
1518 (defconst verilog-end-block-ordered-re
1519 ;; Parenthesis indicate type of keyword found
1520 (concat "\\(\\<endcase\\>\\)\\|" ; 1
1521 "\\(\\<end\\>\\)\\|" ; 2
1522 "\\(\\<end" ; 3, but not used
1523 "\\(" ; 4, but not used
1524 "\\(function\\)\\|" ; 5
1525 "\\(task\\)\\|" ; 6
1526 "\\(module\\)\\|" ; 7
1527 "\\(primitive\\)\\|" ; 8
1528 "\\(interface\\)\\|" ; 9
1529 "\\(package\\)\\|" ; 10
1530 "\\(class\\)\\|" ; 11
1531 "\\(group\\)\\|" ; 12
1532 "\\(program\\)\\|" ; 13
1533 "\\(sequence\\)\\|" ; 14
1534 "\\(clocking\\)\\|" ; 15
1535 "\\)\\>\\)"))
1536 (defconst verilog-end-block-re
1537 (eval-when-compile
1538 (verilog-regexp-words
1539
1540 `("end" ;; closes begin
1541 "endcase" ;; closes any of case, casex casez or randcase
1542 "join" "join_any" "join_none" ;; closes fork
1543 "endclass"
1544 "endtable"
1545 "endspecify"
1546 "endfunction"
1547 "endgenerate"
1548 "endtask"
1549 "endgroup"
1550 "endproperty"
1551 "endinterface"
1552 "endpackage"
1553 "endprogram"
1554 "endsequence"
1555 "endclocking"
1556 ))))
1557
1558
1559 (defconst verilog-endcomment-reason-re
1560 ;; Parenthesis indicate type of keyword found
1561 (concat
1562 "\\(\\<fork\\>\\)\\|"
1563 "\\(\\<begin\\>\\)\\|"
1564 "\\(\\<if\\>\\)\\|"
1565 "\\(\\<clocking\\>\\)\\|"
1566 "\\(\\<else\\>\\)\\|"
1567 "\\(\\<end\\>.*\\<else\\>\\)\\|"
1568 "\\(\\<task\\>\\)\\|"
1569 "\\(\\<function\\>\\)\\|"
1570 "\\(\\<initial\\>\\)\\|"
1571 "\\(\\<interface\\>\\)\\|"
1572 "\\(\\<package\\>\\)\\|"
1573 "\\(\\<final\\>\\)\\|"
1574 "\\(\\<always\\>\\(\[ \t\]*@\\)?\\)\\|"
1575 "\\(\\<always_comb\\>\\(\[ \t\]*@\\)?\\)\\|"
1576 "\\(\\<always_ff\\>\\(\[ \t\]*@\\)?\\)\\|"
1577 "\\(\\<always_latch\\>\\(\[ \t\]*@\\)?\\)\\|"
1578 "\\(@\\)\\|"
1579 "\\(\\<while\\>\\)\\|"
1580 "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|"
1581 "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|"
1582 "#"))
1583
1584 (defconst verilog-named-block-re "begin[ \t]*:")
1585
1586 ;; These words begin a block which can occur inside a module which should be indented,
1587 ;; and closed with the respective word from the end-block list
1588
1589 (defconst verilog-beg-block-re
1590 (eval-when-compile
1591 (verilog-regexp-words
1592 `("begin"
1593 "case" "casex" "casez" "randcase"
1594 "clocking"
1595 "generate"
1596 "fork"
1597 "function"
1598 "property"
1599 "specify"
1600 "table"
1601 "task"
1602 ))))
1603 ;; These are the same words, in a specific order in the regular
1604 ;; expression so that matching will work nicely for
1605 ;; verilog-forward-sexp and verilog-calc-indent
1606
1607 (defconst verilog-beg-block-re-ordered
1608 ( concat "\\(\\<begin\\>\\)" ;1
1609 "\\|\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?case[xz]?\\>\\)" ; 2,3
1610 "\\|\\(\\(\\<disable\\>\\s-+\\)?fork\\>\\)" ;4,5
1611 "\\|\\(\\<class\\>\\)" ;6
1612 "\\|\\(\\<table\\>\\)" ;7
1613 "\\|\\(\\<specify\\>\\)" ;8
1614 "\\|\\(\\<function\\>\\)" ;9
1615 "\\|\\(\\<task\\>\\)" ;10
1616 "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<task\\>\\)" ;11
1617 "\\|\\(\\<generate\\>\\)" ;15
1618 "\\|\\(\\<covergroup\\>\\)" ;16
1619 "\\|\\(\\(\\(\\<cover\\>\\s-+\\)\\|\\(\\<assert\\>\\s-+\\)\\)*\\<property\\>\\)" ;17
1620 "\\|\\(\\<\\(rand\\)?sequence\\>\\)" ;21
1621 "\\|\\(\\<clocking\\>\\)" ;22
1622 ))
1623
1624 (defconst verilog-end-block-ordered-rry
1625 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
1626 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)"
1627 "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
1628 "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)"
1629 "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)"
1630 "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)"
1631 "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)"
1632 "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)"
1633 "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)"
1634 "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)"
1635 "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)"
1636 "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)"
1637 "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)"
1638 ] )
1639
1640 (defconst verilog-nameable-item-re
1641 (eval-when-compile
1642 (verilog-regexp-words
1643 `("begin"
1644 "fork"
1645 "join" "join_any" "join_none"
1646 "end"
1647 "endcase"
1648 "endconfig"
1649 "endclass"
1650 "endclocking"
1651 "endfunction"
1652 "endgenerate"
1653 "endmodule"
1654 "endprimative"
1655 "endinterface"
1656 "endpackage"
1657 "endspecify"
1658 "endtable"
1659 "endtask" )
1660 )))
1661
1662 (defconst verilog-declaration-opener
1663 (eval-when-compile
1664 (verilog-regexp-words
1665 `("module" "begin" "task" "function"))))
1666
1667 (defconst verilog-declaration-prefix-re
1668 (eval-when-compile
1669 (verilog-regexp-words
1670 `(
1671 ;; port direction
1672 "inout" "input" "output" "ref"
1673 ;; changeableness
1674 "const" "static" "protected" "local"
1675 ;; parameters
1676 "localparam" "parameter" "var"
1677 ;; type creation
1678 "typedef"
1679 ))))
1680 (defconst verilog-declaration-core-re
1681 (eval-when-compile
1682 (verilog-regexp-words
1683 `(
1684 ;; port direction (by themselves)
1685 "inout" "input" "output"
1686 ;; integer_atom_type
1687 "byte" "shortint" "int" "longint" "integer" "time"
1688 ;; integer_vector_type
1689 "bit" "logic" "reg"
1690 ;; non_integer_type
1691 "shortreal" "real" "realtime"
1692 ;; net_type
1693 "supply0" "supply1" "tri" "triand" "trior" "trireg" "tri0" "tri1" "uwire" "wire" "wand" "wor"
1694 ;; misc
1695 "string" "event" "chandle" "virtual" "enum" "genvar"
1696 "struct" "union"
1697 ;; builtin classes
1698 "mailbox" "semaphore"
1699 ))))
1700 (defconst verilog-declaration-re
1701 (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re))
1702 (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+")
1703 (defconst verilog-optional-signed-re "\\s-*\\(signed\\)?")
1704 (defconst verilog-optional-signed-range-re
1705 (concat
1706 "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?"))
1707 (defconst verilog-macroexp-re "`\\sw+")
1708
1709 (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)")
1710 (defconst verilog-declaration-re-2-no-macro
1711 (concat "\\s-*" verilog-declaration-re
1712 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
1713 "\\)?"))
1714 (defconst verilog-declaration-re-2-macro
1715 (concat "\\s-*" verilog-declaration-re
1716 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)"
1717 "\\|\\(" verilog-macroexp-re "\\)"
1718 "\\)?"))
1719 (defconst verilog-declaration-re-1-macro
1720 (concat "^" verilog-declaration-re-2-macro))
1721
1722 (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro))
1723
1724 (defconst verilog-defun-re
1725 (eval-when-compile (verilog-regexp-words `("macromodule" "module" "class" "program" "interface" "package" "primitive" "config"))))
1726 (defconst verilog-end-defun-re
1727 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig"))))
1728 (defconst verilog-zero-indent-re
1729 (concat verilog-defun-re "\\|" verilog-end-defun-re))
1730
1731 (defconst verilog-behavioral-block-beg-re
1732 (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff"
1733 "function" "task"))))
1734
1735 (defconst verilog-indent-re
1736 (eval-when-compile
1737 (verilog-regexp-words
1738 `(
1739 "{"
1740 "always" "always_latch" "always_ff" "always_comb"
1741 "begin" "end"
1742 ; "unique" "priority"
1743 "case" "casex" "casez" "randcase" "endcase"
1744 "class" "endclass"
1745 "clocking" "endclocking"
1746 "config" "endconfig"
1747 "covergroup" "endgroup"
1748 "fork" "join" "join_any" "join_none"
1749 "function" "endfunction"
1750 "final"
1751 "generate" "endgenerate"
1752 "initial"
1753 "interface" "endinterface"
1754 "module" "macromodule" "endmodule"
1755 "package" "endpackage"
1756 "primitive" "endprimative"
1757 "program" "endprogram"
1758 "property" "endproperty"
1759 "sequence" "randsequence" "endsequence"
1760 "specify" "endspecify"
1761 "table" "endtable"
1762 "task" "endtask"
1763 "virtual"
1764 "`case"
1765 "`default"
1766 "`define" "`undef"
1767 "`if" "`ifdef" "`ifndef" "`else" "`endif"
1768 "`while" "`endwhile"
1769 "`for" "`endfor"
1770 "`format"
1771 "`include"
1772 "`let"
1773 "`protect" "`endprotect"
1774 "`switch" "`endswitch"
1775 "`timescale"
1776 "`time_scale"
1777 ))))
1778
1779 (defconst verilog-defun-level-re
1780 (eval-when-compile
1781 (verilog-regexp-words
1782 `(
1783 "module" "macromodule" "primitive" "class" "program" "initial" "final" "always" "always_comb"
1784 "always_ff" "always_latch" "endtask" "endfunction" "interface" "package"
1785 "config"))))
1786
1787 (defconst verilog-defun-level-not-generate-re
1788 (eval-when-compile
1789 (verilog-regexp-words
1790 `(
1791 "module" "macromodule" "primitive" "class" "program" "interface" "package" "config"))))
1792
1793 (defconst verilog-cpp-level-re
1794 (eval-when-compile
1795 (verilog-regexp-words
1796 `(
1797 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
1798 ))))
1799 (defconst verilog-disable-fork-re "disable\\s-+fork")
1800 (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?")
1801 (defconst verilog-extended-complete-re
1802 (concat "\\(\\<extern\\s-+\\|\\<virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)"
1803 "\\|\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)"
1804 "\\|" verilog-extended-case-re ))
1805 (defconst verilog-basic-complete-re
1806 (eval-when-compile
1807 (verilog-regexp-words
1808 `(
1809 "always" "assign" "always_latch" "always_ff" "always_comb" "constraint"
1810 "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while"
1811 "if" "for" "forever" "foreach" "else" "parameter" "do"
1812 ))))
1813 (defconst verilog-complete-reg
1814 (concat
1815 verilog-extended-complete-re
1816 "\\|"
1817 verilog-basic-complete-re))
1818
1819 (defconst verilog-end-statement-re
1820 (concat "\\(" verilog-beg-block-re "\\)\\|\\("
1821 verilog-end-block-re "\\)"))
1822
1823 (defconst verilog-endcase-re
1824 (concat verilog-case-re "\\|"
1825 "\\(endcase\\)\\|"
1826 verilog-defun-re
1827 ))
1828
1829 (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----"
1830 "String used to mark beginning of excluded text.")
1831 (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */"
1832 "String used to mark end of excluded text.")
1833 (defconst verilog-preprocessor-re
1834 (eval-when-compile
1835 (verilog-regexp-words
1836 `(
1837 "`define" "`include" "`ifdef" "`ifndef" "`if" "`endif" "`else"
1838 ))))
1839
1840 (defconst verilog-keywords
1841 '( "`case" "`default" "`define" "`else" "`endfor" "`endif"
1842 "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
1843 "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
1844 "`time_scale" "`undef" "`while"
1845
1846 "after" "alias" "always" "always_comb" "always_ff" "always_latch" "and"
1847 "assert" "assign" "assume" "automatic" "before" "begin" "bind"
1848 "bins" "binsof" "bit" "break" "buf" "bufif0" "bufif1" "byte"
1849 "case" "casex" "casez" "cell" "chandle" "class" "clocking" "cmos"
1850 "config" "const" "constraint" "context" "continue" "cover"
1851 "covergroup" "coverpoint" "cross" "deassign" "default" "defparam"
1852 "design" "disable" "dist" "do" "edge" "else" "end" "endcase"
1853 "endclass" "endclocking" "endconfig" "endfunction" "endgenerate"
1854 "endgroup" "endinterface" "endmodule" "endpackage" "endprimitive"
1855 "endprogram" "endproperty" "endspecify" "endsequence" "endtable"
1856 "endtask" "enum" "event" "expect" "export" "extends" "extern"
1857 "final" "first_match" "for" "force" "foreach" "forever" "fork"
1858 "forkjoin" "function" "generate" "genvar" "highz0" "highz1" "if"
1859 "iff" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir"
1860 "include" "initial" "inout" "input" "inside" "instance" "int"
1861 "integer" "interface" "intersect" "join" "join_any" "join_none"
1862 "large" "liblist" "library" "local" "localparam" "logic"
1863 "longint" "macromodule" "mailbox" "matches" "medium" "modport" "module"
1864 "nand" "negedge" "new" "nmos" "nor" "noshowcancelled" "not"
1865 "notif0" "notif1" "null" "or" "output" "package" "packed"
1866 "parameter" "pmos" "posedge" "primitive" "priority" "program"
1867 "property" "protected" "pull0" "pull1" "pulldown" "pullup"
1868 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
1869 "randcase" "randsequence" "rcmos" "real" "realtime" "ref" "reg"
1870 "release" "repeat" "return" "rnmos" "rpmos" "rtran" "rtranif0"
1871 "rtranif1" "scalared" "semaphore" "sequence" "shortint" "shortreal"
1872 "showcancelled" "signed" "small" "solve" "specify" "specparam"
1873 "static" "string" "strong0" "strong1" "struct" "super" "supply0"
1874 "supply1" "table" "tagged" "task" "this" "throughout" "time"
1875 "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri"
1876 "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union"
1877 "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void"
1878 "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard"
1879 "wire" "with" "within" "wor" "xnor" "xor"
1880 )
1881 "List of Verilog keywords.")
1882
1883 (defconst verilog-comment-start-regexp "//\\|/\\*"
1884 "Dual comment value for `comment-start-regexp'.")
1885
1886 (defvar verilog-mode-syntax-table
1887 (let ((table (make-syntax-table)))
1888 ;; Populate the syntax TABLE.
1889 (modify-syntax-entry ?\\ "\\" table)
1890 (modify-syntax-entry ?+ "." table)
1891 (modify-syntax-entry ?- "." table)
1892 (modify-syntax-entry ?= "." table)
1893 (modify-syntax-entry ?% "." table)
1894 (modify-syntax-entry ?< "." table)
1895 (modify-syntax-entry ?> "." table)
1896 (modify-syntax-entry ?& "." table)
1897 (modify-syntax-entry ?| "." table)
1898 (modify-syntax-entry ?` "w" table)
1899 (modify-syntax-entry ?_ "w" table)
1900 (modify-syntax-entry ?\' "." table)
1901
1902 ;; Set up TABLE to handle block and line style comments.
1903 (if (featurep 'xemacs)
1904 (progn
1905 ;; XEmacs (formerly Lucid) has the best implementation
1906 (modify-syntax-entry ?/ ". 1456" table)
1907 (modify-syntax-entry ?* ". 23" table)
1908 (modify-syntax-entry ?\n "> b" table))
1909 ;; Emacs does things differently, but we can work with it
1910 (modify-syntax-entry ?/ ". 124b" table)
1911 (modify-syntax-entry ?* ". 23" table)
1912 (modify-syntax-entry ?\n "> b" table))
1913 table)
1914 "Syntax table used in Verilog mode buffers.")
1915
1916 (defvar verilog-font-lock-keywords nil
1917 "Default highlighting for Verilog mode.")
1918
1919 (defvar verilog-font-lock-keywords-1 nil
1920 "Subdued level highlighting for Verilog mode.")
1921
1922 (defvar verilog-font-lock-keywords-2 nil
1923 "Medium level highlighting for Verilog mode.
1924 See also `verilog-font-lock-extra-types'.")
1925
1926 (defvar verilog-font-lock-keywords-3 nil
1927 "Gaudy level highlighting for Verilog mode.
1928 See also `verilog-font-lock-extra-types'.")
1929 (defvar verilog-font-lock-translate-off-face
1930 'verilog-font-lock-translate-off-face
1931 "Font to use for translated off regions.")
1932 (defface verilog-font-lock-translate-off-face
1933 '((((class color)
1934 (background light))
1935 (:background "gray90" :italic t ))
1936 (((class color)
1937 (background dark))
1938 (:background "gray10" :italic t ))
1939 (((class grayscale) (background light))
1940 (:foreground "DimGray" :italic t))
1941 (((class grayscale) (background dark))
1942 (:foreground "LightGray" :italic t))
1943 (t (:italis t)))
1944 "Font lock mode face used to background highlight translate-off regions."
1945 :group 'font-lock-highlighting-faces)
1946
1947 (defvar verilog-font-lock-p1800-face
1948 'verilog-font-lock-p1800-face
1949 "Font to use for p1800 keywords.")
1950 (defface verilog-font-lock-p1800-face
1951 '((((class color)
1952 (background light))
1953 (:foreground "DarkOrange3" :bold t ))
1954 (((class color)
1955 (background dark))
1956 (:foreground "orange1" :bold t ))
1957 (t (:italic t)))
1958 "Font lock mode face used to highlight P1800 keywords."
1959 :group 'font-lock-highlighting-faces)
1960
1961 (defvar verilog-font-lock-ams-face
1962 'verilog-font-lock-ams-face
1963 "Font to use for Analog/Mixed Signal keywords.")
1964 (defface verilog-font-lock-ams-face
1965 '((((class color)
1966 (background light))
1967 (:foreground "Purple" :bold t ))
1968 (((class color)
1969 (background dark))
1970 (:foreground "orange1" :bold t ))
1971 (t (:italic t)))
1972 "Font lock mode face used to highlight AMS keywords."
1973 :group 'font-lock-highlighting-faces)
1974
1975 (defvar verilog-font-grouping-keywords-face
1976 'verilog-font-lock-grouping-keywords-face
1977 "Font to use for Verilog Grouping Keywords (such as begin..end).")
1978 (defface verilog-font-lock-grouping-keywords-face
1979 '((((class color)
1980 (background light))
1981 (:foreground "red4" :bold t ))
1982 (((class color)
1983 (background dark))
1984 (:foreground "red4" :bold t ))
1985 (t (:italic t)))
1986 "Font lock mode face used to highlight verilog grouping keywords."
1987 :group 'font-lock-highlighting-faces)
1988
1989 (let* ((verilog-type-font-keywords
1990 (eval-when-compile
1991 (verilog-regexp-opt
1992 '(
1993 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
1994 "event" "genvar" "inout" "input" "integer" "localparam"
1995 "logic" "mailbox" "nand" "nmos" "not" "notif0" "notif1" "or"
1996 "output" "parameter" "pmos" "pull0" "pull1" "pullup"
1997 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran"
1998 "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply"
1999 "supply0" "supply1" "time" "tran" "tranif0" "tranif1"
2000 "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef"
2001 "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor"
2002 ) nil )))
2003
2004 (verilog-pragma-keywords
2005 (eval-when-compile
2006 (verilog-regexp-opt
2007 '("surefire" "synopsys" "rtl_synthesis" "verilint" "leda" "0in") nil
2008 )))
2009
2010 (verilog-p1800-keywords
2011 (eval-when-compile
2012 (verilog-regexp-opt
2013 '("alias" "assert" "assume" "automatic" "before" "bind"
2014 "bins" "binsof" "break" "byte" "cell" "chandle" "class"
2015 "clocking" "config" "const" "constraint" "context" "continue"
2016 "cover" "covergroup" "coverpoint" "cross" "deassign" "design"
2017 "dist" "do" "edge" "endclass" "endclocking" "endconfig"
2018 "endgroup" "endprogram" "endproperty" "endsequence" "enum"
2019 "expect" "export" "extends" "extern" "first_match" "foreach"
2020 "forkjoin" "genvar" "highz0" "highz1" "ifnone" "ignore_bins"
2021 "illegal_bins" "import" "incdir" "include" "inside" "instance"
2022 "int" "intersect" "large" "liblist" "library" "local" "longint"
2023 "matches" "medium" "modport" "new" "noshowcancelled" "null"
2024 "packed" "program" "property" "protected" "pull0" "pull1"
2025 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc"
2026 "randcase" "randsequence" "ref" "release" "return" "scalared"
2027 "sequence" "shortint" "shortreal" "showcancelled" "small" "solve"
2028 "specparam" "static" "string" "strong0" "strong1" "struct"
2029 "super" "tagged" "this" "throughout" "timeprecision" "timeunit"
2030 "type" "union" "unsigned" "use" "var" "virtual" "void"
2031 "wait_order" "weak0" "weak1" "wildcard" "with" "within"
2032 ) nil )))
2033
2034 (verilog-ams-keywords
2035 (eval-when-compile
2036 (verilog-regexp-opt
2037 '("above" "abs" "absdelay" "acos" "acosh" "ac_stim"
2038 "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh"
2039 "branch" "ceil" "connectmodule" "connectrules" "cos" "cosh" "ddt"
2040 "ddx" "discipline" "driver_update" "enddiscipline" "endconnectrules"
2041 "endnature" "endparamset" "exclude" "exp" "final_step" "flicker_noise"
2042 "floor" "flow" "from" "ground" "hypot" "idt" "idtmod" "inf"
2043 "initial_step" "laplace_nd" "laplace_np" "laplace_zd" "laplace_zp"
2044 "last_crossing" "limexp" "ln" "log" "max" "min" "nature"
2045 "net_resolution" "noise_table" "paramset" "potential" "pow" "sin"
2046 "sinh" "slew" "sqrt" "tan" "tanh" "timer" "transition" "white_noise"
2047 "wreal" "zi_nd" "zi_np" "zi_zd" ) nil )))
2048
2049 (verilog-font-keywords
2050 (eval-when-compile
2051 (verilog-regexp-opt
2052 '(
2053 "assign" "case" "casex" "casez" "randcase" "deassign"
2054 "default" "disable" "else" "endcase" "endfunction"
2055 "endgenerate" "endinterface" "endmodule" "endprimitive"
2056 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break"
2057 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial"
2058 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge"
2059 "package" "endpackage" "always" "always_comb" "always_ff"
2060 "always_latch" "posedge" "primitive" "priority" "release"
2061 "repeat" "specify" "table" "task" "unique" "wait" "while"
2062 "class" "program" "endclass" "endprogram"
2063 ) nil )))
2064
2065 (verilog-font-grouping-keywords
2066 (eval-when-compile
2067 (verilog-regexp-opt
2068 '( "begin" "end" ) nil ))))
2069
2070 (setq verilog-font-lock-keywords
2071 (list
2072 ;; Fontify all builtin keywords
2073 (concat "\\<\\(" verilog-font-keywords "\\|"
2074 ;; And user/system tasks and functions
2075 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*"
2076 "\\)\\>")
2077 ;; Fontify all types
2078 (if verilog-highlight-grouping-keywords
2079 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
2080 'verilog-font-lock-ams-face)
2081 (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>")
2082 'font-lock-type-face))
2083 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>")
2084 'font-lock-type-face)
2085 ;; Fontify IEEE-P1800 keywords appropriately
2086 (if verilog-highlight-p1800-keywords
2087 (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>")
2088 'verilog-font-lock-p1800-face)
2089 (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>")
2090 'font-lock-type-face))
2091 ;; Fontify Verilog-AMS keywords
2092 (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>")
2093 'verilog-font-lock-ams-face)))
2094
2095 (setq verilog-font-lock-keywords-1
2096 (append verilog-font-lock-keywords
2097 (list
2098 ;; Fontify module definitions
2099 (list
2100 "\\<\\(\\(macro\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)"
2101 '(1 font-lock-keyword-face)
2102 '(3 font-lock-function-name-face 'prepend))
2103 ;; Fontify function definitions
2104 (list
2105 (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" )
2106 '(1 font-lock-keyword-face)
2107 '(3 font-lock-reference-face prepend))
2108 '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)"
2109 (1 font-lock-keyword-face)
2110 (2 font-lock-reference-face append))
2111 '("\\<function\\>\\s-+\\(\\sw+\\)"
2112 1 'font-lock-reference-face append))))
2113
2114 (setq verilog-font-lock-keywords-2
2115 (append verilog-font-lock-keywords-1
2116 (list
2117 ;; Fontify pragmas
2118 (concat "\\(//\\s-*" verilog-pragma-keywords "\\s-.*\\)")
2119 ;; Fontify escaped names
2120 '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face)
2121 ;; Fontify macro definitions/ uses
2122 '("`\\s-*[A-Za-z][A-Za-z0-9_]*" 0 (if (boundp 'font-lock-preprocessor-face)
2123 'font-lock-preprocessor-face
2124 'font-lock-type-face))
2125 ;; Fontify delays/numbers
2126 '("\\(@\\)\\|\\(#\\s-*\\(\\(\[0-9_.\]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)"
2127 0 font-lock-type-face append)
2128 ;; Fontify instantiation names
2129 '("\\([A-Za-z][A-Za-z0-9_]+\\)\\s-*(" 1 font-lock-function-name-face)
2130 )))
2131
2132 (setq verilog-font-lock-keywords-3
2133 (append verilog-font-lock-keywords-2
2134 (when verilog-highlight-translate-off
2135 (list
2136 ;; Fontify things in translate off regions
2137 '(verilog-match-translate-off
2138 (0 'verilog-font-lock-translate-off-face prepend))
2139 )))))
2140
2141
2142 (defun verilog-inside-comment-p ()
2143 "Check if point inside a nested comment."
2144 (save-excursion
2145 (let ((st-point (point)) hitbeg)
2146 (or (search-backward "//" (verilog-get-beg-of-line) t)
2147 (if (progn
2148 ;; This is for tricky case //*, we keep searching if /*
2149 ;; is proceeded by // on same line.
2150 (while
2151 (and (setq hitbeg (search-backward "/*" nil t))
2152 (progn
2153 (forward-char 1)
2154 (search-backward "//" (verilog-get-beg-of-line) t))))
2155 hitbeg)
2156 (not (search-forward "*/" st-point t)))))))
2157
2158 (defun verilog-declaration-end ()
2159 (search-forward ";"))
2160
2161 (defun verilog-point-text (&optional pointnum)
2162 "Return text describing where POINTNUM or current point is (for errors).
2163 Use filename, if current buffer being edited shorten to just buffer name."
2164 (concat (or (and (equal (window-buffer (selected-window)) (current-buffer))
2165 (buffer-name))
2166 buffer-file-name
2167 (buffer-name))
2168 ":" (int-to-string (count-lines (point-min) (or pointnum (point))))))
2169
2170 (defun electric-verilog-backward-sexp ()
2171 "Move backward over one balanced expression."
2172 (interactive)
2173 ;; before that see if we are in a comment
2174 (verilog-backward-sexp))
2175
2176 (defun electric-verilog-forward-sexp ()
2177 "Move forward over one balanced expression."
2178 (interactive)
2179 ;; before that see if we are in a comment
2180 (verilog-forward-sexp))
2181
2182 ;;;used by hs-minor-mode
2183 (defun verilog-forward-sexp-function (arg)
2184 (if (< arg 0)
2185 (verilog-backward-sexp)
2186 (verilog-forward-sexp)))
2187
2188
2189 (defun verilog-backward-sexp ()
2190 (let ((reg)
2191 (elsec 1)
2192 (found nil)
2193 (st (point)))
2194 (if (not (looking-at "\\<"))
2195 (forward-word -1))
2196 (cond
2197 ((verilog-skip-backward-comment-or-string))
2198 ((looking-at "\\<else\\>")
2199 (setq reg (concat
2200 verilog-end-block-re
2201 "\\|\\(\\<else\\>\\)"
2202 "\\|\\(\\<if\\>\\)"))
2203 (while (and (not found)
2204 (verilog-re-search-backward reg nil 'move))
2205 (cond
2206 ((match-end 1) ; matched verilog-end-block-re
2207 ; try to leap back to matching outward block by striding across
2208 ; indent level changing tokens then immediately
2209 ; previous line governs indentation.
2210 (verilog-leap-to-head))
2211 ((match-end 2) ; else, we're in deep
2212 (setq elsec (1+ elsec)))
2213 ((match-end 3) ; found it
2214 (setq elsec (1- elsec))
2215 (if (= 0 elsec)
2216 ;; Now previous line describes syntax
2217 (setq found 't))))))
2218 ((looking-at verilog-end-block-re)
2219 (verilog-leap-to-head))
2220 ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)\\|\\(\\<endclass\\>\\)\\|\\(\\<endprogram\\>\\)\\|\\(\\<endinterface\\>\\)\\|\\(\\<endpackage\\>\\)")
2221 (cond
2222 ((match-end 1)
2223 (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move))
2224 ((match-end 2)
2225 (verilog-re-search-backward "\\<primitive\\>" nil 'move))
2226 ((match-end 3)
2227 (verilog-re-search-backward "\\<class\\>" nil 'move))
2228 ((match-end 4)
2229 (verilog-re-search-backward "\\<program\\>" nil 'move))
2230 ((match-end 5)
2231 (verilog-re-search-backward "\\<interface\\>" nil 'move))
2232 ((match-end 6)
2233 (verilog-re-search-backward "\\<package\\>" nil 'move))
2234 (t
2235 (goto-char st)
2236 (backward-sexp 1))))
2237 (t
2238 (goto-char st)
2239 (backward-sexp)))))
2240
2241 (defun verilog-forward-sexp ()
2242 (let ((reg)
2243 (md 2)
2244 (st (point))
2245 (nest 'yes))
2246 (if (not (looking-at "\\<"))
2247 (forward-word -1))
2248 (cond
2249 ((verilog-skip-forward-comment-or-string)
2250 (verilog-forward-syntactic-ws))
2251 ((looking-at verilog-beg-block-re-ordered)
2252 (cond
2253 ((match-end 1);
2254 ;; Search forward for matching end
2255 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
2256 ((match-end 2)
2257 ;; Search forward for matching endcase
2258 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
2259 (setq md 3) ;; ender is third item in regexp
2260 )
2261 ((match-end 4)
2262 ;; might be "disable fork"
2263 (if (or
2264 (looking-at verilog-disable-fork-re)
2265 (and (looking-at "fork")
2266 (progn
2267 (forward-word -1)
2268 (looking-at verilog-disable-fork-re))))
2269 (progn
2270 (goto-char (match-end 0))
2271 (forward-word)
2272 (setq reg nil))
2273 (progn
2274 ;; Search forward for matching join
2275 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))))
2276 ((match-end 6)
2277 ;; Search forward for matching endclass
2278 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
2279
2280 ((match-end 7)
2281 ;; Search forward for matching endtable
2282 (setq reg "\\<endtable\\>" )
2283 (setq nest 'no))
2284 ((match-end 8)
2285 ;; Search forward for matching endspecify
2286 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
2287 ((match-end 9)
2288 ;; Search forward for matching endfunction
2289 (setq reg "\\<endfunction\\>" )
2290 (setq nest 'no))
2291 ((match-end 10)
2292 ;; Search forward for matching endtask
2293 (setq reg "\\<endtask\\>" )
2294 (setq nest 'no))
2295 ((match-end 11)
2296 ;; Search forward for matching endtask
2297 (setq reg "\\<endtask\\>" )
2298 (setq nest 'no))
2299 ((match-end 15)
2300 ;; Search forward for matching endgenerate
2301 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
2302 ((match-end 16)
2303 ;; Search forward for matching endgroup
2304 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
2305 ((match-end 17)
2306 ;; Search forward for matching endproperty
2307 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
2308 ((match-end 18)
2309 ;; Search forward for matching endsequence
2310 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )
2311 (setq md 3)) ; 3 to get to endsequence in the reg above
2312 ((match-end 19)
2313 ;; Search forward for matching endclocking
2314 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )))
2315 (if (and reg
2316 (forward-word 1))
2317 (catch 'skip
2318 (if (eq nest 'yes)
2319 (let ((depth 1))
2320 (while (verilog-re-search-forward reg nil 'move)
2321 (cond
2322 ((match-end md) ; the closer in reg, so we are climbing out
2323 (setq depth (1- depth))
2324 (if (= 0 depth) ; we are out!
2325 (throw 'skip 1)))
2326 ((match-end 1) ; the opener in reg, so we are deeper now
2327 (setq depth (1+ depth))))))
2328 (if (verilog-re-search-forward reg nil 'move)
2329 (throw 'skip 1))))))
2330
2331 ((looking-at (concat
2332 "\\(\\<\\(macro\\)?module\\>\\)\\|"
2333 "\\(\\<primitive\\>\\)\\|"
2334 "\\(\\<class\\>\\)\\|"
2335 "\\(\\<program\\>\\)\\|"
2336 "\\(\\<interface\\>\\)\\|"
2337 "\\(\\<package\\>\\)"))
2338 (cond
2339 ((match-end 1)
2340 (verilog-re-search-forward "\\<endmodule\\>" nil 'move))
2341 ((match-end 2)
2342 (verilog-re-search-forward "\\<endprimitive\\>" nil 'move))
2343 ((match-end 3)
2344 (verilog-re-search-forward "\\<endclass\\>" nil 'move))
2345 ((match-end 4)
2346 (verilog-re-search-forward "\\<endprogram\\>" nil 'move))
2347 ((match-end 5)
2348 (verilog-re-search-forward "\\<endinterface\\>" nil 'move))
2349 ((match-end 6)
2350 (verilog-re-search-forward "\\<endpackage\\>" nil 'move))
2351 (t
2352 (goto-char st)
2353 (if (= (following-char) ?\) )
2354 (forward-char 1)
2355 (forward-sexp 1)))))
2356 (t
2357 (goto-char st)
2358 (if (= (following-char) ?\) )
2359 (forward-char 1)
2360 (forward-sexp 1))))))
2361
2362 (defun verilog-declaration-beg ()
2363 (verilog-re-search-backward verilog-declaration-re (bobp) t))
2364
2365 (defun verilog-font-lock-init ()
2366 "Initialize fontification."
2367 ;; highlight keywords and standardized types, attributes, enumeration
2368 ;; values, and subprograms
2369 (setq verilog-font-lock-keywords-3
2370 (append verilog-font-lock-keywords-2
2371 (when verilog-highlight-translate-off
2372 (list
2373 ;; Fontify things in translate off regions
2374 '(verilog-match-translate-off
2375 (0 'verilog-font-lock-translate-off-face prepend))))))
2376 (put 'verilog-mode 'font-lock-defaults
2377 '((verilog-font-lock-keywords
2378 verilog-font-lock-keywords-1
2379 verilog-font-lock-keywords-2
2380 verilog-font-lock-keywords-3)
2381 nil ; nil means highlight strings & comments as well as keywords
2382 nil ; nil means keywords must match case
2383 nil ; syntax table handled elsewhere
2384 ;; Function to move to beginning of reasonable region to highlight
2385 verilog-beg-of-defun)))
2386
2387 ;; initialize fontification for Verilog Mode
2388 (verilog-font-lock-init)
2389
2390 ;;
2391 ;;
2392 ;; Mode
2393 ;;
2394 (defvar verilog-which-tool 1)
2395 ;;;###autoload
2396 (defun verilog-mode ()
2397 "Major mode for editing Verilog code.
2398 \\<verilog-mode-map>
2399 See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how
2400 AUTOs can improve coding efficiency.
2401
2402 Use \\[verilog-faq] for a pointer to frequently asked questions.
2403
2404 NEWLINE, TAB indents for Verilog code.
2405 Delete converts tabs to spaces as it moves back.
2406
2407 Supports highlighting.
2408
2409 Turning on Verilog mode calls the value of the variable `verilog-mode-hook'
2410 with no args, if that value is non-nil.
2411
2412 Variables controlling indentation/edit style:
2413
2414 variable `verilog-indent-level' (default 3)
2415 Indentation of Verilog statements with respect to containing block.
2416 `verilog-indent-level-module' (default 3)
2417 Absolute indentation of Module level Verilog statements.
2418 Set to 0 to get initial and always statements lined up
2419 on the left side of your screen.
2420 `verilog-indent-level-declaration' (default 3)
2421 Indentation of declarations with respect to containing block.
2422 Set to 0 to get them list right under containing block.
2423 `verilog-indent-level-behavioral' (default 3)
2424 Indentation of first begin in a task or function block
2425 Set to 0 to get such code to lined up underneath the task or
2426 function keyword.
2427 `verilog-indent-level-directive' (default 1)
2428 Indentation of `ifdef/`endif blocks.
2429 `verilog-cexp-indent' (default 1)
2430 Indentation of Verilog statements broken across lines i.e.:
2431 if (a)
2432 begin
2433 `verilog-case-indent' (default 2)
2434 Indentation for case statements.
2435 `verilog-auto-newline' (default nil)
2436 Non-nil means automatically newline after semicolons and the punctuation
2437 mark after an end.
2438 `verilog-auto-indent-on-newline' (default t)
2439 Non-nil means automatically indent line after newline.
2440 `verilog-tab-always-indent' (default t)
2441 Non-nil means TAB in Verilog mode should always reindent the current line,
2442 regardless of where in the line point is when the TAB command is used.
2443 `verilog-indent-begin-after-if' (default t)
2444 Non-nil means to indent begin statements following a preceding
2445 if, else, while, for and repeat statements, if any. Otherwise,
2446 the begin is lined up with the preceding token. If t, you get:
2447 if (a)
2448 begin // amount of indent based on `verilog-cexp-indent'
2449 otherwise you get:
2450 if (a)
2451 begin
2452 `verilog-auto-endcomments' (default t)
2453 Non-nil means a comment /* ... */ is set after the ends which ends
2454 cases, tasks, functions and modules.
2455 The type and name of the object will be set between the braces.
2456 `verilog-minimum-comment-distance' (default 10)
2457 Minimum distance (in lines) between begin and end required before a comment
2458 will be inserted. Setting this variable to zero results in every
2459 end acquiring a comment; the default avoids too many redundant
2460 comments in tight quarters.
2461 `verilog-auto-lineup' (default `(all))
2462 List of contexts where auto lineup of code should be done.
2463
2464 Variables controlling other actions:
2465
2466 `verilog-linter' (default surelint)
2467 Unix program to call to run the lint checker. This is the default
2468 command for \\[compile-command] and \\[verilog-auto-save-compile].
2469
2470 See \\[customize] for the complete list of variables.
2471
2472 AUTO expansion functions are, in part:
2473
2474 \\[verilog-auto] Expand AUTO statements.
2475 \\[verilog-delete-auto] Remove the AUTOs.
2476 \\[verilog-inject-auto] Insert AUTOs for the first time.
2477
2478 Some other functions are:
2479
2480 \\[verilog-complete-word] Complete word with appropriate possibilities.
2481 \\[verilog-mark-defun] Mark function.
2482 \\[verilog-beg-of-defun] Move to beginning of current function.
2483 \\[verilog-end-of-defun] Move to end of current function.
2484 \\[verilog-label-be] Label matching begin ... end, fork ... join, etc statements.
2485
2486 \\[verilog-comment-region] Put marked area in a comment.
2487 \\[verilog-uncomment-region] Uncomment an area commented with \\[verilog-comment-region].
2488 \\[verilog-insert-block] Insert begin ... end.
2489 \\[verilog-star-comment] Insert /* ... */.
2490
2491 \\[verilog-sk-always] Insert an always @(AS) begin .. end block.
2492 \\[verilog-sk-begin] Insert a begin .. end block.
2493 \\[verilog-sk-case] Insert a case block, prompting for details.
2494 \\[verilog-sk-for] Insert a for (...) begin .. end block, prompting for details.
2495 \\[verilog-sk-generate] Insert a generate .. endgenerate block.
2496 \\[verilog-sk-header] Insert a header block at the top of file.
2497 \\[verilog-sk-initial] Insert an initial begin .. end block.
2498 \\[verilog-sk-fork] Insert a fork begin .. end .. join block.
2499 \\[verilog-sk-module] Insert a module .. (/*AUTOARG*/);.. endmodule block.
2500 \\[verilog-sk-primitive] Insert a primitive .. (.. );.. endprimitive block.
2501 \\[verilog-sk-repeat] Insert a repeat (..) begin .. end block.
2502 \\[verilog-sk-specify] Insert a specify .. endspecify block.
2503 \\[verilog-sk-task] Insert a task .. begin .. end endtask block.
2504 \\[verilog-sk-while] Insert a while (...) begin .. end block, prompting for details.
2505 \\[verilog-sk-casex] Insert a casex (...) item: begin.. end endcase block, prompting for details.
2506 \\[verilog-sk-casez] Insert a casez (...) item: begin.. end endcase block, prompting for details.
2507 \\[verilog-sk-if] Insert an if (..) begin .. end block.
2508 \\[verilog-sk-else-if] Insert an else if (..) begin .. end block.
2509 \\[verilog-sk-comment] Insert a comment block.
2510 \\[verilog-sk-assign] Insert an assign .. = ..; statement.
2511 \\[verilog-sk-function] Insert a function .. begin .. end endfunction block.
2512 \\[verilog-sk-input] Insert an input declaration, prompting for details.
2513 \\[verilog-sk-output] Insert an output declaration, prompting for details.
2514 \\[verilog-sk-state-machine] Insert a state machine definition, prompting for details.
2515 \\[verilog-sk-inout] Insert an inout declaration, prompting for details.
2516 \\[verilog-sk-wire] Insert a wire declaration, prompting for details.
2517 \\[verilog-sk-reg] Insert a register declaration, prompting for details.
2518 \\[verilog-sk-define-signal] Define signal under point as a register at the top of the module.
2519
2520 All key bindings can be seen in a Verilog-buffer with \\[describe-bindings].
2521 Key bindings specific to `verilog-mode-map' are:
2522
2523 \\{verilog-mode-map}"
2524 (interactive)
2525 (kill-all-local-variables)
2526 (use-local-map verilog-mode-map)
2527 (setq major-mode 'verilog-mode)
2528 (setq mode-name "Verilog")
2529 (setq local-abbrev-table verilog-mode-abbrev-table)
2530 (set (make-local-variable 'beginning-of-defun-function)
2531 'verilog-beg-of-defun)
2532 (set (make-local-variable 'end-of-defun-function)
2533 'verilog-end-of-defun)
2534 (set-syntax-table verilog-mode-syntax-table)
2535 (make-local-variable 'indent-line-function)
2536 (setq indent-line-function 'verilog-indent-line-relative)
2537 (setq comment-indent-function 'verilog-comment-indent)
2538 (make-local-variable 'parse-sexp-ignore-comments)
2539 (setq parse-sexp-ignore-comments nil)
2540 (make-local-variable 'comment-start)
2541 (make-local-variable 'comment-end)
2542 (make-local-variable 'comment-multi-line)
2543 (make-local-variable 'comment-start-skip)
2544 (setq comment-start "// "
2545 comment-end ""
2546 comment-start-skip "/\\*+ *\\|// *"
2547 comment-multi-line nil)
2548 ;; Set up for compilation
2549 (setq verilog-which-tool 1)
2550 (setq verilog-tool 'verilog-linter)
2551 (verilog-set-compile-command)
2552 (when (boundp 'hack-local-variables-hook) ;; Also modify any file-local-variables
2553 (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t))
2554
2555 ;; Setting up menus
2556 (when (featurep 'xemacs)
2557 (easy-menu-add verilog-stmt-menu)
2558 (easy-menu-add verilog-menu)
2559 (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu)))
2560
2561 ;; Stuff for GNU Emacs
2562 (set (make-local-variable 'font-lock-defaults)
2563 '((verilog-font-lock-keywords verilog-font-lock-keywords-1
2564 verilog-font-lock-keywords-2
2565 verilog-font-lock-keywords-3)
2566 nil nil nil verilog-beg-of-defun))
2567 ;;------------------------------------------------------------
2568 ;; now hook in 'verilog-colorize-include-files (eldo-mode.el&spice-mode.el)
2569 ;; all buffer local:
2570 (when (featurep 'xemacs)
2571 (make-local-hook 'font-lock-mode-hook)
2572 (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in Emacs
2573 (make-local-hook 'after-change-functions))
2574 (add-hook 'font-lock-mode-hook 'verilog-colorize-include-files-buffer t t)
2575 (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-colorize-include-files-buffer t t) ; not in Emacs
2576 (add-hook 'after-change-functions 'verilog-colorize-include-files t t)
2577
2578 ;; Tell imenu how to handle Verilog.
2579 (make-local-variable 'imenu-generic-expression)
2580 (setq imenu-generic-expression verilog-imenu-generic-expression)
2581 ;; Tell which-func-modes that imenu knows about verilog
2582 (when (boundp 'which-function-modes)
2583 (add-to-list 'which-func-modes 'verilog-mode))
2584 ;; hideshow support
2585 (when (boundp 'hs-special-modes-alist)
2586 (unless (assq 'verilog-mode hs-special-modes-alist)
2587 (setq hs-special-modes-alist
2588 (cons '(verilog-mode-mode "\\<begin\\>" "\\<end\\>" nil
2589 verilog-forward-sexp-function)
2590 hs-special-modes-alist))))
2591
2592 ;; Stuff for autos
2593 (add-hook 'write-contents-hooks 'verilog-auto-save-check) ; already local
2594 ;; (verilog-auto-reeval-locals t) ; Save locals in case user changes them
2595 ;; (verilog-getopt-flags)
2596 (run-hooks 'verilog-mode-hook))
2597 \f
2598
2599 ;;
2600 ;; Electric functions
2601 ;;
2602 (defun electric-verilog-terminate-line (&optional arg)
2603 "Terminate line and indent next line.
2604 With optional ARG, remove existing end of line comments."
2605 (interactive)
2606 ;; before that see if we are in a comment
2607 (let ((state (save-excursion (verilog-syntax-ppss))))
2608 (cond
2609 ((nth 7 state) ; Inside // comment
2610 (if (eolp)
2611 (progn
2612 (delete-horizontal-space)
2613 (newline))
2614 (progn
2615 (newline)
2616 (insert "// ")
2617 (beginning-of-line)))
2618 (verilog-indent-line))
2619 ((nth 4 state) ; Inside any comment (hence /**/)
2620 (newline)
2621 (verilog-more-comment))
2622 ((eolp)
2623 ;; First, check if current line should be indented
2624 (if (save-excursion
2625 (delete-horizontal-space)
2626 (beginning-of-line)
2627 (skip-chars-forward " \t")
2628 (if (looking-at verilog-auto-end-comment-lines-re)
2629 (let ((indent-str (verilog-indent-line)))
2630 ;; Maybe we should set some endcomments
2631 (if verilog-auto-endcomments
2632 (verilog-set-auto-endcomments indent-str arg))
2633 (end-of-line)
2634 (delete-horizontal-space)
2635 (if arg
2636 ()
2637 (newline))
2638 nil)
2639 (progn
2640 (end-of-line)
2641 (delete-horizontal-space)
2642 't)))
2643 ;; see if we should line up assignments
2644 (progn
2645 (if (or (memq 'all verilog-auto-lineup)
2646 (memq 'assignments verilog-auto-lineup))
2647 (verilog-pretty-expr))
2648 (newline))
2649 (forward-line 1))
2650 ;; Indent next line
2651 (if verilog-auto-indent-on-newline
2652 (verilog-indent-line)))
2653 (t
2654 (newline)))))
2655
2656 (defun electric-verilog-terminate-and-indent ()
2657 "Insert a newline and indent for the next statement."
2658 (interactive)
2659 (electric-verilog-terminate-line 1))
2660
2661 (defun electric-verilog-semi ()
2662 "Insert `;' character and reindent the line."
2663 (interactive)
2664 (insert last-command-event)
2665
2666 (if (or (verilog-in-comment-or-string-p)
2667 (verilog-in-escaped-name-p))
2668 ()
2669 (save-excursion
2670 (beginning-of-line)
2671 (verilog-forward-ws&directives)
2672 (verilog-indent-line))
2673 (if (and verilog-auto-newline
2674 (not (verilog-parenthesis-depth)))
2675 (electric-verilog-terminate-line))))
2676
2677 (defun electric-verilog-semi-with-comment ()
2678 "Insert `;' character, reindent the line and indent for comment."
2679 (interactive)
2680 (insert "\;")
2681 (save-excursion
2682 (beginning-of-line)
2683 (verilog-indent-line))
2684 (indent-for-comment))
2685
2686 (defun electric-verilog-colon ()
2687 "Insert `:' and do all indentations except line indent on this line."
2688 (interactive)
2689 (insert last-command-event)
2690 ;; Do nothing if within string.
2691 (if (or
2692 (verilog-within-string)
2693 (not (verilog-in-case-region-p)))
2694 ()
2695 (save-excursion
2696 (let ((p (point))
2697 (lim (progn (verilog-beg-of-statement) (point))))
2698 (goto-char p)
2699 (verilog-backward-case-item lim)
2700 (verilog-indent-line)))
2701 ;; (let ((verilog-tab-always-indent nil))
2702 ;; (verilog-indent-line))
2703 ))
2704
2705 ;;(defun electric-verilog-equal ()
2706 ;; "Insert `=', and do indentation if within block."
2707 ;; (interactive)
2708 ;; (insert last-command-event)
2709 ;; Could auto line up expressions, but not yet
2710 ;; (if (eq (car (verilog-calculate-indent)) 'block)
2711 ;; (let ((verilog-tab-always-indent nil))
2712 ;; (verilog-indent-command)))
2713 ;; )
2714
2715 (defun electric-verilog-tick ()
2716 "Insert back-tick, and indent to column 0 if this is a CPP directive."
2717 (interactive)
2718 (insert last-command-event)
2719 (save-excursion
2720 (if (progn
2721 (beginning-of-line)
2722 (looking-at verilog-directive-re-1))
2723 (verilog-indent-line))))
2724
2725 (defun electric-verilog-tab ()
2726 "Function called when TAB is pressed in Verilog mode."
2727 (interactive)
2728 ;; If verilog-tab-always-indent, indent the beginning of the line.
2729 (cond
2730 ;; The region is active, indent it.
2731 ((and (region-active-p)
2732 (not (eq (region-beginning) (region-end))))
2733 (indent-region (region-beginning) (region-end) nil))
2734 ((or verilog-tab-always-indent
2735 (save-excursion
2736 (skip-chars-backward " \t")
2737 (bolp)))
2738 (let* ((oldpnt (point))
2739 (boi-point
2740 (save-excursion
2741 (beginning-of-line)
2742 (skip-chars-forward " \t")
2743 (verilog-indent-line)
2744 (back-to-indentation)
2745 (point))))
2746 (if (< (point) boi-point)
2747 (back-to-indentation)
2748 (cond ((not verilog-tab-to-comment))
2749 ((not (eolp))
2750 (end-of-line))
2751 (t
2752 (indent-for-comment)
2753 (when (and (eolp) (= oldpnt (point)))
2754 ; kill existing comment
2755 (beginning-of-line)
2756 (re-search-forward comment-start-skip oldpnt 'move)
2757 (goto-char (match-beginning 0))
2758 (skip-chars-backward " \t")
2759 (kill-region (point) oldpnt)))))))
2760 (t (progn (insert "\t")))))
2761
2762 \f
2763
2764 ;;
2765 ;; Interactive functions
2766 ;;
2767
2768 (defun verilog-indent-buffer ()
2769 "Indent-region the entire buffer as Verilog code.
2770 To call this from the command line, see \\[verilog-batch-indent]."
2771 (interactive)
2772 (verilog-mode)
2773 (indent-region (point-min) (point-max) nil))
2774
2775 (defun verilog-insert-block ()
2776 "Insert Verilog begin ... end; block in the code with right indentation."
2777 (interactive)
2778 (verilog-indent-line)
2779 (insert "begin")
2780 (electric-verilog-terminate-line)
2781 (save-excursion
2782 (electric-verilog-terminate-line)
2783 (insert "end")
2784 (beginning-of-line)
2785 (verilog-indent-line)))
2786
2787 (defun verilog-star-comment ()
2788 "Insert Verilog star comment at point."
2789 (interactive)
2790 (verilog-indent-line)
2791 (insert "/*")
2792 (save-excursion
2793 (newline)
2794 (insert " */"))
2795 (newline)
2796 (insert " * "))
2797
2798 (defun verilog-insert-1 (fmt max)
2799 "Use format string FMT to insert integers 0 to MAX - 1.
2800 Inserts one integer per line, at the current column. Stops early
2801 if it reaches the end of the buffer."
2802 (let ((col (current-column))
2803 (n 0))
2804 (save-excursion
2805 (while (< n max)
2806 (insert (format fmt n))
2807 (forward-line 1)
2808 ;; Note that this function does not bother to check for lines
2809 ;; shorter than col.
2810 (if (eobp)
2811 (setq n max)
2812 (setq n (1+ n))
2813 (move-to-column col))))))
2814
2815 (defun verilog-insert-indices (max)
2816 "Insert a set of indices into a rectangle.
2817 The upper left corner is defined by point. Indices begin with 0
2818 and extend to the MAX - 1. If no prefix arg is given, the user
2819 is prompted for a value. The indices are surrounded by square
2820 brackets \[]. For example, the following code with the point
2821 located after the first 'a' gives:
2822
2823 a = b a[ 0] = b
2824 a = b a[ 1] = b
2825 a = b a[ 2] = b
2826 a = b a[ 3] = b
2827 a = b ==> insert-indices ==> a[ 4] = b
2828 a = b a[ 5] = b
2829 a = b a[ 6] = b
2830 a = b a[ 7] = b
2831 a = b a[ 8] = b"
2832
2833 (interactive "NMAX: ")
2834 (verilog-insert-1 "[%3d]" max))
2835
2836 (defun verilog-generate-numbers (max)
2837 "Insert a set of generated numbers into a rectangle.
2838 The upper left corner is defined by point. The numbers are padded to three
2839 digits, starting with 000 and extending to (MAX - 1). If no prefix argument
2840 is supplied, then the user is prompted for the MAX number. Consider the
2841 following code fragment:
2842
2843 buf buf buf buf000
2844 buf buf buf buf001
2845 buf buf buf buf002
2846 buf buf buf buf003
2847 buf buf ==> generate-numbers ==> buf buf004
2848 buf buf buf buf005
2849 buf buf buf buf006
2850 buf buf buf buf007
2851 buf buf buf buf008"
2852
2853 (interactive "NMAX: ")
2854 (verilog-insert-1 "%3.3d" max))
2855
2856 (defun verilog-mark-defun ()
2857 "Mark the current Verilog function (or procedure).
2858 This puts the mark at the end, and point at the beginning."
2859 (interactive)
2860 (if (featurep 'xemacs)
2861 (progn
2862 (push-mark (point))
2863 (verilog-end-of-defun)
2864 (push-mark (point))
2865 (verilog-beg-of-defun)
2866 (if (fboundp 'zmacs-activate-region)
2867 (zmacs-activate-region)))
2868 (mark-defun)))
2869
2870 (defun verilog-comment-region (start end)
2871 ; checkdoc-params: (start end)
2872 "Put the region into a Verilog comment.
2873 The comments that are in this area are \"deformed\":
2874 `*)' becomes `!(*' and `}' becomes `!{'.
2875 These deformed comments are returned to normal if you use
2876 \\[verilog-uncomment-region] to undo the commenting.
2877
2878 The commented area starts with `verilog-exclude-str-start', and ends with
2879 `verilog-exclude-str-end'. But if you change these variables,
2880 \\[verilog-uncomment-region] won't recognize the comments."
2881 (interactive "r")
2882 (save-excursion
2883 ;; Insert start and endcomments
2884 (goto-char end)
2885 (if (and (save-excursion (skip-chars-forward " \t") (eolp))
2886 (not (save-excursion (skip-chars-backward " \t") (bolp))))
2887 (forward-line 1)
2888 (beginning-of-line))
2889 (insert verilog-exclude-str-end)
2890 (setq end (point))
2891 (newline)
2892 (goto-char start)
2893 (beginning-of-line)
2894 (insert verilog-exclude-str-start)
2895 (newline)
2896 ;; Replace end-comments within commented area
2897 (goto-char end)
2898 (save-excursion
2899 (while (re-search-backward "\\*/" start t)
2900 (replace-match "*-/" t t)))
2901 (save-excursion
2902 (let ((s+1 (1+ start)))
2903 (while (re-search-backward "/\\*" s+1 t)
2904 (replace-match "/-*" t t))))))
2905
2906 (defun verilog-uncomment-region ()
2907 "Uncomment a commented area; change deformed comments back to normal.
2908 This command does nothing if the pointer is not in a commented
2909 area. See also `verilog-comment-region'."
2910 (interactive)
2911 (save-excursion
2912 (let ((start (point))
2913 (end (point)))
2914 ;; Find the boundaries of the comment
2915 (save-excursion
2916 (setq start (progn (search-backward verilog-exclude-str-start nil t)
2917 (point)))
2918 (setq end (progn (search-forward verilog-exclude-str-end nil t)
2919 (point))))
2920 ;; Check if we're really inside a comment
2921 (if (or (equal start (point)) (<= end (point)))
2922 (message "Not standing within commented area.")
2923 (progn
2924 ;; Remove endcomment
2925 (goto-char end)
2926 (beginning-of-line)
2927 (let ((pos (point)))
2928 (end-of-line)
2929 (delete-region pos (1+ (point))))
2930 ;; Change comments back to normal
2931 (save-excursion
2932 (while (re-search-backward "\\*-/" start t)
2933 (replace-match "*/" t t)))
2934 (save-excursion
2935 (while (re-search-backward "/-\\*" start t)
2936 (replace-match "/*" t t)))
2937 ;; Remove start comment
2938 (goto-char start)
2939 (beginning-of-line)
2940 (let ((pos (point)))
2941 (end-of-line)
2942 (delete-region pos (1+ (point)))))))))
2943
2944 (defun verilog-beg-of-defun ()
2945 "Move backward to the beginning of the current function or procedure."
2946 (interactive)
2947 (verilog-re-search-backward verilog-defun-re nil 'move))
2948
2949 (defun verilog-end-of-defun ()
2950 "Move forward to the end of the current function or procedure."
2951 (interactive)
2952 (verilog-re-search-forward verilog-end-defun-re nil 'move))
2953
2954 (defun verilog-get-beg-of-defun (&optional warn)
2955 (save-excursion
2956 (cond ((verilog-re-search-forward-quick verilog-defun-re nil t)
2957 (point))
2958 (t
2959 (error "%s: Can't find module beginning" (verilog-point-text))
2960 (point-max)))))
2961 (defun verilog-get-end-of-defun (&optional warn)
2962 (save-excursion
2963 (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t)
2964 (point))
2965 (t
2966 (error "%s: Can't find endmodule" (verilog-point-text))
2967 (point-max)))))
2968
2969 (defun verilog-label-be (&optional arg)
2970 "Label matching begin ... end, fork ... join and case ... endcase statements.
2971 With ARG, first kill any existing labels."
2972 (interactive)
2973 (let ((cnt 0)
2974 (oldpos (point))
2975 (b (progn
2976 (verilog-beg-of-defun)
2977 (point-marker)))
2978 (e (progn
2979 (verilog-end-of-defun)
2980 (point-marker))))
2981 (goto-char (marker-position b))
2982 (if (> (- e b) 200)
2983 (message "Relabeling module..."))
2984 (while (and
2985 (> (marker-position e) (point))
2986 (verilog-re-search-forward
2987 (concat
2988 "\\<end\\(\\(function\\)\\|\\(task\\)\\|\\(module\\)\\|\\(primitive\\)\\|\\(interface\\)\\|\\(package\\)\\|\\(case\\)\\)?\\>"
2989 "\\|\\(`endif\\)\\|\\(`else\\)")
2990 nil 'move))
2991 (goto-char (match-beginning 0))
2992 (let ((indent-str (verilog-indent-line)))
2993 (verilog-set-auto-endcomments indent-str 't)
2994 (end-of-line)
2995 (delete-horizontal-space))
2996 (setq cnt (1+ cnt))
2997 (if (= 9 (% cnt 10))
2998 (message "%d..." cnt)))
2999 (goto-char oldpos)
3000 (if (or
3001 (> (- e b) 200)
3002 (> cnt 20))
3003 (message "%d lines auto commented" cnt))))
3004
3005 (defun verilog-beg-of-statement ()
3006 "Move backward to beginning of statement."
3007 (interactive)
3008 ;; Move back token by token until we see the end
3009 ;; of some ealier line.
3010 (while
3011 ;; If the current point does not begin a new
3012 ;; statement, as in the character ahead of us is a ';', or SOF
3013 ;; or the string after us unambiguosly starts a statement,
3014 ;; or the token before us unambiguously ends a statement,
3015 ;; then move back a token and test again.
3016 (not (or
3017 (bolp)
3018 (= (preceding-char) ?\;)
3019 (not (or
3020 (looking-at "\\<")
3021 (forward-word -1)))
3022 (and
3023 (looking-at verilog-extended-complete-re)
3024 (not (save-excursion
3025 (verilog-backward-token)
3026 (looking-at verilog-extended-complete-re))))
3027 (looking-at verilog-basic-complete-re)
3028 (save-excursion
3029 (verilog-backward-token)
3030 (or
3031 (looking-at verilog-end-block-re)
3032 (looking-at verilog-preprocessor-re)))))
3033 (verilog-backward-syntactic-ws)
3034 (verilog-backward-token))
3035 ;; Now point is where the previous line ended.
3036 (verilog-forward-syntactic-ws))
3037
3038 (defun verilog-beg-of-statement-1 ()
3039 "Move backward to beginning of statement."
3040 (interactive)
3041 (let ((pt (point)))
3042
3043 (while (and (not (looking-at verilog-complete-reg))
3044 (setq pt (point))
3045 (verilog-backward-token)
3046 (not (looking-at verilog-complete-reg))
3047 (verilog-backward-syntactic-ws)
3048 (setq pt (point))
3049 (not (bolp))
3050 (not (= (preceding-char) ?\;))))
3051 (goto-char pt)
3052 (verilog-forward-ws&directives)))
3053
3054 (defun verilog-end-of-statement ()
3055 "Move forward to end of current statement."
3056 (interactive)
3057 (let ((nest 0) pos)
3058 (or (looking-at verilog-beg-block-re)
3059 ;; Skip to end of statement
3060 (setq pos (catch 'found
3061 (while t
3062 (forward-sexp 1)
3063 (verilog-skip-forward-comment-or-string)
3064 (cond ((looking-at "[ \t]*;")
3065 (skip-chars-forward "^;")
3066 (forward-char 1)
3067 (throw 'found (point)))
3068 ((save-excursion
3069 (forward-sexp -1)
3070 (looking-at verilog-beg-block-re))
3071 (goto-char (match-beginning 0))
3072 (throw 'found nil))
3073 ((looking-at "[ \t]*)")
3074 (throw 'found (point)))
3075 ((eobp)
3076 (throw 'found (point))))))))
3077 (if (not pos)
3078 ;; Skip a whole block
3079 (catch 'found
3080 (while t
3081 (verilog-re-search-forward verilog-end-statement-re nil 'move)
3082 (setq nest (if (match-end 1)
3083 (1+ nest)
3084 (1- nest)))
3085 (cond ((eobp)
3086 (throw 'found (point)))
3087 ((= 0 nest)
3088 (throw 'found (verilog-end-of-statement))))))
3089 pos)))
3090
3091 (defun verilog-in-case-region-p ()
3092 "Return true if in a case region.
3093 More specifically, point @ in the line foo : @ begin"
3094 (interactive)
3095 (save-excursion
3096 (if (and
3097 (progn (verilog-forward-syntactic-ws)
3098 (looking-at "\\<begin\\>"))
3099 (progn (verilog-backward-syntactic-ws)
3100 (= (preceding-char) ?\:)))
3101 (catch 'found
3102 (let ((nest 1))
3103 (while t
3104 (verilog-re-search-backward
3105 (concat "\\(\\<module\\>\\)\\|\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|"
3106 "\\(\\<endcase\\>\\)\\>")
3107 nil 'move)
3108 (cond
3109 ((match-end 3)
3110 (setq nest (1+ nest)))
3111 ((match-end 2)
3112 (if (= nest 1)
3113 (throw 'found 1))
3114 (setq nest (1- nest)))
3115 (t
3116 (throw 'found (= nest 0)))))))
3117 nil)))
3118 (defun verilog-in-struct-region-p ()
3119 "Return true if in a struct region.
3120 More specifically, in a list after a struct|union keyword."
3121 (interactive)
3122 (save-excursion
3123 (let* ((state (verilog-syntax-ppss))
3124 (depth (nth 0 state)))
3125 (if depth
3126 (progn (backward-up-list depth)
3127 (verilog-beg-of-statement)
3128 (looking-at "\\<typedef\\>?\\s-*\\<struct\\|union\\>"))))))
3129
3130 (defun verilog-in-generate-region-p ()
3131 "Return true if in a generate region.
3132 More specifically, after a generate and before an endgenerate."
3133 (interactive)
3134 (let ((lim (save-excursion (verilog-beg-of-defun) (point)))
3135 (nest 1))
3136 (save-excursion
3137 (while (and
3138 (/= nest 0)
3139 (verilog-re-search-backward "\\<\\(generate\\)\\|\\(endgenerate\\)\\>" lim 'move)
3140 (cond
3141 ((match-end 1) ; generate
3142 (setq nest (1- nest)))
3143 ((match-end 2) ; endgenerate
3144 (setq nest (1+ nest)))))))
3145 (= nest 0) )) ; return nest
3146
3147 (defun verilog-in-fork-region-p ()
3148 "Return true if between a fork and join."
3149 (interactive)
3150 (let ((lim (save-excursion (verilog-beg-of-defun) (point)))
3151 (nest 1))
3152 (save-excursion
3153 (while (and
3154 (/= nest 0)
3155 (verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\(_any\\|_none\\)?\\)\\>" lim 'move)
3156 (cond
3157 ((match-end 1) ; fork
3158 (setq nest (1- nest)))
3159 ((match-end 2) ; join
3160 (setq nest (1+ nest)))))))
3161 (= nest 0) )) ; return nest
3162
3163 (defun verilog-backward-case-item (lim)
3164 "Skip backward to nearest enclosing case item.
3165 Limit search to point LIM."
3166 (interactive)
3167 (let ((str 'nil)
3168 (lim1
3169 (progn
3170 (save-excursion
3171 (verilog-re-search-backward verilog-endcomment-reason-re
3172 lim 'move)
3173 (point)))))
3174 ;; Try to find the real :
3175 (if (save-excursion (search-backward ":" lim1 t))
3176 (let ((colon 0)
3177 b e )
3178 (while
3179 (and
3180 (< colon 1)
3181 (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)"
3182 lim1 'move))
3183 (cond
3184 ((match-end 1) ;; [
3185 (setq colon (1+ colon))
3186 (if (>= colon 0)
3187 (error "%s: unbalanced [" (verilog-point-text))))
3188 ((match-end 2) ;; ]
3189 (setq colon (1- colon)))
3190
3191 ((match-end 3) ;; :
3192 (setq colon (1+ colon)))))
3193 ;; Skip back to beginning of case item
3194 (skip-chars-backward "\t ")
3195 (verilog-skip-backward-comment-or-string)
3196 (setq e (point))
3197 (setq b
3198 (progn
3199 (if
3200 (verilog-re-search-backward
3201 "\\<\\(case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move)
3202 (progn
3203 (cond
3204 ((match-end 1)
3205 (goto-char (match-end 1))
3206 (verilog-forward-ws&directives)
3207 (if (looking-at "(")
3208 (progn
3209 (forward-sexp)
3210 (verilog-forward-ws&directives)))
3211 (point))
3212 (t
3213 (goto-char (match-end 0))
3214 (verilog-forward-ws&directives)
3215 (point))))
3216 (error "Malformed case item"))))
3217 (setq str (buffer-substring b e))
3218 (if
3219 (setq e
3220 (string-match
3221 "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
3222 (setq str (concat (substring str 0 e) "...")))
3223 str)
3224 'nil)))
3225 \f
3226
3227 ;;
3228 ;; Other functions
3229 ;;
3230
3231 (defun verilog-kill-existing-comment ()
3232 "Kill auto comment on this line."
3233 (save-excursion
3234 (let* (
3235 (e (progn
3236 (end-of-line)
3237 (point)))
3238 (b (progn
3239 (beginning-of-line)
3240 (search-forward "//" e t))))
3241 (if b
3242 (delete-region (- b 2) e)))))
3243
3244 (defconst verilog-directive-nest-re
3245 (concat "\\(`else\\>\\)\\|"
3246 "\\(`endif\\>\\)\\|"
3247 "\\(`if\\>\\)\\|"
3248 "\\(`ifdef\\>\\)\\|"
3249 "\\(`ifndef\\>\\)"))
3250 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment)
3251 "Add ending comment with given INDENT-STR.
3252 With KILL-EXISTING-COMMENT, remove what was there before.
3253 Insert `// case: 7 ' or `// NAME ' on this line if appropriate.
3254 Insert `// case expr ' if this line ends a case block.
3255 Insert `// ifdef FOO ' if this line ends code conditional on FOO.
3256 Insert `// NAME ' if this line ends a function, task, module,
3257 primitive or interface named NAME."
3258 (save-excursion
3259 (cond
3260 (; Comment close preprocessor directives
3261 (and
3262 (looking-at "\\(`endif\\)\\|\\(`else\\)")
3263 (or kill-existing-comment
3264 (not (save-excursion
3265 (end-of-line)
3266 (search-backward "//" (verilog-get-beg-of-line) t)))))
3267 (let ((nest 1) b e
3268 m
3269 (else (if (match-end 2) "!" " ")))
3270 (end-of-line)
3271 (if kill-existing-comment
3272 (verilog-kill-existing-comment))
3273 (delete-horizontal-space)
3274 (save-excursion
3275 (backward-sexp 1)
3276 (while (and (/= nest 0)
3277 (verilog-re-search-backward verilog-directive-nest-re nil 'move))
3278 (cond
3279 ((match-end 1) ; `else
3280 (if (= nest 1)
3281 (setq else "!")))
3282 ((match-end 2) ; `endif
3283 (setq nest (1+ nest)))
3284 ((match-end 3) ; `if
3285 (setq nest (1- nest)))
3286 ((match-end 4) ; `ifdef
3287 (setq nest (1- nest)))
3288 ((match-end 5) ; `ifndef
3289 (setq nest (1- nest)))))
3290 (if (match-end 0)
3291 (setq
3292 m (buffer-substring
3293 (match-beginning 0)
3294 (match-end 0))
3295 b (progn
3296 (skip-chars-forward "^ \t")
3297 (verilog-forward-syntactic-ws)
3298 (point))
3299 e (progn
3300 (skip-chars-forward "a-zA-Z0-9_")
3301 (point)))))
3302 (if b
3303 (if (> (count-lines (point) b) verilog-minimum-comment-distance)
3304 (insert (concat " // " else m " " (buffer-substring b e))))
3305 (progn
3306 (insert " // unmatched `else or `endif")
3307 (ding 't)))))
3308
3309 (; Comment close case/class/function/task/module and named block
3310 (and (looking-at "\\<end")
3311 (or kill-existing-comment
3312 (not (save-excursion
3313 (end-of-line)
3314 (search-backward "//" (verilog-get-beg-of-line) t)))))
3315 (let ((type (car indent-str)))
3316 (unless (eq type 'declaration)
3317 (unless (looking-at (concat "\\(" verilog-end-block-ordered-re "\\)[ \t]*:")) ;; ignore named ends
3318 (if (looking-at verilog-end-block-ordered-re)
3319 (cond
3320 (;- This is a case block; search back for the start of this case
3321 (match-end 1) ;; of verilog-end-block-ordered-re
3322
3323 (let ((err 't)
3324 (str "UNMATCHED!!"))
3325 (save-excursion
3326 (verilog-leap-to-head)
3327 (cond
3328 ((looking-at "\\<randcase\\>")
3329 (setq str "randcase")
3330 (setq err nil))
3331 ((match-end 0)
3332 (goto-char (match-end 1))
3333 (if nil
3334 (let (s f)
3335 (setq s (match-beginning 1))
3336 (setq f (progn (end-of-line)
3337 (point)))
3338 (setq str (buffer-substring s f)))
3339 (setq err nil))
3340 (setq str (concat (buffer-substring (match-beginning 1) (match-end 1))
3341 " "
3342 (verilog-get-expr))))))
3343 (end-of-line)
3344 (if kill-existing-comment
3345 (verilog-kill-existing-comment))
3346 (delete-horizontal-space)
3347 (insert (concat " // " str ))
3348 (if err (ding 't))))
3349
3350 (;- This is a begin..end block
3351 (match-end 2) ;; of verilog-end-block-ordered-re
3352 (let ((str " // UNMATCHED !!")
3353 (err 't)
3354 (here (point))
3355 there
3356 cntx)
3357 (save-excursion
3358 (verilog-leap-to-head)
3359 (setq there (point))
3360 (if (not (match-end 0))
3361 (progn
3362 (goto-char here)
3363 (end-of-line)
3364 (if kill-existing-comment
3365 (verilog-kill-existing-comment))
3366 (delete-horizontal-space)
3367 (insert str)
3368 (ding 't))
3369 (let ((lim
3370 (save-excursion (verilog-beg-of-defun) (point)))
3371 (here (point)))
3372 (cond
3373 (;-- handle named block differently
3374 (looking-at verilog-named-block-re)
3375 (search-forward ":")
3376 (setq there (point))
3377 (setq str (verilog-get-expr))
3378 (setq err nil)
3379 (setq str (concat " // block: " str )))
3380
3381 ((verilog-in-case-region-p) ;-- handle case item differently
3382 (goto-char here)
3383 (setq str (verilog-backward-case-item lim))
3384 (setq there (point))
3385 (setq err nil)
3386 (setq str (concat " // case: " str )))
3387
3388 (;- try to find "reason" for this begin
3389 (cond
3390 (;
3391 (eq here (progn
3392 (verilog-backward-token)
3393 (verilog-beg-of-statement-1)
3394 (point)))
3395 (setq err nil)
3396 (setq str ""))
3397 ((looking-at verilog-endcomment-reason-re)
3398 (setq there (match-end 0))
3399 (setq cntx (concat
3400 (buffer-substring (match-beginning 0) (match-end 0)) " "))
3401 (cond
3402 (;- begin
3403 (match-end 2)
3404 (setq err nil)
3405 (save-excursion
3406 (if (and (verilog-continued-line)
3407 (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>"))
3408 (progn
3409 (goto-char (match-end 0))
3410 (setq there (point))
3411 (setq str
3412 (concat " // "
3413 (buffer-substring (match-beginning 0) (match-end 0)) " "
3414 (verilog-get-expr))))
3415 (setq str ""))))
3416
3417 (;- else
3418 (match-end 4)
3419 (let ((nest 0)
3420 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)"))
3421 (catch 'skip
3422 (while (verilog-re-search-backward reg nil 'move)
3423 (cond
3424 ((match-end 1) ; begin
3425 (setq nest (1- nest)))
3426 ((match-end 2) ; end
3427 (setq nest (1+ nest)))
3428 ((match-end 3)
3429 (if (= 0 nest)
3430 (progn
3431 (goto-char (match-end 0))
3432 (setq there (point))
3433 (setq err nil)
3434 (setq str (verilog-get-expr))
3435 (setq str (concat " // else: !if" str ))
3436 (throw 'skip 1)))))))))
3437
3438 (;- end else
3439 (match-end 5)
3440 (goto-char there)
3441 (let ((nest 0)
3442 (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)"))
3443 (catch 'skip
3444 (while (verilog-re-search-backward reg nil 'move)
3445 (cond
3446 ((match-end 1) ; begin
3447 (setq nest (1- nest)))
3448 ((match-end 2) ; end
3449 (setq nest (1+ nest)))
3450 ((match-end 3)
3451 (if (= 0 nest)
3452 (progn
3453 (goto-char (match-end 0))
3454 (setq there (point))
3455 (setq err nil)
3456 (setq str (verilog-get-expr))
3457 (setq str (concat " // else: !if" str ))
3458 (throw 'skip 1)))))))))
3459
3460 (;- task/function/initial et cetera
3461 t
3462 (match-end 0)
3463 (goto-char (match-end 0))
3464 (setq there (point))
3465 (setq err nil)
3466 (setq str (verilog-get-expr))
3467 (setq str (concat " // " cntx str )))
3468
3469 (;-- otherwise...
3470 (setq str " // auto-endcomment confused "))))
3471
3472 ((and
3473 (verilog-in-case-region-p) ;-- handle case item differently
3474 (progn
3475 (setq there (point))
3476 (goto-char here)
3477 (setq str (verilog-backward-case-item lim))))
3478 (setq err nil)
3479 (setq str (concat " // case: " str )))
3480
3481 ((verilog-in-fork-region-p)
3482 (setq err nil)
3483 (setq str " // fork branch" ))
3484
3485 ((looking-at "\\<end\\>")
3486 ;; HERE
3487 (forward-word 1)
3488 (verilog-forward-syntactic-ws)
3489 (setq err nil)
3490 (setq str (verilog-get-expr))
3491 (setq str (concat " // " cntx str )))
3492
3493 ))))
3494 (goto-char here)
3495 (end-of-line)
3496 (if kill-existing-comment
3497 (verilog-kill-existing-comment))
3498 (delete-horizontal-space)
3499 (if (or err
3500 (> (count-lines here there) verilog-minimum-comment-distance))
3501 (insert str))
3502 (if err (ding 't))
3503 ))))
3504 (;- this is endclass, which can be nested
3505 (match-end 11) ;; of verilog-end-block-ordered-re
3506 ;;(goto-char there)
3507 (let ((nest 0)
3508 (reg "\\<\\(class\\)\\|\\(endclass\\)\\|\\(package\\|primitive\\|\\(macro\\)?module\\)\\>")
3509 string)
3510 (save-excursion
3511 (catch 'skip
3512 (while (verilog-re-search-backward reg nil 'move)
3513 (cond
3514 ((match-end 3) ; endclass
3515 (ding 't)
3516 (setq string "unmatched endclass")
3517 (throw 'skip 1))
3518
3519 ((match-end 2) ; endclass
3520 (setq nest (1+ nest)))
3521
3522 ((match-end 1) ; class
3523 (setq nest (1- nest))
3524 (if (< nest 0)
3525 (progn
3526 (goto-char (match-end 0))
3527 (let (b e)
3528 (setq b (progn
3529 (skip-chars-forward "^ \t")
3530 (verilog-forward-ws&directives)
3531 (point))
3532 e (progn
3533 (skip-chars-forward "a-zA-Z0-9_")
3534 (point)))
3535 (setq string (buffer-substring b e)))
3536 (throw 'skip 1))))
3537 ))))
3538 (end-of-line)
3539 (insert (concat " // " string ))))
3540
3541 (;- this is end{function,generate,task,module,primitive,table,generate}
3542 ;- which can not be nested.
3543 t
3544 (let (string reg (name-re nil))
3545 (end-of-line)
3546 (if kill-existing-comment
3547 (save-match-data
3548 (verilog-kill-existing-comment)))
3549 (delete-horizontal-space)
3550 (backward-sexp)
3551 (cond
3552 ((match-end 5) ;; of verilog-end-block-ordered-re
3553 (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)")
3554 (setq name-re "\\w+\\s-*(")
3555 )
3556 ((match-end 6) ;; of verilog-end-block-ordered-re
3557 (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)"))
3558 ((match-end 7) ;; of verilog-end-block-ordered-re
3559 (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>"))
3560 ((match-end 8) ;; of verilog-end-block-ordered-re
3561 (setq reg "\\(\\<primitive\\>\\)\\|\\(\\<\\(endprimitive\\|package\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
3562 ((match-end 9) ;; of verilog-end-block-ordered-re
3563 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<\\(endinterface\\|package\\|primitive\\|\\(macro\\)?module\\)\\>\\)"))
3564 ((match-end 10) ;; of verilog-end-block-ordered-re
3565 (setq reg "\\(\\<package\\>\\)\\|\\(\\<\\(endpackage\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
3566 ((match-end 11) ;; of verilog-end-block-ordered-re
3567 (setq reg "\\(\\<class\\>\\)\\|\\(\\<\\(endclass\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
3568 ((match-end 12) ;; of verilog-end-block-ordered-re
3569 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<\\(endcovergroup\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
3570 ((match-end 13) ;; of verilog-end-block-ordered-re
3571 (setq reg "\\(\\<program\\>\\)\\|\\(\\<\\(endprogram\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
3572 ((match-end 14) ;; of verilog-end-block-ordered-re
3573 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<\\(endsequence\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)"))
3574 ((match-end 15) ;; of verilog-end-block-ordered-re
3575 (setq reg "\\(\\<clocking\\>\\)\\|\\<endclocking\\>"))
3576
3577 (t (error "Problem in verilog-set-auto-endcomments")))
3578 (let (b e)
3579 (save-excursion
3580 (verilog-re-search-backward reg nil 'move)
3581 (cond
3582 ((match-end 1)
3583 (setq b (progn
3584 (skip-chars-forward "^ \t")
3585 (verilog-forward-ws&directives)
3586 (if (and name-re (verilog-re-search-forward name-re nil 'move))
3587 (progn
3588 (goto-char (match-beginning 0))
3589 (verilog-forward-ws&directives)))
3590 (point))
3591 e (progn
3592 (skip-chars-forward "a-zA-Z0-9_")
3593 (point)))
3594 (setq string (buffer-substring b e)))
3595 (t
3596 (ding 't)
3597 (setq string "unmatched end(function|task|module|primitive|interface|package|class|clocking)")))))
3598 (end-of-line)
3599 (insert (concat " // " string )))
3600 ))))))))))
3601
3602 (defun verilog-get-expr()
3603 "Grab expression at point, e.g, case ( a | b & (c ^d))."
3604 (let* ((b (progn
3605 (verilog-forward-syntactic-ws)
3606 (skip-chars-forward " \t")
3607 (point)))
3608 (e (let ((par 1))
3609 (cond
3610 ((looking-at "@")
3611 (forward-char 1)
3612 (verilog-forward-syntactic-ws)
3613 (if (looking-at "(")
3614 (progn
3615 (forward-char 1)
3616 (while (and (/= par 0)
3617 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
3618 (cond
3619 ((match-end 1)
3620 (setq par (1+ par)))
3621 ((match-end 2)
3622 (setq par (1- par)))))))
3623 (point))
3624 ((looking-at "(")
3625 (forward-char 1)
3626 (while (and (/= par 0)
3627 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move))
3628 (cond
3629 ((match-end 1)
3630 (setq par (1+ par)))
3631 ((match-end 2)
3632 (setq par (1- par)))))
3633 (point))
3634 ((looking-at "\\[")
3635 (forward-char 1)
3636 (while (and (/= par 0)
3637 (verilog-re-search-forward "\\(\\[\\)\\|\\(\\]\\)" nil 'move))
3638 (cond
3639 ((match-end 1)
3640 (setq par (1+ par)))
3641 ((match-end 2)
3642 (setq par (1- par)))))
3643 (verilog-forward-syntactic-ws)
3644 (skip-chars-forward "^ \t\n\f")
3645 (point))
3646 ((looking-at "/[/\\*]")
3647 b)
3648 ('t
3649 (skip-chars-forward "^: \t\n\f")
3650 (point)))))
3651 (str (buffer-substring b e)))
3652 (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str))
3653 (setq str (concat (substring str 0 e) "...")))
3654 str))
3655
3656 (defun verilog-expand-vector ()
3657 "Take a signal vector on the current line and expand it to multiple lines.
3658 Useful for creating tri's and other expanded fields."
3659 (interactive)
3660 (verilog-expand-vector-internal "[" "]"))
3661
3662 (defun verilog-expand-vector-internal (bra ket)
3663 "Given BRA, the start brace and KET, the end brace, expand one line into many lines."
3664 (save-excursion
3665 (forward-line 0)
3666 (let ((signal-string (buffer-substring (point)
3667 (progn
3668 (end-of-line) (point)))))
3669 (if (string-match
3670 (concat "\\(.*\\)"
3671 (regexp-quote bra)
3672 "\\([0-9]*\\)\\(:[0-9]*\\|\\)\\(::[0-9---]*\\|\\)"
3673 (regexp-quote ket)
3674 "\\(.*\\)$") signal-string)
3675 (let* ((sig-head (match-string 1 signal-string))
3676 (vec-start (string-to-number (match-string 2 signal-string)))
3677 (vec-end (if (= (match-beginning 3) (match-end 3))
3678 vec-start
3679 (string-to-number
3680 (substring signal-string (1+ (match-beginning 3))
3681 (match-end 3)))))
3682 (vec-range
3683 (if (= (match-beginning 4) (match-end 4))
3684 1
3685 (string-to-number
3686 (substring signal-string (+ 2 (match-beginning 4))
3687 (match-end 4)))))
3688 (sig-tail (match-string 5 signal-string))
3689 vec)
3690 ;; Decode vectors
3691 (setq vec nil)
3692 (if (< vec-range 0)
3693 (let ((tmp vec-start))
3694 (setq vec-start vec-end
3695 vec-end tmp
3696 vec-range (- vec-range))))
3697 (if (< vec-end vec-start)
3698 (while (<= vec-end vec-start)
3699 (setq vec (append vec (list vec-start)))
3700 (setq vec-start (- vec-start vec-range)))
3701 (while (<= vec-start vec-end)
3702 (setq vec (append vec (list vec-start)))
3703 (setq vec-start (+ vec-start vec-range))))
3704 ;;
3705 ;; Delete current line
3706 (delete-region (point) (progn (forward-line 0) (point)))
3707 ;;
3708 ;; Expand vector
3709 (while vec
3710 (insert (concat sig-head bra
3711 (int-to-string (car vec)) ket sig-tail "\n"))
3712 (setq vec (cdr vec)))
3713 (delete-char -1)
3714 ;;
3715 )))))
3716
3717 (defun verilog-strip-comments ()
3718 "Strip all comments from the Verilog code."
3719 (interactive)
3720 (goto-char (point-min))
3721 (while (re-search-forward "//" nil t)
3722 (if (verilog-within-string)
3723 (re-search-forward "\"" nil t)
3724 (if (verilog-in-star-comment-p)
3725 (re-search-forward "\*/" nil t)
3726 (let ((bpt (- (point) 2)))
3727 (end-of-line)
3728 (delete-region bpt (point))))))
3729 ;;
3730 (goto-char (point-min))
3731 (while (re-search-forward "/\\*" nil t)
3732 (if (verilog-within-string)
3733 (re-search-forward "\"" nil t)
3734 (let ((bpt (- (point) 2)))
3735 (re-search-forward "\\*/")
3736 (delete-region bpt (point))))))
3737
3738 (defun verilog-one-line ()
3739 "Convert structural Verilog instances to occupy one line."
3740 (interactive)
3741 (goto-char (point-min))
3742 (while (re-search-forward "\\([^;]\\)[ \t]*\n[ \t]*" nil t)
3743 (replace-match "\\1 " nil nil)))
3744
3745 (defun verilog-linter-name ()
3746 "Return name of linter, either surelint or verilint."
3747 (let ((compile-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
3748 compile-command))
3749 (lint-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil
3750 verilog-linter)))
3751 (cond ((equal compile-word1 "surelint") `surelint)
3752 ((equal compile-word1 "verilint") `verilint)
3753 ((equal lint-word1 "surelint") `surelint)
3754 ((equal lint-word1 "verilint") `verilint)
3755 (t `surelint)))) ;; back compatibility
3756
3757 (defun verilog-lint-off ()
3758 "Convert a Verilog linter warning line into a disable statement.
3759 For example:
3760 pci_bfm_null.v, line 46: Unused input: pci_rst_
3761 becomes a comment for the appropriate tool.
3762
3763 The first word of the `compile-command' or `verilog-linter'
3764 variables is used to determine which product is being used.
3765
3766 See \\[verilog-surelint-off] and \\[verilog-verilint-off]."
3767 (interactive)
3768 (let ((linter (verilog-linter-name)))
3769 (cond ((equal linter `surelint)
3770 (verilog-surelint-off))
3771 ((equal linter `verilint)
3772 (verilog-verilint-off))
3773 (t (error "Linter name not set")))))
3774
3775 (defvar compilation-last-buffer)
3776
3777 (defun verilog-surelint-off ()
3778 "Convert a SureLint warning line into a disable statement.
3779 Run from Verilog source window; assumes there is a *compile* buffer
3780 with point set appropriately.
3781
3782 For example:
3783 WARNING [STD-UDDONX]: xx.v, line 8: output out is never assigned.
3784 becomes:
3785 // surefire lint_line_off UDDONX"
3786 (interactive)
3787 (let ((buff (if (boundp 'next-error-last-buffer)
3788 next-error-last-buffer
3789 compilation-last-buffer)))
3790 (when (buffer-live-p buff)
3791 ;; FIXME with-current-buffer?
3792 (save-excursion
3793 (switch-to-buffer buff)
3794 (beginning-of-line)
3795 (when
3796 (looking-at "\\(INFO\\|WARNING\\|ERROR\\) \\[[^-]+-\\([^]]+\\)\\]: \\([^,]+\\), line \\([0-9]+\\): \\(.*\\)$")
3797 (let* ((code (match-string 2))
3798 (file (match-string 3))
3799 (line (match-string 4))
3800 (buffer (get-file-buffer file))
3801 dir filename)
3802 (unless buffer
3803 (progn
3804 (setq buffer
3805 (and (file-exists-p file)
3806 (find-file-noselect file)))
3807 (or buffer
3808 (let* ((pop-up-windows t))
3809 (let ((name (expand-file-name
3810 (read-file-name
3811 (format "Find this error in: (default %s) "
3812 file)
3813 dir file t))))
3814 (if (file-directory-p name)
3815 (setq name (expand-file-name filename name)))
3816 (setq buffer
3817 (and (file-exists-p name)
3818 (find-file-noselect name))))))))
3819 (switch-to-buffer buffer)
3820 (goto-line (string-to-number line))
3821 (end-of-line)
3822 (catch 'already
3823 (cond
3824 ((verilog-in-slash-comment-p)
3825 (re-search-backward "//")
3826 (cond
3827 ((looking-at "// surefire lint_off_line ")
3828 (goto-char (match-end 0))
3829 (let ((lim (save-excursion (end-of-line) (point))))
3830 (if (re-search-forward code lim 'move)
3831 (throw 'already t)
3832 (insert (concat " " code)))))
3833 (t
3834 )))
3835 ((verilog-in-star-comment-p)
3836 (re-search-backward "/\*")
3837 (insert (format " // surefire lint_off_line %6s" code )))
3838 (t
3839 (insert (format " // surefire lint_off_line %6s" code ))
3840 )))))))))
3841
3842 (defun verilog-verilint-off ()
3843 "Convert a Verilint warning line into a disable statement.
3844
3845 For example:
3846 (W240) pci_bfm_null.v, line 46: Unused input: pci_rst_
3847 becomes:
3848 //Verilint 240 off // WARNING: Unused input"
3849 (interactive)
3850 (save-excursion
3851 (beginning-of-line)
3852 (when (looking-at "\\(.*\\)([WE]\\([0-9A-Z]+\\)).*,\\s +line\\s +[0-9]+:\\s +\\([^:\n]+\\):?.*$")
3853 (replace-match (format
3854 ;; %3s makes numbers 1-999 line up nicely
3855 "\\1//Verilint %3s off // WARNING: \\3"
3856 (match-string 2)))
3857 (beginning-of-line)
3858 (verilog-indent-line))))
3859
3860 (defun verilog-auto-save-compile ()
3861 "Update automatics with \\[verilog-auto], save the buffer, and compile."
3862 (interactive)
3863 (verilog-auto) ; Always do it for safety
3864 (save-buffer)
3865 (compile compile-command))
3866
3867 \f
3868
3869 ;;
3870 ;; Batch
3871 ;;
3872
3873 (defmacro verilog-batch-error-wrapper (&rest body)
3874 "Execute BODY and add error prefix to any errors found.
3875 This lets programs calling batch mode to easily extract error messages."
3876 `(condition-case err
3877 (progn ,@body)
3878 (error
3879 (error "%%Error: %s%s" (error-message-string err)
3880 (if (featurep 'xemacs) "\n" ""))))) ;; XEmacs forgets to add a newline
3881
3882 (defun verilog-batch-execute-func (funref)
3883 "Internal processing of a batch command, running FUNREF on all command arguments."
3884 (verilog-batch-error-wrapper
3885 ;; General globals needed
3886 (setq make-backup-files nil)
3887 (setq-default make-backup-files nil)
3888 (setq enable-local-variables t)
3889 (setq enable-local-eval t)
3890 ;; Make sure any sub-files we read get proper mode
3891 (setq default-major-mode `verilog-mode)
3892 ;; Ditto files already read in
3893 (mapc (lambda (buf)
3894 (when (buffer-file-name buf)
3895 (save-excursion
3896 (set-buffer buf)
3897 (verilog-mode))))
3898 (buffer-list))
3899 ;; Process the files
3900 (mapcar '(lambda (buf)
3901 (when (buffer-file-name buf)
3902 (save-excursion
3903 (if (not (file-exists-p (buffer-file-name buf)))
3904 (error
3905 (concat "File not found: " (buffer-file-name buf))))
3906 (message (concat "Processing " (buffer-file-name buf)))
3907 (set-buffer buf)
3908 (funcall funref)
3909 (save-buffer))))
3910 (buffer-list))))
3911
3912 (defun verilog-batch-auto ()
3913 "For use with --batch, perform automatic expansions as a stand-alone tool.
3914 This sets up the appropriate Verilog mode environment, updates automatics
3915 with \\[verilog-auto] on all command-line files, and saves the buffers.
3916 For proper results, multiple filenames need to be passed on the command
3917 line in bottom-up order."
3918 (unless noninteractive
3919 (error "Use verilog-batch-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
3920 (verilog-batch-execute-func `verilog-auto))
3921
3922 (defun verilog-batch-delete-auto ()
3923 "For use with --batch, perform automatic deletion as a stand-alone tool.
3924 This sets up the appropriate Verilog mode environment, deletes automatics
3925 with \\[verilog-delete-auto] on all command-line files, and saves the buffers."
3926 (unless noninteractive
3927 (error "Use verilog-batch-delete-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
3928 (verilog-batch-execute-func `verilog-delete-auto))
3929
3930 (defun verilog-batch-inject-auto ()
3931 "For use with --batch, perform automatic injection as a stand-alone tool.
3932 This sets up the appropriate Verilog mode environment, injects new automatics
3933 with \\[verilog-inject-auto] on all command-line files, and saves the buffers.
3934 For proper results, multiple filenames need to be passed on the command
3935 line in bottom-up order."
3936 (unless noninteractive
3937 (error "Use verilog-batch-inject-auto only with --batch")) ;; Otherwise we'd mess up buffer modes
3938 (verilog-batch-execute-func `verilog-inject-auto))
3939
3940 (defun verilog-batch-indent ()
3941 "For use with --batch, reindent an a entire file as a stand-alone tool.
3942 This sets up the appropriate Verilog mode environment, calls
3943 \\[verilog-indent-buffer] on all command-line files, and saves the buffers."
3944 (unless noninteractive
3945 (error "Use verilog-batch-indent only with --batch")) ;; Otherwise we'd mess up buffer modes
3946 (verilog-batch-execute-func `verilog-indent-buffer))
3947 \f
3948
3949 ;;
3950 ;; Indentation
3951 ;;
3952 (defconst verilog-indent-alist
3953 '((block . (+ ind verilog-indent-level))
3954 (case . (+ ind verilog-case-indent))
3955 (cparenexp . (+ ind verilog-indent-level))
3956 (cexp . (+ ind verilog-cexp-indent))
3957 (defun . verilog-indent-level-module)
3958 (declaration . verilog-indent-level-declaration)
3959 (directive . (verilog-calculate-indent-directive))
3960 (tf . verilog-indent-level)
3961 (behavioral . (+ verilog-indent-level-behavioral verilog-indent-level-module))
3962 (statement . ind)
3963 (cpp . 0)
3964 (comment . (verilog-comment-indent))
3965 (unknown . 3)
3966 (string . 0)))
3967
3968 (defun verilog-continued-line-1 (lim)
3969 "Return true if this is a continued line.
3970 Set point to where line starts. Limit search to point LIM."
3971 (let ((continued 't))
3972 (if (eq 0 (forward-line -1))
3973 (progn
3974 (end-of-line)
3975 (verilog-backward-ws&directives lim)
3976 (if (bobp)
3977 (setq continued nil)
3978 (setq continued (verilog-backward-token))))
3979 (setq continued nil))
3980 continued))
3981
3982 (defun verilog-calculate-indent ()
3983 "Calculate the indent of the current Verilog line.
3984 Examine previous lines. Once a line is found that is definitive as to the
3985 type of the current line, return that lines' indent level and its type.
3986 Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)."
3987 (save-excursion
3988 (let* ((starting_position (point))
3989 (par 0)
3990 (begin (looking-at "[ \t]*begin\\>"))
3991 (lim (save-excursion (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil t)))
3992 (type (catch 'nesting
3993 ;; Keep working backwards until we can figure out
3994 ;; what type of statement this is.
3995 ;; Basically we need to figure out
3996 ;; 1) if this is a continuation of the previous line;
3997 ;; 2) are we in a block scope (begin..end)
3998
3999 ;; if we are in a comment, done.
4000 (if (verilog-in-star-comment-p)
4001 (throw 'nesting 'comment))
4002
4003 ;; if we have a directive, done.
4004 (if (save-excursion (beginning-of-line) (looking-at verilog-directive-re-1))
4005 (throw 'nesting 'directive))
4006
4007 ;; unless we are in the newfangled coverpoint or constraint blocks
4008 ;; if we are in a parenthesized list, and the user likes to indent these, return.
4009 (if (and
4010 verilog-indent-lists
4011 (not (verilog-in-coverage))
4012 (verilog-in-paren))
4013 (progn (setq par 1)
4014 (throw 'nesting 'block)))
4015
4016 ;; See if we are continuing a previous line
4017 (while t
4018 ;; trap out if we crawl off the top of the buffer
4019 (if (bobp) (throw 'nesting 'cpp))
4020
4021 (if (verilog-continued-line-1 lim)
4022 (let ((sp (point)))
4023 (if (and
4024 (not (looking-at verilog-complete-reg))
4025 (verilog-continued-line-1 lim))
4026 (progn (goto-char sp)
4027 (throw 'nesting 'cexp))
4028
4029 (goto-char sp))
4030
4031 (if (and begin
4032 (not verilog-indent-begin-after-if)
4033 (looking-at verilog-no-indent-begin-re))
4034 (progn
4035 (beginning-of-line)
4036 (skip-chars-forward " \t")
4037 (throw 'nesting 'statement))
4038 (progn
4039 (throw 'nesting 'cexp))))
4040 ;; not a continued line
4041 (goto-char starting_position))
4042
4043 (if (looking-at "\\<else\\>")
4044 ;; search back for governing if, striding across begin..end pairs
4045 ;; appropriately
4046 (let ((elsec 1))
4047 (while (verilog-re-search-backward verilog-ends-re nil 'move)
4048 (cond
4049 ((match-end 1) ; else, we're in deep
4050 (setq elsec (1+ elsec)))
4051 ((match-end 2) ; if
4052 (setq elsec (1- elsec))
4053 (if (= 0 elsec)
4054 (if verilog-align-ifelse
4055 (throw 'nesting 'statement)
4056 (progn ;; back up to first word on this line
4057 (beginning-of-line)
4058 (verilog-forward-syntactic-ws)
4059 (throw 'nesting 'statement)))))
4060 (t ; endblock
4061 ; try to leap back to matching outward block by striding across
4062 ; indent level changing tokens then immediately
4063 ; previous line governs indentation.
4064 (let (( reg) (nest 1))
4065 ;; verilog-ends => else|if|end|join(_any|_none|)|endcase|endclass|endtable|endspecify|endfunction|endtask|endgenerate|endgroup
4066 (cond
4067 ((match-end 3) ; end
4068 ;; Search back for matching begin
4069 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
4070 ((match-end 4) ; endcase
4071 ;; Search back for matching case
4072 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
4073 ((match-end 5) ; endfunction
4074 ;; Search back for matching function
4075 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
4076 ((match-end 6) ; endtask
4077 ;; Search back for matching task
4078 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" ))
4079 ((match-end 7) ; endspecify
4080 ;; Search back for matching specify
4081 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
4082 ((match-end 8) ; endtable
4083 ;; Search back for matching table
4084 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
4085 ((match-end 9) ; endgenerate
4086 ;; Search back for matching generate
4087 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
4088 ((match-end 10) ; joins
4089 ;; Search back for matching fork
4090 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|none\\)?\\>\\)" ))
4091 ((match-end 11) ; class
4092 ;; Search back for matching class
4093 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
4094 ((match-end 12) ; covergroup
4095 ;; Search back for matching covergroup
4096 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )))
4097 (catch 'skip
4098 (while (verilog-re-search-backward reg nil 'move)
4099 (cond
4100 ((match-end 1) ; begin
4101 (setq nest (1- nest))
4102 (if (= 0 nest)
4103 (throw 'skip 1)))
4104 ((match-end 2) ; end
4105 (setq nest (1+ nest)))))
4106 )))))))
4107 (throw 'nesting (verilog-calc-1)))
4108 );; catch nesting
4109 );; type
4110 )
4111 ;; Return type of block and indent level.
4112 (if (not type)
4113 (setq type 'cpp))
4114 (if (> par 0) ; Unclosed Parenthesis
4115 (list 'cparenexp par)
4116 (cond
4117 ((eq type 'case)
4118 (list type (verilog-case-indent-level)))
4119 ((eq type 'statement)
4120 (list type (current-column)))
4121 ((eq type 'defun)
4122 (list type 0))
4123 (t
4124 (list type (verilog-current-indent-level))))))))
4125
4126 (defun verilog-wai ()
4127 "Show matching nesting block for debugging."
4128 (interactive)
4129 (save-excursion
4130 (let* ((type (verilog-calc-1))
4131 depth)
4132 ;; Return type of block and indent level.
4133 (if (not type)
4134 (setq type 'cpp))
4135 (if (and
4136 verilog-indent-lists
4137 (not (verilog-in-coverage))
4138 (verilog-in-paren))
4139 (setq depth 1)
4140 (cond
4141 ((eq type 'case)
4142 (setq depth (verilog-case-indent-level)))
4143 ((eq type 'statement)
4144 (setq depth (current-column)))
4145 ((eq type 'defun)
4146 (setq depth 0))
4147 (t
4148 (setq depth (verilog-current-indent-level)))))
4149 (message "You are at nesting %s depth %d" type depth))))
4150
4151 (defun verilog-calc-1 ()
4152 (catch 'nesting
4153 (while (verilog-re-search-backward (concat "\\({\\|}\\|" verilog-indent-re "\\)") nil 'move)
4154 (cond
4155 ((equal (char-after) ?\{)
4156 (if (verilog-at-constraint-p)
4157 (throw 'nesting 'block)))
4158 ((equal (char-after) ?\})
4159
4160 (let ((there (verilog-at-close-constraint-p)))
4161 (if there (goto-char there))))
4162
4163 ((looking-at verilog-beg-block-re-ordered)
4164 (cond
4165 ((match-end 2) ; *sigh* could be "unique case" or "priority casex"
4166 (let ((here (point)))
4167 (verilog-beg-of-statement)
4168 (if (looking-at verilog-extended-case-re)
4169 (throw 'nesting 'case)
4170 (goto-char here)))
4171 (throw 'nesting 'case))
4172
4173 ((match-end 4) ; *sigh* could be "disable fork"
4174 (let ((here (point)))
4175 (verilog-beg-of-statement)
4176 (if (looking-at verilog-disable-fork-re)
4177 t ; is disable fork, this is a normal statement
4178 (progn ; or is fork, starts a new block
4179 (goto-char here)
4180 (throw 'nesting 'block)))))
4181
4182
4183 ;; need to consider typedef struct here...
4184 ((looking-at "\\<class\\|struct\\|function\\|task\\>")
4185 ; *sigh* These words have an optional prefix:
4186 ; extern {virtual|protected}? function a();
4187 ; typedef class foo;
4188 ; and we don't want to confuse this with
4189 ; function a();
4190 ; property
4191 ; ...
4192 ; endfunction
4193 (verilog-beg-of-statement)
4194 (if (looking-at verilog-beg-block-re-ordered)
4195 (throw 'nesting 'block)
4196 (throw 'nesting 'defun)))
4197
4198 ((looking-at "\\<property\\>")
4199 ; *sigh*
4200 ; {assert|assume|cover} property (); are complete
4201 ; but
4202 ; property ID () ... needs end_property
4203 (verilog-beg-of-statement)
4204 (if (looking-at "\\(assert\\|assume\\|cover\\)\\s-+property\\>")
4205 (throw 'nesting 'statement) ; We don't need an endproperty for these
4206 (throw 'nesting 'block) ;We still need a endproperty
4207 ))
4208
4209 (t (throw 'nesting 'block))))
4210
4211 ((looking-at verilog-end-block-re)
4212 (verilog-leap-to-head)
4213 (if (verilog-in-case-region-p)
4214 (progn
4215 (verilog-leap-to-case-head)
4216 (if (looking-at verilog-case-re)
4217 (throw 'nesting 'case)))))
4218
4219 ((looking-at (if (verilog-in-generate-region-p)
4220 verilog-defun-level-not-generate-re
4221 verilog-defun-level-re))
4222 (throw 'nesting 'defun))
4223
4224 ((looking-at verilog-cpp-level-re)
4225 (throw 'nesting 'cpp))
4226
4227 ((bobp)
4228 (throw 'nesting 'cpp))))
4229 (throw 'nesting 'cpp)))
4230
4231 (defun verilog-calculate-indent-directive ()
4232 "Return indentation level for directive.
4233 For speed, the searcher looks at the last directive, not the indent
4234 of the appropriate enclosing block."
4235 (let ((base -1) ;; Indent of the line that determines our indentation
4236 (ind 0)) ;; Relative offset caused by other directives (like `endif on same line as `else)
4237 ;; Start at current location, scan back for another directive
4238
4239 (save-excursion
4240 (beginning-of-line)
4241 (while (and (< base 0)
4242 (verilog-re-search-backward verilog-directive-re nil t))
4243 (cond ((save-excursion (skip-chars-backward " \t") (bolp))
4244 (setq base (current-indentation))))
4245 (cond ((and (looking-at verilog-directive-end) (< base 0)) ;; Only matters when not at BOL
4246 (setq ind (- ind verilog-indent-level-directive)))
4247 ((and (looking-at verilog-directive-middle) (>= base 0)) ;; Only matters when at BOL
4248 (setq ind (+ ind verilog-indent-level-directive)))
4249 ((looking-at verilog-directive-begin)
4250 (setq ind (+ ind verilog-indent-level-directive)))))
4251 ;; Adjust indent to starting indent of critical line
4252 (setq ind (max 0 (+ ind base))))
4253
4254 (save-excursion
4255 (beginning-of-line)
4256 (skip-chars-forward " \t")
4257 (cond ((or (looking-at verilog-directive-middle)
4258 (looking-at verilog-directive-end))
4259 (setq ind (max 0 (- ind verilog-indent-level-directive))))))
4260 ind))
4261
4262 (defun verilog-leap-to-case-head ()
4263 (let ((nest 1))
4264 (while (/= 0 nest)
4265 (verilog-re-search-backward "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" nil 'move)
4266 (cond
4267 ((match-end 1)
4268 (setq nest (1- nest)))
4269 ((match-end 2)
4270 (setq nest (1+ nest)))
4271 ((bobp)
4272 (ding 't)
4273 (setq nest 0))))))
4274
4275 (defun verilog-leap-to-head ()
4276 "Move point to the head of this block.
4277 Jump from end to matching begin, from endcase to matching case, and so on."
4278 (let ((reg nil)
4279 snest
4280 (nesting 'yes)
4281 (nest 1))
4282 (cond
4283 ((looking-at "\\<end\\>")
4284 ;; 1: Search back for matching begin
4285 (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|"
4286 "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))
4287 ((looking-at "\\<endtask\\>")
4288 ;; 9: Search back for matching task
4289 (setq reg "\\(\\<task\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<task\\>\\)")
4290 (setq nesting 'no))
4291 ((looking-at "\\<endcase\\>")
4292 ;; 2: Search back for matching case
4293 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)" ))
4294 ((looking-at "\\<join\\(_any\\|_none\\)?\\>")
4295 ;; 3: Search back for matching fork
4296 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
4297 ((looking-at "\\<endclass\\>")
4298 ;; 4: Search back for matching class
4299 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
4300 ((looking-at "\\<endtable\\>")
4301 ;; 5: Search back for matching table
4302 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
4303 ((looking-at "\\<endspecify\\>")
4304 ;; 6: Search back for matching specify
4305 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
4306 ((looking-at "\\<endfunction\\>")
4307 ;; 7: Search back for matching function
4308 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
4309 ((looking-at "\\<endgenerate\\>")
4310 ;; 8: Search back for matching generate
4311 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
4312 ((looking-at "\\<endgroup\\>")
4313 ;; 10: Search back for matching covergroup
4314 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
4315 ((looking-at "\\<endproperty\\>")
4316 ;; 11: Search back for matching property
4317 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
4318 ((looking-at "\\<endinterface\\>")
4319 ;; 12: Search back for matching interface
4320 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" ))
4321 ((looking-at "\\<endsequence\\>")
4322 ;; 12: Search back for matching sequence
4323 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ))
4324 ((looking-at "\\<endclocking\\>")
4325 ;; 12: Search back for matching clocking
4326 (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" )))
4327 (if reg
4328 (catch 'skip
4329 (if (eq nesting 'yes)
4330 (let (sreg)
4331 (while (verilog-re-search-backward reg nil 'move)
4332 (cond
4333 ((match-end 1) ; begin
4334 (setq nest (1- nest))
4335 (if (= 0 nest)
4336 ;; Now previous line describes syntax
4337 (throw 'skip 1))
4338 (if (and snest
4339 (= snest nest))
4340 (setq reg sreg)))
4341 ((match-end 2) ; end
4342 (setq nest (1+ nest)))
4343 ((match-end 3)
4344 ;; endcase, jump to case
4345 (setq snest nest)
4346 (setq nest (1+ nest))
4347 (setq sreg reg)
4348 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ))
4349 ((match-end 4)
4350 ;; join, jump to fork
4351 (setq snest nest)
4352 (setq nest (1+ nest))
4353 (setq sreg reg)
4354 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
4355 )))
4356 ;no nesting
4357 (if (and
4358 (verilog-re-search-backward reg nil 'move)
4359 (match-end 1)) ; task -> could be virtual and/or protected
4360 (progn
4361 (verilog-beg-of-statement)
4362 (throw 'skip 1))
4363 (throw 'skip 1)))))))
4364
4365 (defun verilog-continued-line ()
4366 "Return true if this is a continued line.
4367 Set point to where line starts."
4368 (let ((continued 't))
4369 (if (eq 0 (forward-line -1))
4370 (progn
4371 (end-of-line)
4372 (verilog-backward-ws&directives)
4373 (if (bobp)
4374 (setq continued nil)
4375 (while (and continued
4376 (save-excursion
4377 (skip-chars-backward " \t")
4378 (not (bolp))))
4379 (setq continued (verilog-backward-token)))))
4380 (setq continued nil))
4381 continued))
4382
4383 (defun verilog-backward-token ()
4384 "Step backward token, returning true if we are now at an end of line token."
4385 (interactive)
4386 (verilog-backward-syntactic-ws)
4387 (cond
4388 ((bolp)
4389 nil)
4390 (;-- Anything ending in a ; is complete
4391 (= (preceding-char) ?\;)
4392 nil)
4393 (; If a "}" is prefixed by a ";", then this is a complete statement
4394 ; i.e.: constraint foo { a = b; }
4395 (= (preceding-char) ?\})
4396 (progn
4397 (backward-char)
4398 (verilog-at-close-constraint-p)))
4399 (;-- constraint foo { a = b }
4400 ; is a complete statement. *sigh*
4401 (= (preceding-char) ?\{)
4402 (progn
4403 (backward-char)
4404 (not (verilog-at-constraint-p))))
4405 (;-- Could be 'case (foo)' or 'always @(bar)' which is complete
4406 ; also could be simply '@(foo)'
4407 ; or foo u1 #(a=8)
4408 ; (b, ... which ISN'T complete
4409 ;;;; Do we need this???
4410 (= (preceding-char) ?\))
4411 (progn
4412 (backward-char)
4413 (backward-up-list 1)
4414 (verilog-backward-syntactic-ws)
4415 (let ((back (point)))
4416 (forward-word -1)
4417 (cond
4418 ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>")
4419 (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]")))
4420 (t
4421 (goto-char back)
4422 (cond
4423 ((= (preceding-char) ?\@)
4424 (backward-char)
4425 (save-excursion
4426 (verilog-backward-token)
4427 (not (looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|initial\\|while\\)\\>"))))
4428 ((= (preceding-char) ?\#)
4429 (backward-char))
4430 (t t)))))))
4431
4432 (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete
4433 t
4434 (forward-word -1)
4435 (cond
4436 ((looking-at "\\<else\\>")
4437 t)
4438 ((looking-at verilog-behavioral-block-beg-re)
4439 t)
4440 ((looking-at verilog-indent-re)
4441 nil)
4442 (t
4443 (let
4444 ((back (point)))
4445 (verilog-backward-syntactic-ws)
4446 (cond
4447 ((= (preceding-char) ?\:)
4448 (backward-char)
4449 (verilog-backward-syntactic-ws)
4450 (backward-sexp)
4451 (if (looking-at verilog-nameable-item-re )
4452 nil
4453 t))
4454 ((= (preceding-char) ?\#)
4455 (backward-char)
4456 t)
4457 ((= (preceding-char) ?\`)
4458 (backward-char)
4459 t)
4460
4461 (t
4462 (goto-char back)
4463 t))))))))
4464
4465 (defun verilog-backward-syntactic-ws (&optional bound)
4466 "Backward skip over syntactic whitespace for Emacs 19.
4467 Optional BOUND limits search."
4468 (save-restriction
4469 (let* ((bound (or bound (point-min))) (here bound) )
4470 (if (< bound (point))
4471 (progn
4472 (narrow-to-region bound (point))
4473 (while (/= here (point))
4474 (setq here (point))
4475 (verilog-skip-backward-comments))))))
4476 t)
4477
4478 (defun verilog-forward-syntactic-ws (&optional bound)
4479 "Forward skip over syntactic whitespace for Emacs 19.
4480 Optional BOUND limits search."
4481 (save-restriction
4482 (let* ((bound (or bound (point-max)))
4483 (here bound))
4484 (if (> bound (point))
4485 (progn
4486 (narrow-to-region (point) bound)
4487 (while (/= here (point))
4488 (setq here (point))
4489 (forward-comment (buffer-size))))))))
4490
4491 (defun verilog-backward-ws&directives (&optional bound)
4492 "Backward skip over syntactic whitespace and compiler directives for Emacs 19.
4493 Optional BOUND limits search."
4494 (save-restriction
4495 (let* ((bound (or bound (point-min)))
4496 (here bound)
4497 (p nil) )
4498 (if (< bound (point))
4499 (progn
4500 (let ((state (save-excursion (verilog-syntax-ppss))))
4501 (cond
4502 ((nth 7 state) ;; in // comment
4503 (verilog-re-search-backward "//" nil 'move)
4504 (skip-chars-backward "/"))
4505 ((nth 4 state) ;; in /* */ comment
4506 (verilog-re-search-backward "/\*" nil 'move))))
4507 (narrow-to-region bound (point))
4508 (while (/= here (point))
4509 (setq here (point))
4510 (verilog-skip-backward-comments)
4511 (setq p
4512 (save-excursion
4513 (beginning-of-line)
4514 (cond
4515 ((verilog-within-translate-off)
4516 (verilog-back-to-start-translate-off (point-min)))
4517 ((looking-at verilog-directive-re-1)
4518 (point))
4519 (t
4520 nil))))
4521 (if p (goto-char p))))))))
4522
4523 (defun verilog-forward-ws&directives (&optional bound)
4524 "Forward skip over syntactic whitespace and compiler directives for Emacs 19.
4525 Optional BOUND limits search."
4526 (save-restriction
4527 (let* ((bound (or bound (point-max)))
4528 (here bound)
4529 jump)
4530 (if (> bound (point))
4531 (progn
4532 (let ((state (save-excursion (verilog-syntax-ppss))))
4533 (cond
4534 ((nth 7 state) ;; in // comment
4535 (verilog-re-search-forward "//" nil 'move))
4536 ((nth 4 state) ;; in /* */ comment
4537 (verilog-re-search-forward "/\*" nil 'move))))
4538 (narrow-to-region (point) bound)
4539 (while (/= here (point))
4540 (setq here (point)
4541 jump nil)
4542 (forward-comment (buffer-size))
4543 (save-excursion
4544 (beginning-of-line)
4545 (if (looking-at verilog-directive-re-1)
4546 (setq jump t)))
4547 (if jump
4548 (beginning-of-line 2))))))))
4549
4550 (defun verilog-in-comment-p ()
4551 "Return true if in a star or // comment."
4552 (let ((state (save-excursion (verilog-syntax-ppss))))
4553 (or (nth 4 state) (nth 7 state))))
4554
4555 (defun verilog-in-star-comment-p ()
4556 "Return true if in a star comment."
4557 (let ((state (save-excursion (verilog-syntax-ppss))))
4558 (and
4559 (nth 4 state) ; t if in a comment of style a // or b /**/
4560 (not
4561 (nth 7 state) ; t if in a comment of style b /**/
4562 ))))
4563
4564 (defun verilog-in-slash-comment-p ()
4565 "Return true if in a slash comment."
4566 (let ((state (save-excursion (verilog-syntax-ppss))))
4567 (nth 7 state)))
4568
4569 (defun verilog-in-comment-or-string-p ()
4570 "Return true if in a string or comment."
4571 (let ((state (save-excursion (verilog-syntax-ppss))))
4572 (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment)
4573
4574 (defun verilog-in-escaped-name-p ()
4575 "Return true if in an escaped name."
4576 (save-excursion
4577 (backward-char)
4578 (skip-chars-backward "^ \t\n\f")
4579 (if (equal (char-after (point) ) ?\\ )
4580 t
4581 nil)))
4582
4583 (defun verilog-in-paren ()
4584 "Return true if in a parenthetical expression."
4585 (let ((state (save-excursion (verilog-syntax-ppss))))
4586 (> (nth 0 state) 0 )))
4587
4588 (defun verilog-in-coverage ()
4589 "Return true if in a constraint or coverpoint expression."
4590 (interactive)
4591 (save-excursion
4592 (if (verilog-in-paren)
4593 (progn
4594 (backward-up-list 1)
4595 (verilog-at-constraint-p)
4596 )
4597 nil)))
4598 (defun verilog-at-close-constraint-p ()
4599 "If at the } that closes a constraint or covergroup, return true."
4600 (if (and
4601 (equal (char-after) ?\})
4602 (verilog-in-paren))
4603
4604 (save-excursion
4605 (verilog-backward-ws&directives)
4606 (if (equal (char-before) ?\;)
4607 (point)
4608 nil))))
4609
4610 (defun verilog-at-constraint-p ()
4611 "If at the { of a constraint or coverpoint definition, return true, moving point to constraint."
4612 (if (save-excursion
4613 (and
4614 (equal (char-after) ?\{)
4615 (forward-list)
4616 (progn (backward-char 1)
4617 (verilog-backward-ws&directives)
4618 (equal (char-before) ?\;))))
4619 ;; maybe
4620 (verilog-re-search-backward "\\<constraint\\|coverpoint\\|cross\\>" nil 'move)
4621 ;; not
4622 nil))
4623
4624 (defun verilog-parenthesis-depth ()
4625 "Return non zero if in parenthetical-expression."
4626 (save-excursion (nth 1 (verilog-syntax-ppss))))
4627
4628
4629 (defun verilog-skip-forward-comment-or-string ()
4630 "Return true if in a string or comment."
4631 (let ((state (save-excursion (verilog-syntax-ppss))))
4632 (cond
4633 ((nth 3 state) ;Inside string
4634 (search-forward "\"")
4635 t)
4636 ((nth 7 state) ;Inside // comment
4637 (forward-line 1)
4638 t)
4639 ((nth 4 state) ;Inside any comment (hence /**/)
4640 (search-forward "*/"))
4641 (t
4642 nil))))
4643
4644 (defun verilog-skip-backward-comment-or-string ()
4645 "Return true if in a string or comment."
4646 (let ((state (save-excursion (verilog-syntax-ppss))))
4647 (cond
4648 ((nth 3 state) ;Inside string
4649 (search-backward "\"")
4650 t)
4651 ((nth 7 state) ;Inside // comment
4652 (search-backward "//")
4653 (skip-chars-backward "/")
4654 t)
4655 ((nth 4 state) ;Inside /* */ comment
4656 (search-backward "/*")
4657 t)
4658 (t
4659 nil))))
4660
4661 (defun verilog-skip-backward-comments ()
4662 "Return true if a comment was skipped."
4663 (let ((more t))
4664 (while more
4665 (setq more
4666 (let ((state (save-excursion (verilog-syntax-ppss))))
4667 (cond
4668 ((nth 7 state) ;Inside // comment
4669 (search-backward "//")
4670 (skip-chars-backward "/")
4671 (skip-chars-backward " \t\n\f")
4672 t)
4673 ((nth 4 state) ;Inside /* */ comment
4674 (search-backward "/*")
4675 (skip-chars-backward " \t\n\f")
4676 t)
4677 ((and (not (bobp))
4678 (= (char-before) ?\/)
4679 (= (char-before (1- (point))) ?\*))
4680 (goto-char (- (point) 2))
4681 t)
4682 (t
4683 (skip-chars-backward " \t\n\f")
4684 nil)))))))
4685
4686 (defun verilog-skip-forward-comment-p ()
4687 "If in comment, move to end and return true."
4688 (let (state)
4689 (progn
4690 (setq state (save-excursion (verilog-syntax-ppss)))
4691 (cond
4692 ((nth 3 state)
4693 t)
4694 ((nth 7 state) ;Inside // comment
4695 (end-of-line)
4696 (forward-char 1)
4697 t)
4698 ((nth 4 state) ;Inside any comment
4699 t)
4700 (t
4701 nil)))))
4702
4703 (defun verilog-indent-line-relative ()
4704 "Cheap version of indent line.
4705 Only look at a few lines to determine indent level."
4706 (interactive)
4707 (let ((indent-str)
4708 (sp (point)))
4709 (if (looking-at "^[ \t]*$")
4710 (cond ;- A blank line; No need to be too smart.
4711 ((bobp)
4712 (setq indent-str (list 'cpp 0)))
4713 ((verilog-continued-line)
4714 (let ((sp1 (point)))
4715 (if (verilog-continued-line)
4716 (progn
4717 (goto-char sp)
4718 (setq indent-str
4719 (list 'statement (verilog-current-indent-level))))
4720 (goto-char sp1)
4721 (setq indent-str (list 'block (verilog-current-indent-level)))))
4722 (goto-char sp))
4723 ((goto-char sp)
4724 (setq indent-str (verilog-calculate-indent))))
4725 (progn (skip-chars-forward " \t")
4726 (setq indent-str (verilog-calculate-indent))))
4727 (verilog-do-indent indent-str)))
4728
4729 (defun verilog-indent-line ()
4730 "Indent for special part of code."
4731 (verilog-do-indent (verilog-calculate-indent)))
4732
4733 (defun verilog-do-indent (indent-str)
4734 (let ((type (car indent-str))
4735 (ind (car (cdr indent-str))))
4736 (cond
4737 (; handle continued exp
4738 (eq type 'cexp)
4739 (let ((here (point)))
4740 (verilog-backward-syntactic-ws)
4741 (cond
4742 ((or
4743 (= (preceding-char) ?\,)
4744 (= (preceding-char) ?\])
4745 (save-excursion
4746 (verilog-beg-of-statement-1)
4747 (looking-at verilog-declaration-re)))
4748 (let* ( fst
4749 (val
4750 (save-excursion
4751 (backward-char 1)
4752 (verilog-beg-of-statement-1)
4753 (setq fst (point))
4754 (if (looking-at verilog-declaration-re)
4755 (progn ;; we have multiple words
4756 (goto-char (match-end 0))
4757 (skip-chars-forward " \t")
4758 (cond
4759 ((and verilog-indent-declaration-macros
4760 (= (following-char) ?\`))
4761 (progn
4762 (forward-char 1)
4763 (forward-word 1)
4764 (skip-chars-forward " \t")))
4765 ((= (following-char) ?\[)
4766 (progn
4767 (forward-char 1)
4768 (backward-up-list -1)
4769 (skip-chars-forward " \t"))))
4770 (current-column))
4771 (progn
4772 (goto-char fst)
4773 (+ (current-column) verilog-cexp-indent))))))
4774 (goto-char here)
4775 (indent-line-to val)))
4776 ((= (preceding-char) ?\) )
4777 (goto-char here)
4778 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
4779 (indent-line-to val)))
4780 (t
4781 (goto-char here)
4782 (let ((val))
4783 (verilog-beg-of-statement-1)
4784 (if (and (< (point) here)
4785 (verilog-re-search-forward "=[ \\t]*" here 'move))
4786 (setq val (current-column))
4787 (setq val (eval (cdr (assoc type verilog-indent-alist)))))
4788 (goto-char here)
4789 (indent-line-to val))))))
4790
4791 (; handle inside parenthetical expressions
4792 (eq type 'cparenexp)
4793 (let ((val (save-excursion
4794 (backward-up-list 1)
4795 (forward-char 1)
4796 (skip-chars-forward " \t")
4797 (current-column))))
4798 (indent-line-to val)
4799 ))
4800
4801 (;-- Handle the ends
4802 (or
4803 (looking-at verilog-end-block-re )
4804 (verilog-at-close-constraint-p))
4805 (let ((val (if (eq type 'statement)
4806 (- ind verilog-indent-level)
4807 ind)))
4808 (indent-line-to val)))
4809
4810 (;-- Case -- maybe line 'em up
4811 (and (eq type 'case) (not (looking-at "^[ \t]*$")))
4812 (progn
4813 (cond
4814 ((looking-at "\\<endcase\\>")
4815 (indent-line-to ind))
4816 (t
4817 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
4818 (indent-line-to val))))))
4819
4820 (;-- defun
4821 (and (eq type 'defun)
4822 (looking-at verilog-zero-indent-re))
4823 (indent-line-to 0))
4824
4825 (;-- declaration
4826 (and (or
4827 (eq type 'defun)
4828 (eq type 'block))
4829 (looking-at verilog-declaration-re))
4830 (verilog-indent-declaration ind))
4831
4832 (;-- Everything else
4833 t
4834 (let ((val (eval (cdr (assoc type verilog-indent-alist)))))
4835 (indent-line-to val))))
4836
4837 (if (looking-at "[ \t]+$")
4838 (skip-chars-forward " \t"))
4839 indent-str ; Return indent data
4840 ))
4841
4842 (defun verilog-current-indent-level ()
4843 "Return the indent-level of the current statement."
4844 (save-excursion
4845 (let (par-pos)
4846 (beginning-of-line)
4847 (setq par-pos (verilog-parenthesis-depth))
4848 (while par-pos
4849 (goto-char par-pos)
4850 (beginning-of-line)
4851 (setq par-pos (verilog-parenthesis-depth)))
4852 (skip-chars-forward " \t")
4853 (current-column))))
4854
4855 (defun verilog-case-indent-level ()
4856 "Return the indent-level of the current statement.
4857 Do not count named blocks or case-statements."
4858 (save-excursion
4859 (skip-chars-forward " \t")
4860 (cond
4861 ((looking-at verilog-named-block-re)
4862 (current-column))
4863 ((and (not (looking-at verilog-case-re))
4864 (looking-at "^[^:;]+[ \t]*:"))
4865 (verilog-re-search-forward ":" nil t)
4866 (skip-chars-forward " \t")
4867 (current-column))
4868 (t
4869 (current-column)))))
4870
4871 (defun verilog-indent-comment ()
4872 "Indent current line as comment."
4873 (let* ((stcol
4874 (cond
4875 ((verilog-in-star-comment-p)
4876 (save-excursion
4877 (re-search-backward "/\\*" nil t)
4878 (1+(current-column))))
4879 (comment-column
4880 comment-column )
4881 (t
4882 (save-excursion
4883 (re-search-backward "//" nil t)
4884 (current-column))))))
4885 (indent-line-to stcol)
4886 stcol))
4887
4888 (defun verilog-more-comment ()
4889 "Make more comment lines like the previous."
4890 (let* ((star 0)
4891 (stcol
4892 (cond
4893 ((verilog-in-star-comment-p)
4894 (save-excursion
4895 (setq star 1)
4896 (re-search-backward "/\\*" nil t)
4897 (1+(current-column))))
4898 (comment-column
4899 comment-column )
4900 (t
4901 (save-excursion
4902 (re-search-backward "//" nil t)
4903 (current-column))))))
4904 (progn
4905 (indent-to stcol)
4906 (if (and star
4907 (save-excursion
4908 (forward-line -1)
4909 (skip-chars-forward " \t")
4910 (looking-at "\*")))
4911 (insert "* ")))))
4912
4913 (defun verilog-comment-indent (&optional arg)
4914 "Return the column number the line should be indented to.
4915 ARG is ignored, for `comment-indent-function' compatibility."
4916 (cond
4917 ((verilog-in-star-comment-p)
4918 (save-excursion
4919 (re-search-backward "/\\*" nil t)
4920 (1+(current-column))))
4921 ( comment-column
4922 comment-column )
4923 (t
4924 (save-excursion
4925 (re-search-backward "//" nil t)
4926 (current-column)))))
4927
4928 ;;
4929
4930 (defun verilog-pretty-declarations (&optional quiet)
4931 "Line up declarations around point."
4932 (interactive)
4933 (save-excursion
4934 (if (progn
4935 (verilog-beg-of-statement-1)
4936 (looking-at verilog-declaration-re))
4937 (let* ((m1 (make-marker))
4938 (e) (r)
4939 (here (point))
4940 ;; Start of declaration range
4941 (start
4942 (progn
4943 (verilog-beg-of-statement-1)
4944 (while (looking-at verilog-declaration-re)
4945 (beginning-of-line)
4946 (setq e (point))
4947 (verilog-backward-syntactic-ws)
4948 (backward-char)
4949 (verilog-beg-of-statement-1)) ;Ack, need to grok `define
4950 e))
4951 ;; End of declaration range
4952 (end
4953 (progn
4954 (goto-char here)
4955 (verilog-end-of-statement)
4956 (setq e (point)) ;Might be on last line
4957 (verilog-forward-syntactic-ws)
4958 (while (looking-at verilog-declaration-re)
4959 (beginning-of-line)
4960 (verilog-end-of-statement)
4961 (setq e (point))
4962 (verilog-forward-syntactic-ws))
4963 e))
4964 (edpos (set-marker (make-marker) end))
4965 (ind)
4966 (base-ind
4967 (progn
4968 (goto-char start)
4969 (verilog-do-indent (verilog-calculate-indent))
4970 (verilog-forward-ws&directives)
4971 (current-column))))
4972 (goto-char end)
4973 (goto-char start)
4974 (if (and (not quiet)
4975 (> (- end start) 100))
4976 (message "Lining up declarations..(please stand by)"))
4977 ;; Get the beginning of line indent first
4978 (while (progn (setq e (marker-position edpos))
4979 (< (point) e))
4980 (cond
4981 ( (save-excursion (skip-chars-backward " \t")
4982 (bolp))
4983 (verilog-forward-ws&directives)
4984 (indent-line-to base-ind)
4985 (verilog-forward-ws&directives)
4986 (verilog-re-search-forward "[ \t\n\f]" e 'move))
4987 (t
4988 (just-one-space)
4989 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
4990 ;;(forward-line)
4991 )
4992 ;; Now find biggest prefix
4993 (setq ind (verilog-get-lineup-indent start edpos))
4994 ;; Now indent each line.
4995 (goto-char start)
4996 (while (progn (setq e (marker-position edpos))
4997 (setq r (- e (point)))
4998 (> r 0))
4999 (setq e (point))
5000 (unless quiet (message "%d" r))
5001 (cond
5002 ((or (and verilog-indent-declaration-macros
5003 (looking-at verilog-declaration-re-1-macro))
5004 (looking-at verilog-declaration-re-1-no-macro))
5005 (let ((p (match-end 0)))
5006 (set-marker m1 p)
5007 (if (verilog-re-search-forward "[[#`]" p 'move)
5008 (progn
5009 (forward-char -1)
5010 (just-one-space)
5011 (goto-char (marker-position m1))
5012 (just-one-space)
5013 (indent-to ind))
5014 (progn
5015 (just-one-space)
5016 (indent-to ind)))))
5017 ((verilog-continued-line-1 start)
5018 (goto-char e)
5019 (indent-line-to ind))
5020 (t ; Must be comment or white space
5021 (goto-char e)
5022 (verilog-forward-ws&directives)
5023 (forward-line -1)))
5024 (forward-line 1))
5025 (unless quiet (message ""))))))
5026
5027 (defun verilog-pretty-expr (&optional quiet myre)
5028 "Line up expressions around point, or optional regexp MYRE."
5029 (interactive "sRegular Expression: ((<|:)?=) ")
5030 (save-excursion
5031 (if (or (eq myre nil)
5032 (string-equal myre ""))
5033 (setq myre "\\(<\\|:\\)?="))
5034 (setq myre (concat "\\(^[^;#<=>]*\\)\\(" myre "\\)"))
5035 (let ((rexp(concat "^\\s-*" verilog-complete-reg)))
5036 (beginning-of-line)
5037 (if (and (not (looking-at rexp ))
5038 (looking-at myre))
5039 (let* ((here (point))
5040 (e) (r)
5041 (start
5042 (progn
5043 (beginning-of-line)
5044 (setq e (point))
5045 (verilog-backward-syntactic-ws)
5046 (beginning-of-line)
5047 (while (and (not (looking-at rexp ))
5048 (looking-at myre)
5049 (not (bobp))
5050 )
5051 (setq e (point))
5052 (verilog-backward-syntactic-ws)
5053 (beginning-of-line)
5054 ) ;Ack, need to grok `define
5055 e))
5056 (end
5057 (progn
5058 (goto-char here)
5059 (end-of-line)
5060 (setq e (point)) ;Might be on last line
5061 (verilog-forward-syntactic-ws)
5062 (beginning-of-line)
5063 (while (and (not (looking-at rexp ))
5064 (looking-at myre))
5065 (end-of-line)
5066 (setq e (point))
5067 (verilog-forward-syntactic-ws)
5068 (beginning-of-line)
5069 )
5070 e))
5071 (edpos (set-marker (make-marker) end))
5072 (ind)
5073 )
5074 (goto-char start)
5075 (verilog-do-indent (verilog-calculate-indent))
5076 (if (and (not quiet)
5077 (> (- end start) 100))
5078 (message "Lining up expressions..(please stand by)"))
5079
5080 ;; Set indent to minimum throughout region
5081 (while (< (point) (marker-position edpos))
5082 (beginning-of-line)
5083 (verilog-just-one-space myre)
5084 (end-of-line)
5085 (verilog-forward-syntactic-ws)
5086 )
5087
5088 ;; Now find biggest prefix
5089 (setq ind (verilog-get-lineup-indent-2 myre start edpos))
5090
5091 ;; Now indent each line.
5092 (goto-char start)
5093 (while (progn (setq e (marker-position edpos))
5094 (setq r (- e (point)))
5095 (> r 0))
5096 (setq e (point))
5097 (if (not quiet) (message "%d" r))
5098 (cond
5099 ((looking-at myre)
5100 (goto-char (match-end 1))
5101 (if (not (verilog-parenthesis-depth)) ;; ignore parenthsized exprs
5102 (if (eq (char-after) ?=)
5103 (indent-to (1+ ind)) ; line up the = of the <= with surrounding =
5104 (indent-to ind)
5105 )))
5106 ((verilog-continued-line-1 start)
5107 (goto-char e)
5108 (indent-line-to ind))
5109 (t ; Must be comment or white space
5110 (goto-char e)
5111 (verilog-forward-ws&directives)
5112 (forward-line -1))
5113 )
5114 (forward-line 1))
5115 (unless quiet (message ""))
5116 )))))
5117
5118 (defun verilog-just-one-space (myre)
5119 "Remove extra spaces around regular expression MYRE."
5120 (interactive)
5121 (if (and (not(looking-at verilog-complete-reg))
5122 (looking-at myre))
5123 (let ((p1 (match-end 1))
5124 (p2 (match-end 2)))
5125 (progn
5126 (goto-char p2)
5127 (if (looking-at "\\s-") (just-one-space))
5128 (goto-char p1)
5129 (forward-char -1)
5130 (if (looking-at "\\s-") (just-one-space))
5131 ))))
5132
5133 (defun verilog-indent-declaration (baseind)
5134 "Indent current lines as declaration.
5135 Line up the variable names based on previous declaration's indentation.
5136 BASEIND is the base indent to offset everything."
5137 (interactive)
5138 (let ((pos (point-marker))
5139 (lim (save-excursion
5140 ;; (verilog-re-search-backward verilog-declaration-opener nil 'move)
5141 (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)\\|\\(\\<task\\>\\)" nil 'move)
5142 (point)))
5143 (ind)
5144 (val)
5145 (m1 (make-marker)))
5146 (setq val
5147 (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist)))))
5148 (indent-line-to val)
5149
5150 ;; Use previous declaration (in this module) as template.
5151 (if (or (memq 'all verilog-auto-lineup)
5152 (memq 'declaration verilog-auto-lineup))
5153 (if (verilog-re-search-backward
5154 (or (and verilog-indent-declaration-macros
5155 verilog-declaration-re-1-macro)
5156 verilog-declaration-re-1-no-macro) lim t)
5157 (progn
5158 (goto-char (match-end 0))
5159 (skip-chars-forward " \t")
5160 (setq ind (current-column))
5161 (goto-char pos)
5162 (setq val
5163 (+ baseind
5164 (eval (cdr (assoc 'declaration verilog-indent-alist)))))
5165 (indent-line-to val)
5166 (if (and verilog-indent-declaration-macros
5167 (looking-at verilog-declaration-re-2-macro))
5168 (let ((p (match-end 0)))
5169 (set-marker m1 p)
5170 (if (verilog-re-search-forward "[[#`]" p 'move)
5171 (progn
5172 (forward-char -1)
5173 (just-one-space)
5174 (goto-char (marker-position m1))
5175 (just-one-space)
5176 (indent-to ind))
5177 (if (/= (current-column) ind)
5178 (progn
5179 (just-one-space)
5180 (indent-to ind)))))
5181 (if (looking-at verilog-declaration-re-2-no-macro)
5182 (let ((p (match-end 0)))
5183 (set-marker m1 p)
5184 (if (verilog-re-search-forward "[[`#]" p 'move)
5185 (progn
5186 (forward-char -1)
5187 (just-one-space)
5188 (goto-char (marker-position m1))
5189 (just-one-space)
5190 (indent-to ind))
5191 (if (/= (current-column) ind)
5192 (progn
5193 (just-one-space)
5194 (indent-to ind))))))))))
5195 (goto-char pos)))
5196
5197 (defun verilog-get-lineup-indent (b edpos)
5198 "Return the indent level that will line up several lines within the region.
5199 Region is defined by B and EDPOS."
5200 (save-excursion
5201 (let ((ind 0) e)
5202 (goto-char b)
5203 ;; Get rightmost position
5204 (while (progn (setq e (marker-position edpos))
5205 (< (point) e))
5206 (if (verilog-re-search-forward
5207 (or (and verilog-indent-declaration-macros
5208 verilog-declaration-re-1-macro)
5209 verilog-declaration-re-1-no-macro) e 'move)
5210 (progn
5211 (goto-char (match-end 0))
5212 (verilog-backward-syntactic-ws)
5213 (if (> (current-column) ind)
5214 (setq ind (current-column)))
5215 (goto-char (match-end 0)))))
5216 (if (> ind 0)
5217 (1+ ind)
5218 ;; No lineup-string found
5219 (goto-char b)
5220 (end-of-line)
5221 (skip-chars-backward " \t")
5222 (1+ (current-column))))))
5223
5224 (defun verilog-get-lineup-indent-2 (myre b edpos)
5225 "Return the indent level that will line up several lines within the region."
5226 (save-excursion
5227 (let ((ind 0) e)
5228 (goto-char b)
5229 ;; Get rightmost position
5230 (while (progn (setq e (marker-position edpos))
5231 (< (point) e))
5232 (if (and (verilog-re-search-forward myre e 'move)
5233 (not (verilog-parenthesis-depth))) ;; skip parenthsized exprs
5234 (progn
5235 (goto-char (match-beginning 2))
5236 (verilog-backward-syntactic-ws)
5237 (if (> (current-column) ind)
5238 (setq ind (current-column)))
5239 (goto-char (match-end 0)))
5240 ))
5241 (if (> ind 0)
5242 (1+ ind)
5243 ;; No lineup-string found
5244 (goto-char b)
5245 (end-of-line)
5246 (skip-chars-backward " \t")
5247 (1+ (current-column))))))
5248
5249 (defun verilog-comment-depth (type val)
5250 "A useful mode debugging aide. TYPE and VAL are comments for insertion."
5251 (save-excursion
5252 (let
5253 ((b (prog2
5254 (beginning-of-line)
5255 (point-marker)
5256 (end-of-line)))
5257 (e (point-marker)))
5258 (if (re-search-backward " /\\* \[#-\]# \[a-zA-Z\]+ \[0-9\]+ ## \\*/" b t)
5259 (progn
5260 (replace-match " /* -# ## */")
5261 (end-of-line))
5262 (progn
5263 (end-of-line)
5264 (insert " /* ## ## */"))))
5265 (backward-char 6)
5266 (insert
5267 (format "%s %d" type val))))
5268
5269 ;; \f
5270 ;;
5271 ;; Completion
5272 ;;
5273 (defvar verilog-str nil)
5274 (defvar verilog-all nil)
5275 (defvar verilog-pred nil)
5276 (defvar verilog-buffer-to-use nil)
5277 (defvar verilog-flag nil)
5278 (defvar verilog-toggle-completions nil
5279 "*True means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one.
5280 Repeated use of \\[verilog-complete-word] will show you all of them.
5281 Normally, when there is more than one possible completion,
5282 it displays a list of all possible completions.")
5283
5284
5285 (defvar verilog-type-keywords
5286 '(
5287 "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input"
5288 "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0"
5289 "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pullup"
5290 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0"
5291 "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1"
5292 "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor"
5293 )
5294 "*Keywords for types used when completing a word in a declaration or parmlist.
5295 \(Eg. integer, real, reg...)")
5296
5297 (defvar verilog-cpp-keywords
5298 '("module" "macromodule" "primitive" "timescale" "define" "ifdef" "ifndef" "else"
5299 "endif")
5300 "*Keywords to complete when at first word of a line in declarative scope.
5301 \(Eg. initial, always, begin, assign.)
5302 The procedures and variables defined within the Verilog program
5303 will be completed at runtime and should not be added to this list.")
5304
5305 (defvar verilog-defun-keywords
5306 (append
5307 '(
5308 "always" "always_comb" "always_ff" "always_latch" "assign"
5309 "begin" "end" "generate" "endgenerate" "module" "endmodule"
5310 "specify" "endspecify" "function" "endfunction" "initial" "final"
5311 "task" "endtask" "primitive" "endprimitive"
5312 )
5313 verilog-type-keywords)
5314 "*Keywords to complete when at first word of a line in declarative scope.
5315 \(Eg. initial, always, begin, assign.)
5316 The procedures and variables defined within the Verilog program
5317 will be completed at runtime and should not be added to this list.")
5318
5319 (defvar verilog-block-keywords
5320 '(
5321 "begin" "break" "case" "continue" "else" "end" "endfunction"
5322 "endgenerate" "endinterface" "endpackage" "endspecify" "endtask"
5323 "for" "fork" "if" "join" "join_any" "join_none" "repeat" "return"
5324 "while")
5325 "*Keywords to complete when at first word of a line in behavioral scope.
5326 \(Eg. begin, if, then, else, for, fork.)
5327 The procedures and variables defined within the Verilog program
5328 will be completed at runtime and should not be added to this list.")
5329
5330 (defvar verilog-tf-keywords
5331 '("begin" "break" "fork" "join" "join_any" "join_none" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat")
5332 "*Keywords to complete when at first word of a line in a task or function.
5333 \(Eg. begin, if, then, else, for, fork.)
5334 The procedures and variables defined within the Verilog program
5335 will be completed at runtime and should not be added to this list.")
5336
5337 (defvar verilog-case-keywords
5338 '("begin" "fork" "join" "join_any" "join_none" "case" "end" "endcase" "if" "else" "for" "repeat")
5339 "*Keywords to complete when at first word of a line in case scope.
5340 \(Eg. begin, if, then, else, for, fork.)
5341 The procedures and variables defined within the Verilog program
5342 will be completed at runtime and should not be added to this list.")
5343
5344 (defvar verilog-separator-keywords
5345 '("else" "then" "begin")
5346 "*Keywords to complete when NOT standing at the first word of a statement.
5347 \(Eg. else, then.)
5348 Variables and function names defined within the Verilog program
5349 will be completed at runtime and should not be added to this list.")
5350
5351 (defun verilog-string-diff (str1 str2)
5352 "Return index of first letter where STR1 and STR2 differs."
5353 (catch 'done
5354 (let ((diff 0))
5355 (while t
5356 (if (or (> (1+ diff) (length str1))
5357 (> (1+ diff) (length str2)))
5358 (throw 'done diff))
5359 (or (equal (aref str1 diff) (aref str2 diff))
5360 (throw 'done diff))
5361 (setq diff (1+ diff))))))
5362
5363 ;; Calculate all possible completions for functions if argument is `function',
5364 ;; completions for procedures if argument is `procedure' or both functions and
5365 ;; procedures otherwise.
5366
5367 (defun verilog-func-completion (type)
5368 "Build regular expression for module/task/function names.
5369 TYPE is 'module, 'tf for task or function, or t if unknown."
5370 (if (string= verilog-str "")
5371 (setq verilog-str "[a-zA-Z_]"))
5372 (let ((verilog-str (concat (cond
5373 ((eq type 'module) "\\<\\(module\\)\\s +")
5374 ((eq type 'tf) "\\<\\(task\\|function\\)\\s +")
5375 (t "\\<\\(task\\|function\\|module\\)\\s +"))
5376 "\\<\\(" verilog-str "[a-zA-Z0-9_.]*\\)\\>"))
5377 match)
5378
5379 (if (not (looking-at verilog-defun-re))
5380 (verilog-re-search-backward verilog-defun-re nil t))
5381 (forward-char 1)
5382
5383 ;; Search through all reachable functions
5384 (goto-char (point-min))
5385 (while (verilog-re-search-forward verilog-str (point-max) t)
5386 (progn (setq match (buffer-substring (match-beginning 2)
5387 (match-end 2)))
5388 (if (or (null verilog-pred)
5389 (funcall verilog-pred match))
5390 (setq verilog-all (cons match verilog-all)))))
5391 (if (match-beginning 0)
5392 (goto-char (match-beginning 0)))))
5393
5394 (defun verilog-get-completion-decl (end)
5395 "Macro for searching through current declaration (var, type or const)
5396 for matches of `str' and adding the occurrence tp `all' through point END."
5397 (let ((re (or (and verilog-indent-declaration-macros
5398 verilog-declaration-re-2-macro)
5399 verilog-declaration-re-2-no-macro))
5400 decl-end match)
5401 ;; Traverse lines
5402 (while (and (< (point) end)
5403 (verilog-re-search-forward re end t))
5404 ;; Traverse current line
5405 (setq decl-end (save-excursion (verilog-declaration-end)))
5406 (while (and (verilog-re-search-forward verilog-symbol-re decl-end t)
5407 (not (match-end 1)))
5408 (setq match (buffer-substring (match-beginning 0) (match-end 0)))
5409 (if (string-match (concat "\\<" verilog-str) match)
5410 (if (or (null verilog-pred)
5411 (funcall verilog-pred match))
5412 (setq verilog-all (cons match verilog-all)))))
5413 (forward-line 1)))
5414 verilog-all)
5415
5416 (defun verilog-type-completion ()
5417 "Calculate all possible completions for types."
5418 (let ((start (point))
5419 goon)
5420 ;; Search for all reachable type declarations
5421 (while (or (verilog-beg-of-defun)
5422 (setq goon (not goon)))
5423 (save-excursion
5424 (if (and (< start (prog1 (save-excursion (verilog-end-of-defun)
5425 (point))
5426 (forward-char 1)))
5427 (verilog-re-search-forward
5428 "\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>"
5429 start t)
5430 (not (match-end 1)))
5431 ;; Check current type declaration
5432 (verilog-get-completion-decl start))))))
5433
5434 (defun verilog-var-completion ()
5435 "Calculate all possible completions for variables (or constants)."
5436 (let ((start (point)))
5437 ;; Search for all reachable var declarations
5438 (verilog-beg-of-defun)
5439 (save-excursion
5440 ;; Check var declarations
5441 (verilog-get-completion-decl start))))
5442
5443 (defun verilog-keyword-completion (keyword-list)
5444 "Give list of all possible completions of keywords in KEYWORD-LIST."
5445 (mapcar '(lambda (s)
5446 (if (string-match (concat "\\<" verilog-str) s)
5447 (if (or (null verilog-pred)
5448 (funcall verilog-pred s))
5449 (setq verilog-all (cons s verilog-all)))))
5450 keyword-list))
5451
5452
5453 (defun verilog-completion (verilog-str verilog-pred verilog-flag)
5454 "Function passed to `completing-read', `try-completion' or `all-completions'.
5455 Called to get completion on VERILOG-STR. If VERILOG-PRED is non-nil, it
5456 must be a function to be called for every match to check if this should
5457 really be a match. If VERILOG-FLAG is t, the function returns a list of
5458 all possible completions. If VERILOG-FLAG is nil it returns a string,
5459 the longest possible completion, or t if VERILOG-STR is an exact match.
5460 If VERILOG-FLAG is 'lambda, the function returns t if VERILOG-STR is an
5461 exact match, nil otherwise."
5462 (save-excursion
5463 (let ((verilog-all nil))
5464 ;; Set buffer to use for searching labels. This should be set
5465 ;; within functions which use verilog-completions
5466 (set-buffer verilog-buffer-to-use)
5467
5468 ;; Determine what should be completed
5469 (let ((state (car (verilog-calculate-indent))))
5470 (cond ((eq state 'defun)
5471 (save-excursion (verilog-var-completion))
5472 (verilog-func-completion 'module)
5473 (verilog-keyword-completion verilog-defun-keywords))
5474
5475 ((eq state 'behavioral)
5476 (save-excursion (verilog-var-completion))
5477 (verilog-func-completion 'module)
5478 (verilog-keyword-completion verilog-defun-keywords))
5479
5480 ((eq state 'block)
5481 (save-excursion (verilog-var-completion))
5482 (verilog-func-completion 'tf)
5483 (verilog-keyword-completion verilog-block-keywords))
5484
5485 ((eq state 'case)
5486 (save-excursion (verilog-var-completion))
5487 (verilog-func-completion 'tf)
5488 (verilog-keyword-completion verilog-case-keywords))
5489
5490 ((eq state 'tf)
5491 (save-excursion (verilog-var-completion))
5492 (verilog-func-completion 'tf)
5493 (verilog-keyword-completion verilog-tf-keywords))
5494
5495 ((eq state 'cpp)
5496 (save-excursion (verilog-var-completion))
5497 (verilog-keyword-completion verilog-cpp-keywords))
5498
5499 ((eq state 'cparenexp)
5500 (save-excursion (verilog-var-completion)))
5501
5502 (t;--Anywhere else
5503 (save-excursion (verilog-var-completion))
5504 (verilog-func-completion 'both)
5505 (verilog-keyword-completion verilog-separator-keywords))))
5506
5507 ;; Now we have built a list of all matches. Give response to caller
5508 (verilog-completion-response))))
5509
5510 (defun verilog-completion-response ()
5511 (cond ((or (equal verilog-flag 'lambda) (null verilog-flag))
5512 ;; This was not called by all-completions
5513 (if (null verilog-all)
5514 ;; Return nil if there was no matching label
5515 nil
5516 ;; Get longest string common in the labels
5517 (let* ((elm (cdr verilog-all))
5518 (match (car verilog-all))
5519 (min (length match))
5520 tmp)
5521 (if (string= match verilog-str)
5522 ;; Return t if first match was an exact match
5523 (setq match t)
5524 (while (not (null elm))
5525 ;; Find longest common string
5526 (if (< (setq tmp (verilog-string-diff match (car elm))) min)
5527 (progn
5528 (setq min tmp)
5529 (setq match (substring match 0 min))))
5530 ;; Terminate with match=t if this is an exact match
5531 (if (string= (car elm) verilog-str)
5532 (progn
5533 (setq match t)
5534 (setq elm nil))
5535 (setq elm (cdr elm)))))
5536 ;; If this is a test just for exact match, return nil ot t
5537 (if (and (equal verilog-flag 'lambda) (not (equal match 't)))
5538 nil
5539 match))))
5540 ;; If flag is t, this was called by all-completions. Return
5541 ;; list of all possible completions
5542 (verilog-flag
5543 verilog-all)))
5544
5545 (defvar verilog-last-word-numb 0)
5546 (defvar verilog-last-word-shown nil)
5547 (defvar verilog-last-completions nil)
5548
5549 (defun verilog-complete-word ()
5550 "Complete word at current point.
5551 \(See also `verilog-toggle-completions', `verilog-type-keywords',
5552 and `verilog-separator-keywords'.)"
5553 (interactive)
5554 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
5555 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
5556 (verilog-str (buffer-substring b e))
5557 ;; The following variable is used in verilog-completion
5558 (verilog-buffer-to-use (current-buffer))
5559 (allcomp (if (and verilog-toggle-completions
5560 (string= verilog-last-word-shown verilog-str))
5561 verilog-last-completions
5562 (all-completions verilog-str 'verilog-completion)))
5563 (match (if verilog-toggle-completions
5564 "" (try-completion
5565 verilog-str (mapcar '(lambda (elm)
5566 (cons elm 0)) allcomp)))))
5567 ;; Delete old string
5568 (delete-region b e)
5569
5570 ;; Toggle-completions inserts whole labels
5571 (if verilog-toggle-completions
5572 (progn
5573 ;; Update entry number in list
5574 (setq verilog-last-completions allcomp
5575 verilog-last-word-numb
5576 (if (>= verilog-last-word-numb (1- (length allcomp)))
5577 0
5578 (1+ verilog-last-word-numb)))
5579 (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb))
5580 ;; Display next match or same string if no match was found
5581 (if (not (null allcomp))
5582 (insert "" verilog-last-word-shown)
5583 (insert "" verilog-str)
5584 (message "(No match)")))
5585 ;; The other form of completion does not necessarily do that.
5586
5587 ;; Insert match if found, or the original string if no match
5588 (if (or (null match) (equal match 't))
5589 (progn (insert "" verilog-str)
5590 (message "(No match)"))
5591 (insert "" match))
5592 ;; Give message about current status of completion
5593 (cond ((equal match 't)
5594 (if (not (null (cdr allcomp)))
5595 (message "(Complete but not unique)")
5596 (message "(Sole completion)")))
5597 ;; Display buffer if the current completion didn't help
5598 ;; on completing the label.
5599 ((and (not (null (cdr allcomp))) (= (length verilog-str)
5600 (length match)))
5601 (with-output-to-temp-buffer "*Completions*"
5602 (display-completion-list allcomp))
5603 ;; Wait for a key press. Then delete *Completion* window
5604 (momentary-string-display "" (point))
5605 (delete-window (get-buffer-window (get-buffer "*Completions*")))
5606 )))))
5607
5608 (defun verilog-show-completions ()
5609 "Show all possible completions at current point."
5610 (interactive)
5611 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point)))
5612 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point)))
5613 (verilog-str (buffer-substring b e))
5614 ;; The following variable is used in verilog-completion
5615 (verilog-buffer-to-use (current-buffer))
5616 (allcomp (if (and verilog-toggle-completions
5617 (string= verilog-last-word-shown verilog-str))
5618 verilog-last-completions
5619 (all-completions verilog-str 'verilog-completion))))
5620 ;; Show possible completions in a temporary buffer.
5621 (with-output-to-temp-buffer "*Completions*"
5622 (display-completion-list allcomp))
5623 ;; Wait for a key press. Then delete *Completion* window
5624 (momentary-string-display "" (point))
5625 (delete-window (get-buffer-window (get-buffer "*Completions*")))))
5626
5627
5628 (defun verilog-get-default-symbol ()
5629 "Return symbol around current point as a string."
5630 (save-excursion
5631 (buffer-substring (progn
5632 (skip-chars-backward " \t")
5633 (skip-chars-backward "a-zA-Z0-9_")
5634 (point))
5635 (progn
5636 (skip-chars-forward "a-zA-Z0-9_")
5637 (point)))))
5638
5639 (defun verilog-build-defun-re (str &optional arg)
5640 "Return function/task/module starting with STR as regular expression.
5641 With optional second ARG non-nil, STR is the complete name of the instruction."
5642 (if arg
5643 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "\\)\\>")
5644 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>")))
5645
5646 (defun verilog-comp-defun (verilog-str verilog-pred verilog-flag)
5647 "Function passed to `completing-read', `try-completion' or `all-completions'.
5648 Returns a completion on any function name based on VERILOG-STR prefix. If
5649 VERILOG-PRED is non-nil, it must be a function to be called for every match
5650 to check if this should really be a match. If VERILOG-FLAG is t, the
5651 function returns a list of all possible completions. If it is nil it
5652 returns a string, the longest possible completion, or t if VERILOG-STR is
5653 an exact match. If VERILOG-FLAG is 'lambda, the function returns t if
5654 VERILOG-STR is an exact match, nil otherwise."
5655 (save-excursion
5656 (let ((verilog-all nil)
5657 match)
5658
5659 ;; Set buffer to use for searching labels. This should be set
5660 ;; within functions which use verilog-completions
5661 (set-buffer verilog-buffer-to-use)
5662
5663 (let ((verilog-str verilog-str))
5664 ;; Build regular expression for functions
5665 (if (string= verilog-str "")
5666 (setq verilog-str (verilog-build-defun-re "[a-zA-Z_]"))
5667 (setq verilog-str (verilog-build-defun-re verilog-str)))
5668 (goto-char (point-min))
5669
5670 ;; Build a list of all possible completions
5671 (while (verilog-re-search-forward verilog-str nil t)
5672 (setq match (buffer-substring (match-beginning 2) (match-end 2)))
5673 (if (or (null verilog-pred)
5674 (funcall verilog-pred match))
5675 (setq verilog-all (cons match verilog-all)))))
5676
5677 ;; Now we have built a list of all matches. Give response to caller
5678 (verilog-completion-response))))
5679
5680 (defun verilog-goto-defun ()
5681 "Move to specified Verilog module/task/function.
5682 The default is a name found in the buffer around point.
5683 If search fails, other files are checked based on
5684 `verilog-library-flags'."
5685 (interactive)
5686 (let* ((default (verilog-get-default-symbol))
5687 ;; The following variable is used in verilog-comp-function
5688 (verilog-buffer-to-use (current-buffer))
5689 (label (if (not (string= default ""))
5690 ;; Do completion with default
5691 (completing-read (concat "Label: (default " default ") ")
5692 'verilog-comp-defun nil nil "")
5693 ;; There is no default value. Complete without it
5694 (completing-read "Label: "
5695 'verilog-comp-defun nil nil "")))
5696 pt)
5697 ;; If there was no response on prompt, use default value
5698 (if (string= label "")
5699 (setq label default))
5700 ;; Goto right place in buffer if label is not an empty string
5701 (or (string= label "")
5702 (progn
5703 (save-excursion
5704 (goto-char (point-min))
5705 (setq pt
5706 (re-search-forward (verilog-build-defun-re label t) nil t)))
5707 (when pt
5708 (goto-char pt)
5709 (beginning-of-line))
5710 pt)
5711 (verilog-goto-defun-file label))))
5712
5713 ;; Eliminate compile warning
5714 (defvar occur-pos-list)
5715
5716 (defun verilog-showscopes ()
5717 "List all scopes in this module."
5718 (interactive)
5719 (let ((buffer (current-buffer))
5720 (linenum 1)
5721 (nlines 0)
5722 (first 1)
5723 (prevpos (point-min))
5724 (final-context-start (make-marker))
5725 (regexp "\\(module\\s-+\\w+\\s-*(\\)\\|\\(\\w+\\s-+\\w+\\s-*(\\)"))
5726 (with-output-to-temp-buffer "*Occur*"
5727 (save-excursion
5728 (message (format "Searching for %s ..." regexp))
5729 ;; Find next match, but give up if prev match was at end of buffer.
5730 (while (and (not (= prevpos (point-max)))
5731 (verilog-re-search-forward regexp nil t))
5732 (goto-char (match-beginning 0))
5733 (beginning-of-line)
5734 (save-match-data
5735 (setq linenum (+ linenum (count-lines prevpos (point)))))
5736 (setq prevpos (point))
5737 (goto-char (match-end 0))
5738 (let* ((start (save-excursion
5739 (goto-char (match-beginning 0))
5740 (forward-line (if (< nlines 0) nlines (- nlines)))
5741 (point)))
5742 (end (save-excursion
5743 (goto-char (match-end 0))
5744 (if (> nlines 0)
5745 (forward-line (1+ nlines))
5746 (forward-line 1))
5747 (point)))
5748 (tag (format "%3d" linenum))
5749 (empty (make-string (length tag) ?\ ))
5750 tem)
5751 (save-excursion
5752 (setq tem (make-marker))
5753 (set-marker tem (point))
5754 (set-buffer standard-output)
5755 (setq occur-pos-list (cons tem occur-pos-list))
5756 (or first (zerop nlines)
5757 (insert "--------\n"))
5758 (setq first nil)
5759 (insert-buffer-substring buffer start end)
5760 (backward-char (- end start))
5761 (setq tem (if (< nlines 0) (- nlines) nlines))
5762 (while (> tem 0)
5763 (insert empty ?:)
5764 (forward-line 1)
5765 (setq tem (1- tem)))
5766 (let ((this-linenum linenum))
5767 (set-marker final-context-start
5768 (+ (point) (- (match-end 0) (match-beginning 0))))
5769 (while (< (point) final-context-start)
5770 (if (null tag)
5771 (setq tag (format "%3d" this-linenum)))
5772 (insert tag ?:)))))))
5773 (set-buffer-modified-p nil))))
5774
5775
5776 ;; Highlight helper functions
5777 (defconst verilog-directive-regexp "\\(translate\\|coverage\\|lint\\)_")
5778 (defun verilog-within-translate-off ()
5779 "Return point if within translate-off region, else nil."
5780 (and (save-excursion
5781 (re-search-backward
5782 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>")
5783 nil t))
5784 (equal "off" (match-string 2))
5785 (point)))
5786
5787 (defun verilog-start-translate-off (limit)
5788 "Return point before translate-off directive if before LIMIT, else nil."
5789 (when (re-search-forward
5790 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
5791 limit t)
5792 (match-beginning 0)))
5793
5794 (defun verilog-back-to-start-translate-off (limit)
5795 "Return point before translate-off directive if before LIMIT, else nil."
5796 (when (re-search-backward
5797 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>")
5798 limit t)
5799 (match-beginning 0)))
5800
5801 (defun verilog-end-translate-off (limit)
5802 "Return point after translate-on directive if before LIMIT, else nil."
5803
5804 (re-search-forward (concat
5805 "//\\s-*.*\\s-*" verilog-directive-regexp "on\\>") limit t))
5806
5807 (defun verilog-match-translate-off (limit)
5808 "Match a translate-off block, setting `match-data' and returning t, else nil.
5809 Bound search by LIMIT."
5810 (when (< (point) limit)
5811 (let ((start (or (verilog-within-translate-off)
5812 (verilog-start-translate-off limit)))
5813 (case-fold-search t))
5814 (when start
5815 (let ((end (or (verilog-end-translate-off limit) limit)))
5816 (set-match-data (list start end))
5817 (goto-char end))))))
5818
5819 (defun verilog-font-lock-match-item (limit)
5820 "Match, and move over, any declaration item after point.
5821 Bound search by LIMIT. Adapted from
5822 `font-lock-match-c-style-declaration-item-and-skip-to-next'."
5823 (condition-case nil
5824 (save-restriction
5825 (narrow-to-region (point-min) limit)
5826 ;; match item
5827 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)")
5828 (save-match-data
5829 (goto-char (match-end 1))
5830 ;; move to next item
5831 (if (looking-at "\\(\\s-*,\\)")
5832 (goto-char (match-end 1))
5833 (end-of-line) t))))
5834 (error nil)))
5835
5836
5837 ;; Added by Subbu Meiyappan for Header
5838
5839 (defun verilog-header ()
5840 "Insert a standard Verilog file header."
5841 (interactive)
5842 (let ((start (point)))
5843 (insert "\
5844 //-----------------------------------------------------------------------------
5845 // Title : <title>
5846 // Project : <project>
5847 //-----------------------------------------------------------------------------
5848 // File : <filename>
5849 // Author : <author>
5850 // Created : <credate>
5851 // Last modified : <moddate>
5852 //-----------------------------------------------------------------------------
5853 // Description :
5854 // <description>
5855 //-----------------------------------------------------------------------------
5856 // Copyright (c) <copydate> by <company> This model is the confidential and
5857 // proprietary property of <company> and the possession or use of this
5858 // file requires a written license from <company>.
5859 //------------------------------------------------------------------------------
5860 // Modification history :
5861 // <modhist>
5862 //-----------------------------------------------------------------------------
5863
5864 ")
5865 (goto-char start)
5866 (search-forward "<filename>")
5867 (replace-match (buffer-name) t t)
5868 (search-forward "<author>") (replace-match "" t t)
5869 (insert (user-full-name))
5870 (insert " <" (user-login-name) "@" (system-name) ">")
5871 (search-forward "<credate>") (replace-match "" t t)
5872 (verilog-insert-date)
5873 (search-forward "<moddate>") (replace-match "" t t)
5874 (verilog-insert-date)
5875 (search-forward "<copydate>") (replace-match "" t t)
5876 (verilog-insert-year)
5877 (search-forward "<modhist>") (replace-match "" t t)
5878 (verilog-insert-date)
5879 (insert " : created")
5880 (goto-char start)
5881 (let (string)
5882 (setq string (read-string "title: "))
5883 (search-forward "<title>")
5884 (replace-match string t t)
5885 (setq string (read-string "project: " verilog-project))
5886 (setq verilog-project string)
5887 (search-forward "<project>")
5888 (replace-match string t t)
5889 (setq string (read-string "Company: " verilog-company))
5890 (setq verilog-company string)
5891 (search-forward "<company>")
5892 (replace-match string t t)
5893 (search-forward "<company>")
5894 (replace-match string t t)
5895 (search-forward "<company>")
5896 (replace-match string t t)
5897 (search-backward "<description>")
5898 (replace-match "" t t))))
5899
5900 ;; verilog-header Uses the verilog-insert-date function
5901
5902 (defun verilog-insert-date ()
5903 "Insert date from the system."
5904 (interactive)
5905 (let ((timpos))
5906 (setq timpos (point))
5907 (if verilog-date-scientific-format
5908 (shell-command "date \"+@%Y/%m/%d\"" t)
5909 (shell-command "date \"+@%d.%m.%Y\"" t))
5910 (search-forward "@")
5911 (delete-region timpos (point))
5912 (end-of-line))
5913 (delete-char 1))
5914
5915 (defun verilog-insert-year ()
5916 "Insert year from the system."
5917 (interactive)
5918 (let ((timpos))
5919 (setq timpos (point))
5920 (shell-command "date \"+@%Y\"" t)
5921 (search-forward "@")
5922 (delete-region timpos (point))
5923 (end-of-line))
5924 (delete-char 1))
5925
5926 \f
5927 ;;
5928 ;; Signal list parsing
5929 ;;
5930
5931 ;; Elements of a signal list
5932 (defsubst verilog-sig-name (sig)
5933 (car sig))
5934 (defsubst verilog-sig-bits (sig)
5935 (nth 1 sig))
5936 (defsubst verilog-sig-comment (sig)
5937 (nth 2 sig))
5938 (defsubst verilog-sig-memory (sig)
5939 (nth 3 sig))
5940 (defsubst verilog-sig-enum (sig)
5941 (nth 4 sig))
5942 (defsubst verilog-sig-signed (sig)
5943 (nth 5 sig))
5944 (defsubst verilog-sig-type (sig)
5945 (nth 6 sig))
5946 (defsubst verilog-sig-multidim (sig)
5947 (nth 7 sig))
5948 (defsubst verilog-sig-multidim-string (sig)
5949 (if (verilog-sig-multidim sig)
5950 (let ((str "") (args (verilog-sig-multidim sig)))
5951 (while args
5952 (setq str (concat str (car args)))
5953 (setq args (cdr args)))
5954 str)))
5955 (defsubst verilog-sig-width (sig)
5956 (verilog-make-width-expression (verilog-sig-bits sig)))
5957
5958 (defsubst verilog-alw-get-inputs (sigs)
5959 (nth 2 sigs))
5960 (defsubst verilog-alw-get-outputs (sigs)
5961 (nth 0 sigs))
5962 (defsubst verilog-alw-get-uses-delayed (sigs)
5963 (nth 3 sigs))
5964
5965 (defun verilog-signals-not-in (in-list not-list)
5966 "Return list of signals in IN-LIST that aren't also in NOT-LIST.
5967 Also remove any duplicates in IN-LIST.
5968 Signals must be in standard (base vector) form."
5969 (let (out-list)
5970 (while in-list
5971 (if (not (or (assoc (car (car in-list)) not-list)
5972 (assoc (car (car in-list)) out-list)))
5973 (setq out-list (cons (car in-list) out-list)))
5974 (setq in-list (cdr in-list)))
5975 (nreverse out-list)))
5976 ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" "")))
5977
5978 (defun verilog-signals-in (in-list other-list)
5979 "Return list of signals in IN-LIST that are also in OTHER-LIST.
5980 Signals must be in standard (base vector) form."
5981 (let (out-list)
5982 (while in-list
5983 (if (assoc (car (car in-list)) other-list)
5984 (setq out-list (cons (car in-list) out-list)))
5985 (setq in-list (cdr in-list)))
5986 (nreverse out-list)))
5987 ;;(verilog-signals-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" "")))
5988
5989 (defun verilog-signals-memory (in-list)
5990 "Return list of signals in IN-LIST that are memoried (multidimensional)."
5991 (let (out-list)
5992 (while in-list
5993 (if (nth 3 (car in-list))
5994 (setq out-list (cons (car in-list) out-list)))
5995 (setq in-list (cdr in-list)))
5996 out-list))
5997 ;;(verilog-signals-memory '(("A" nil nil "[3:0]")) '(("B" nil nil nil)))
5998
5999 (defun verilog-signals-sort-compare (a b)
6000 "Compare signal A and B for sorting."
6001 (string< (car a) (car b)))
6002
6003 (defun verilog-signals-not-params (in-list)
6004 "Return list of signals in IN-LIST that aren't parameters or numeric constants."
6005 (let (out-list)
6006 (while in-list
6007 (unless (boundp (intern (concat "vh-" (car (car in-list)))))
6008 (setq out-list (cons (car in-list) out-list)))
6009 (setq in-list (cdr in-list)))
6010 (nreverse out-list)))
6011
6012 (defun verilog-signals-combine-bus (in-list)
6013 "Return a list of signals in IN-LIST, with busses combined.
6014 Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]."
6015 (let (combo buswarn
6016 out-list
6017 sig highbit lowbit ; Temp information about current signal
6018 sv-name sv-highbit sv-lowbit ; Details about signal we are forming
6019 sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring
6020 bus)
6021 ;; Shove signals so duplicated signals will be adjacent
6022 (setq in-list (sort in-list `verilog-signals-sort-compare))
6023 (while in-list
6024 (setq sig (car in-list))
6025 ;; No current signal; form from existing details
6026 (unless sv-name
6027 (setq sv-name (verilog-sig-name sig)
6028 sv-highbit nil
6029 sv-busstring nil
6030 sv-comment (verilog-sig-comment sig)
6031 sv-memory (verilog-sig-memory sig)
6032 sv-enum (verilog-sig-enum sig)
6033 sv-signed (verilog-sig-signed sig)
6034 sv-type (verilog-sig-type sig)
6035 sv-multidim (verilog-sig-multidim sig)
6036 combo ""
6037 buswarn ""))
6038 ;; Extract bus details
6039 (setq bus (verilog-sig-bits sig))
6040 (cond ((and bus
6041 (or (and (string-match "\\[\\([0-9]+\\):\\([0-9]+\\)\\]" bus)
6042 (setq highbit (string-to-number (match-string 1 bus))
6043 lowbit (string-to-number
6044 (match-string 2 bus))))
6045 (and (string-match "\\[\\([0-9]+\\)\\]" bus)
6046 (setq highbit (string-to-number (match-string 1 bus))
6047 lowbit highbit))))
6048 ;; Combine bits in bus
6049 (if sv-highbit
6050 (setq sv-highbit (max highbit sv-highbit)
6051 sv-lowbit (min lowbit sv-lowbit))
6052 (setq sv-highbit highbit
6053 sv-lowbit lowbit)))
6054 (bus
6055 ;; String, probably something like `preproc:0
6056 (setq sv-busstring bus)))
6057 ;; Peek ahead to next signal
6058 (setq in-list (cdr in-list))
6059 (setq sig (car in-list))
6060 (cond ((and sig (equal sv-name (verilog-sig-name sig)))
6061 ;; Combine with this signal
6062 (when (and sv-busstring
6063 (not (equal sv-busstring (verilog-sig-bits sig))))
6064 (when nil ;; Debugging
6065 (message (concat "Warning, can't merge into single bus "
6066 sv-name bus
6067 ", the AUTOs may be wrong")))
6068 (setq buswarn ", Couldn't Merge"))
6069 (if (verilog-sig-comment sig) (setq combo ", ..."))
6070 (setq sv-memory (or sv-memory (verilog-sig-memory sig))
6071 sv-enum (or sv-enum (verilog-sig-enum sig))
6072 sv-signed (or sv-signed (verilog-sig-signed sig))
6073 sv-type (or sv-type (verilog-sig-type sig))
6074 sv-multidim (or sv-multidim (verilog-sig-multidim sig))))
6075 ;; Doesn't match next signal, add to queue, zero in prep for next
6076 ;; Note sig may also be nil for the last signal in the list
6077 (t
6078 (setq out-list
6079 (cons
6080 (list sv-name
6081 (or sv-busstring
6082 (if sv-highbit
6083 (concat "[" (int-to-string sv-highbit) ":"
6084 (int-to-string sv-lowbit) "]")))
6085 (concat sv-comment combo buswarn)
6086 sv-memory sv-enum sv-signed sv-type sv-multidim)
6087 out-list)
6088 sv-name nil))))
6089 ;;
6090 out-list))
6091
6092 (defun verilog-sig-tieoff (sig &optional no-width)
6093 "Return tieoff expression for given SIG, with appropriate width.
6094 Ignore width if optional NO-WIDTH is set."
6095 (let* ((width (if no-width nil (verilog-sig-width sig))))
6096 (concat
6097 (if (and verilog-active-low-regexp
6098 (string-match verilog-active-low-regexp (verilog-sig-name sig)))
6099 "~" "")
6100 (cond ((not width)
6101 "0")
6102 ((string-match "^[0-9]+$" width)
6103 (concat width (if (verilog-sig-signed sig) "'sh0" "'h0")))
6104 (t
6105 (concat "{" width "{1'b0}}"))))))
6106
6107 ;;
6108 ;; Port/Wire/Etc Reading
6109 ;;
6110
6111 (defun verilog-read-inst-backward-name ()
6112 "Internal. Move point back to beginning of inst-name."
6113 (verilog-backward-open-paren)
6114 (let (done)
6115 (while (not done)
6116 (verilog-re-search-backward-quick "\\()\\|\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil) ; ] isn't word boundary
6117 (cond ((looking-at ")")
6118 (verilog-backward-open-paren))
6119 (t (setq done t)))))
6120 (while (looking-at "\\]")
6121 (verilog-backward-open-bracket)
6122 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil))
6123 (skip-chars-backward "a-zA-Z0-9`_$"))
6124
6125 (defun verilog-read-inst-module ()
6126 "Return module_name when point is inside instantiation."
6127 (save-excursion
6128 (verilog-read-inst-backward-name)
6129 ;; Skip over instantiation name
6130 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary
6131 ;; Check for parameterized instantiations
6132 (when (looking-at ")")
6133 (verilog-backward-open-paren)
6134 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil))
6135 (skip-chars-backward "a-zA-Z0-9'_$")
6136 (looking-at "[a-zA-Z0-9`_\$]+")
6137 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
6138 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))
6139
6140 (defun verilog-read-inst-name ()
6141 "Return instance_name when point is inside instantiation."
6142 (save-excursion
6143 (verilog-read-inst-backward-name)
6144 (looking-at "[a-zA-Z0-9`_\$]+")
6145 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
6146 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))
6147
6148 (defun verilog-read-module-name ()
6149 "Return module name when after its ( or ;."
6150 (save-excursion
6151 (re-search-backward "[(;]")
6152 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil)
6153 (skip-chars-backward "a-zA-Z0-9`_$")
6154 (looking-at "[a-zA-Z0-9`_\$]+")
6155 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
6156 (buffer-substring-no-properties (match-beginning 0) (match-end 0))))
6157
6158 (defun verilog-read-inst-param-value ()
6159 "Return list of parameters and values when point is inside instantiation."
6160 (save-excursion
6161 (verilog-read-inst-backward-name)
6162 ;; Skip over instantiation name
6163 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary
6164 ;; If there are parameterized instantiations
6165 (when (looking-at ")")
6166 (let ((end-pt (point))
6167 params
6168 param-name paren-beg-pt param-value)
6169 (verilog-backward-open-paren)
6170 (while (verilog-re-search-forward-quick "\\." end-pt t)
6171 (verilog-re-search-forward-quick "\\([a-zA-Z0-9`_\$]\\)" nil nil)
6172 (skip-chars-backward "a-zA-Z0-9'_$")
6173 (looking-at "[a-zA-Z0-9`_\$]+")
6174 (setq param-name (buffer-substring-no-properties
6175 (match-beginning 0) (match-end 0)))
6176 (verilog-re-search-forward-quick "(" nil nil)
6177 (setq paren-beg-pt (point))
6178 (verilog-forward-close-paren)
6179 (setq param-value (verilog-string-remove-spaces
6180 (buffer-substring-no-properties
6181 paren-beg-pt (1- (point)))))
6182 (setq params (cons (list param-name param-value) params)))
6183 params))))
6184
6185 (defun verilog-read-auto-params (num-param &optional max-param)
6186 "Return parameter list inside auto.
6187 Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters."
6188 (let ((olist))
6189 (save-excursion
6190 ;; /*AUTOPUNT("parameter", "parameter")*/
6191 (search-backward "(")
6192 (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?")
6193 (setq olist (cons (match-string 1) olist))
6194 (goto-char (match-end 0))))
6195 (or (eq nil num-param)
6196 (<= num-param (length olist))
6197 (error "%s: Expected %d parameters" (verilog-point-text) num-param))
6198 (if (eq max-param nil) (setq max-param num-param))
6199 (or (eq nil max-param)
6200 (>= max-param (length olist))
6201 (error "%s: Expected <= %d parameters" (verilog-point-text) max-param))
6202 (nreverse olist)))
6203
6204 (defun verilog-read-decls ()
6205 "Compute signal declaration information for the current module at point.
6206 Return a array of [outputs inouts inputs wire reg assign const]."
6207 (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max)))
6208 (functask 0) (paren 0) (sig-paren 0)
6209 sigs-in sigs-out sigs-inout sigs-wire sigs-reg sigs-assign sigs-const sigs-gparam
6210 vec expect-signal keywd newsig rvalue enum io signed typedefed multidim)
6211 (save-excursion
6212 (verilog-beg-of-defun)
6213 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point))
6214 (while (< (point) end-mod-point)
6215 ;;(if dbg (setq dbg (cons (format "Pt %s Vec %s Kwd'%s'\n" (point) vec keywd) dbg)))
6216 (cond
6217 ((looking-at "//")
6218 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
6219 (setq enum (match-string 1)))
6220 (search-forward "\n"))
6221 ((looking-at "/\\*")
6222 (forward-char 2)
6223 (if (looking-at "[^*]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
6224 (setq enum (match-string 1)))
6225 (or (search-forward "*/")
6226 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
6227 ((looking-at "(\\*")
6228 (forward-char 2)
6229 (or (looking-at "\\s-*)") ; It's a "always @ (*)"
6230 (search-forward "*)")
6231 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
6232 ((eq ?\" (following-char))
6233 (or (re-search-forward "[^\\]\"" nil t) ;; don't forward-char first, since we look for a non backslash first
6234 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
6235 ((eq ?\; (following-char))
6236 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil)
6237 (forward-char 1))
6238 ((eq ?= (following-char))
6239 (setq rvalue t newsig nil)
6240 (forward-char 1))
6241 ((and (or rvalue sig-paren)
6242 (cond ((and (eq ?, (following-char))
6243 (eq paren sig-paren))
6244 (setq rvalue nil)
6245 (forward-char 1)
6246 t)
6247 ;; ,'s can occur inside {} & funcs
6248 ((looking-at "[{(]")
6249 (setq paren (1+ paren))
6250 (forward-char 1)
6251 t)
6252 ((looking-at "[})]")
6253 (setq paren (1- paren))
6254 (forward-char 1)
6255 (when (< paren sig-paren)
6256 (setq expect-signal nil)) ; ) that ends variables inside v2k arg list
6257 t))))
6258 ((looking-at "\\s-*\\(\\[[^]]+\\]\\)")
6259 (goto-char (match-end 0))
6260 (cond (newsig ; Memory, not just width. Patch last signal added's memory (nth 3)
6261 (setcar (cdr (cdr (cdr newsig))) (match-string 1)))
6262 (vec ;; Multidimensional
6263 (setq multidim (cons vec multidim))
6264 (setq vec (verilog-string-replace-matches
6265 "\\s-+" "" nil nil (match-string 1))))
6266 (t ;; Bit width
6267 (setq vec (verilog-string-replace-matches
6268 "\\s-+" "" nil nil (match-string 1))))))
6269 ;; Normal or escaped identifier -- note we remember the \ if escaped
6270 ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)")
6271 (goto-char (match-end 0))
6272 (setq keywd (match-string 1))
6273 (when (string-match "^\\\\" keywd)
6274 (setq keywd (concat keywd " "))) ;; Escaped ID needs space at end
6275 (cond ((equal keywd "input")
6276 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren
6277 expect-signal 'sigs-in io t))
6278 ((equal keywd "output")
6279 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren
6280 expect-signal 'sigs-out io t))
6281 ((equal keywd "inout")
6282 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren
6283 expect-signal 'sigs-inout io t))
6284 ((or (equal keywd "wire")
6285 (equal keywd "tri")
6286 (equal keywd "tri0")
6287 (equal keywd "tri1"))
6288 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
6289 expect-signal 'sigs-wire)))
6290 ((member keywd (list "reg" "trireg"
6291 "byte" "shortint" "int" "longint" "integer" "time"
6292 "bit" "logic"))
6293 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
6294 expect-signal 'sigs-reg)))
6295 ((equal keywd "assign")
6296 (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
6297 expect-signal 'sigs-assign))
6298 ((or (equal keywd "supply0")
6299 (equal keywd "supply1")
6300 (equal keywd "supply")
6301 (equal keywd "localparam")
6302 (equal keywd "genvar"))
6303 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
6304 expect-signal 'sigs-const)))
6305 ((or (equal keywd "parameter"))
6306 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
6307 expect-signal 'sigs-gparam)))
6308 ((equal keywd "signed")
6309 (setq signed "signed"))
6310 ((or (equal keywd "function")
6311 (equal keywd "task"))
6312 (setq functask (1+ functask)))
6313 ((or (equal keywd "endfunction")
6314 (equal keywd "endtask"))
6315 (setq functask (1- functask)))
6316 ((or (equal keywd "`ifdef")
6317 (equal keywd "`ifndef"))
6318 (setq rvalue t))
6319 ((verilog-typedef-name-p keywd)
6320 (setq typedefed keywd))
6321 ((and expect-signal
6322 (eq functask 0)
6323 (not rvalue)
6324 (eq paren sig-paren)
6325 (not (member keywd verilog-keywords)))
6326 ;; Add new signal to expect-signal's variable
6327 (setq newsig (list keywd vec nil nil enum signed typedefed multidim))
6328 (set expect-signal (cons newsig
6329 (symbol-value expect-signal))))))
6330 (t
6331 (forward-char 1)))
6332 (skip-syntax-forward " "))
6333 ;; Return arguments
6334 (vector (nreverse sigs-out)
6335 (nreverse sigs-inout)
6336 (nreverse sigs-in)
6337 (nreverse sigs-wire)
6338 (nreverse sigs-reg)
6339 (nreverse sigs-assign)
6340 (nreverse sigs-const)
6341 (nreverse sigs-gparam)))))
6342
6343 (eval-when-compile
6344 ;; Prevent compile warnings; these are let's, not globals
6345 ;; Do not remove the eval-when-compile
6346 ;; - we want a error when we are debugging this code if they are refed.
6347 (defvar sigs-in)
6348 (defvar sigs-inout)
6349 (defvar sigs-out))
6350
6351
6352 (defsubst verilog-modi-get-decls (modi)
6353 (verilog-modi-cache-results modi 'verilog-read-decls))
6354
6355 (defsubst verilog-modi-get-sub-decls (modi)
6356 (verilog-modi-cache-results modi 'verilog-read-sub-decls))
6357
6358
6359 ;; Signal reading for given module
6360 ;; Note these all take modi's - as returned from the
6361 ;; verilog-modi-current function.
6362 (defsubst verilog-decls-get-outputs (decls)
6363 (aref decls 0))
6364 (defsubst verilog-decls-get-inouts (decls)
6365 (aref decls 1))
6366 (defsubst verilog-decls-get-inputs (decls)
6367 (aref decls 2))
6368 (defsubst verilog-decls-get-wires (decls)
6369 (aref decls 3))
6370 (defsubst verilog-decls-get-regs (decls)
6371 (aref decls 4))
6372 (defsubst verilog-decls-get-assigns (decls)
6373 (aref decls 5))
6374 (defsubst verilog-decls-get-consts (decls)
6375 (aref decls 6))
6376 (defsubst verilog-decls-get-gparams (decls)
6377 (aref decls 7))
6378 (defsubst verilog-subdecls-get-outputs (subdecls)
6379 (aref subdecls 0))
6380 (defsubst verilog-subdecls-get-inouts (subdecls)
6381 (aref subdecls 1))
6382 (defsubst verilog-subdecls-get-inputs (subdecls)
6383 (aref subdecls 2))
6384
6385
6386 (defun verilog-read-sub-decls-sig (submoddecls comment port sig vec multidim)
6387 "For `verilog-read-sub-decls-line', add a signal."
6388 (let (portdata)
6389 (when sig
6390 (setq port (verilog-symbol-detick-denumber port))
6391 (setq sig (verilog-symbol-detick-denumber sig))
6392 (if sig (setq sig (verilog-string-replace-matches "^[---+~!|&]+" "" nil nil sig)))
6393 (if vec (setq vec (verilog-symbol-detick-denumber vec)))
6394 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim)))
6395 (unless (or (not sig)
6396 (equal sig "")) ;; Ignore .foo(1'b1) assignments
6397 (cond ((setq portdata (assoc port (verilog-decls-get-inouts submoddecls)))
6398 (setq sigs-inout (cons (list sig vec (concat "To/From " comment) nil nil
6399 (verilog-sig-signed portdata)
6400 (verilog-sig-type portdata)
6401 multidim)
6402 sigs-inout)))
6403 ((setq portdata (assoc port (verilog-decls-get-outputs submoddecls)))
6404 (setq sigs-out (cons (list sig vec (concat "From " comment) nil nil
6405 (verilog-sig-signed portdata)
6406 (verilog-sig-type portdata)
6407 multidim)
6408 sigs-out)))
6409 ((setq portdata (assoc port (verilog-decls-get-inputs submoddecls)))
6410 (setq sigs-in (cons (list sig vec (concat "To " comment) nil nil
6411 (verilog-sig-signed portdata)
6412 (verilog-sig-type portdata)
6413 multidim)
6414 sigs-in)))
6415 ;; (t -- warning pin isn't defined.) ; Leave for lint tool
6416 )))))
6417
6418 (defun verilog-read-sub-decls-line (submoddecls comment)
6419 "For `verilog-read-sub-decls', read lines of port defs until none match anymore.
6420 Return the list of signals found, using submodi to look up each port."
6421 (let (done port sig vec multidim)
6422 (save-excursion
6423 (forward-line 1)
6424 (while (not done)
6425 ;; Get port name
6426 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*")
6427 (setq port (match-string 1))
6428 (goto-char (match-end 0)))
6429 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*")
6430 (setq port (concat (match-string 1) " ")) ;; escaped id's need trailing space
6431 (goto-char (match-end 0)))
6432 ((looking-at "\\s-*\\.[^(]*(")
6433 (setq port nil) ;; skip this line
6434 (goto-char (match-end 0)))
6435 (t
6436 (setq port nil done t))) ;; Unknown, ignore rest of line
6437 ;; Get signal name
6438 (when port
6439 (setq multidim nil)
6440 (cond ((looking-at "\\(\\\\[^ \t\n\f]*\\)\\s-*)")
6441 (setq sig (concat (match-string 1) " ") ;; escaped id's need trailing space
6442 vec nil))
6443 ; We intentionally ignore (non-escaped) signals with .s in them
6444 ; this prevents AUTOWIRE etc from noticing hierarchical sigs.
6445 ((looking-at "\\([^[({).]*\\)\\s-*)")
6446 (setq sig (verilog-string-remove-spaces (match-string 1))
6447 vec nil))
6448 ((looking-at "\\([^[({).]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)")
6449 (setq sig (verilog-string-remove-spaces (match-string 1))
6450 vec (match-string 2)))
6451 ((looking-at "\\([^[({).]*\\)\\s-*/\\*\\(\\[[^*]+\\]\\)\\*/\\s-*)")
6452 (setq sig (verilog-string-remove-spaces (match-string 1))
6453 vec nil)
6454 (let ((parse (match-string 2)))
6455 (while (string-match "^\\(\\[[^]]+\\]\\)\\(.*\\)$" parse)
6456 (when vec (setq multidim (cons vec multidim)))
6457 (setq vec (match-string 1 parse))
6458 (setq parse (match-string 2 parse)))))
6459 ((looking-at "{\\(.*\\)}.*\\s-*)")
6460 (let ((mlst (split-string (match-string 1) ","))
6461 mstr)
6462 (while (setq mstr (pop mlst))
6463 ;;(unless noninteractive (message "sig: %s " mstr))
6464 (cond
6465 ((string-match "\\(['`a-zA-Z0-9_$]+\\)\\s-*$" mstr)
6466 (setq sig (verilog-string-remove-spaces (match-string 1 mstr))
6467 vec nil)
6468 ;;(unless noninteractive (message "concat sig1: %s %s" mstr (match-string 1 mstr)))
6469 )
6470 ((string-match "\\([^[({).]+\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*" mstr)
6471 (setq sig (verilog-string-remove-spaces (match-string 1 mstr))
6472 vec (match-string 2 mstr))
6473 ;;(unless noninteractive (message "concat sig2: '%s' '%s' '%s'" mstr (match-string 1 mstr) (match-string 2 mstr)))
6474 )
6475 (t
6476 (setq sig nil)))
6477 ;; Process signals
6478 (verilog-read-sub-decls-sig submoddecls comment port sig vec multidim))))
6479 (t
6480 (setq sig nil)))
6481 ;; Process signals
6482 (verilog-read-sub-decls-sig submoddecls comment port sig vec multidim))
6483 ;;
6484 (forward-line 1)))))
6485
6486 (defun verilog-read-sub-decls ()
6487 "Internally parse signals going to modules under this module.
6488 Return a array of [ outputs inouts inputs ] signals for modules that are
6489 instantiated in this module. For example if declare A A (.B(SIG)) and SIG
6490 is a output, then SIG will be included in the list.
6491
6492 This only works on instantiations created with /*AUTOINST*/ converted by
6493 \\[verilog-auto-inst]. Otherwise, it would have to read in the whole
6494 component library to determine connectivity of the design.
6495
6496 One work around for this problem is to manually create // Inputs and //
6497 Outputs comments above subcell signals, for example:
6498
6499 module ModuleName (
6500 // Outputs
6501 .out (out),
6502 // Inputs
6503 .in (in));"
6504 (save-excursion
6505 (let ((end-mod-point (verilog-get-end-of-defun t))
6506 st-point end-inst-point
6507 ;; below 3 modified by verilog-read-sub-decls-line
6508 sigs-out sigs-inout sigs-in)
6509 (verilog-beg-of-defun)
6510 (while (verilog-re-search-forward "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t)
6511 (save-excursion
6512 (goto-char (match-beginning 0))
6513 (unless (verilog-inside-comment-p)
6514 ;; Attempt to snarf a comment
6515 (let* ((submod (verilog-read-inst-module))
6516 (inst (verilog-read-inst-name))
6517 (comment (concat inst " of " submod ".v"))
6518 submodi submoddecls)
6519 (when (setq submodi (verilog-modi-lookup submod t))
6520 (setq submoddecls (verilog-modi-get-decls submodi))
6521 ;; This could have used a list created by verilog-auto-inst
6522 ;; However I want it to be runnable even on user's manually added signals
6523 (verilog-backward-open-paren)
6524 (setq end-inst-point (save-excursion (forward-sexp 1) (point))
6525 st-point (point))
6526 (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t)
6527 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
6528 (goto-char st-point)
6529 (while (re-search-forward "\\s *// Inouts" end-inst-point t)
6530 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-inout
6531 (goto-char st-point)
6532 (while (re-search-forward "\\s *// Inputs" end-inst-point t)
6533 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-in
6534 )))))
6535 ;; Combine duplicate bits
6536 ;;(setq rr (vector sigs-out sigs-inout sigs-in))
6537 (vector (verilog-signals-combine-bus (nreverse sigs-out))
6538 (verilog-signals-combine-bus (nreverse sigs-inout))
6539 (verilog-signals-combine-bus (nreverse sigs-in))))))
6540
6541 (defun verilog-read-inst-pins ()
6542 "Return an array of [ pins ] for the current instantiation at point.
6543 For example if declare A A (.B(SIG)) then B will be included in the list."
6544 (save-excursion
6545 (let ((end-mod-point (point)) ;; presume at /*AUTOINST*/ point
6546 pins pin)
6547 (verilog-backward-open-paren)
6548 (while (re-search-forward "\\.\\([^(,) \t\n\f]*\\)\\s-*" end-mod-point t)
6549 (setq pin (match-string 1))
6550 (unless (verilog-inside-comment-p)
6551 (setq pins (cons (list pin) pins))
6552 (when (looking-at "(")
6553 (forward-sexp 1))))
6554 (vector pins))))
6555
6556 (defun verilog-read-arg-pins ()
6557 "Return an array of [ pins ] for the current argument declaration at point."
6558 (save-excursion
6559 (let ((end-mod-point (point)) ;; presume at /*AUTOARG*/ point
6560 pins pin)
6561 (verilog-backward-open-paren)
6562 (while (re-search-forward "\\([a-zA-Z0-9$_.%`]+\\)" end-mod-point t)
6563 (setq pin (match-string 1))
6564 (unless (verilog-inside-comment-p)
6565 (setq pins (cons (list pin) pins))))
6566 (vector pins))))
6567
6568 (defun verilog-read-auto-constants (beg end-mod-point)
6569 "Return a list of AUTO_CONSTANTs used in the region from BEG to END-MOD-POINT."
6570 ;; Insert new
6571 (save-excursion
6572 (let (sig-list tpl-end-pt)
6573 (goto-char beg)
6574 (while (re-search-forward "\\<AUTO_CONSTANT" end-mod-point t)
6575 (if (not (looking-at "\\s *("))
6576 (error "%s: Missing () after AUTO_CONSTANT" (verilog-point-text)))
6577 (search-forward "(" end-mod-point)
6578 (setq tpl-end-pt (save-excursion
6579 (backward-char 1)
6580 (forward-sexp 1) ;; Moves to paren that closes argdecl's
6581 (backward-char 1)
6582 (point)))
6583 (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t)
6584 (setq sig-list (cons (list (match-string 1) nil nil) sig-list))))
6585 sig-list)))
6586
6587 (defun verilog-read-auto-lisp (start end)
6588 "Look for and evaluate a AUTO_LISP between START and END."
6589 (save-excursion
6590 (goto-char start)
6591 (while (re-search-forward "\\<AUTO_LISP(" end t)
6592 (backward-char)
6593 (let* ((beg-pt (prog1 (point)
6594 (forward-sexp 1))) ;; Closing paren
6595 (end-pt (point)))
6596 (eval-region beg-pt end-pt nil)))))
6597
6598 (eval-when-compile
6599 ;; Prevent compile warnings; these are let's, not globals
6600 ;; Do not remove the eval-when-compile
6601 ;; - we want a error when we are debugging this code if they are refed.
6602 (defvar sigs-in)
6603 (defvar sigs-out)
6604 (defvar got-sig)
6605 (defvar got-rvalue)
6606 (defvar uses-delayed)
6607 (defvar vector-skip-list))
6608
6609 (defun verilog-read-always-signals-recurse
6610 (exit-keywd rvalue ignore-next)
6611 "Recursive routine for parentheses/bracket matching.
6612 EXIT-KEYWD is expression to stop at, nil if top level.
6613 RVALUE is true if at right hand side of equal.
6614 IGNORE-NEXT is true to ignore next token, fake from inside case statement."
6615 (let* ((semi-rvalue (equal "endcase" exit-keywd)) ;; true if after a ; we are looking for rvalue
6616 keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-rvalue end-else-check)
6617 ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue ignore-next))))
6618 (while (not (or (eobp) gotend))
6619 (cond
6620 ((looking-at "//")
6621 (search-forward "\n"))
6622 ((looking-at "/\\*")
6623 (or (search-forward "*/")
6624 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
6625 ((looking-at "(\\*")
6626 (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)"
6627 (search-forward "*)")
6628 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
6629 (t (setq keywd (buffer-substring-no-properties
6630 (point)
6631 (save-excursion (when (eq 0 (skip-chars-forward "a-zA-Z0-9$_.%`"))
6632 (forward-char 1))
6633 (point)))
6634 sig-last-tolk sig-tolk
6635 sig-tolk nil)
6636 ;;(if dbg (setq dbg (concat dbg (format "\tPt=%S %S\trv=%S in=%S ee=%S\n" (point) keywd rvalue ignore-next end-else-check))))
6637 (cond
6638 ((equal keywd "\"")
6639 (or (re-search-forward "[^\\]\"" nil t)
6640 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
6641 ;; else at top level loop, keep parsing
6642 ((and end-else-check (equal keywd "else"))
6643 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else %s\n" keywd))))
6644 ;; no forward movement, want to see else in lower loop
6645 (setq end-else-check nil))
6646 ;; End at top level loop
6647 ((and end-else-check (looking-at "[^ \t\n\f]"))
6648 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else-other %s\n" keywd))))
6649 (setq gotend t))
6650 ;; Final statement?
6651 ((and exit-keywd (equal keywd exit-keywd))
6652 (setq gotend t)
6653 (forward-char (length keywd)))
6654 ;; Standard tokens...
6655 ((equal keywd ";")
6656 (setq ignore-next nil rvalue semi-rvalue)
6657 ;; Final statement at top level loop?
6658 (when (not exit-keywd)
6659 ;;(if dbg (setq dbg (concat dbg (format "\ttop-end-check %s\n" keywd))))
6660 (setq end-else-check t))
6661 (forward-char 1))
6662 ((equal keywd "'")
6663 (if (looking-at "'s?[hdxbo][0-9a-fA-F_xz? \t]*")
6664 (goto-char (match-end 0))
6665 (forward-char 1)))
6666 ((equal keywd ":") ;; Case statement, begin/end label, x?y:z
6667 (cond ((equal "endcase" exit-keywd) ;; case x: y=z; statement next
6668 (setq ignore-next nil rvalue nil))
6669 ((equal "?" exit-keywd) ;; x?y:z rvalue
6670 ) ;; NOP
6671 (got-sig ;; label: statement
6672 (setq ignore-next nil rvalue semi-rvalue got-sig nil))
6673 ((not rvalue) ;; begin label
6674 (setq ignore-next t rvalue nil)))
6675 (forward-char 1))
6676 ((equal keywd "=")
6677 (if (eq (char-before) ?< )
6678 (setq uses-delayed 1))
6679 (setq ignore-next nil rvalue t)
6680 (forward-char 1))
6681 ((equal keywd "?")
6682 (forward-char 1)
6683 (verilog-read-always-signals-recurse ":" rvalue nil))
6684 ((equal keywd "[")
6685 (forward-char 1)
6686 (verilog-read-always-signals-recurse "]" t nil))
6687 ((equal keywd "(")
6688 (forward-char 1)
6689 (cond (sig-last-tolk ;; Function call; zap last signal
6690 (setq got-sig nil)))
6691 (cond ((equal last-keywd "for")
6692 (verilog-read-always-signals-recurse ";" nil nil)
6693 (verilog-read-always-signals-recurse ";" t nil)
6694 (verilog-read-always-signals-recurse ")" nil nil))
6695 (t (verilog-read-always-signals-recurse ")" t nil))))
6696 ((equal keywd "begin")
6697 (skip-syntax-forward "w_")
6698 (verilog-read-always-signals-recurse "end" nil nil)
6699 ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd))))
6700 (setq ignore-next nil rvalue semi-rvalue)
6701 (if (not exit-keywd) (setq end-else-check t)))
6702 ((or (equal keywd "case")
6703 (equal keywd "casex")
6704 (equal keywd "casez"))
6705 (skip-syntax-forward "w_")
6706 (verilog-read-always-signals-recurse "endcase" t nil)
6707 (setq ignore-next nil rvalue semi-rvalue)
6708 (if (not exit-keywd) (setq gotend t))) ;; top level begin/end
6709 ((string-match "^[$`a-zA-Z_]" keywd) ;; not exactly word constituent
6710 (cond ((or (equal keywd "`ifdef")
6711 (equal keywd "`ifndef"))
6712 (setq ignore-next t))
6713 ((or ignore-next
6714 (member keywd verilog-keywords)
6715 (string-match "^\\$" keywd)) ;; PLI task
6716 (setq ignore-next nil))
6717 (t
6718 (setq keywd (verilog-symbol-detick-denumber keywd))
6719 (when got-sig
6720 (if got-rvalue (setq sigs-in (cons got-sig sigs-in))
6721 (setq sigs-out (cons got-sig sigs-out)))
6722 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S rv=%S\n" got-sig got-rvalue))))
6723 )
6724 (setq got-rvalue rvalue
6725 got-sig (if (or (not keywd)
6726 (assoc keywd (if got-rvalue sigs-in sigs-out)))
6727 nil (list keywd nil nil))
6728 sig-tolk t)))
6729 (skip-chars-forward "a-zA-Z0-9$_.%`"))
6730 (t
6731 (forward-char 1)))
6732 ;; End of non-comment token
6733 (setq last-keywd keywd)))
6734 (skip-syntax-forward " "))
6735 ;; Append the final pending signal
6736 (when got-sig
6737 (if got-rvalue (setq sigs-in (cons got-sig sigs-in))
6738 (setq sigs-out (cons got-sig sigs-out)))
6739 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S rv=%S\n" got-sig got-rvalue))))
6740 (setq got-sig nil))
6741 ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd))))
6742 ))
6743
6744 (defun verilog-read-always-signals ()
6745 "Parse always block at point and return list of (outputs inout inputs)."
6746 ;; Insert new
6747 (save-excursion
6748 (let* (;;(dbg "")
6749 sigs-in sigs-out
6750 uses-delayed) ;; Found signal/rvalue; push if not function
6751 (search-forward ")")
6752 (verilog-read-always-signals-recurse nil nil nil)
6753 ;;(if dbg (save-excursion (set-buffer (get-buffer-create "*vl-dbg*")) (delete-region (point-min) (point-max)) (insert dbg) (setq dbg "")))
6754 ;; Return what was found
6755 (list sigs-out nil sigs-in uses-delayed))))
6756
6757 (defun verilog-read-instants ()
6758 "Parse module at point and return list of ( ( file instance ) ... )."
6759 (verilog-beg-of-defun)
6760 (let* ((end-mod-point (verilog-get-end-of-defun t))
6761 (state nil)
6762 (instants-list nil))
6763 (save-excursion
6764 (while (< (point) end-mod-point)
6765 ;; Stay at level 0, no comments
6766 (while (progn
6767 (setq state (parse-partial-sexp (point) end-mod-point 0 t nil))
6768 (or (> (car state) 0) ; in parens
6769 (nth 5 state) ; comment
6770 ))
6771 (forward-line 1))
6772 (beginning-of-line)
6773 (if (looking-at "^\\s-*\\([a-zA-Z0-9`_$]+\\)\\s-+\\([a-zA-Z0-9`_$]+\\)\\s-*(")
6774 ;;(if (looking-at "^\\(.+\\)$")
6775 (let ((module (match-string 1))
6776 (instant (match-string 2)))
6777 (if (not (member module verilog-keywords))
6778 (setq instants-list (cons (list module instant) instants-list)))))
6779 (forward-line 1)))
6780 instants-list))
6781
6782
6783 (defun verilog-read-auto-template (module)
6784 "Look for a auto_template for the instantiation of the given MODULE.
6785 If found returns the signal name connections. Return REGEXP and
6786 list of ( (signal_name connection_name)... )."
6787 (save-excursion
6788 ;; Find beginning
6789 (let ((tpl-regexp "\\([0-9]+\\)")
6790 (lineno 0)
6791 (templateno 0)
6792 tpl-sig-list tpl-wild-list tpl-end-pt rep)
6793 (cond ((or
6794 (re-search-backward (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)
6795 (progn
6796 (goto-char (point-min))
6797 (re-search-forward (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t)))
6798 (goto-char (match-end 0))
6799 ;; Parse "REGEXP"
6800 ;; We reserve @"..." for future lisp expressions that evaluate once-per-AUTOINST
6801 (when (looking-at "\\s-*\"\\([^\"]*)\\)\"")
6802 (setq tpl-regexp (match-string 1))
6803 (goto-char (match-end 0)))
6804 (search-forward "(")
6805 ;; Parse lines in the template
6806 (when verilog-auto-inst-template-numbers
6807 (save-excursion
6808 (goto-char (point-min))
6809 (while (search-forward "AUTO_TEMPLATE" nil t)
6810 (setq templateno (1+ templateno)))))
6811 (setq tpl-end-pt (save-excursion
6812 (backward-char 1)
6813 (forward-sexp 1) ;; Moves to paren that closes argdecl's
6814 (backward-char 1)
6815 (point)))
6816 ;;
6817 (while (< (point) tpl-end-pt)
6818 (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
6819 (setq tpl-sig-list (cons (list
6820 (match-string-no-properties 1)
6821 (match-string-no-properties 2)
6822 templateno lineno)
6823 tpl-sig-list))
6824 (goto-char (match-end 0)))
6825 ;; Regexp form??
6826 ((looking-at
6827 ;; Regexp bug in XEmacs disallows ][ inside [], and wants + last
6828 "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]+\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)")
6829 (setq rep (match-string-no-properties 3))
6830 (goto-char (match-end 0))
6831 (setq tpl-wild-list
6832 (cons (list
6833 (concat "^"
6834 (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil
6835 (match-string 1))
6836 "$")
6837 rep
6838 templateno lineno)
6839 tpl-wild-list)))
6840 ((looking-at "[ \t\f]+")
6841 (goto-char (match-end 0)))
6842 ((looking-at "\n")
6843 (setq lineno (1+ lineno))
6844 (goto-char (match-end 0)))
6845 ((looking-at "//")
6846 (search-forward "\n"))
6847 ((looking-at "/\\*")
6848 (forward-char 2)
6849 (or (search-forward "*/")
6850 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
6851 (t
6852 (error "%s: AUTO_TEMPLATE parsing error: %s"
6853 (verilog-point-text)
6854 (progn (looking-at ".*$") (match-string 0))))))
6855 ;; Return
6856 (vector tpl-regexp
6857 (list tpl-sig-list tpl-wild-list)))
6858 ;; If no template found
6859 (t (vector tpl-regexp nil))))))
6860 ;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry"))
6861
6862 (defun verilog-set-define (defname defvalue &optional buffer enumname)
6863 "Set the definition DEFNAME to the DEFVALUE in the given BUFFER.
6864 Optionally associate it with the specified enumeration ENUMNAME."
6865 (save-excursion
6866 (set-buffer (or buffer (current-buffer)))
6867 (let ((mac (intern (concat "vh-" defname))))
6868 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
6869 ;; Need to define to a constant if no value given
6870 (set (make-variable-buffer-local mac)
6871 (if (equal defvalue "") "1" defvalue)))
6872 (if enumname
6873 (let ((enumvar (intern (concat "venum-" enumname))))
6874 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
6875 (make-variable-buffer-local enumvar)
6876 (add-to-list enumvar defname)))))
6877
6878 (defun verilog-read-defines (&optional filename recurse subcall)
6879 "Read `defines and parameters for the current file, or optional FILENAME.
6880 If the filename is provided, `verilog-library-flags' will be used to
6881 resolve it. If optional RECURSE is non-nil, recurse through `includes.
6882
6883 Parameters must be simple assignments to constants, or have their own
6884 \"parameter\" label rather than a list of parameters. Thus:
6885
6886 parameter X = 5, Y = 10; // Ok
6887 parameter X = {1'b1, 2'h2}; // Ok
6888 parameter X = {1'b1, 2'h2}, Y = 10; // Bad, make into 2 parameter lines
6889
6890 Defines must be simple text substitutions, one on a line, starting
6891 at the beginning of the line. Any ifdefs or multiline comments around the
6892 define are ignored.
6893
6894 Defines are stored inside Emacs variables using the name vh-{definename}.
6895
6896 This function is useful for setting vh-* variables. The file variables
6897 feature can be used to set defines that `verilog-mode' can see; put at the
6898 *END* of your file something like:
6899
6900 // Local Variables:
6901 // vh-macro:\"macro_definition\"
6902 // End:
6903
6904 If macros are defined earlier in the same file and you want their values,
6905 you can read them automatically (provided `enable-local-eval' is on):
6906
6907 // Local Variables:
6908 // eval:(verilog-read-defines)
6909 // eval:(verilog-read-defines \"group_standard_includes.v\")
6910 // End:
6911
6912 Note these are only read when the file is first visited, you must use
6913 \\[find-alternate-file] RET to have these take effect after editing them!
6914
6915 If you want to disable the \"Process `eval' or hook local variables\"
6916 warning message, you need to add to your .emacs file:
6917
6918 (setq enable-local-eval t)"
6919 (let ((origbuf (current-buffer)))
6920 (save-excursion
6921 (unless subcall (verilog-getopt-flags))
6922 (when filename
6923 (let ((fns (verilog-library-filenames filename (buffer-file-name))))
6924 (if fns
6925 (set-buffer (find-file-noselect (car fns)))
6926 (error (concat (verilog-point-text)
6927 ": Can't find verilog-read-defines file: " filename)))))
6928 (when recurse
6929 (goto-char (point-min))
6930 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
6931 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string-no-properties 1))))
6932 (unless (verilog-inside-comment-p)
6933 (verilog-read-defines inc recurse t)))))
6934 ;; Read `defines
6935 ;; note we don't use verilog-re... it's faster this way, and that
6936 ;; function has problems when comments are at the end of the define
6937 (goto-char (point-min))
6938 (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t)
6939 (let ((defname (match-string-no-properties 1))
6940 (defvalue (match-string-no-properties 2)))
6941 (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue))
6942 (verilog-set-define defname defvalue origbuf)))
6943 ;; Hack: Read parameters
6944 (goto-char (point-min))
6945 (while (re-search-forward
6946 "^\\s-*\\(parameter\\|localparam\\)\\(\\(\\s-*\\[[^]]*\\]\\|\\)\\s-+\\([a-zA-Z0-9_$]+\\)\\s-*=\\s-*\\([^;,]*\\),?\\|\\)\\s-*" nil t)
6947 (let ((var (match-string-no-properties 4))
6948 (val (match-string-no-properties 5))
6949 enumname)
6950 ;; The primary way of getting defines is verilog-read-decls
6951 ;; However, that isn't called yet for included files, so we'll add another scheme
6952 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
6953 (setq enumname (match-string-no-properties 1)))
6954 (if var
6955 (verilog-set-define var val origbuf enumname))
6956 (forward-comment 999)
6957 (while (looking-at "\\s-*,?\\s-*\\([a-zA-Z0-9_$]+\\)\\s-*=\\s-*\\([^;,]*\\),?\\s-*")
6958 (verilog-set-define (match-string-no-properties 1) (match-string-no-properties 2) origbuf enumname)
6959 (goto-char (match-end 0))
6960 (forward-comment 999)))))))
6961
6962 (defun verilog-read-includes ()
6963 "Read `includes for the current file.
6964 This will find all of the `includes which are at the beginning of lines,
6965 ignoring any ifdefs or multiline comments around them.
6966 `verilog-read-defines' is then performed on the current and each included
6967 file.
6968
6969 It is often useful put at the *END* of your file something like:
6970
6971 // Local Variables:
6972 // eval:(verilog-read-defines)
6973 // eval:(verilog-read-includes)
6974 // End:
6975
6976 Note includes are only read when the file is first visited, you must use
6977 \\[find-alternate-file] RET to have these take effect after editing them!
6978
6979 It is good to get in the habit of including all needed files in each .v
6980 file that needs it, rather than waiting for compile time. This will aid
6981 this process, Verilint, and readability. To prevent defining the same
6982 variable over and over when many modules are compiled together, put a test
6983 around the inside each include file:
6984
6985 foo.v (a include):
6986 `ifdef _FOO_V // include if not already included
6987 `else
6988 `define _FOO_V
6989 ... contents of file
6990 `endif // _FOO_V"
6991 ;;slow: (verilog-read-defines nil t))
6992 (save-excursion
6993 (verilog-getopt-flags)
6994 (goto-char (point-min))
6995 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t)
6996 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string 1))))
6997 (verilog-read-defines inc nil t)))))
6998
6999 (defun verilog-read-signals (&optional start end)
7000 "Return a simple list of all possible signals in the file.
7001 Bounded by optional region from START to END. Overly aggressive but fast.
7002 Some macros and such are also found and included. For dinotrace.el."
7003 (let (sigs-all keywd)
7004 (progn;save-excursion
7005 (goto-char (or start (point-min)))
7006 (setq end (or end (point-max)))
7007 (while (re-search-forward "[\"/a-zA-Z_.%`]" end t)
7008 (forward-char -1)
7009 (cond
7010 ((looking-at "//")
7011 (search-forward "\n"))
7012 ((looking-at "/\\*")
7013 (search-forward "*/"))
7014 ((looking-at "(\\*")
7015 (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)"
7016 (search-forward "*)")))
7017 ((eq ?\" (following-char))
7018 (re-search-forward "[^\\]\"")) ;; don't forward-char first, since we look for a non backslash first
7019 ((looking-at "\\s-*\\([a-zA-Z0-9$_.%`]+\\)")
7020 (goto-char (match-end 0))
7021 (setq keywd (match-string-no-properties 1))
7022 (or (member keywd verilog-keywords)
7023 (member keywd sigs-all)
7024 (setq sigs-all (cons keywd sigs-all))))
7025 (t (forward-char 1))))
7026 ;; Return list
7027 sigs-all)))
7028
7029 ;;
7030 ;; Argument file parsing
7031 ;;
7032
7033 (defun verilog-getopt (arglist)
7034 "Parse -f, -v etc arguments in ARGLIST list or string."
7035 (unless (listp arglist) (setq arglist (list arglist)))
7036 (let ((space-args '())
7037 arg next-param)
7038 ;; Split on spaces, so users can pass whole command lines
7039 (while arglist
7040 (setq arg (car arglist)
7041 arglist (cdr arglist))
7042 (while (string-match "^\\([^ \t\n\f]+\\)[ \t\n\f]*\\(.*$\\)" arg)
7043 (setq space-args (append space-args
7044 (list (match-string-no-properties 1 arg))))
7045 (setq arg (match-string 2 arg))))
7046 ;; Parse arguments
7047 (while space-args
7048 (setq arg (car space-args)
7049 space-args (cdr space-args))
7050 (cond
7051 ;; Need another arg
7052 ((equal arg "-f")
7053 (setq next-param arg))
7054 ((equal arg "-v")
7055 (setq next-param arg))
7056 ((equal arg "-y")
7057 (setq next-param arg))
7058 ;; +libext+(ext1)+(ext2)...
7059 ((string-match "^\\+libext\\+\\(.*\\)" arg)
7060 (setq arg (match-string 1 arg))
7061 (while (string-match "\\([^+]+\\)\\+?\\(.*\\)" arg)
7062 (verilog-add-list-unique `verilog-library-extensions
7063 (match-string 1 arg))
7064 (setq arg (match-string 2 arg))))
7065 ;;
7066 ((or (string-match "^-D\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; -Ddefine=val
7067 (string-match "^-D\\([^+=]*\\)\\(\\)" arg) ;; -Ddefine
7068 (string-match "^\\+define\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; +define+val
7069 (string-match "^\\+define\\([^+=]*\\)\\(\\)" arg)) ;; +define+define
7070 (verilog-set-define (match-string 1 arg) (match-string 2 arg)))
7071 ;;
7072 ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ;; +incdir+dir
7073 (string-match "^-I\\(.*\\)" arg)) ;; -Idir
7074 (verilog-add-list-unique `verilog-library-directories
7075 (match-string 1 arg)))
7076 ;; Ignore
7077 ((equal "+librescan" arg))
7078 ((string-match "^-U\\(.*\\)" arg)) ;; -Udefine
7079 ;; Second parameters
7080 ((equal next-param "-f")
7081 (setq next-param nil)
7082 (verilog-getopt-file arg))
7083 ((equal next-param "-v")
7084 (setq next-param nil)
7085 (verilog-add-list-unique `verilog-library-files arg))
7086 ((equal next-param "-y")
7087 (setq next-param nil)
7088 (verilog-add-list-unique `verilog-library-directories arg))
7089 ;; Filename
7090 ((string-match "^[^-+]" arg)
7091 (verilog-add-list-unique `verilog-library-files arg))
7092 ;; Default - ignore; no warning
7093 ))))
7094 ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir"))
7095
7096 (defun verilog-getopt-file (filename)
7097 "Read Verilog options from the specified FILENAME."
7098 (save-excursion
7099 (let ((fns (verilog-library-filenames filename (buffer-file-name)))
7100 (orig-buffer (current-buffer))
7101 line)
7102 (if fns
7103 (set-buffer (find-file-noselect (car fns)))
7104 (error (concat (verilog-point-text)
7105 ": Can't find verilog-getopt-file -f file: " filename)))
7106 (goto-char (point-min))
7107 (while (not (eobp))
7108 (setq line (buffer-substring (point)
7109 (save-excursion (end-of-line) (point))))
7110 (forward-line 1)
7111 (when (string-match "//" line)
7112 (setq line (substring line 0 (match-beginning 0))))
7113 (save-excursion
7114 (set-buffer orig-buffer) ; Variables are buffer-local, so need right context.
7115 (verilog-getopt line))))))
7116
7117 (defun verilog-getopt-flags ()
7118 "Convert `verilog-library-flags' into standard library variables."
7119 ;; If the flags are local, then all the outputs should be local also
7120 (when (local-variable-p `verilog-library-flags (current-buffer))
7121 (mapc 'make-local-variable '(verilog-library-extensions
7122 verilog-library-directories
7123 verilog-library-files
7124 verilog-library-flags)))
7125 ;; Allow user to customize
7126 (run-hooks 'verilog-before-getopt-flags-hook)
7127 ;; Process arguments
7128 (verilog-getopt verilog-library-flags)
7129 ;; Allow user to customize
7130 (run-hooks 'verilog-getopt-flags-hook))
7131
7132 (defun verilog-add-list-unique (varref object)
7133 "Append to VARREF list the given OBJECT,
7134 unless it is already a member of the variable's list."
7135 (unless (member object (symbol-value varref))
7136 (set varref (append (symbol-value varref) (list object))))
7137 varref)
7138 ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l)
7139
7140 \f
7141 ;;
7142 ;; Cached directory support
7143 ;;
7144
7145 (defvar verilog-dir-cache-preserving nil
7146 "If set, the directory cache is enabled, and file system changes are ignored.
7147 See `verilog-dir-exists-p' and `verilog-dir-files'.")
7148
7149 ;; If adding new cached variable, add also to verilog-preserve-dir-cache
7150 (defvar verilog-dir-cache-list nil
7151 "Alist of (((Cwd Dirname) Results)...) for caching `verilog-dir-files'.")
7152 (defvar verilog-dir-cache-lib-filenames nil
7153 "Cached data for `verilog-library-filenames'.")
7154
7155 (defmacro verilog-preserve-dir-cache (&rest body)
7156 "Execute the BODY forms, allowing directory cache preservation within BODY.
7157 This means that changes inside BODY made to the file system will not be
7158 seen by the `verilog-dir-files' and related functions."
7159 `(let ((verilog-dir-cache-preserving t)
7160 verilog-dir-cache-list
7161 verilog-dir-cache-lib-filenames)
7162 (progn ,@body)))
7163
7164 (defun verilog-dir-files (dirname)
7165 "Return all filenames in the DIRNAME directory.
7166 Relative paths depend on the `default-directory'.
7167 Results are cached if inside `verilog-preserve-dir-cache'."
7168 (unless verilog-dir-cache-preserving
7169 (setq verilog-dir-cache-list nil)) ;; Cache disabled
7170 ;; We don't use expand-file-name on the dirname to make key, as it's slow
7171 (let* ((cache-key (list dirname default-directory))
7172 (fass (assoc cache-key verilog-dir-cache-list))
7173 exp-dirname data)
7174 (cond (fass ;; Return data from cache hit
7175 (nth 1 fass))
7176 (t
7177 (setq exp-dirname (expand-file-name dirname)
7178 data (and (file-directory-p exp-dirname)
7179 (directory-files exp-dirname nil nil nil)))
7180 ;; Note we also encache nil for non-existing dirs.
7181 (setq verilog-dir-cache-list (cons (list cache-key data)
7182 verilog-dir-cache-list))
7183 data))))
7184 ;; Miss-and-hit test:
7185 ;;(verilog-preserve-dir-cache (prin1 (verilog-dir-files "."))
7186 ;; (prin1 (verilog-dir-files ".")) nil)
7187
7188 (defun verilog-dir-file-exists-p (filename)
7189 "Return true if FILENAME exists.
7190 Like `file-exists-p' but results are cached if inside
7191 `verilog-preserve-dir-cache'."
7192 (let* ((dirname (file-name-directory filename))
7193 ;; Correct for file-name-nondirectory returning same if no slash.
7194 (dirnamed (if (or (not dirname) (equal dirname filename))
7195 default-directory dirname))
7196 (flist (verilog-dir-files dirnamed)))
7197 (and flist
7198 (member (file-name-nondirectory filename) flist)
7199 t)))
7200 ;;(verilog-dir-file-exists-p "verilog-mode.el")
7201 ;;(verilog-dir-file-exists-p "../verilog-mode/verilog-mode.el")
7202
7203 \f
7204 ;;
7205 ;; Module name lookup
7206 ;;
7207
7208 (defun verilog-module-inside-filename-p (module filename)
7209 "Return point if MODULE is specified inside FILENAME, else nil.
7210 Allows version control to check out the file if need be."
7211 (and (or (file-exists-p filename)
7212 (and (fboundp 'vc-backend)
7213 (vc-backend filename)))
7214 (let (pt)
7215 (save-excursion
7216 (set-buffer (find-file-noselect filename))
7217 (goto-char (point-min))
7218 (while (and
7219 ;; It may be tempting to look for verilog-defun-re, don't, it slows things down a lot!
7220 (verilog-re-search-forward-quick "\\<module\\>" nil t)
7221 (verilog-re-search-forward-quick "[(;]" nil t))
7222 (if (equal module (verilog-read-module-name))
7223 (setq pt (point))))
7224 pt))))
7225
7226 (defun verilog-is-number (symbol)
7227 "Return true if SYMBOL is number-like."
7228 (or (string-match "^[0-9 \t:]+$" symbol)
7229 (string-match "^[---]*[0-9]+$" symbol)
7230 (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol)))
7231
7232 (defun verilog-symbol-detick (symbol wing-it)
7233 "Return an expanded SYMBOL name without any defines.
7234 If the variable vh-{symbol} is defined, return that value.
7235 If undefined, and WING-IT, return just SYMBOL without the tick, else nil."
7236 (while (and symbol (string-match "^`" symbol))
7237 (setq symbol (substring symbol 1))
7238 (setq symbol
7239 (if (boundp (intern (concat "vh-" symbol)))
7240 ;; Emacs has a bug where boundp on a buffer-local
7241 ;; variable in only one buffer returns t in another.
7242 ;; This can confuse, so check for nil.
7243 (let ((val (eval (intern (concat "vh-" symbol)))))
7244 (if (eq val nil)
7245 (if wing-it symbol nil)
7246 val))
7247 (if wing-it symbol nil))))
7248 symbol)
7249 ;;(verilog-symbol-detick "`mod" nil)
7250
7251 (defun verilog-symbol-detick-denumber (symbol)
7252 "Return SYMBOL with defines converted and any numbers dropped to nil."
7253 (when (string-match "^`" symbol)
7254 ;; This only will work if the define is a simple signal, not
7255 ;; something like a[b]. Sorry, it should be substituted into the parser
7256 (setq symbol
7257 (verilog-string-replace-matches
7258 "\[[^0-9: \t]+\]" "" nil nil
7259 (or (verilog-symbol-detick symbol nil)
7260 (if verilog-auto-sense-defines-constant
7261 "0"
7262 symbol)))))
7263 (if (verilog-is-number symbol)
7264 nil
7265 symbol))
7266
7267 (defun verilog-symbol-detick-text (text)
7268 "Return TEXT without any known defines.
7269 If the variable vh-{symbol} is defined, substitute that value."
7270 (let ((ok t) symbol val)
7271 (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text))
7272 (setq symbol (match-string 1 text))
7273 (message symbol)
7274 (cond ((and
7275 (boundp (intern (concat "vh-" symbol)))
7276 ;; Emacs has a bug where boundp on a buffer-local
7277 ;; variable in only one buffer returns t in another.
7278 ;; This can confuse, so check for nil.
7279 (setq val (eval (intern (concat "vh-" symbol)))))
7280 (setq text (replace-match val nil nil text)))
7281 (t (setq ok nil)))))
7282 text)
7283 ;;(progn (setq vh-mod "`foo" vh-foo "bar") (verilog-symbol-detick-text "bar `mod `undefed"))
7284
7285 (defun verilog-expand-dirnames (&optional dirnames)
7286 "Return a list of existing directories given a list of wildcarded DIRNAMES.
7287 Or, just the existing dirnames themselves if there are no wildcards."
7288 ;; Note this function is performance critical.
7289 ;; Do not call anything that requires disk access that cannot be cached.
7290 (interactive)
7291 (unless dirnames (error "`verilog-library-directories' should include at least '.'"))
7292 (setq dirnames (reverse dirnames)) ; not nreverse
7293 (let ((dirlist nil)
7294 pattern dirfile dirfiles dirname root filename rest basefile)
7295 (while dirnames
7296 (setq dirname (substitute-in-file-name (car dirnames))
7297 dirnames (cdr dirnames))
7298 (cond ((string-match (concat "^\\(\\|[/\\]*[^*?]*[/\\]\\)" ;; root
7299 "\\([^/\\]*[*?][^/\\]*\\)" ;; filename with *?
7300 "\\(.*\\)") ;; rest
7301 dirname)
7302 (setq root (match-string 1 dirname)
7303 filename (match-string 2 dirname)
7304 rest (match-string 3 dirname)
7305 pattern filename)
7306 ;; now replace those * and ? with .+ and .
7307 ;; use ^ and /> to get only whole file names
7308 (setq pattern (verilog-string-replace-matches "[*]" ".+" nil nil pattern)
7309 pattern (verilog-string-replace-matches "[?]" "." nil nil pattern)
7310 pattern (concat "^" pattern "$")
7311 dirfiles (verilog-dir-files root))
7312 (while dirfiles
7313 (setq basefile (car dirfiles)
7314 dirfile (expand-file-name (concat root basefile rest))
7315 dirfiles (cdr dirfiles))
7316 (if (and (string-match pattern basefile)
7317 ;; Don't allow abc/*/rtl to match abc/rtl via ..
7318 (not (equal basefile "."))
7319 (not (equal basefile ".."))
7320 (file-directory-p dirfile))
7321 (setq dirlist (cons dirfile dirlist)))))
7322 ;; Defaults
7323 (t
7324 (if (file-directory-p dirname)
7325 (setq dirlist (cons dirname dirlist))))))
7326 dirlist))
7327 ;;(verilog-expand-dirnames (list "." ".." "nonexist" "../*" "/home/wsnyder/*/v"))
7328
7329 (defun verilog-library-filenames (filename current &optional check-ext)
7330 "Return a search path to find the given FILENAME or module name.
7331 Uses the CURRENT filename, `verilog-library-directories' and
7332 `verilog-library-extensions' variables to build the path.
7333 With optional CHECK-EXT also check `verilog-library-extensions'."
7334 (unless verilog-dir-cache-preserving
7335 (setq verilog-dir-cache-lib-filenames nil))
7336 (let* ((cache-key (list filename current check-ext))
7337 (fass (assoc cache-key verilog-dir-cache-lib-filenames))
7338 chkdirs chkdir chkexts fn outlist)
7339 (cond (fass ;; Return data from cache hit
7340 (nth 1 fass))
7341 (t
7342 ;; Note this expand can't be easily cached, as we need to
7343 ;; pick up buffer-local variables for newly read sub-module files
7344 (setq chkdirs (verilog-expand-dirnames verilog-library-directories))
7345 (while chkdirs
7346 (setq chkdir (expand-file-name (car chkdirs)
7347 (file-name-directory current))
7348 chkexts (if check-ext verilog-library-extensions `("")))
7349 (while chkexts
7350 (setq fn (expand-file-name (concat filename (car chkexts))
7351 chkdir))
7352 ;;(message "Check for %s" fn)
7353 (if (verilog-dir-file-exists-p fn)
7354 (setq outlist (cons (expand-file-name
7355 fn (file-name-directory current))
7356 outlist)))
7357 (setq chkexts (cdr chkexts)))
7358 (setq chkdirs (cdr chkdirs)))
7359 (setq outlist (nreverse outlist))
7360 (setq verilog-dir-cache-lib-filenames
7361 (cons (list cache-key outlist)
7362 verilog-dir-cache-lib-filenames))
7363 outlist))))
7364
7365 (defun verilog-module-filenames (module current)
7366 "Return a search path to find the given MODULE name.
7367 Uses the CURRENT filename, `verilog-library-extensions',
7368 `verilog-library-directories' and `verilog-library-files'
7369 variables to build the path."
7370 ;; Return search locations for it
7371 (append (list current) ; first, current buffer
7372 (verilog-library-filenames module current t)
7373 verilog-library-files)) ; finally, any libraries
7374
7375 ;;
7376 ;; Module Information
7377 ;;
7378 ;; Many of these functions work on "modi" a module information structure
7379 ;; A modi is: [module-name-string file-name begin-point]
7380
7381 (defvar verilog-cache-enabled t
7382 "If true, enable caching of signals, etc. Set to nil for debugging to make things SLOW!")
7383
7384 (defvar verilog-modi-cache-list nil
7385 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)...
7386 For speeding up verilog-modi-get-* commands.
7387 Buffer-local.")
7388
7389 (make-variable-buffer-local 'verilog-modi-cache-list)
7390
7391 (defvar verilog-modi-cache-preserve-tick nil
7392 "Modification tick after which the cache is still considered valid.
7393 Use `verilog-preserve-modi-cache' to set it.")
7394 (defvar verilog-modi-cache-preserve-buffer nil
7395 "Modification tick after which the cache is still considered valid.
7396 Use `verilog-preserve-modi-cache' to set it.")
7397
7398 (defun verilog-modi-current ()
7399 "Return the modi structure for the module currently at point."
7400 (let* (name pt)
7401 ;; read current module's name
7402 (save-excursion
7403 (verilog-re-search-backward-quick verilog-defun-re nil nil)
7404 (verilog-re-search-forward-quick "(" nil nil)
7405 (setq name (verilog-read-module-name))
7406 (setq pt (point)))
7407 ;; return
7408 (vector name (or (buffer-file-name) (current-buffer)) pt)))
7409
7410 (defvar verilog-modi-lookup-last-mod nil "Cache of last module looked up.")
7411 (defvar verilog-modi-lookup-last-modi nil "Cache of last modi returned.")
7412 (defvar verilog-modi-lookup-last-current nil "Cache of last `current-buffer' looked up.")
7413 (defvar verilog-modi-lookup-last-tick nil "Cache of last `buffer-modified-tick' looked up.")
7414
7415 (defun verilog-modi-lookup (module allow-cache &optional ignore-error)
7416 "Find the file and point at which MODULE is defined.
7417 If ALLOW-CACHE is set, check and remember cache of previous lookups.
7418 Return modi if successful, else print message unless IGNORE-ERROR is true."
7419 (let* ((current (or (buffer-file-name) (current-buffer))))
7420 (cond ((and verilog-modi-lookup-last-modi
7421 verilog-cache-enabled
7422 allow-cache
7423 (equal verilog-modi-lookup-last-mod module)
7424 (equal verilog-modi-lookup-last-current current)
7425 (equal verilog-modi-lookup-last-tick (buffer-modified-tick)))
7426 ;; ok as is
7427 )
7428 (t (let* ((realmod (verilog-symbol-detick module t))
7429 (orig-filenames (verilog-module-filenames realmod current))
7430 (filenames orig-filenames)
7431 pt)
7432 (while (and filenames (not pt))
7433 (if (not (setq pt (verilog-module-inside-filename-p realmod (car filenames))))
7434 (setq filenames (cdr filenames))))
7435 (cond (pt (setq verilog-modi-lookup-last-modi
7436 (vector realmod (car filenames) pt)))
7437 (t (setq verilog-modi-lookup-last-modi nil)
7438 (or ignore-error
7439 (error (concat (verilog-point-text)
7440 ": Can't locate " module " module definition"
7441 (if (not (equal module realmod))
7442 (concat " (Expanded macro to " realmod ")")
7443 "")
7444 "\n Check the verilog-library-directories variable."
7445 "\n I looked in (if not listed, doesn't exist):\n\t"
7446 (mapconcat 'concat orig-filenames "\n\t"))))))
7447 (setq verilog-modi-lookup-last-mod module
7448 verilog-modi-lookup-last-current current
7449 verilog-modi-lookup-last-tick (buffer-modified-tick)))))
7450 verilog-modi-lookup-last-modi))
7451
7452 (defsubst verilog-modi-name (modi)
7453 (aref modi 0))
7454 (defsubst verilog-modi-file-or-buffer (modi)
7455 (aref modi 1))
7456 (defsubst verilog-modi-point (modi)
7457 (aref modi 2))
7458
7459 (defun verilog-modi-filename (modi)
7460 "Filename of MODI, or name of buffer if it's never been saved."
7461 (if (bufferp (verilog-modi-file-or-buffer modi))
7462 (or (buffer-file-name (verilog-modi-file-or-buffer modi))
7463 (buffer-name (verilog-modi-file-or-buffer modi)))
7464 (verilog-modi-file-or-buffer modi)))
7465
7466 (defun verilog-modi-goto (modi)
7467 "Move point/buffer to specified MODI."
7468 (or modi (error "Passed unfound modi to goto, check earlier"))
7469 (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi))
7470 (verilog-modi-file-or-buffer modi)
7471 (find-file-noselect (verilog-modi-file-or-buffer modi))))
7472 (or (equal major-mode `verilog-mode) ;; Put into Verilog mode to get syntax
7473 (verilog-mode))
7474 (goto-char (verilog-modi-point modi)))
7475
7476 (defun verilog-goto-defun-file (module)
7477 "Move point to the file at which a given MODULE is defined."
7478 (interactive "sGoto File for Module: ")
7479 (let* ((modi (verilog-modi-lookup module nil)))
7480 (when modi
7481 (verilog-modi-goto modi)
7482 (switch-to-buffer (current-buffer)))))
7483
7484 (defun verilog-modi-cache-results (modi function)
7485 "Run on MODI the given FUNCTION. Locate the module in a file.
7486 Cache the output of function so next call may have faster access."
7487 (let (fass)
7488 (save-excursion ;; Cache is buffer-local so can't avoid this.
7489 (verilog-modi-goto modi)
7490 (if (and (setq fass (assoc (list modi function)
7491 verilog-modi-cache-list))
7492 ;; Destroy caching when incorrect; Modified or file changed
7493 (not (and verilog-cache-enabled
7494 (or (equal (buffer-modified-tick) (nth 1 fass))
7495 (and verilog-modi-cache-preserve-tick
7496 (<= verilog-modi-cache-preserve-tick (nth 1 fass))
7497 (equal verilog-modi-cache-preserve-buffer (current-buffer))))
7498 (equal (visited-file-modtime) (nth 2 fass)))))
7499 (setq verilog-modi-cache-list nil
7500 fass nil))
7501 (cond (fass
7502 ;; Return data from cache hit
7503 (nth 3 fass))
7504 (t
7505 ;; Read from file
7506 ;; Clear then restore any hilighting to make emacs19 happy
7507 (let ((fontlocked (when (and (boundp 'font-lock-mode)
7508 font-lock-mode)
7509 (font-lock-mode 0)
7510 t))
7511 func-returns)
7512 (setq func-returns (funcall function))
7513 (when fontlocked (font-lock-mode t))
7514 ;; Cache for next time
7515 (setq verilog-modi-cache-list
7516 (cons (list (list modi function)
7517 (buffer-modified-tick)
7518 (visited-file-modtime)
7519 func-returns)
7520 verilog-modi-cache-list))
7521 func-returns))))))
7522
7523 (defun verilog-modi-cache-add (modi function element sig-list)
7524 "Add function return results to the module cache.
7525 Update MODI's cache for given FUNCTION so that the return ELEMENT of that
7526 function now contains the additional SIG-LIST parameters."
7527 (let (fass)
7528 (save-excursion
7529 (verilog-modi-goto modi)
7530 (if (setq fass (assoc (list modi function)
7531 verilog-modi-cache-list))
7532 (let ((func-returns (nth 3 fass)))
7533 (aset func-returns element
7534 (append sig-list (aref func-returns element))))))))
7535
7536 (defmacro verilog-preserve-modi-cache (&rest body)
7537 "Execute the BODY forms, allowing cache preservation within BODY.
7538 This means that changes to the buffer will not result in the cache being
7539 flushed. If the changes affect the modsig state, they must call the
7540 modsig-cache-add-* function, else the results of later calls may be
7541 incorrect. Without this, changes are assumed to be adding/removing signals
7542 and invalidating the cache."
7543 `(let ((verilog-modi-cache-preserve-tick (buffer-modified-tick))
7544 (verilog-modi-cache-preserve-buffer (current-buffer)))
7545 (progn ,@body)))
7546
7547
7548 (defun verilog-signals-matching-enum (in-list enum)
7549 "Return all signals in IN-LIST matching the given ENUM."
7550 (let (out-list)
7551 (while in-list
7552 (if (equal (verilog-sig-enum (car in-list)) enum)
7553 (setq out-list (cons (car in-list) out-list)))
7554 (setq in-list (cdr in-list)))
7555 ;; New scheme
7556 (let* ((enumvar (intern (concat "venum-" enum)))
7557 (enumlist (and (boundp enumvar) (eval enumvar))))
7558 (while enumlist
7559 (add-to-list 'out-list (list (car enumlist)))
7560 (setq enumlist (cdr enumlist))))
7561 (nreverse out-list)))
7562
7563 (defun verilog-signals-matching-regexp (in-list regexp)
7564 "Return all signals in IN-LIST matching the given REGEXP, if non-nil."
7565 (if (not regexp)
7566 in-list
7567 (let (out-list)
7568 (while in-list
7569 (if (string-match regexp (verilog-sig-name (car in-list)))
7570 (setq out-list (cons (car in-list) out-list)))
7571 (setq in-list (cdr in-list)))
7572 (nreverse out-list))))
7573
7574 (defun verilog-signals-not-matching-regexp (in-list regexp)
7575 "Return all signals in IN-LIST not matching the given REGEXP, if non-nil."
7576 (if (not regexp)
7577 in-list
7578 (let (out-list)
7579 (while in-list
7580 (if (not (string-match regexp (verilog-sig-name (car in-list))))
7581 (setq out-list (cons (car in-list) out-list)))
7582 (setq in-list (cdr in-list)))
7583 (nreverse out-list))))
7584
7585 ;; Combined
7586 (defun verilog-decls-get-signals (decls)
7587 (append
7588 (verilog-decls-get-outputs decls)
7589 (verilog-decls-get-inouts decls)
7590 (verilog-decls-get-inputs decls)
7591 (verilog-decls-get-wires decls)
7592 (verilog-decls-get-regs decls)
7593 (verilog-decls-get-assigns decls)
7594 (verilog-decls-get-consts decls)
7595 (verilog-decls-get-gparams decls)))
7596
7597 (defun verilog-decls-get-ports (decls)
7598 (append
7599 (verilog-decls-get-outputs decls)
7600 (verilog-decls-get-inouts decls)
7601 (verilog-decls-get-inputs decls)))
7602
7603 (defsubst verilog-modi-cache-add-outputs (modi sig-list)
7604 (verilog-modi-cache-add modi 'verilog-read-decls 0 sig-list))
7605 (defsubst verilog-modi-cache-add-inouts (modi sig-list)
7606 (verilog-modi-cache-add modi 'verilog-read-decls 1 sig-list))
7607 (defsubst verilog-modi-cache-add-inputs (modi sig-list)
7608 (verilog-modi-cache-add modi 'verilog-read-decls 2 sig-list))
7609 (defsubst verilog-modi-cache-add-wires (modi sig-list)
7610 (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list))
7611 (defsubst verilog-modi-cache-add-regs (modi sig-list)
7612 (verilog-modi-cache-add modi 'verilog-read-decls 4 sig-list))
7613
7614 (defun verilog-signals-from-signame (signame-list)
7615 "Return signals in standard form from SIGNAME-LIST, a simple list of signal names."
7616 (mapcar (function (lambda (name) (list name nil nil)))
7617 signame-list))
7618 \f
7619 ;;
7620 ;; Auto creation utilities
7621 ;;
7622
7623 (defun verilog-auto-re-search-do (search-for func)
7624 "Search for the given auto text regexp SEARCH-FOR, and perform FUNC where it occurs."
7625 (goto-char (point-min))
7626 (while (verilog-re-search-forward search-for nil t)
7627 (funcall func)))
7628
7629 (defun verilog-insert-one-definition (sig type indent-pt)
7630 "Print out a definition for SIG of the given TYPE,
7631 with appropriate INDENT-PT indentation."
7632 (indent-to indent-pt)
7633 (insert type)
7634 (when (verilog-sig-signed sig)
7635 (insert " " (verilog-sig-signed sig)))
7636 (when (verilog-sig-multidim sig)
7637 (insert " " (verilog-sig-multidim-string sig)))
7638 (when (verilog-sig-bits sig)
7639 (insert " " (verilog-sig-bits sig)))
7640 (indent-to (max 24 (+ indent-pt 16)))
7641 (unless (= (char-syntax (preceding-char)) ?\ )
7642 (insert " ")) ; Need space between "]name" if indent-to did nothing
7643 (insert (verilog-sig-name sig)))
7644
7645 (defun verilog-insert-definition (sigs direction indent-pt v2k &optional dont-sort)
7646 "Print out a definition for a list of SIGS of the given DIRECTION,
7647 with appropriate INDENT-PT indentation. If V2K, use Verilog 2001 I/O
7648 format. Sort unless DONT-SORT. DIRECTION is normally wire/reg/output."
7649 (or dont-sort
7650 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
7651 (while sigs
7652 (let ((sig (car sigs)))
7653 (verilog-insert-one-definition
7654 sig
7655 ;; Want "type x" or "output type x", not "wire type x"
7656 (cond ((verilog-sig-type sig)
7657 (concat
7658 (if (not (equal direction "wire"))
7659 (concat direction " "))
7660 (verilog-sig-type sig)))
7661 (t direction))
7662 indent-pt)
7663 (insert (if v2k "," ";"))
7664 (if (or (not (verilog-sig-comment sig))
7665 (equal "" (verilog-sig-comment sig)))
7666 (insert "\n")
7667 (indent-to (max 48 (+ indent-pt 40)))
7668 (insert (concat "// " (verilog-sig-comment sig) "\n")))
7669 (setq sigs (cdr sigs)))))
7670
7671 (eval-when-compile
7672 (if (not (boundp 'indent-pt))
7673 (defvar indent-pt nil "Local used by insert-indent")))
7674
7675 (defun verilog-insert-indent (&rest stuff)
7676 "Indent to position stored in local `indent-pt' variable, then insert STUFF.
7677 Presumes that any newlines end a list element."
7678 (let ((need-indent t))
7679 (while stuff
7680 (if need-indent (indent-to indent-pt))
7681 (setq need-indent nil)
7682 (insert (car stuff))
7683 (setq need-indent (string-match "\n$" (car stuff))
7684 stuff (cdr stuff)))))
7685 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n"))
7686
7687 (defun verilog-repair-open-comma ()
7688 "If backwards-from-point is other than a open parenthesis insert comma."
7689 (save-excursion
7690 (verilog-backward-syntactic-ws)
7691 (when (save-excursion
7692 (backward-char 1)
7693 (and (not (looking-at "[(,]"))
7694 (progn
7695 (verilog-re-search-backward "[(`]" nil t)
7696 (looking-at "("))))
7697 (insert ","))))
7698
7699 (defun verilog-repair-close-comma ()
7700 "If point is at a comma followed by a close parenthesis, fix it.
7701 This repairs those mis-inserted by a AUTOARG."
7702 ;; It would be much nicer if Verilog allowed extra commas like Perl does!
7703 (save-excursion
7704 (verilog-forward-close-paren)
7705 (backward-char 1)
7706 (verilog-backward-syntactic-ws)
7707 (backward-char 1)
7708 (when (looking-at ",")
7709 (delete-char 1))))
7710
7711 (defun verilog-get-list (start end)
7712 "Return the elements of a comma separated list between START and END."
7713 (interactive)
7714 (let ((my-list (list))
7715 my-string)
7716 (save-excursion
7717 (while (< (point) end)
7718 (when (re-search-forward "\\([^,{]+\\)" end t)
7719 (setq my-string (verilog-string-remove-spaces (match-string 1)))
7720 (setq my-list (nconc my-list (list my-string) ))
7721 (goto-char (match-end 0))))
7722 my-list)))
7723
7724 (defun verilog-make-width-expression (range-exp)
7725 "Return an expression calculating the length of a range [x:y] in RANGE-EXP."
7726 ;; strip off the []
7727 (cond ((not range-exp)
7728 "1")
7729 (t
7730 (if (string-match "^\\[\\(.*\\)\\]$" range-exp)
7731 (setq range-exp (match-string 1 range-exp)))
7732 (cond ((not range-exp)
7733 "1")
7734 ((string-match "^\\s *\\([0-9]+\\)\\s *:\\s *\\([0-9]+\\)\\s *$"
7735 range-exp)
7736 (int-to-string
7737 (1+ (abs (- (string-to-number (match-string 1 range-exp))
7738 (string-to-number (match-string 2 range-exp)))))))
7739 ((string-match "^\\(.*\\)\\s *:\\s *\\(.*\\)\\s *$" range-exp)
7740 (concat "(1+(" (match-string 1 range-exp) ")"
7741 (if (equal "0" (match-string 2 range-exp))
7742 "" ;; Don't bother with -(0)
7743 (concat "-(" (match-string 2 range-exp) ")"))
7744 ")"))
7745 (t nil)))))
7746 ;;(verilog-make-width-expression "`A:`B")
7747
7748 (defun verilog-simplify-range-expression (range-exp)
7749 "Return a simplified range expression with constants eliminated from RANGE-EXP."
7750 (let ((out range-exp)
7751 (last-pass ""))
7752 (while (not (equal last-pass out))
7753 (setq last-pass out)
7754 (while (string-match "(\\<\\([0-9A-Z-az_]+\\)\\>)" out)
7755 (setq out (replace-match "\\1" nil nil out)))
7756 (while (string-match "\\<\\([0-9]+\\)\\>\\s *\\+\\s *\\<\\([0-9]+\\)\\>" out)
7757 (setq out (replace-match
7758 (int-to-string (+ (string-to-number (match-string 1 out))
7759 (string-to-number (match-string 2 out))))
7760 nil nil out)))
7761 (while (string-match "\\<\\([0-9]+\\)\\>\\s *\\-\\s *\\<\\([0-9]+\\)\\>" out)
7762 (setq out (replace-match
7763 (int-to-string (- (string-to-number (match-string 1 out))
7764 (string-to-number (match-string 2 out))))
7765 nil nil out))))
7766 out))
7767 ;;(verilog-simplify-range-expression "1")
7768 ;;(verilog-simplify-range-expression "(((16)+1)-3)")
7769
7770 (defun verilog-typedef-name-p (variable-name)
7771 "Return true if the VARIABLE-NAME is a type definition."
7772 (when verilog-typedef-regexp
7773 (string-match verilog-typedef-regexp variable-name)))
7774 \f
7775 ;;
7776 ;; Auto deletion
7777 ;;
7778
7779 (defun verilog-delete-autos-lined ()
7780 "Delete autos that occupy multiple lines, between begin and end comments."
7781 (let ((pt (point)))
7782 (forward-line 1)
7783 (when (and
7784 (looking-at "\\s-*// Beginning")
7785 (search-forward "// End of automatic" nil t))
7786 ;; End exists
7787 (end-of-line)
7788 (delete-region pt (point))
7789 (forward-line 1))))
7790
7791 (defun verilog-forward-close-paren ()
7792 "Find the close parenthesis that match the current point.
7793 Ignore other close parenthesis with matching open parens."
7794 (let ((parens 1))
7795 (while (> parens 0)
7796 (unless (verilog-re-search-forward-quick "[()]" nil t)
7797 (error "%s: Mismatching ()" (verilog-point-text)))
7798 (cond ((= (preceding-char) ?\( )
7799 (setq parens (1+ parens)))
7800 ((= (preceding-char) ?\) )
7801 (setq parens (1- parens)))))))
7802
7803 (defun verilog-backward-open-paren ()
7804 "Find the open parenthesis that match the current point.
7805 Ignore other open parenthesis with matching close parens."
7806 (let ((parens 1))
7807 (while (> parens 0)
7808 (unless (verilog-re-search-backward-quick "[()]" nil t)
7809 (error "%s: Mismatching ()" (verilog-point-text)))
7810 (cond ((= (following-char) ?\) )
7811 (setq parens (1+ parens)))
7812 ((= (following-char) ?\( )
7813 (setq parens (1- parens)))))))
7814
7815 (defun verilog-backward-open-bracket ()
7816 "Find the open bracket that match the current point.
7817 Ignore other open bracket with matching close bracket."
7818 (let ((parens 1))
7819 (while (> parens 0)
7820 (unless (verilog-re-search-backward-quick "[][]" nil t)
7821 (error "%s: Mismatching []" (verilog-point-text)))
7822 (cond ((= (following-char) ?\] )
7823 (setq parens (1+ parens)))
7824 ((= (following-char) ?\[ )
7825 (setq parens (1- parens)))))))
7826
7827 (defun verilog-delete-to-paren ()
7828 "Delete the automatic inst/sense/arg created by autos.
7829 Deletion stops at the matching end parenthesis."
7830 (delete-region (point)
7831 (save-excursion
7832 (verilog-backward-open-paren)
7833 (forward-sexp 1) ;; Moves to paren that closes argdecl's
7834 (backward-char 1)
7835 (point))))
7836
7837 (defun verilog-auto-star-safe ()
7838 "Return if a .* AUTOINST is safe to delete or expand.
7839 It was created by the AUTOS themselves, or by the user."
7840 (and verilog-auto-star-expand
7841 (looking-at "[ \t\n\f,]*\\([)]\\|// \\(Outputs\\|Inouts\\|Inputs\\)\\)")))
7842
7843 (defun verilog-delete-auto-star-all ()
7844 "Delete a .* AUTOINST, if it is safe."
7845 (when (verilog-auto-star-safe)
7846 (verilog-delete-to-paren)))
7847
7848 (defun verilog-delete-auto-star-implicit ()
7849 "Delete all .* implicit connections created by `verilog-auto-star'.
7850 This function will be called automatically at save unless
7851 `verilog-auto-star-save' is set, any non-templated expanded pins will be
7852 removed."
7853 (interactive)
7854 (let (paren-pt indent have-close-paren)
7855 (save-excursion
7856 (goto-char (point-min))
7857 ;; We need to match these even outside of comments.
7858 ;; For reasonable performance, we don't check if inside comments, sorry.
7859 (while (re-search-forward "// Implicit \\.\\*" nil t)
7860 (setq paren-pt (point))
7861 (beginning-of-line)
7862 (setq have-close-paren
7863 (save-excursion
7864 (when (search-forward ");" paren-pt t)
7865 (setq indent (current-indentation))
7866 t)))
7867 (delete-region (point) (+ 1 paren-pt)) ; Nuke line incl CR
7868 (when have-close-paren
7869 ;; Delete extra commentary
7870 (save-excursion
7871 (while (progn
7872 (forward-line -1)
7873 (looking-at "\\s *//\\s *\\(Outputs\\|Inouts\\|Inputs\\)\n"))
7874 (delete-region (match-beginning 0) (match-end 0))))
7875 ;; If it is simple, we can put the ); on the same line as the last text
7876 (let ((rtn-pt (point)))
7877 (save-excursion
7878 (while (progn (backward-char 1)
7879 (looking-at "[ \t\n\f]")))
7880 (when (looking-at ",")
7881 (delete-region (+ 1 (point)) rtn-pt))))
7882 (when (bolp)
7883 (indent-to indent))
7884 (insert ");\n")
7885 ;; Still need to kill final comma - always is one as we put one after the .*
7886 (re-search-backward ",")
7887 (delete-char 1))))))
7888
7889 (defun verilog-delete-auto ()
7890 "Delete the automatic outputs, regs, and wires created by \\[verilog-auto].
7891 Use \\[verilog-auto] to re-insert the updated AUTOs.
7892
7893 The hooks `verilog-before-delete-auto-hook' and `verilog-delete-auto-hook' are
7894 called before and after this function, respectively."
7895 (interactive)
7896 (save-excursion
7897 (if (buffer-file-name)
7898 (find-file-noselect (buffer-file-name))) ;; To check we have latest version
7899 ;; Allow user to customize
7900 (run-hooks 'verilog-before-delete-auto-hook)
7901
7902 ;; Remove those that have multi-line insertions, possibly with parameters
7903 (verilog-auto-re-search-do
7904 (concat "/\\*"
7905 (eval-when-compile
7906 (verilog-regexp-words
7907 `("AUTOASCIIENUM" "AUTOCONCATCOMMENT" "AUTODEFINEVALUE"
7908 "AUTOINOUT" "AUTOINOUTCOMP" "AUTOINOUTMODULE"
7909 "AUTOINPUT" "AUTOOUTPUT" "AUTOOUTPUTEVERY"
7910 "AUTOREG" "AUTOREGINPUT" "AUTORESET" "AUTOTIEOFF"
7911 "AUTOUNUSED" "AUTOWIRE")))
7912 "\\(\\|([^)]*)\\|(\"[^\"]*\")\\)" ; Optional parens or quoted parameter
7913 "\\*/")
7914 'verilog-delete-autos-lined)
7915 ;; Remove those that are in parenthesis
7916 (verilog-auto-re-search-do
7917 (concat "/\\*"
7918 (eval-when-compile
7919 (verilog-regexp-words
7920 `("AS" "AUTOARG" "AUTOCONCATWIDTH" "AUTOINST" "AUTOINSTPARAM"
7921 "AUTOSENSE")))
7922 "\\*/")
7923 'verilog-delete-to-paren)
7924 ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments
7925 (verilog-auto-re-search-do "\\.\\*"
7926 'verilog-delete-auto-star-all)
7927 ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed
7928 (goto-char (point-min))
7929 (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)[ \tLT0-9]*$" nil t)
7930 (replace-match ""))
7931
7932 ;; Final customize
7933 (run-hooks 'verilog-delete-auto-hook)))
7934 \f
7935 ;;
7936 ;; Auto inject
7937 ;;
7938
7939 (defun verilog-inject-auto ()
7940 "Examine legacy non-AUTO code and insert AUTOs in appropriate places.
7941
7942 Any always @ blocks with sensitivity lists that match computed lists will
7943 be replaced with /*AS*/ comments.
7944
7945 Any cells will get /*AUTOINST*/ added to the end of the pin list.
7946 Pins with have identical names will be deleted.
7947
7948 Argument lists will not be deleted, /*AUTOARG*/ will only be inserted to
7949 support adding new ports. You may wish to delete older ports yourself.
7950
7951 For example:
7952
7953 module ExampInject (i, o);
7954 input i;
7955 input j;
7956 output o;
7957 always @ (i or j)
7958 o = i | j;
7959 InstModule instName
7960 (.foobar(baz),
7961 j(j));
7962 endmodule
7963
7964 Typing \\[verilog-inject-auto] will make this into:
7965
7966 module ExampInject (i, o/*AUTOARG*/
7967 // Inputs
7968 j);
7969 input i;
7970 output o;
7971 always @ (/*AS*/i or j)
7972 o = i | j;
7973 InstModule instName
7974 (.foobar(baz),
7975 /*AUTOINST*/
7976 // Outputs
7977 j(j));
7978 endmodule"
7979 (interactive)
7980 (verilog-auto t))
7981
7982 (defun verilog-inject-arg ()
7983 "Inject AUTOARG into new code. See `verilog-inject-auto'."
7984 ;; Presume one module per file.
7985 (save-excursion
7986 (goto-char (point-min))
7987 (while (verilog-re-search-forward-quick "\\<module\\>" nil t)
7988 (let ((endmodp (save-excursion
7989 (verilog-re-search-forward-quick "\\<endmodule\\>" nil t)
7990 (point))))
7991 ;; See if there's already a comment .. inside a comment so not verilog-re-search
7992 (when (not (re-search-forward "/\\*AUTOARG\\*/" endmodp t))
7993 (verilog-re-search-forward-quick ";" nil t)
7994 (backward-char 1)
7995 (verilog-backward-syntactic-ws)
7996 (backward-char 1) ; Moves to paren that closes argdecl's
7997 (when (looking-at ")")
7998 (insert "/*AUTOARG*/")))))))
7999
8000 (defun verilog-inject-sense ()
8001 "Inject AUTOSENSE into new code. See `verilog-inject-auto'."
8002 (save-excursion
8003 (goto-char (point-min))
8004 (while (verilog-re-search-forward-quick "\\<always\\s *@\\s *(" nil t)
8005 (let* ((start-pt (point))
8006 (modi (verilog-modi-current))
8007 (moddecls (verilog-modi-get-decls modi))
8008 pre-sigs
8009 got-sigs)
8010 (backward-char 1)
8011 (forward-sexp 1)
8012 (backward-char 1) ;; End )
8013 (when (not (verilog-re-search-backward "/\\*\\(AUTOSENSE\\|AS\\)\\*/" start-pt t))
8014 (setq pre-sigs (verilog-signals-from-signame
8015 (verilog-read-signals start-pt (point)))
8016 got-sigs (verilog-auto-sense-sigs moddecls nil))
8017 (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal?
8018 (verilog-signals-not-in got-sigs pre-sigs)))
8019 (delete-region start-pt (point))
8020 (insert "/*AS*/")))))))
8021
8022 (defun verilog-inject-inst ()
8023 "Inject AUTOINST into new code. See `verilog-inject-auto'."
8024 (save-excursion
8025 (goto-char (point-min))
8026 ;; It's hard to distinguish modules; we'll instead search for pins.
8027 (while (verilog-re-search-forward-quick "\\.\\s *[a-zA-Z0-9`_\$]+\\s *(\\s *[a-zA-Z0-9`_\$]+\\s *)" nil t)
8028 (verilog-backward-open-paren) ;; Inst start
8029 (cond
8030 ((= (preceding-char) ?\#) ;; #(...) parameter section, not pin. Skip.
8031 (forward-char 1)
8032 (verilog-forward-close-paren)) ;; Parameters done
8033 (t
8034 (forward-char 1)
8035 (let ((indent-pt (+ (current-column)))
8036 (end-pt (save-excursion (verilog-forward-close-paren) (point))))
8037 (cond ((verilog-re-search-forward "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-pt t)
8038 (goto-char end-pt)) ;; Already there, continue search with next instance
8039 (t
8040 ;; Delete identical interconnect
8041 (let ((case-fold-search nil)) ;; So we don't convert upper-to-lower, etc
8042 (while (verilog-re-search-forward "\\.\\s *\\([a-zA-Z0-9`_\$]+\\)*\\s *(\\s *\\1\\s *)\\s *" end-pt t)
8043 (delete-region (match-beginning 0) (match-end 0))
8044 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))) ;; Keep it correct
8045 (while (or (looking-at "[ \t\n\f,]+")
8046 (looking-at "//[^\n]*"))
8047 (delete-region (match-beginning 0) (match-end 0))
8048 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))))))
8049 (verilog-forward-close-paren)
8050 (backward-char 1)
8051 ;; Not verilog-re-search, as we don't want to strip comments
8052 (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t)
8053 (delete-region (match-beginning 0) (match-end 0)))
8054 (insert "\n")
8055 (indent-to indent-pt)
8056 (insert "/*AUTOINST*/")))))))))
8057 \f
8058 ;;
8059 ;; Auto save
8060 ;;
8061
8062 (defun verilog-auto-save-check ()
8063 "On saving see if we need auto update."
8064 (cond ((not verilog-auto-save-policy)) ; disabled
8065 ((not (save-excursion
8066 (save-match-data
8067 (let ((case-fold-search nil))
8068 (goto-char (point-min))
8069 (re-search-forward "AUTO" nil t))))))
8070 ((eq verilog-auto-save-policy 'force)
8071 (verilog-auto))
8072 ((not (buffer-modified-p)))
8073 ((eq verilog-auto-update-tick (buffer-modified-tick))) ; up-to-date
8074 ((eq verilog-auto-save-policy 'detect)
8075 (verilog-auto))
8076 (t
8077 (when (yes-or-no-p "AUTO statements not recomputed, do it now? ")
8078 (verilog-auto))
8079 ;; Don't ask again if didn't update
8080 (set (make-local-variable 'verilog-auto-update-tick) (buffer-modified-tick))))
8081 (when (not verilog-auto-star-save)
8082 (verilog-delete-auto-star-implicit))
8083 nil) ;; Always return nil -- we don't write the file ourselves
8084
8085 (defun verilog-auto-read-locals ()
8086 "Return file local variable segment at bottom of file."
8087 (save-excursion
8088 (goto-char (point-max))
8089 (if (re-search-backward "Local Variables:" nil t)
8090 (buffer-substring-no-properties (point) (point-max))
8091 "")))
8092
8093 (defun verilog-auto-reeval-locals (&optional force)
8094 "Read file local variable segment at bottom of file if it has changed.
8095 If FORCE, always reread it."
8096 (make-local-variable 'verilog-auto-last-file-locals)
8097 (let ((curlocal (verilog-auto-read-locals)))
8098 (when (or force (not (equal verilog-auto-last-file-locals curlocal)))
8099 (setq verilog-auto-last-file-locals curlocal)
8100 ;; Note this may cause this function to be recursively invoked.
8101 ;; The above when statement will prevent it from recursing forever.
8102 (hack-local-variables)
8103 t)))
8104 \f
8105 ;;
8106 ;; Auto creation
8107 ;;
8108
8109 (defun verilog-auto-arg-ports (sigs message indent-pt)
8110 "Print a list of ports for a AUTOINST.
8111 Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT."
8112 (when sigs
8113 (insert "\n")
8114 (indent-to indent-pt)
8115 (insert message)
8116 (insert "\n")
8117 (let ((space ""))
8118 (indent-to indent-pt)
8119 (while sigs
8120 (cond ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column)
8121 (insert "\n")
8122 (indent-to indent-pt))
8123 (t (insert space)))
8124 (insert (verilog-sig-name (car sigs)) ",")
8125 (setq sigs (cdr sigs)
8126 space " ")))))
8127
8128 (defun verilog-auto-arg ()
8129 "Expand AUTOARG statements.
8130 Replace the argument declarations at the beginning of the
8131 module with ones automatically derived from input and output
8132 statements. This can be dangerous if the module is instantiated
8133 using position-based connections, so use only name-based when
8134 instantiating the resulting module. Long lines are split based
8135 on the `fill-column', see \\[set-fill-column].
8136
8137 Limitations:
8138 Concatenation and outputting partial busses is not supported.
8139
8140 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
8141
8142 For example:
8143
8144 module ExampArg (/*AUTOARG*/);
8145 input i;
8146 output o;
8147 endmodule
8148
8149 Typing \\[verilog-auto] will make this into:
8150
8151 module ExampArg (/*AUTOARG*/
8152 // Outputs
8153 o,
8154 // Inputs
8155 i
8156 );
8157 input i;
8158 output o;
8159 endmodule
8160
8161 Any ports declared between the ( and /*AUTOARG*/ are presumed to be
8162 predeclared and are not redeclared by AUTOARG. AUTOARG will make a
8163 conservative guess on adding a comma for the first signal, if you have
8164 any ifdefs or complicated expressions before the AUTOARG you will need
8165 to choose the comma yourself.
8166
8167 Avoid declaring ports manually, as it makes code harder to maintain."
8168 (save-excursion
8169 (let* ((modi (verilog-modi-current))
8170 (moddecls (verilog-modi-get-decls modi))
8171 (skip-pins (aref (verilog-read-arg-pins) 0)))
8172 (verilog-repair-open-comma)
8173 (verilog-auto-arg-ports (verilog-signals-not-in
8174 (verilog-decls-get-outputs moddecls)
8175 skip-pins)
8176 "// Outputs"
8177 verilog-indent-level-declaration)
8178 (verilog-auto-arg-ports (verilog-signals-not-in
8179 (verilog-decls-get-inouts moddecls)
8180 skip-pins)
8181 "// Inouts"
8182 verilog-indent-level-declaration)
8183 (verilog-auto-arg-ports (verilog-signals-not-in
8184 (verilog-decls-get-inputs moddecls)
8185 skip-pins)
8186 "// Inputs"
8187 verilog-indent-level-declaration)
8188 (verilog-repair-close-comma)
8189 (unless (eq (char-before) ?/ )
8190 (insert "\n"))
8191 (indent-to verilog-indent-level-declaration))))
8192
8193 (defun verilog-auto-inst-port-map (port-st)
8194 nil)
8195
8196 (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning
8197 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
8198 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
8199 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning
8200 (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning
8201
8202 (defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star par-values)
8203 "Print out a instantiation connection for this PORT-ST.
8204 Insert to INDENT-PT, use template TPL-LIST.
8205 @ are instantiation numbers, replaced with TPL-NUM.
8206 @\"(expression @)\" are evaluated, with @ as a variable.
8207 If FOR-STAR add comment it is a .* expansion.
8208 If PAR-VALUES replace final strings with these parameter values."
8209 (let* ((port (verilog-sig-name port-st))
8210 (tpl-ass (or (assoc port (car tpl-list))
8211 (verilog-auto-inst-port-map port-st)))
8212 ;; vl-* are documented for user use
8213 (vl-name (verilog-sig-name port-st))
8214 (vl-width (verilog-sig-width port-st))
8215 (vl-bits (if (or verilog-auto-inst-vector
8216 (not (assoc port vector-skip-list))
8217 (not (equal (verilog-sig-bits port-st)
8218 (verilog-sig-bits (assoc port vector-skip-list)))))
8219 (or (verilog-sig-bits port-st) "")
8220 ""))
8221 (case-fold-search nil)
8222 (check-values par-values)
8223 tpl-net)
8224 ;; Replace parameters in bit-width
8225 (when (and check-values
8226 (not (equal vl-bits "")))
8227 (while check-values
8228 (setq vl-bits (verilog-string-replace-matches
8229 (concat "\\<" (nth 0 (car check-values)) "\\>")
8230 (concat "(" (nth 1 (car check-values)) ")")
8231 t t vl-bits)
8232 check-values (cdr check-values)))
8233 (setq vl-bits (verilog-simplify-range-expression vl-bits))) ; Not in the loop for speed
8234 ;; Default net value if not found
8235 (setq tpl-net (if (verilog-sig-multidim port-st)
8236 (concat port "/*" (verilog-sig-multidim-string port-st)
8237 vl-bits "*/")
8238 (concat port vl-bits)))
8239 ;; Find template
8240 (cond (tpl-ass ; Template of exact port name
8241 (setq tpl-net (nth 1 tpl-ass)))
8242 ((nth 1 tpl-list) ; Wildcards in template, search them
8243 (let ((wildcards (nth 1 tpl-list)))
8244 (while wildcards
8245 (when (string-match (nth 0 (car wildcards)) port)
8246 (setq tpl-ass (car wildcards) ; so allow @ parsing
8247 tpl-net (replace-match (nth 1 (car wildcards))
8248 t nil port)))
8249 (setq wildcards (cdr wildcards))))))
8250 ;; Parse Templated variable
8251 (when tpl-ass
8252 ;; Evaluate @"(lispcode)"
8253 (when (string-match "@\".*[^\\]\"" tpl-net)
8254 (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net)
8255 (setq tpl-net
8256 (concat
8257 (substring tpl-net 0 (match-beginning 0))
8258 (save-match-data
8259 (let* ((expr (match-string 1 tpl-net))
8260 (value
8261 (progn
8262 (setq expr (verilog-string-replace-matches "\\\\\"" "\"" nil nil expr))
8263 (setq expr (verilog-string-replace-matches "@" tpl-num nil nil expr))
8264 (prin1 (eval (car (read-from-string expr)))
8265 (lambda (ch) ())))))
8266 (if (numberp value) (setq value (number-to-string value)))
8267 value))
8268 (substring tpl-net (match-end 0))))))
8269 ;; Replace @ and [] magic variables in final output
8270 (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net))
8271 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)))
8272 ;; Insert it
8273 (indent-to indent-pt)
8274 (insert "." port)
8275 (indent-to verilog-auto-inst-column)
8276 (insert "(" tpl-net "),")
8277 (cond (tpl-ass
8278 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
8279 verilog-auto-inst-column))
8280 (insert " // Templated")
8281 (when verilog-auto-inst-template-numbers
8282 (insert " T" (int-to-string (nth 2 tpl-ass))
8283 " L" (int-to-string (nth 3 tpl-ass)))))
8284 (for-star
8285 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16)
8286 verilog-auto-inst-column))
8287 (insert " // Implicit .\*"))) ;For some reason the . or * must be escaped...
8288 (insert "\n")))
8289 ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3")
8290 ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]")
8291 ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));")
8292
8293 (defun verilog-auto-inst-first ()
8294 "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]."
8295 ;; Do we need a trailing comma?
8296 ;; There maybe a ifdef or something similar before us. What a mess. Thus
8297 ;; to avoid trouble we only insert on preceeding ) or *.
8298 ;; Insert first port on new line
8299 (insert "\n") ;; Must insert before search, so point will move forward if insert comma
8300 (save-excursion
8301 (verilog-re-search-backward "[^ \t\n\f]" nil nil)
8302 (when (looking-at ")\\|\\*") ;; Generally don't insert, unless we are fairly sure
8303 (forward-char 1)
8304 (insert ","))))
8305
8306 (defun verilog-auto-star ()
8307 "Expand SystemVerilog .* pins, as part of \\[verilog-auto].
8308
8309 If `verilog-auto-star-expand' is set, .* pins are treated if they were
8310 AUTOINST statements, otherwise they are ignored. For safety, Verilog mode
8311 will also ignore any .* that are not last in your pin list (this prevents
8312 it from deleting pins following the .* when it expands the AUTOINST.)
8313
8314 On writing your file, unless `verilog-auto-star-save' is set, any
8315 non-templated expanded pins will be removed. You may do this at any time
8316 with \\[verilog-delete-auto-star-implicit].
8317
8318 If you are converting a module to use .* for the first time, you may wish
8319 to use \\[verilog-inject-auto] and then replace the created AUTOINST with .*.
8320
8321 See `verilog-auto-inst' for examples, templates, and more information."
8322 (when (verilog-auto-star-safe)
8323 (verilog-auto-inst)))
8324
8325 (defun verilog-auto-inst ()
8326 "Expand AUTOINST statements, as part of \\[verilog-auto].
8327 Replace the pin connections to an instantiation with ones
8328 automatically derived from the module header of the instantiated netlist.
8329
8330 If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports,
8331 and delete them before saving unless `verilog-auto-star-save' is set.
8332 See `verilog-auto-star' for more information.
8333
8334 Limitations:
8335 Module names must be resolvable to filenames by adding a
8336 `verilog-library-extensions', and being found in the same directory, or
8337 by changing the variable `verilog-library-flags' or
8338 `verilog-library-directories'. Macros `modname are translated through the
8339 vh-{name} Emacs variable, if that is not found, it just ignores the `.
8340
8341 In templates you must have one signal per line, ending in a ), or ));,
8342 and have proper () nesting, including a final ); to end the template.
8343
8344 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
8345
8346 SystemVerilog multidimensional input/output has only experimental support.
8347
8348 Parameters referenced by the instantiation will remain symbolic, unless
8349 `verilog-auto-inst-param-value' is set.
8350
8351 For example, first take the submodule InstModule.v:
8352
8353 module InstModule (o,i)
8354 output [31:0] o;
8355 input i;
8356 wire [31:0] o = {32{i}};
8357 endmodule
8358
8359 This is then used in a upper level module:
8360
8361 module ExampInst (o,i)
8362 output o;
8363 input i;
8364 InstModule instName
8365 (/*AUTOINST*/);
8366 endmodule
8367
8368 Typing \\[verilog-auto] will make this into:
8369
8370 module ExampInst (o,i)
8371 output o;
8372 input i;
8373 InstModule instName
8374 (/*AUTOINST*/
8375 // Outputs
8376 .ov (ov[31:0]),
8377 // Inputs
8378 .i (i));
8379 endmodule
8380
8381 Where the list of inputs and outputs came from the inst module.
8382 \f
8383 Exceptions:
8384
8385 Unless you are instantiating a module multiple times, or the module is
8386 something trivial like an adder, DO NOT CHANGE SIGNAL NAMES ACROSS HIERARCHY.
8387 It just makes for unmaintainable code. To sanitize signal names, try
8388 vrename from http://www.veripool.org.
8389
8390 When you need to violate this suggestion there are two ways to list
8391 exceptions, placing them before the AUTOINST, or using templates.
8392
8393 Any ports defined before the /*AUTOINST*/ are not included in the list of
8394 automatics. This is similar to making a template as described below, but
8395 is restricted to simple connections just like you normally make. Also note
8396 that any signals before the AUTOINST will only be picked up by AUTOWIRE if
8397 you have the appropriate // Input or // Output comment, and exactly the
8398 same line formatting as AUTOINST itself uses.
8399
8400 InstModule instName
8401 (// Inputs
8402 .i (my_i_dont_mess_with_it),
8403 /*AUTOINST*/
8404 // Outputs
8405 .ov (ov[31:0]));
8406
8407 \f
8408 Templates:
8409
8410 For multiple instantiations based upon a single template, create a
8411 commented out template:
8412
8413 /* InstModule AUTO_TEMPLATE (
8414 .sig3 (sigz[]),
8415 );
8416 */
8417
8418 Templates go ABOVE the instantiation(s). When an instantiation is
8419 expanded `verilog-mode' simply searches up for the closest template.
8420 Thus you can have multiple templates for the same module, just alternate
8421 between the template for an instantiation and the instantiation itself.
8422
8423 The module name must be the same as the name of the module in the
8424 instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact
8425 words and capitalized. Only signals that must be different for each
8426 instantiation need to be listed.
8427
8428 Inside a template, a [] in a connection name (with nothing else inside
8429 the brackets) will be replaced by the same bus subscript as it is being
8430 connected to, or the [] will be removed if it is a single bit signal.
8431 Generally it is a good idea to do this for all connections in a template,
8432 as then they will work for any width signal, and with AUTOWIRE. See
8433 PTL_BUS becoming PTL_BUSNEW below.
8434
8435 If you have a complicated template, set `verilog-auto-inst-template-numbers'
8436 to see which regexps are matching. Don't leave that mode set after
8437 debugging is completed though, it will result in lots of extra differences
8438 and merge conflicts.
8439
8440 For example:
8441
8442 /* InstModule AUTO_TEMPLATE (
8443 .ptl_bus (ptl_busnew[]),
8444 );
8445 */
8446 InstModule ms2m (/*AUTOINST*/);
8447
8448 Typing \\[verilog-auto] will make this into:
8449
8450 InstModule ms2m (/*AUTOINST*/
8451 // Outputs
8452 .NotInTemplate (NotInTemplate),
8453 .ptl_bus (ptl_busnew[3:0]), // Templated
8454 ....
8455 \f
8456 @ Templates:
8457
8458 It is common to instantiate a cell multiple times, so templates make it
8459 trivial to substitute part of the cell name into the connection name.
8460
8461 /* InstName AUTO_TEMPLATE <optional \"REGEXP\"> (
8462 .sig1 (sigx[@]),
8463 .sig2 (sigy[@\"(% (+ 1 @) 4)\"]),
8464 );
8465 */
8466
8467 If no regular expression is provided immediately after the AUTO_TEMPLATE
8468 keyword, then the @ character in any connection names will be replaced
8469 with the instantiation number; the first digits found in the cell's
8470 instantiation name.
8471
8472 If a regular expression is provided, the @ character will be replaced
8473 with the first \(\) grouping that matches against the cell name. Using a
8474 regexp of \"\\([0-9]+\\)\" provides identical values for @ as when no
8475 regexp is provided. If you use multiple layers of parenthesis,
8476 \"test\\([^0-9]+\\)_\\([0-9]+\\)\" would replace @ with non-number
8477 characters after test and before _, whereas
8478 \"\\(test\\([a-z]+\\)_\\([0-9]+\\)\\)\" would replace @ with the entire
8479 match.
8480
8481 For example:
8482
8483 /* InstModule AUTO_TEMPLATE (
8484 .ptl_mapvalidx (ptl_mapvalid[@]),
8485 .ptl_mapvalidp1x (ptl_mapvalid[@\"(% (+ 1 @) 4)\"]),
8486 );
8487 */
8488 InstModule ms2m (/*AUTOINST*/);
8489
8490 Typing \\[verilog-auto] will make this into:
8491
8492 InstModule ms2m (/*AUTOINST*/
8493 // Outputs
8494 .ptl_mapvalidx (ptl_mapvalid[2]),
8495 .ptl_mapvalidp1x (ptl_mapvalid[3]));
8496
8497 Note the @ character was replaced with the 2 from \"ms2m\".
8498
8499 Alternatively, using a regular expression for @:
8500
8501 /* InstModule AUTO_TEMPLATE \"_\\([a-z]+\\)\" (
8502 .ptl_mapvalidx (@_ptl_mapvalid),
8503 .ptl_mapvalidp1x (ptl_mapvalid_@),
8504 );
8505 */
8506 InstModule ms2_FOO (/*AUTOINST*/);
8507 InstModule ms2_BAR (/*AUTOINST*/);
8508
8509 Typing \\[verilog-auto] will make this into:
8510
8511 InstModule ms2_FOO (/*AUTOINST*/
8512 // Outputs
8513 .ptl_mapvalidx (FOO_ptl_mapvalid),
8514 .ptl_mapvalidp1x (ptl_mapvalid_FOO));
8515 InstModule ms2_BAR (/*AUTOINST*/
8516 // Outputs
8517 .ptl_mapvalidx (BAR_ptl_mapvalid),
8518 .ptl_mapvalidp1x (ptl_mapvalid_BAR));
8519
8520 \f
8521 Regexp Templates:
8522
8523 A template entry of the form
8524
8525 .pci_req\\([0-9]+\\)_l (pci_req_jtag_[\\1]),
8526
8527 will apply an Emacs style regular expression search for any port beginning
8528 in pci_req followed by numbers and ending in _l and connecting that to
8529 the pci_req_jtag_[] net, with the bus subscript coming from what matches
8530 inside the first set of \\( \\). Thus pci_req2_l becomes pci_req_jtag_[2].
8531
8532 Since \\([0-9]+\\) is so common and ugly to read, a @ in the port name
8533 does the same thing. (Note a @ in the connection/replacement text is
8534 completely different -- still use \\1 there!) Thus this is the same as
8535 the above template:
8536
8537 .pci_req@_l (pci_req_jtag_[\\1]),
8538
8539 Here's another example to remove the _l, useful when naming conventions
8540 specify _ alone to mean active low. Note the use of [] to keep the bus
8541 subscript:
8542
8543 .\\(.*\\)_l (\\1_[]),
8544 \f
8545 Lisp Templates:
8546
8547 First any regular expression template is expanded.
8548
8549 If the syntax @\"( ... )\" is found in a connection, the expression in
8550 quotes will be evaluated as a Lisp expression, with @ replaced by the
8551 instantiation number. The MAPVALIDP1X example above would put @+1 modulo
8552 4 into the brackets. Quote all double-quotes inside the expression with
8553 a leading backslash (\\\"). There are special variables defined that are
8554 useful in these Lisp functions:
8555
8556 vl-name Name portion of the input/output port.
8557 vl-bits Bus bits portion of the input/output port ('[2:0]').
8558 vl-width Width of the input/output port ('3' for [2:0]).
8559 May be a (...) expression if bits isn't a constant.
8560 vl-dir Direction of the pin input/output/inout.
8561 vl-cell-type Module name/type of the cell ('InstModule').
8562 vl-cell-name Instance name of the cell ('instName').
8563
8564 Normal Lisp variables may be used in expressions. See
8565 `verilog-read-defines' which can set vh-{definename} variables for use
8566 here. Also, any comments of the form:
8567
8568 /*AUTO_LISP(setq foo 1)*/
8569
8570 will evaluate any Lisp expression inside the parenthesis between the
8571 beginning of the buffer and the point of the AUTOINST. This allows
8572 functions to be defined or variables to be changed between instantiations.
8573
8574 Note that when using lisp expressions errors may occur when @ is not a
8575 number; you may need to use the standard Emacs Lisp functions
8576 `number-to-string' and `string-to-number'.
8577
8578 After the evaluation is completed, @ substitution and [] substitution
8579 occur."
8580 (save-excursion
8581 ;; Find beginning
8582 (let* ((pt (point))
8583 (for-star (save-excursion (backward-char 2) (looking-at "\\.\\*")))
8584 (indent-pt (save-excursion (verilog-backward-open-paren)
8585 (1+ (current-column))))
8586 (verilog-auto-inst-column (max verilog-auto-inst-column
8587 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
8588 (modi (verilog-modi-current))
8589 (moddecls (verilog-modi-get-decls modi))
8590 (vector-skip-list (unless verilog-auto-inst-vector
8591 (verilog-decls-get-signals moddecls)))
8592 submod submodi submoddecls
8593 inst skip-pins tpl-list tpl-num did-first par-values)
8594
8595 ;; Find module name that is instantiated
8596 (setq submod (verilog-read-inst-module)
8597 inst (verilog-read-inst-name)
8598 vl-cell-type submod
8599 vl-cell-name inst
8600 skip-pins (aref (verilog-read-inst-pins) 0))
8601
8602 ;; Parse any AUTO_LISP() before here
8603 (verilog-read-auto-lisp (point-min) pt)
8604
8605 ;; Read parameters (after AUTO_LISP)
8606 (setq par-values (and verilog-auto-inst-param-value
8607 (verilog-read-inst-param-value)))
8608
8609 ;; Lookup position, etc of submodule
8610 ;; Note this may raise an error
8611 (when (setq submodi (verilog-modi-lookup submod t))
8612 (setq submoddecls (verilog-modi-get-decls submodi))
8613 ;; If there's a number in the instantiation, it may be a argument to the
8614 ;; automatic variable instantiation program.
8615 (let* ((tpl-info (verilog-read-auto-template submod))
8616 (tpl-regexp (aref tpl-info 0)))
8617 (setq tpl-num (if (string-match tpl-regexp inst)
8618 (match-string 1 inst)
8619 "")
8620 tpl-list (aref tpl-info 1)))
8621 ;; Find submodule's signals and dump
8622 (let ((sig-list (verilog-signals-not-in
8623 (verilog-decls-get-outputs submoddecls)
8624 skip-pins))
8625 (vl-dir "output"))
8626 (when sig-list
8627 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
8628 (indent-to indent-pt)
8629 ;; Note these are searched for in verilog-read-sub-decls.
8630 (insert "// Outputs\n")
8631 (mapc (lambda (port)
8632 (verilog-auto-inst-port port indent-pt
8633 tpl-list tpl-num for-star par-values))
8634 sig-list)))
8635 (let ((sig-list (verilog-signals-not-in
8636 (verilog-decls-get-inouts submoddecls)
8637 skip-pins))
8638 (vl-dir "inout"))
8639 (when sig-list
8640 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
8641 (indent-to indent-pt)
8642 (insert "// Inouts\n")
8643 (mapc (lambda (port)
8644 (verilog-auto-inst-port port indent-pt
8645 tpl-list tpl-num for-star par-values))
8646 sig-list)))
8647 (let ((sig-list (verilog-signals-not-in
8648 (verilog-decls-get-inputs submoddecls)
8649 skip-pins))
8650 (vl-dir "input"))
8651 (when sig-list
8652 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
8653 (indent-to indent-pt)
8654 (insert "// Inputs\n")
8655 (mapc (lambda (port)
8656 (verilog-auto-inst-port port indent-pt
8657 tpl-list tpl-num for-star par-values))
8658 sig-list)))
8659 ;; Kill extra semi
8660 (save-excursion
8661 (cond (did-first
8662 (re-search-backward "," pt t)
8663 (delete-char 1)
8664 (insert ");")
8665 (search-forward "\n") ;; Added by inst-port
8666 (delete-backward-char 1)
8667 (if (search-forward ")" nil t) ;; From user, moved up a line
8668 (delete-backward-char 1))
8669 (if (search-forward ";" nil t) ;; Don't error if user had syntax error and forgot it
8670 (delete-backward-char 1)))))))))
8671
8672 (defun verilog-auto-inst-param ()
8673 "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto].
8674 Replace the parameter connections to an instantiation with ones
8675 automatically derived from the module header of the instantiated netlist.
8676
8677 See \\[verilog-auto-inst] for limitations, and templates to customize the
8678 output.
8679
8680 For example, first take the submodule InstModule.v:
8681
8682 module InstModule (o,i)
8683 parameter PAR;
8684 endmodule
8685
8686 This is then used in a upper level module:
8687
8688 module ExampInst (o,i)
8689 parameter PAR;
8690 InstModule #(/*AUTOINSTPARAM*/)
8691 instName (/*AUTOINST*/);
8692 endmodule
8693
8694 Typing \\[verilog-auto] will make this into:
8695
8696 module ExampInst (o,i)
8697 output o;
8698 input i;
8699 InstModule #(/*AUTOINSTPARAM*/
8700 // Parameters
8701 .PAR (PAR));
8702 instName (/*AUTOINST*/);
8703 endmodule
8704
8705 Where the list of parameter connections come from the inst module.
8706 \f
8707 Templates:
8708
8709 You can customize the parameter connections using AUTO_TEMPLATEs,
8710 just as you would with \\[verilog-auto-inst]."
8711 (save-excursion
8712 ;; Find beginning
8713 (let* ((pt (point))
8714 (indent-pt (save-excursion (verilog-backward-open-paren)
8715 (1+ (current-column))))
8716 (verilog-auto-inst-column (max verilog-auto-inst-column
8717 (+ 16 (* 8 (/ (+ indent-pt 7) 8)))))
8718 (modi (verilog-modi-current))
8719 (moddecls (verilog-modi-get-decls modi))
8720 (vector-skip-list (unless verilog-auto-inst-vector
8721 (verilog-decls-get-signals moddecls)))
8722 submod submodi submoddecls
8723 inst skip-pins tpl-list tpl-num did-first)
8724 ;; Find module name that is instantiated
8725 (setq submod (save-excursion
8726 ;; Get to the point where AUTOINST normally is to read the module
8727 (verilog-re-search-forward-quick "[(;]" nil nil)
8728 (verilog-read-inst-module))
8729 inst (save-excursion
8730 ;; Get to the point where AUTOINST normally is to read the module
8731 (verilog-re-search-forward-quick "[(;]" nil nil)
8732 (verilog-read-inst-name))
8733 vl-cell-type submod
8734 vl-cell-name inst
8735 skip-pins (aref (verilog-read-inst-pins) 0))
8736
8737 ;; Parse any AUTO_LISP() before here
8738 (verilog-read-auto-lisp (point-min) pt)
8739
8740 ;; Lookup position, etc of submodule
8741 ;; Note this may raise an error
8742 (when (setq submodi (verilog-modi-lookup submod t))
8743 (setq submoddecls (verilog-modi-get-decls submodi))
8744 ;; If there's a number in the instantiation, it may be a argument to the
8745 ;; automatic variable instantiation program.
8746 (let* ((tpl-info (verilog-read-auto-template submod))
8747 (tpl-regexp (aref tpl-info 0)))
8748 (setq tpl-num (if (string-match tpl-regexp inst)
8749 (match-string 1 inst)
8750 "")
8751 tpl-list (aref tpl-info 1)))
8752 ;; Find submodule's signals and dump
8753 (let ((sig-list (verilog-signals-not-in
8754 (verilog-decls-get-gparams submoddecls)
8755 skip-pins))
8756 (vl-dir "parameter"))
8757 (when sig-list
8758 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
8759 (indent-to indent-pt)
8760 ;; Note these are searched for in verilog-read-sub-decls.
8761 (insert "// Parameters\n")
8762 (mapc (lambda (port)
8763 (verilog-auto-inst-port port indent-pt
8764 tpl-list tpl-num nil nil))
8765 sig-list)))
8766 ;; Kill extra semi
8767 (save-excursion
8768 (cond (did-first
8769 (re-search-backward "," pt t)
8770 (delete-char 1)
8771 (insert ")")
8772 (search-forward "\n") ;; Added by inst-port
8773 (delete-backward-char 1)
8774 (if (search-forward ")" nil t) ;; From user, moved up a line
8775 (delete-backward-char 1)))))))))
8776
8777 (defun verilog-auto-reg ()
8778 "Expand AUTOREG statements, as part of \\[verilog-auto].
8779 Make reg statements for any output that isn't already declared,
8780 and isn't a wire output from a block.
8781
8782 Limitations:
8783 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
8784
8785 This does NOT work on memories, declare those yourself.
8786
8787 An example:
8788
8789 module ExampReg (o,i)
8790 output o;
8791 input i;
8792 /*AUTOREG*/
8793 always o = i;
8794 endmodule
8795
8796 Typing \\[verilog-auto] will make this into:
8797
8798 module ExampReg (o,i)
8799 output o;
8800 input i;
8801 /*AUTOREG*/
8802 // Beginning of automatic regs (for this module's undeclared outputs)
8803 reg o;
8804 // End of automatics
8805 always o = i;
8806 endmodule"
8807 (save-excursion
8808 ;; Point must be at insertion point.
8809 (let* ((indent-pt (current-indentation))
8810 (modi (verilog-modi-current))
8811 (moddecls (verilog-modi-get-decls modi))
8812 (modsubdecls (verilog-modi-get-sub-decls modi))
8813 (sig-list (verilog-signals-not-in
8814 (verilog-decls-get-outputs moddecls)
8815 (append (verilog-decls-get-wires moddecls)
8816 (verilog-decls-get-regs moddecls)
8817 (verilog-decls-get-assigns moddecls)
8818 (verilog-decls-get-consts moddecls)
8819 (verilog-decls-get-gparams moddecls)
8820 (verilog-subdecls-get-outputs modsubdecls)
8821 (verilog-subdecls-get-inouts modsubdecls)))))
8822 (forward-line 1)
8823 (when sig-list
8824 (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n")
8825 (verilog-insert-definition sig-list "reg" indent-pt nil)
8826 (verilog-modi-cache-add-regs modi sig-list)
8827 (verilog-insert-indent "// End of automatics\n")))))
8828
8829 (defun verilog-auto-reg-input ()
8830 "Expand AUTOREGINPUT statements, as part of \\[verilog-auto].
8831 Make reg statements instantiation inputs that aren't already declared.
8832 This is useful for making a top level shell for testing the module that is
8833 to be instantiated.
8834
8835 Limitations:
8836 This ONLY detects inputs of AUTOINSTants (see `verilog-read-sub-decls').
8837
8838 This does NOT work on memories, declare those yourself.
8839
8840 An example (see `verilog-auto-inst' for what else is going on here):
8841
8842 module ExampRegInput (o,i)
8843 output o;
8844 input i;
8845 /*AUTOREGINPUT*/
8846 InstModule instName
8847 (/*AUTOINST*/);
8848 endmodule
8849
8850 Typing \\[verilog-auto] will make this into:
8851
8852 module ExampRegInput (o,i)
8853 output o;
8854 input i;
8855 /*AUTOREGINPUT*/
8856 // Beginning of automatic reg inputs (for undeclared ...
8857 reg [31:0] iv; // From inst of inst.v
8858 // End of automatics
8859 InstModule instName
8860 (/*AUTOINST*/
8861 // Outputs
8862 .o (o[31:0]),
8863 // Inputs
8864 .iv (iv));
8865 endmodule"
8866 (save-excursion
8867 ;; Point must be at insertion point.
8868 (let* ((indent-pt (current-indentation))
8869 (modi (verilog-modi-current))
8870 (moddecls (verilog-modi-get-decls modi))
8871 (modsubdecls (verilog-modi-get-sub-decls modi))
8872 (sig-list (verilog-signals-combine-bus
8873 (verilog-signals-not-in
8874 (append (verilog-subdecls-get-inputs modsubdecls)
8875 (verilog-subdecls-get-inouts modsubdecls))
8876 (verilog-decls-get-signals moddecls)))))
8877 (forward-line 1)
8878 (when sig-list
8879 (verilog-insert-indent "// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)\n")
8880 (verilog-insert-definition sig-list "reg" indent-pt nil)
8881 (verilog-modi-cache-add-regs modi sig-list)
8882 (verilog-insert-indent "// End of automatics\n")))))
8883
8884 (defun verilog-auto-wire ()
8885 "Expand AUTOWIRE statements, as part of \\[verilog-auto].
8886 Make wire statements for instantiations outputs that aren't
8887 already declared.
8888
8889 Limitations:
8890 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'),
8891 and all busses must have widths, such as those from AUTOINST, or using []
8892 in AUTO_TEMPLATEs.
8893
8894 This does NOT work on memories or SystemVerilog .name connections,
8895 declare those yourself.
8896
8897 Verilog mode will add \"Couldn't Merge\" comments to signals it cannot
8898 determine how to bus together. This occurs when you have ports with
8899 non-numeric or non-sequential bus subscripts. If Verilog mode
8900 mis-guessed, you'll have to declare them yourself.
8901
8902 An example (see `verilog-auto-inst' for what else is going on here):
8903
8904 module ExampWire (o,i)
8905 output o;
8906 input i;
8907 /*AUTOWIRE*/
8908 InstModule instName
8909 (/*AUTOINST*/);
8910 endmodule
8911
8912 Typing \\[verilog-auto] will make this into:
8913
8914 module ExampWire (o,i)
8915 output o;
8916 input i;
8917 /*AUTOWIRE*/
8918 // Beginning of automatic wires
8919 wire [31:0] ov; // From inst of inst.v
8920 // End of automatics
8921 InstModule instName
8922 (/*AUTOINST*/
8923 // Outputs
8924 .ov (ov[31:0]),
8925 // Inputs
8926 .i (i));
8927 wire o = | ov;
8928 endmodule"
8929 (save-excursion
8930 ;; Point must be at insertion point.
8931 (let* ((indent-pt (current-indentation))
8932 (modi (verilog-modi-current))
8933 (moddecls (verilog-modi-get-decls modi))
8934 (modsubdecls (verilog-modi-get-sub-decls modi))
8935 (sig-list (verilog-signals-combine-bus
8936 (verilog-signals-not-in
8937 (append (verilog-subdecls-get-outputs modsubdecls)
8938 (verilog-subdecls-get-inouts modsubdecls))
8939 (verilog-decls-get-signals moddecls)))))
8940 (forward-line 1)
8941 (when sig-list
8942 (verilog-insert-indent "// Beginning of automatic wires (for undeclared instantiated-module outputs)\n")
8943 (verilog-insert-definition sig-list "wire" indent-pt nil)
8944 (verilog-modi-cache-add-wires modi sig-list)
8945 (verilog-insert-indent "// End of automatics\n")
8946 (when nil ;; Too slow on huge modules, plus makes everyone's module change
8947 (beginning-of-line)
8948 (setq pnt (point))
8949 (verilog-pretty-declarations quiet)
8950 (goto-char pnt)
8951 (verilog-pretty-expr "//"))))))
8952
8953 (defun verilog-auto-output (&optional with-params)
8954 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto].
8955 Make output statements for any output signal from an /*AUTOINST*/ that
8956 isn't a input to another AUTOINST. This is useful for modules which
8957 only instantiate other modules.
8958
8959 Limitations:
8960 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
8961
8962 If placed inside the parenthesis of a module declaration, it creates
8963 Verilog 2001 style, else uses Verilog 1995 style.
8964
8965 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
8966 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE).
8967
8968 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
8969
8970 Signals matching `verilog-auto-output-ignore-regexp' are not included.
8971
8972 An example (see `verilog-auto-inst' for what else is going on here):
8973
8974 module ExampOutput (ov,i)
8975 input i;
8976 /*AUTOOUTPUT*/
8977 InstModule instName
8978 (/*AUTOINST*/);
8979 endmodule
8980
8981 Typing \\[verilog-auto] will make this into:
8982
8983 module ExampOutput (ov,i)
8984 input i;
8985 /*AUTOOUTPUT*/
8986 // Beginning of automatic outputs (from unused autoinst outputs)
8987 output [31:0] ov; // From inst of inst.v
8988 // End of automatics
8989 InstModule instName
8990 (/*AUTOINST*/
8991 // Outputs
8992 .ov (ov[31:0]),
8993 // Inputs
8994 .i (i));
8995 endmodule
8996
8997 You may also provide an optional regular expression, in which case only
8998 signals matching the regular expression will be included. For example the
8999 same expansion will result from only extracting outputs starting with ov:
9000
9001 /*AUTOOUTPUT(\"^ov\")*/"
9002 (save-excursion
9003 ;; Point must be at insertion point.
9004 (let* ((indent-pt (current-indentation))
9005 (regexp (and with-params
9006 (nth 0 (verilog-read-auto-params 1))))
9007 (v2k (verilog-in-paren))
9008 (modi (verilog-modi-current))
9009 (moddecls (verilog-modi-get-decls modi))
9010 (modsubdecls (verilog-modi-get-sub-decls modi))
9011 (sig-list (verilog-signals-not-in
9012 (verilog-subdecls-get-outputs modsubdecls)
9013 (append (verilog-decls-get-outputs moddecls)
9014 (verilog-decls-get-inouts moddecls)
9015 (verilog-subdecls-get-inputs modsubdecls)
9016 (verilog-subdecls-get-inouts modsubdecls)))))
9017 (when regexp
9018 (setq sig-list (verilog-signals-matching-regexp
9019 sig-list regexp)))
9020 (setq sig-list (verilog-signals-not-matching-regexp
9021 sig-list verilog-auto-output-ignore-regexp))
9022 (forward-line 1)
9023 (when v2k (verilog-repair-open-comma))
9024 (when sig-list
9025 (verilog-insert-indent "// Beginning of automatic outputs (from unused autoinst outputs)\n")
9026 (verilog-insert-definition sig-list "output" indent-pt v2k)
9027 (verilog-modi-cache-add-outputs modi sig-list)
9028 (verilog-insert-indent "// End of automatics\n"))
9029 (when v2k (verilog-repair-close-comma)))))
9030
9031 (defun verilog-auto-output-every ()
9032 "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto].
9033 Make output statements for any signals that aren't primary inputs or
9034 outputs already. This makes every signal in the design a output. This is
9035 useful to get Synopsys to preserve every signal in the design, since it
9036 won't optimize away the outputs.
9037
9038 An example:
9039
9040 module ExampOutputEvery (o,i,tempa,tempb)
9041 output o;
9042 input i;
9043 /*AUTOOUTPUTEVERY*/
9044 wire tempa = i;
9045 wire tempb = tempa;
9046 wire o = tempb;
9047 endmodule
9048
9049 Typing \\[verilog-auto] will make this into:
9050
9051 module ExampOutputEvery (o,i,tempa,tempb)
9052 output o;
9053 input i;
9054 /*AUTOOUTPUTEVERY*/
9055 // Beginning of automatic outputs (every signal)
9056 output tempb;
9057 output tempa;
9058 // End of automatics
9059 wire tempa = i;
9060 wire tempb = tempa;
9061 wire o = tempb;
9062 endmodule"
9063 (save-excursion
9064 ;;Point must be at insertion point
9065 (let* ((indent-pt (current-indentation))
9066 (v2k (verilog-in-paren))
9067 (modi (verilog-modi-current))
9068 (moddecls (verilog-modi-get-decls modi))
9069 (sig-list (verilog-signals-combine-bus
9070 (verilog-signals-not-in
9071 (verilog-decls-get-signals moddecls)
9072 (verilog-decls-get-ports moddecls)))))
9073 (forward-line 1)
9074 (when v2k (verilog-repair-open-comma))
9075 (when sig-list
9076 (verilog-insert-indent "// Beginning of automatic outputs (every signal)\n")
9077 (verilog-insert-definition sig-list "output" indent-pt v2k)
9078 (verilog-modi-cache-add-outputs modi sig-list)
9079 (verilog-insert-indent "// End of automatics\n"))
9080 (when v2k (verilog-repair-close-comma)))))
9081
9082 (defun verilog-auto-input (&optional with-params)
9083 "Expand AUTOINPUT statements, as part of \\[verilog-auto].
9084 Make input statements for any input signal into an /*AUTOINST*/ that
9085 isn't declared elsewhere inside the module. This is useful for modules which
9086 only instantiate other modules.
9087
9088 Limitations:
9089 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
9090
9091 If placed inside the parenthesis of a module declaration, it creates
9092 Verilog 2001 style, else uses Verilog 1995 style.
9093
9094 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
9095 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE).
9096
9097 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
9098
9099 Signals matching `verilog-auto-input-ignore-regexp' are not included.
9100
9101 An example (see `verilog-auto-inst' for what else is going on here):
9102
9103 module ExampInput (ov,i)
9104 output [31:0] ov;
9105 /*AUTOINPUT*/
9106 InstModule instName
9107 (/*AUTOINST*/);
9108 endmodule
9109
9110 Typing \\[verilog-auto] will make this into:
9111
9112 module ExampInput (ov,i)
9113 output [31:0] ov;
9114 /*AUTOINPUT*/
9115 // Beginning of automatic inputs (from unused autoinst inputs)
9116 input i; // From inst of inst.v
9117 // End of automatics
9118 InstModule instName
9119 (/*AUTOINST*/
9120 // Outputs
9121 .ov (ov[31:0]),
9122 // Inputs
9123 .i (i));
9124 endmodule
9125
9126 You may also provide an optional regular expression, in which case only
9127 signals matching the regular expression will be included. For example the
9128 same expansion will result from only extracting inputs starting with i:
9129
9130 /*AUTOINPUT(\"^i\")*/"
9131 (save-excursion
9132 (let* ((indent-pt (current-indentation))
9133 (regexp (and with-params
9134 (nth 0 (verilog-read-auto-params 1))))
9135 (v2k (verilog-in-paren))
9136 (modi (verilog-modi-current))
9137 (moddecls (verilog-modi-get-decls modi))
9138 (modsubdecls (verilog-modi-get-sub-decls modi))
9139 (sig-list (verilog-signals-not-in
9140 (verilog-subdecls-get-inputs modsubdecls)
9141 (append (verilog-decls-get-inputs moddecls)
9142 (verilog-decls-get-inouts moddecls)
9143 (verilog-decls-get-wires moddecls)
9144 (verilog-decls-get-regs moddecls)
9145 (verilog-decls-get-consts moddecls)
9146 (verilog-decls-get-gparams moddecls)
9147 (verilog-subdecls-get-outputs modsubdecls)
9148 (verilog-subdecls-get-inouts modsubdecls)))))
9149 (when regexp
9150 (setq sig-list (verilog-signals-matching-regexp
9151 sig-list regexp)))
9152 (setq sig-list (verilog-signals-not-matching-regexp
9153 sig-list verilog-auto-input-ignore-regexp))
9154 (forward-line 1)
9155 (when v2k (verilog-repair-open-comma))
9156 (when sig-list
9157 (verilog-insert-indent "// Beginning of automatic inputs (from unused autoinst inputs)\n")
9158 (verilog-insert-definition sig-list "input" indent-pt v2k)
9159 (verilog-modi-cache-add-inputs modi sig-list)
9160 (verilog-insert-indent "// End of automatics\n"))
9161 (when v2k (verilog-repair-close-comma)))))
9162
9163 (defun verilog-auto-inout (&optional with-params)
9164 "Expand AUTOINOUT statements, as part of \\[verilog-auto].
9165 Make inout statements for any inout signal in an /*AUTOINST*/ that
9166 isn't declared elsewhere inside the module.
9167
9168 Limitations:
9169 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls').
9170
9171 If placed inside the parenthesis of a module declaration, it creates
9172 Verilog 2001 style, else uses Verilog 1995 style.
9173
9174 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's
9175 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE).
9176
9177 Typedefs must match `verilog-typedef-regexp', which is disabled by default.
9178
9179 Signals matching `verilog-auto-inout-ignore-regexp' are not included.
9180
9181 An example (see `verilog-auto-inst' for what else is going on here):
9182
9183 module ExampInout (ov,i)
9184 input i;
9185 /*AUTOINOUT*/
9186 InstModule instName
9187 (/*AUTOINST*/);
9188 endmodule
9189
9190 Typing \\[verilog-auto] will make this into:
9191
9192 module ExampInout (ov,i)
9193 input i;
9194 /*AUTOINOUT*/
9195 // Beginning of automatic inouts (from unused autoinst inouts)
9196 inout [31:0] ov; // From inst of inst.v
9197 // End of automatics
9198 InstModule instName
9199 (/*AUTOINST*/
9200 // Inouts
9201 .ov (ov[31:0]),
9202 // Inputs
9203 .i (i));
9204 endmodule
9205
9206 You may also provide an optional regular expression, in which case only
9207 signals matching the regular expression will be included. For example the
9208 same expansion will result from only extracting inouts starting with i:
9209
9210 /*AUTOINOUT(\"^i\")*/"
9211 (save-excursion
9212 ;; Point must be at insertion point.
9213 (let* ((indent-pt (current-indentation))
9214 (regexp (and with-params
9215 (nth 0 (verilog-read-auto-params 1))))
9216 (v2k (verilog-in-paren))
9217 (modi (verilog-modi-current))
9218 (moddecls (verilog-modi-get-decls modi))
9219 (modsubdecls (verilog-modi-get-sub-decls modi))
9220 (sig-list (verilog-signals-not-in
9221 (verilog-subdecls-get-inouts modsubdecls)
9222 (append (verilog-decls-get-outputs moddecls)
9223 (verilog-decls-get-inouts moddecls)
9224 (verilog-decls-get-inputs moddecls)
9225 (verilog-subdecls-get-inputs modsubdecls)
9226 (verilog-subdecls-get-outputs modsubdecls)))))
9227 (when regexp
9228 (setq sig-list (verilog-signals-matching-regexp
9229 sig-list regexp)))
9230 (setq sig-list (verilog-signals-not-matching-regexp
9231 sig-list verilog-auto-inout-ignore-regexp))
9232 (forward-line 1)
9233 (when v2k (verilog-repair-open-comma))
9234 (when sig-list
9235 (verilog-insert-indent "// Beginning of automatic inouts (from unused autoinst inouts)\n")
9236 (verilog-insert-definition sig-list "inout" indent-pt v2k)
9237 (verilog-modi-cache-add-inouts modi sig-list)
9238 (verilog-insert-indent "// End of automatics\n"))
9239 (when v2k (verilog-repair-close-comma)))))
9240
9241 (defun verilog-auto-inout-module (&optional complement)
9242 "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto].
9243 Take input/output/inout statements from the specified module and insert
9244 into the current module. This is useful for making null templates and
9245 shell modules which need to have identical I/O with another module.
9246 Any I/O which are already defined in this module will not be redefined.
9247
9248 Limitations:
9249 If placed inside the parenthesis of a module declaration, it creates
9250 Verilog 2001 style, else uses Verilog 1995 style.
9251
9252 Concatenation and outputting partial busses is not supported.
9253
9254 Module names must be resolvable to filenames. See `verilog-auto-inst'.
9255
9256 Signals are not inserted in the same order as in the original module,
9257 though they will appear to be in the same order to a AUTOINST
9258 instantiating either module.
9259
9260 An example:
9261
9262 module ExampShell (/*AUTOARG*/)
9263 /*AUTOINOUTMODULE(\"ExampMain\")*/
9264 endmodule
9265
9266 module ExampMain (i,o,io)
9267 input i;
9268 output o;
9269 inout io;
9270 endmodule
9271
9272 Typing \\[verilog-auto] will make this into:
9273
9274 module ExampShell (/*AUTOARG*/i,o,io)
9275 /*AUTOINOUTMODULE(\"ExampMain\")*/
9276 // Beginning of automatic in/out/inouts (from specific module)
9277 output o;
9278 inout io;
9279 input i;
9280 // End of automatics
9281 endmodule
9282
9283 You may also provide an optional regular expression, in which case only
9284 signals matching the regular expression will be included. For example the
9285 same expansion will result from only extracting signals starting with i:
9286
9287 /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/"
9288 (save-excursion
9289 (let* ((params (verilog-read-auto-params 1 2))
9290 (submod (nth 0 params))
9291 (regexp (nth 1 params))
9292 submodi)
9293 ;; Lookup position, etc of co-module
9294 ;; Note this may raise an error
9295 (when (setq submodi (verilog-modi-lookup submod t))
9296 (let* ((indent-pt (current-indentation))
9297 (v2k (verilog-in-paren))
9298 (modi (verilog-modi-current))
9299 (moddecls (verilog-modi-get-decls modi))
9300 (submoddecls (verilog-modi-get-decls submodi))
9301 (sig-list-i (verilog-signals-not-in
9302 (if complement
9303 (verilog-decls-get-outputs submoddecls)
9304 (verilog-decls-get-inputs submoddecls))
9305 (append (verilog-decls-get-inputs moddecls))))
9306 (sig-list-o (verilog-signals-not-in
9307 (if complement
9308 (verilog-decls-get-inputs submoddecls)
9309 (verilog-decls-get-outputs submoddecls))
9310 (append (verilog-decls-get-outputs moddecls))))
9311 (sig-list-io (verilog-signals-not-in
9312 (verilog-decls-get-inouts submoddecls)
9313 (append (verilog-decls-get-inouts moddecls)))))
9314 (forward-line 1)
9315 (when regexp
9316 (setq sig-list-i (verilog-signals-matching-regexp
9317 sig-list-i regexp)
9318 sig-list-o (verilog-signals-matching-regexp
9319 sig-list-o regexp)
9320 sig-list-io (verilog-signals-matching-regexp
9321 sig-list-io regexp)))
9322 (when v2k (verilog-repair-open-comma))
9323 (when (or sig-list-i sig-list-o sig-list-io)
9324 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n")
9325 ;; Don't sort them so a upper AUTOINST will match the main module
9326 (verilog-insert-definition sig-list-o "output" indent-pt v2k t)
9327 (verilog-insert-definition sig-list-io "inout" indent-pt v2k t)
9328 (verilog-insert-definition sig-list-i "input" indent-pt v2k t)
9329 (verilog-modi-cache-add-inputs modi sig-list-i)
9330 (verilog-modi-cache-add-outputs modi sig-list-o)
9331 (verilog-modi-cache-add-inouts modi sig-list-io)
9332 (verilog-insert-indent "// End of automatics\n"))
9333 (when v2k (verilog-repair-close-comma)))))))
9334
9335 (defun verilog-auto-inout-comp ()
9336 "Expand AUTOINOUTCOMP statements, as part of \\[verilog-auto].
9337 Take input/output/inout statements from the specified module and
9338 insert the inverse into the current module (inputs become outputs
9339 and vice-versa.) This is useful for making test and stimulus
9340 modules which need to have complementing I/O with another module.
9341 Any I/O which are already defined in this module will not be
9342 redefined.
9343
9344 Limitations:
9345 If placed inside the parenthesis of a module declaration, it creates
9346 Verilog 2001 style, else uses Verilog 1995 style.
9347
9348 Concatenation and outputting partial busses is not supported.
9349
9350 Module names must be resolvable to filenames. See `verilog-auto-inst'.
9351
9352 Signals are not inserted in the same order as in the original module,
9353 though they will appear to be in the same order to a AUTOINST
9354 instantiating either module.
9355
9356 An example:
9357
9358 module ExampShell (/*AUTOARG*/)
9359 /*AUTOINOUTCOMP(\"ExampMain\")*/
9360 endmodule
9361
9362 module ExampMain (i,o,io)
9363 input i;
9364 output o;
9365 inout io;
9366 endmodule
9367
9368 Typing \\[verilog-auto] will make this into:
9369
9370 module ExampShell (/*AUTOARG*/i,o,io)
9371 /*AUTOINOUTCOMP(\"ExampMain\")*/
9372 // Beginning of automatic in/out/inouts (from specific module)
9373 output i;
9374 inout io;
9375 input o;
9376 // End of automatics
9377 endmodule
9378
9379 You may also provide an optional regular expression, in which case only
9380 signals matching the regular expression will be included. For example the
9381 same expansion will result from only extracting signals starting with i:
9382
9383 /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/"
9384 (verilog-auto-inout-module t))
9385
9386 (defun verilog-auto-sense-sigs (moddecls presense-sigs)
9387 "Return list of signals for current AUTOSENSE block."
9388 (let* ((sigss (verilog-read-always-signals))
9389 (sig-list (verilog-signals-not-params
9390 (verilog-signals-not-in (verilog-alw-get-inputs sigss)
9391 (append (and (not verilog-auto-sense-include-inputs)
9392 (verilog-alw-get-outputs sigss))
9393 (verilog-decls-get-consts moddecls)
9394 (verilog-decls-get-gparams moddecls)
9395 presense-sigs)))))
9396 sig-list))
9397
9398 (defun verilog-auto-sense ()
9399 "Expand AUTOSENSE statements, as part of \\[verilog-auto].
9400 Replace the always (/*AUTOSENSE*/) sensitivity list (/*AS*/ for short)
9401 with one automatically derived from all inputs declared in the always
9402 statement. Signals that are generated within the same always block are NOT
9403 placed into the sensitivity list (see `verilog-auto-sense-include-inputs').
9404 Long lines are split based on the `fill-column', see \\[set-fill-column].
9405
9406 Limitations:
9407 Verilog does not allow memories (multidimensional arrays) in sensitivity
9408 lists. AUTOSENSE will thus exclude them, and add a /*memory or*/ comment.
9409
9410 Constant signals:
9411 AUTOSENSE cannot always determine if a `define is a constant or a signal
9412 (it could be in a include file for example). If a `define or other signal
9413 is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT
9414 declaration anywhere in the module (parenthesis are required):
9415
9416 /* AUTO_CONSTANT ( `this_is_really_constant_dont_autosense_it ) */
9417
9418 Better yet, use a parameter, which will be understood to be constant
9419 automatically.
9420
9421 OOps!
9422 If AUTOSENSE makes a mistake, please report it. (First try putting
9423 a begin/end after your always!) As a workaround, if a signal that
9424 shouldn't be in the sensitivity list was, use the AUTO_CONSTANT above.
9425 If a signal should be in the sensitivity list wasn't, placing it before
9426 the /*AUTOSENSE*/ comment will prevent it from being deleted when the
9427 autos are updated (or added if it occurs there already).
9428
9429 An example:
9430
9431 always @ (/*AS*/) begin
9432 /* AUTO_CONSTANT (`constant) */
9433 outin = ina | inb | `constant;
9434 out = outin;
9435 end
9436
9437 Typing \\[verilog-auto] will make this into:
9438
9439 always @ (/*AS*/ina or inb) begin
9440 /* AUTO_CONSTANT (`constant) */
9441 outin = ina | inb | `constant;
9442 out = outin;
9443 end
9444
9445 Note in Verilog 2001, you can often get the same result from the new @*
9446 operator. (This was added to the language in part due to AUTOSENSE!)
9447
9448 always @* begin
9449 outin = ina | inb | `constant;
9450 out = outin;
9451 end"
9452 (save-excursion
9453 ;; Find beginning
9454 (let* ((start-pt (save-excursion
9455 (verilog-re-search-backward "(" nil t)
9456 (point)))
9457 (indent-pt (save-excursion
9458 (or (and (goto-char start-pt) (1+ (current-column)))
9459 (current-indentation))))
9460 (modi (verilog-modi-current))
9461 (moddecls (verilog-modi-get-decls modi))
9462 (sig-memories (verilog-signals-memory
9463 (append
9464 (verilog-decls-get-regs moddecls)
9465 (verilog-decls-get-wires moddecls))))
9466 sig-list not-first presense-sigs)
9467 ;; Read signals in always, eliminate outputs from sense list
9468 (setq presense-sigs (verilog-signals-from-signame
9469 (save-excursion
9470 (verilog-read-signals start-pt (point)))))
9471 (setq sig-list (verilog-auto-sense-sigs moddecls presense-sigs))
9472 (when sig-memories
9473 (let ((tlen (length sig-list)))
9474 (setq sig-list (verilog-signals-not-in sig-list sig-memories))
9475 (if (not (eq tlen (length sig-list))) (insert " /*memory or*/ "))))
9476 (if (and presense-sigs ;; Add a "or" if not "(.... or /*AUTOSENSE*/"
9477 (save-excursion (goto-char (point))
9478 (verilog-re-search-backward "[a-zA-Z0-9$_.%`]+" start-pt t)
9479 (verilog-re-search-backward "\\s-" start-pt t)
9480 (while (looking-at "\\s-`endif")
9481 (verilog-re-search-backward "[a-zA-Z0-9$_.%`]+" start-pt t)
9482 (verilog-re-search-backward "\\s-" start-pt t))
9483 (not (looking-at "\\s-or\\b"))))
9484 (setq not-first t))
9485 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
9486 (while sig-list
9487 (cond ((> (+ 4 (current-column) (length (verilog-sig-name (car sig-list)))) fill-column) ;+4 for width of or
9488 (insert "\n")
9489 (indent-to indent-pt)
9490 (if not-first (insert "or ")))
9491 (not-first (insert " or ")))
9492 (insert (verilog-sig-name (car sig-list)))
9493 (setq sig-list (cdr sig-list)
9494 not-first t)))))
9495
9496 (defun verilog-auto-reset ()
9497 "Expand AUTORESET statements, as part of \\[verilog-auto].
9498 Replace the /*AUTORESET*/ comment with code to initialize all
9499 registers set elsewhere in the always block.
9500
9501 Limitations:
9502 AUTORESET will not clear memories.
9503
9504 AUTORESET uses <= if there are any <= in the block, else it uses =.
9505
9506 /*AUTORESET*/ presumes that any signals mentioned between the previous
9507 begin/case/if statement and the AUTORESET comment are being reset manually
9508 and should not be automatically reset. This includes omitting any signals
9509 used on the right hand side of assignments.
9510
9511 By default, AUTORESET will include the width of the signal in the autos,
9512 this is a recent change. To control this behavior, see
9513 `verilog-auto-reset-widths'.
9514
9515 AUTORESET ties signals to deasserted, which is presumed to be zero.
9516 Signals that match `verilog-active-low-regexp' will be deasserted by tieing
9517 them to a one.
9518
9519 An example:
9520
9521 always @(posedge clk or negedge reset_l) begin
9522 if (!reset_l) begin
9523 c <= 1;
9524 /*AUTORESET*/
9525 end
9526 else begin
9527 a <= in_a;
9528 b <= in_b;
9529 c <= in_c;
9530 end
9531 end
9532
9533 Typing \\[verilog-auto] will make this into:
9534
9535 always @(posedge core_clk or negedge reset_l) begin
9536 if (!reset_l) begin
9537 c <= 1;
9538 /*AUTORESET*/
9539 // Beginning of autoreset for uninitialized flops
9540 a <= 0;
9541 b <= 0;
9542 // End of automatics
9543 end
9544 else begin
9545 a <= in_a;
9546 b <= in_b;
9547 c <= in_c;
9548 end
9549 end"
9550
9551 (interactive)
9552 (save-excursion
9553 ;; Find beginning
9554 (let* ((indent-pt (current-indentation))
9555 (modi (verilog-modi-current))
9556 (moddecls (verilog-modi-get-decls modi))
9557 (all-list (verilog-decls-get-signals moddecls))
9558 sigss sig-list prereset-sigs assignment-str)
9559 ;; Read signals in always, eliminate outputs from reset list
9560 (setq prereset-sigs (verilog-signals-from-signame
9561 (save-excursion
9562 (verilog-read-signals
9563 (save-excursion
9564 (verilog-re-search-backward "\\(@\\|\\<begin\\>\\|\\<if\\>\\|\\<case\\>\\)" nil t)
9565 (point))
9566 (point)))))
9567 (save-excursion
9568 (verilog-re-search-backward "@" nil t)
9569 (setq sigss (verilog-read-always-signals)))
9570 (setq assignment-str (if (verilog-alw-get-uses-delayed sigss)
9571 (concat " <= " verilog-assignment-delay)
9572 " = "))
9573 (setq sig-list (verilog-signals-not-in (verilog-alw-get-outputs sigss)
9574 prereset-sigs))
9575 (setq sig-list (sort sig-list `verilog-signals-sort-compare))
9576 (when sig-list
9577 (insert "\n");
9578 (indent-to indent-pt)
9579 (insert "// Beginning of autoreset for uninitialized flops\n");
9580 (indent-to indent-pt)
9581 (while sig-list
9582 (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ;; As sig-list has no widths
9583 (car sig-list))))
9584 (insert (verilog-sig-name sig)
9585 assignment-str
9586 (verilog-sig-tieoff sig (not verilog-auto-reset-widths))
9587 ";\n")
9588 (indent-to indent-pt)
9589 (setq sig-list (cdr sig-list))))
9590 (insert "// End of automatics")))))
9591
9592 (defun verilog-auto-tieoff ()
9593 "Expand AUTOTIEOFF statements, as part of \\[verilog-auto].
9594 Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output
9595 signals to deasserted.
9596
9597 /*AUTOTIEOFF*/ is used to make stub modules; modules that have the same
9598 input/output list as another module, but no internals. Specifically, it
9599 finds all outputs in the module, and if that input is not otherwise declared
9600 as a register or wire, creates a tieoff.
9601
9602 AUTORESET ties signals to deasserted, which is presumed to be zero.
9603 Signals that match `verilog-active-low-regexp' will be deasserted by tieing
9604 them to a one.
9605
9606 An example of making a stub for another module:
9607
9608 module ExampStub (/*AUTOINST*/);
9609 /*AUTOINOUTMODULE(\"Foo\")*/
9610 /*AUTOTIEOFF*/
9611 // verilator lint_off UNUSED
9612 wire _unused_ok = &{1'b0,
9613 /*AUTOUNUSED*/
9614 1'b0};
9615 // verilator lint_on UNUSED
9616 endmodule
9617
9618 Typing \\[verilog-auto] will make this into:
9619
9620 module ExampStub (/*AUTOINST*/...);
9621 /*AUTOINOUTMODULE(\"Foo\")*/
9622 // Beginning of autotieoff
9623 output [2:0] foo;
9624 // End of automatics
9625
9626 /*AUTOTIEOFF*/
9627 // Beginning of autotieoff
9628 wire [2:0] foo = 3'b0;
9629 // End of automatics
9630 ...
9631 endmodule"
9632 (interactive)
9633 (save-excursion
9634 ;; Find beginning
9635 (let* ((indent-pt (current-indentation))
9636 (modi (verilog-modi-current))
9637 (moddecls (verilog-modi-get-decls modi))
9638 (modsubdecls (verilog-modi-get-sub-decls modi))
9639 (sig-list (verilog-signals-not-in
9640 (verilog-decls-get-outputs moddecls)
9641 (append (verilog-decls-get-wires moddecls)
9642 (verilog-decls-get-regs moddecls)
9643 (verilog-decls-get-assigns moddecls)
9644 (verilog-decls-get-consts moddecls)
9645 (verilog-decls-get-gparams moddecls)
9646 (verilog-subdecls-get-outputs modsubdecls)
9647 (verilog-subdecls-get-inouts modsubdecls)))))
9648 (when sig-list
9649 (forward-line 1)
9650 (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n")
9651 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
9652 (verilog-modi-cache-add-wires modi sig-list) ; Before we trash list
9653 (while sig-list
9654 (let ((sig (car sig-list)))
9655 (verilog-insert-one-definition sig "wire" indent-pt)
9656 (indent-to (max 48 (+ indent-pt 40)))
9657 (insert "= " (verilog-sig-tieoff sig)
9658 ";\n")
9659 (setq sig-list (cdr sig-list))))
9660 (verilog-insert-indent "// End of automatics\n")))))
9661
9662 (defun verilog-auto-unused ()
9663 "Expand AUTOUNUSED statements, as part of \\[verilog-auto].
9664 Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused
9665 input and inout signals.
9666
9667 /*AUTOUNUSED*/ is used to make stub modules; modules that have the same
9668 input/output list as another module, but no internals. Specifically, it
9669 finds all inputs and inouts in the module, and if that input is not otherwise
9670 used, adds it to a comma separated list.
9671
9672 The comma separated list is intended to be used to create a _unused_ok
9673 signal. Using the exact name \"_unused_ok\" for name of the temporary
9674 signal is recommended as it will insure maximum forward compatibility, it
9675 also makes lint warnings easy to understand; ignore any unused warnings
9676 with \"unused\" in the signal name.
9677
9678 To reduce simulation time, the _unused_ok signal should be forced to a
9679 constant to prevent wiggling. The easiest thing to do is use a
9680 reduction-and with 1'b0 as shown.
9681
9682 This way all unused signals are in one place, making it convenient to add
9683 your tool's specific pragmas around the assignment to disable any unused
9684 warnings.
9685
9686 You can add signals you do not want included in AUTOUNUSED with
9687 `verilog-auto-unused-ignore-regexp'.
9688
9689 An example of making a stub for another module:
9690
9691 module ExampStub (/*AUTOINST*/);
9692 /*AUTOINOUTMODULE(\"Examp\")*/
9693 /*AUTOTIEOFF*/
9694 // verilator lint_off UNUSED
9695 wire _unused_ok = &{1'b0,
9696 /*AUTOUNUSED*/
9697 1'b0};
9698 // verilator lint_on UNUSED
9699 endmodule
9700
9701 Typing \\[verilog-auto] will make this into:
9702
9703 ...
9704 // verilator lint_off UNUSED
9705 wire _unused_ok = &{1'b0,
9706 /*AUTOUNUSED*/
9707 // Beginning of automatics
9708 unused_input_a,
9709 unused_input_b,
9710 unused_input_c,
9711 // End of automatics
9712 1'b0};
9713 // verilator lint_on UNUSED
9714 endmodule"
9715 (interactive)
9716 (save-excursion
9717 ;; Find beginning
9718 (let* ((indent-pt (progn (search-backward "/*") (current-column)))
9719 (modi (verilog-modi-current))
9720 (moddecls (verilog-modi-get-decls modi))
9721 (modsubdecls (verilog-modi-get-sub-decls modi))
9722 (sig-list (verilog-signals-not-in
9723 (append (verilog-decls-get-inputs moddecls)
9724 (verilog-decls-get-inouts moddecls))
9725 (append (verilog-subdecls-get-inputs modsubdecls)
9726 (verilog-subdecls-get-inouts modsubdecls)))))
9727 (setq sig-list (verilog-signals-not-matching-regexp
9728 sig-list verilog-auto-unused-ignore-regexp))
9729 (when sig-list
9730 (forward-line 1)
9731 (verilog-insert-indent "// Beginning of automatic unused inputs\n")
9732 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare))
9733 (while sig-list
9734 (let ((sig (car sig-list)))
9735 (indent-to indent-pt)
9736 (insert (verilog-sig-name sig) ",\n")
9737 (setq sig-list (cdr sig-list))))
9738 (verilog-insert-indent "// End of automatics\n")))))
9739
9740 (defun verilog-enum-ascii (signm elim-regexp)
9741 "Convert an enum name SIGNM to an ascii string for insertion.
9742 Remove user provided prefix ELIM-REGEXP."
9743 (or elim-regexp (setq elim-regexp "_ DONT MATCH IT_"))
9744 (let ((case-fold-search t))
9745 ;; All upper becomes all lower for readability
9746 (downcase (verilog-string-replace-matches elim-regexp "" nil nil signm))))
9747
9748 (defun verilog-auto-ascii-enum ()
9749 "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto].
9750 Create a register to contain the ASCII decode of a enumerated signal type.
9751 This will allow trace viewers to show the ASCII name of states.
9752
9753 First, parameters are built into a enumeration using the synopsys enum
9754 comment. The comment must be between the keyword and the symbol.
9755 \(Annoying, but that's what Synopsys's dc_shell FSM reader requires.)
9756
9757 Next, registers which that enum applies to are also tagged with the same
9758 enum. Synopsys also suggests labeling state vectors, but `verilog-mode'
9759 doesn't care.
9760
9761 Finally, a AUTOASCIIENUM command is used.
9762
9763 The first parameter is the name of the signal to be decoded.
9764
9765 The second parameter is the name to store the ASCII code into. For the
9766 signal foo, I suggest the name _foo__ascii, where the leading _ indicates
9767 a signal that is just for simulation, and the magic characters _ascii
9768 tell viewers like Dinotrace to display in ASCII format.
9769
9770 The final optional parameter is a string which will be removed from the
9771 state names.
9772
9773 An example:
9774
9775 //== State enumeration
9776 parameter [2:0] // synopsys enum state_info
9777 SM_IDLE = 3'b000,
9778 SM_SEND = 3'b001,
9779 SM_WAIT1 = 3'b010;
9780 //== State variables
9781 reg [2:0] /* synopsys enum state_info */
9782 state_r; /* synopsys state_vector state_r */
9783 reg [2:0] /* synopsys enum state_info */
9784 state_e1;
9785
9786 //== ASCII state decoding
9787
9788 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
9789
9790 Typing \\[verilog-auto] will make this into:
9791
9792 ... same front matter ...
9793
9794 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
9795 // Beginning of automatic ASCII enum decoding
9796 reg [39:0] state_ascii_r; // Decode of state_r
9797 always @(state_r) begin
9798 case ({state_r})
9799 SM_IDLE: state_ascii_r = \"idle \";
9800 SM_SEND: state_ascii_r = \"send \";
9801 SM_WAIT1: state_ascii_r = \"wait1\";
9802 default: state_ascii_r = \"%Erro\";
9803 endcase
9804 end
9805 // End of automatics"
9806 (save-excursion
9807 (let* ((params (verilog-read-auto-params 2 3))
9808 (undecode-name (nth 0 params))
9809 (ascii-name (nth 1 params))
9810 (elim-regexp (nth 2 params))
9811 ;;
9812 (indent-pt (current-indentation))
9813 (modi (verilog-modi-current))
9814 (moddecls (verilog-modi-get-decls modi))
9815 ;;
9816 (sig-list-consts (append (verilog-decls-get-consts moddecls)
9817 (verilog-decls-get-gparams moddecls)))
9818 (sig-list-all (append (verilog-decls-get-regs moddecls)
9819 (verilog-decls-get-outputs moddecls)
9820 (verilog-decls-get-inouts moddecls)
9821 (verilog-decls-get-inputs moddecls)
9822 (verilog-decls-get-wires moddecls)))
9823 ;;
9824 (undecode-sig (or (assoc undecode-name sig-list-all)
9825 (error "%s: Signal %s not found in design" (verilog-point-text) undecode-name)))
9826 (undecode-enum (or (verilog-sig-enum undecode-sig)
9827 (error "%s: Signal %s does not have a enum tag" (verilog-point-text) undecode-name)))
9828 ;;
9829 (enum-sigs (or (verilog-signals-matching-enum sig-list-consts undecode-enum)
9830 (error "%s: No state definitions for %s" (verilog-point-text) undecode-enum)))
9831 ;;
9832 (enum-chars 0)
9833 (ascii-chars 0))
9834 ;;
9835 ;; Find number of ascii chars needed
9836 (let ((tmp-sigs enum-sigs))
9837 (while tmp-sigs
9838 (setq enum-chars (max enum-chars (length (verilog-sig-name (car tmp-sigs))))
9839 ascii-chars (max ascii-chars (length (verilog-enum-ascii
9840 (verilog-sig-name (car tmp-sigs))
9841 elim-regexp)))
9842 tmp-sigs (cdr tmp-sigs))))
9843 ;;
9844 (forward-line 1)
9845 (verilog-insert-indent "// Beginning of automatic ASCII enum decoding\n")
9846 (let ((decode-sig-list (list (list ascii-name (format "[%d:0]" (- (* ascii-chars 8) 1))
9847 (concat "Decode of " undecode-name) nil nil))))
9848 (verilog-insert-definition decode-sig-list "reg" indent-pt nil)
9849 (verilog-modi-cache-add-regs modi decode-sig-list))
9850 ;;
9851 (verilog-insert-indent "always @(" undecode-name ") begin\n")
9852 (setq indent-pt (+ indent-pt verilog-indent-level))
9853 (indent-to indent-pt)
9854 (insert "case ({" undecode-name "})\n")
9855 (setq indent-pt (+ indent-pt verilog-case-indent))
9856 ;;
9857 (let ((tmp-sigs enum-sigs)
9858 (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n" (1+ (max 8 enum-chars))
9859 ascii-name ascii-chars))
9860 (errname (substring "%Error" 0 (min 6 ascii-chars))))
9861 (while tmp-sigs
9862 (verilog-insert-indent
9863 (format chrfmt (concat (verilog-sig-name (car tmp-sigs)) ":")
9864 (verilog-enum-ascii (verilog-sig-name (car tmp-sigs))
9865 elim-regexp)))
9866 (setq tmp-sigs (cdr tmp-sigs)))
9867 (verilog-insert-indent (format chrfmt "default:" errname)))
9868 ;;
9869 (setq indent-pt (- indent-pt verilog-case-indent))
9870 (verilog-insert-indent "endcase\n")
9871 (setq indent-pt (- indent-pt verilog-indent-level))
9872 (verilog-insert-indent "end\n"
9873 "// End of automatics\n"))))
9874
9875 (defun verilog-auto-templated-rel ()
9876 "Replace Templated relative line numbers with absolute line numbers.
9877 Internal use only. This hacks around the line numbers in AUTOINST Templates
9878 being different from the final output's line numbering."
9879 (let ((templateno 0) (template-line (list 0)))
9880 ;; Find line number each template is on
9881 (goto-char (point-min))
9882 (while (search-forward "AUTO_TEMPLATE" nil t)
9883 (setq templateno (1+ templateno))
9884 (setq template-line
9885 (cons (count-lines (point-min) (point)) template-line)))
9886 (setq template-line (nreverse template-line))
9887 ;; Replace T# L# with absolute line number
9888 (goto-char (point-min))
9889 (while (re-search-forward " Templated T\\([0-9]+\\) L\\([0-9]+\\)" nil t)
9890 (replace-match
9891 (concat " Templated "
9892 (int-to-string (+ (nth (string-to-number (match-string 1))
9893 template-line)
9894 (string-to-number (match-string 2)))))
9895 t t))))
9896
9897 \f
9898 ;;
9899 ;; Auto top level
9900 ;;
9901
9902 (defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing a arg
9903 "Expand AUTO statements.
9904 Look for any /*AUTO...*/ commands in the code, as used in
9905 instantiations or argument headers. Update the list of signals
9906 following the /*AUTO...*/ command.
9907
9908 Use \\[verilog-delete-auto] to remove the AUTOs.
9909
9910 Use \\[verilog-inject-auto] to insert AUTOs for the first time.
9911
9912 Use \\[verilog-faq] for a pointer to frequently asked questions.
9913
9914 The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are
9915 called before and after this function, respectively.
9916
9917 For example:
9918 module ModuleName (/*AUTOARG*/)
9919 /*AUTOINPUT*/
9920 /*AUTOOUTPUT*/
9921 /*AUTOWIRE*/
9922 /*AUTOREG*/
9923 InstMod instName #(/*AUTOINSTPARAM*/) (/*AUTOINST*/);
9924
9925 You can also update the AUTOs from the shell using:
9926 emacs --batch <filenames.v> -f verilog-batch-auto
9927 Or fix indentation with:
9928 emacs --batch <filenames.v> -f verilog-batch-indent
9929 Likewise, you can delete or inject AUTOs with:
9930 emacs --batch <filenames.v> -f verilog-batch-delete-auto
9931 emacs --batch <filenames.v> -f verilog-batch-inject-auto
9932
9933 Using \\[describe-function], see also:
9934 `verilog-auto-arg' for AUTOARG module instantiations
9935 `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding
9936 `verilog-auto-inout-comp' for AUTOINOUTCOMP copy complemented i/o
9937 `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere
9938 `verilog-auto-inout' for AUTOINOUT making hierarchy inouts
9939 `verilog-auto-input' for AUTOINPUT making hierarchy inputs
9940 `verilog-auto-inst' for AUTOINST instantiation pins
9941 `verilog-auto-star' for AUTOINST .* SystemVerilog pins
9942 `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params
9943 `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs
9944 `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs
9945 `verilog-auto-reg' for AUTOREG registers
9946 `verilog-auto-reg-input' for AUTOREGINPUT instantiation registers
9947 `verilog-auto-reset' for AUTORESET flop resets
9948 `verilog-auto-sense' for AUTOSENSE always sensitivity lists
9949 `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs
9950 `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts
9951 `verilog-auto-wire' for AUTOWIRE instantiation wires
9952
9953 `verilog-read-defines' for reading `define values
9954 `verilog-read-includes' for reading `includes
9955
9956 If you have bugs with these autos, try contacting the AUTOAUTHOR
9957 Wilson Snyder (wsnyder@wsnyder.org), and/or see http://www.veripool.org."
9958 (interactive)
9959 (unless noninteractive (message "Updating AUTOs..."))
9960 (if (fboundp 'dinotrace-unannotate-all)
9961 (dinotrace-unannotate-all))
9962 (let ((oldbuf (if (not (buffer-modified-p))
9963 (buffer-string)))
9964 ;; Before version 20, match-string with font-lock returns a
9965 ;; vector that is not equal to the string. IE if on "input"
9966 ;; nil==(equal "input" (progn (looking-at "input") (match-string 0)))
9967 (fontlocked (when (and (boundp 'font-lock-mode)
9968 font-lock-mode)
9969 (font-lock-mode 0)
9970 t))
9971 ;; Cache directories; we don't write new files, so can't change
9972 (verilog-dir-cache-preserving t))
9973 (unwind-protect
9974 (save-excursion
9975 ;; If we're not in verilog-mode, change syntax table so parsing works right
9976 (unless (eq major-mode `verilog-mode) (verilog-mode))
9977 ;; Allow user to customize
9978 (run-hooks 'verilog-before-auto-hook)
9979 ;; Try to save the user from needing to revert-file to reread file local-variables
9980 (verilog-auto-reeval-locals)
9981 (verilog-read-auto-lisp (point-min) (point-max))
9982 (verilog-getopt-flags)
9983 ;; From here on out, we can cache anything we read from disk
9984 (verilog-preserve-dir-cache
9985 ;; These two may seem obvious to do always, but on large includes it can be way too slow
9986 (when verilog-auto-read-includes
9987 (verilog-read-includes)
9988 (verilog-read-defines nil nil t))
9989 ;; This particular ordering is important
9990 ;; INST: Lower modules correct, no internal dependencies, FIRST
9991 (verilog-preserve-modi-cache
9992 ;; Clear existing autos else we'll be screwed by existing ones
9993 (verilog-delete-auto)
9994 ;; Injection if appropriate
9995 (when inject
9996 (verilog-inject-inst)
9997 (verilog-inject-sense)
9998 (verilog-inject-arg))
9999 ;;
10000 (verilog-auto-re-search-do "/\\*AUTOINSTPARAM\\*/" 'verilog-auto-inst-param)
10001 (verilog-auto-re-search-do "/\\*AUTOINST\\*/" 'verilog-auto-inst)
10002 (verilog-auto-re-search-do "\\.\\*" 'verilog-auto-star)
10003 ;; Doesn't matter when done, but combine it with a common changer
10004 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense)
10005 (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset)
10006 ;; Must be done before autoin/out as creates a reg
10007 (verilog-auto-re-search-do "/\\*AUTOASCIIENUM([^)]*)\\*/" 'verilog-auto-ascii-enum)
10008 ;;
10009 ;; first in/outs from other files
10010 (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE([^)]*)\\*/" 'verilog-auto-inout-module)
10011 (verilog-auto-re-search-do "/\\*AUTOINOUTCOMP([^)]*)\\*/" 'verilog-auto-inout-comp)
10012 ;; next in/outs which need previous sucked inputs first
10013 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\((\"[^\"]*\")\\)\\*/"
10014 '(lambda () (verilog-auto-output t)))
10015 (verilog-auto-re-search-do "/\\*AUTOOUTPUT\\*/" 'verilog-auto-output)
10016 (verilog-auto-re-search-do "/\\*AUTOINPUT\\((\"[^\"]*\")\\)\\*/"
10017 '(lambda () (verilog-auto-input t)))
10018 (verilog-auto-re-search-do "/\\*AUTOINPUT\\*/" 'verilog-auto-input)
10019 (verilog-auto-re-search-do "/\\*AUTOINOUT\\((\"[^\"]*\")\\)\\*/"
10020 '(lambda () (verilog-auto-inout t)))
10021 (verilog-auto-re-search-do "/\\*AUTOINOUT\\*/" 'verilog-auto-inout)
10022 ;; Then tie off those in/outs
10023 (verilog-auto-re-search-do "/\\*AUTOTIEOFF\\*/" 'verilog-auto-tieoff)
10024 ;; Wires/regs must be after inputs/outputs
10025 (verilog-auto-re-search-do "/\\*AUTOWIRE\\*/" 'verilog-auto-wire)
10026 (verilog-auto-re-search-do "/\\*AUTOREG\\*/" 'verilog-auto-reg)
10027 (verilog-auto-re-search-do "/\\*AUTOREGINPUT\\*/" 'verilog-auto-reg-input)
10028 ;; outputevery needs AUTOOUTPUTs done first
10029 (verilog-auto-re-search-do "/\\*AUTOOUTPUTEVERY\\*/" 'verilog-auto-output-every)
10030 ;; After we've created all new variables
10031 (verilog-auto-re-search-do "/\\*AUTOUNUSED\\*/" 'verilog-auto-unused)
10032 ;; Must be after all inputs outputs are generated
10033 (verilog-auto-re-search-do "/\\*AUTOARG\\*/" 'verilog-auto-arg)
10034 ;; Fix line numbers (comments only)
10035 (verilog-auto-templated-rel)))
10036 ;;
10037 (run-hooks 'verilog-auto-hook)
10038 ;;
10039 (set (make-local-variable 'verilog-auto-update-tick) (buffer-modified-tick))
10040 ;;
10041 ;; If end result is same as when started, clear modified flag
10042 (cond ((and oldbuf (equal oldbuf (buffer-string)))
10043 (set-buffer-modified-p nil)
10044 (unless noninteractive (message "Updating AUTOs...done (no changes)")))
10045 (t (unless noninteractive (message "Updating AUTOs...done")))))
10046 ;; Unwind forms
10047 (progn
10048 ;; Restore font-lock
10049 (when fontlocked (font-lock-mode t))))))
10050 \f
10051
10052 ;;
10053 ;; Skeleton based code insertion
10054 ;;
10055 (defvar verilog-template-map
10056 (let ((map (make-sparse-keymap)))
10057 (define-key map "a" 'verilog-sk-always)
10058 (define-key map "b" 'verilog-sk-begin)
10059 (define-key map "c" 'verilog-sk-case)
10060 (define-key map "f" 'verilog-sk-for)
10061 (define-key map "g" 'verilog-sk-generate)
10062 (define-key map "h" 'verilog-sk-header)
10063 (define-key map "i" 'verilog-sk-initial)
10064 (define-key map "j" 'verilog-sk-fork)
10065 (define-key map "m" 'verilog-sk-module)
10066 (define-key map "p" 'verilog-sk-primitive)
10067 (define-key map "r" 'verilog-sk-repeat)
10068 (define-key map "s" 'verilog-sk-specify)
10069 (define-key map "t" 'verilog-sk-task)
10070 (define-key map "w" 'verilog-sk-while)
10071 (define-key map "x" 'verilog-sk-casex)
10072 (define-key map "z" 'verilog-sk-casez)
10073 (define-key map "?" 'verilog-sk-if)
10074 (define-key map ":" 'verilog-sk-else-if)
10075 (define-key map "/" 'verilog-sk-comment)
10076 (define-key map "A" 'verilog-sk-assign)
10077 (define-key map "F" 'verilog-sk-function)
10078 (define-key map "I" 'verilog-sk-input)
10079 (define-key map "O" 'verilog-sk-output)
10080 (define-key map "S" 'verilog-sk-state-machine)
10081 (define-key map "=" 'verilog-sk-inout)
10082 (define-key map "W" 'verilog-sk-wire)
10083 (define-key map "R" 'verilog-sk-reg)
10084 (define-key map "D" 'verilog-sk-define-signal)
10085 map)
10086 "Keymap used in Verilog mode for smart template operations.")
10087
10088
10089 ;;
10090 ;; Place the templates into Verilog Mode. They may be inserted under any key.
10091 ;; C-c C-t will be the default. If you use templates a lot, you
10092 ;; may want to consider moving the binding to another key in your .emacs
10093 ;; file.
10094 ;;
10095 ;(define-key verilog-mode-map "\C-ct" verilog-template-map)
10096 (define-key verilog-mode-map "\C-c\C-t" verilog-template-map)
10097
10098 ;;; ---- statement skeletons ------------------------------------------
10099
10100 (define-skeleton verilog-sk-prompt-condition
10101 "Prompt for the loop condition."
10102 "[condition]: " str )
10103
10104 (define-skeleton verilog-sk-prompt-init
10105 "Prompt for the loop init statement."
10106 "[initial statement]: " str )
10107
10108 (define-skeleton verilog-sk-prompt-inc
10109 "Prompt for the loop increment statement."
10110 "[increment statement]: " str )
10111
10112 (define-skeleton verilog-sk-prompt-name
10113 "Prompt for the name of something."
10114 "[name]: " str)
10115
10116 (define-skeleton verilog-sk-prompt-clock
10117 "Prompt for the name of something."
10118 "name and edge of clock(s): " str)
10119
10120 (defvar verilog-sk-reset nil)
10121 (defun verilog-sk-prompt-reset ()
10122 "Prompt for the name of a state machine reset."
10123 (setq verilog-sk-reset (read-string "name of reset: " "rst")))
10124
10125
10126 (define-skeleton verilog-sk-prompt-state-selector
10127 "Prompt for the name of a state machine selector."
10128 "name of selector (eg {a,b,c,d}): " str )
10129
10130 (define-skeleton verilog-sk-prompt-output
10131 "Prompt for the name of something."
10132 "output: " str)
10133
10134 (define-skeleton verilog-sk-prompt-msb
10135 "Prompt for least significant bit specification."
10136 "msb:" str & ?: & '(verilog-sk-prompt-lsb) | -1 )
10137
10138 (define-skeleton verilog-sk-prompt-lsb
10139 "Prompt for least significant bit specification."
10140 "lsb:" str )
10141
10142 (defvar verilog-sk-p nil)
10143 (define-skeleton verilog-sk-prompt-width
10144 "Prompt for a width specification."
10145 ()
10146 (progn
10147 (setq verilog-sk-p (point))
10148 (verilog-sk-prompt-msb)
10149 (if (> (point) verilog-sk-p) "] " " ")))
10150
10151 (defun verilog-sk-header ()
10152 "Insert a descriptive header at the top of the file."
10153 (interactive "*")
10154 (save-excursion
10155 (goto-char (point-min))
10156 (verilog-sk-header-tmpl)))
10157
10158 (define-skeleton verilog-sk-header-tmpl
10159 "Insert a comment block containing the module title, author, etc."
10160 "[Description]: "
10161 "// -*- Mode: Verilog -*-"
10162 "\n// Filename : " (buffer-name)
10163 "\n// Description : " str
10164 "\n// Author : " (user-full-name)
10165 "\n// Created On : " (current-time-string)
10166 "\n// Last Modified By: ."
10167 "\n// Last Modified On: ."
10168 "\n// Update Count : 0"
10169 "\n// Status : Unknown, Use with caution!"
10170 "\n")
10171
10172 (define-skeleton verilog-sk-module
10173 "Insert a module definition."
10174 ()
10175 > "module " '(verilog-sk-prompt-name) " (/*AUTOARG*/ ) ;" \n
10176 > _ \n
10177 > (- verilog-indent-level-behavioral) "endmodule" (progn (electric-verilog-terminate-line) nil))
10178
10179 (define-skeleton verilog-sk-primitive
10180 "Insert a task definition."
10181 ()
10182 > "primitive " '(verilog-sk-prompt-name) " ( " '(verilog-sk-prompt-output) ("input:" ", " str ) " );"\n
10183 > _ \n
10184 > (- verilog-indent-level-behavioral) "endprimitive" (progn (electric-verilog-terminate-line) nil))
10185
10186 (define-skeleton verilog-sk-task
10187 "Insert a task definition."
10188 ()
10189 > "task " '(verilog-sk-prompt-name) & ?; \n
10190 > _ \n
10191 > "begin" \n
10192 > \n
10193 > (- verilog-indent-level-behavioral) "end" \n
10194 > (- verilog-indent-level-behavioral) "endtask" (progn (electric-verilog-terminate-line) nil))
10195
10196 (define-skeleton verilog-sk-function
10197 "Insert a function definition."
10198 ()
10199 > "function [" '(verilog-sk-prompt-width) | -1 '(verilog-sk-prompt-name) ?; \n
10200 > _ \n
10201 > "begin" \n
10202 > \n
10203 > (- verilog-indent-level-behavioral) "end" \n
10204 > (- verilog-indent-level-behavioral) "endfunction" (progn (electric-verilog-terminate-line) nil))
10205
10206 (define-skeleton verilog-sk-always
10207 "Insert always block. Uses the minibuffer to prompt
10208 for sensitivity list."
10209 ()
10210 > "always @ ( /*AUTOSENSE*/ ) begin\n"
10211 > _ \n
10212 > (- verilog-indent-level-behavioral) "end" \n >
10213 )
10214
10215 (define-skeleton verilog-sk-initial
10216 "Insert an initial block."
10217 ()
10218 > "initial begin\n"
10219 > _ \n
10220 > (- verilog-indent-level-behavioral) "end" \n > )
10221
10222 (define-skeleton verilog-sk-specify
10223 "Insert specify block. "
10224 ()
10225 > "specify\n"
10226 > _ \n
10227 > (- verilog-indent-level-behavioral) "endspecify" \n > )
10228
10229 (define-skeleton verilog-sk-generate
10230 "Insert generate block. "
10231 ()
10232 > "generate\n"
10233 > _ \n
10234 > (- verilog-indent-level-behavioral) "endgenerate" \n > )
10235
10236 (define-skeleton verilog-sk-begin
10237 "Insert begin end block. Uses the minibuffer to prompt for name."
10238 ()
10239 > "begin" '(verilog-sk-prompt-name) \n
10240 > _ \n
10241 > (- verilog-indent-level-behavioral) "end"
10242 )
10243
10244 (define-skeleton verilog-sk-fork
10245 "Insert a fork join block."
10246 ()
10247 > "fork\n"
10248 > "begin" \n
10249 > _ \n
10250 > (- verilog-indent-level-behavioral) "end" \n
10251 > "begin" \n
10252 > \n
10253 > (- verilog-indent-level-behavioral) "end" \n
10254 > (- verilog-indent-level-behavioral) "join" \n
10255 > )
10256
10257
10258 (define-skeleton verilog-sk-case
10259 "Build skeleton case statement, prompting for the selector expression,
10260 and the case items."
10261 "[selector expression]: "
10262 > "case (" str ") " \n
10263 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n )
10264 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
10265
10266 (define-skeleton verilog-sk-casex
10267 "Build skeleton casex statement, prompting for the selector expression,
10268 and the case items."
10269 "[selector expression]: "
10270 > "casex (" str ") " \n
10271 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n )
10272 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
10273
10274 (define-skeleton verilog-sk-casez
10275 "Build skeleton casez statement, prompting for the selector expression,
10276 and the case items."
10277 "[selector expression]: "
10278 > "casez (" str ") " \n
10279 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n )
10280 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
10281
10282 (define-skeleton verilog-sk-if
10283 "Insert a skeleton if statement."
10284 > "if (" '(verilog-sk-prompt-condition) & ")" " begin" \n
10285 > _ \n
10286 > (- verilog-indent-level-behavioral) "end " \n )
10287
10288 (define-skeleton verilog-sk-else-if
10289 "Insert a skeleton else if statement."
10290 > (verilog-indent-line) "else if ("
10291 (progn (setq verilog-sk-p (point)) nil) '(verilog-sk-prompt-condition) (if (> (point) verilog-sk-p) ") " -1 ) & " begin" \n
10292 > _ \n
10293 > "end" (progn (electric-verilog-terminate-line) nil))
10294
10295 (define-skeleton verilog-sk-datadef
10296 "Common routine to get data definition."
10297 ()
10298 '(verilog-sk-prompt-width) | -1 ("name (RET to end):" str ", ") -2 ";" \n)
10299
10300 (define-skeleton verilog-sk-input
10301 "Insert an input definition."
10302 ()
10303 > "input [" '(verilog-sk-datadef))
10304
10305 (define-skeleton verilog-sk-output
10306 "Insert an output definition."
10307 ()
10308 > "output [" '(verilog-sk-datadef))
10309
10310 (define-skeleton verilog-sk-inout
10311 "Insert an inout definition."
10312 ()
10313 > "inout [" '(verilog-sk-datadef))
10314
10315 (defvar verilog-sk-signal nil)
10316 (define-skeleton verilog-sk-def-reg
10317 "Insert a reg definition."
10318 ()
10319 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations) )
10320
10321 (defun verilog-sk-define-signal ()
10322 "Insert a definition of signal under point at top of module."
10323 (interactive "*")
10324 (let* ((sig-re "[a-zA-Z0-9_]*")
10325 (v1 (buffer-substring
10326 (save-excursion
10327 (skip-chars-backward sig-re)
10328 (point))
10329 (save-excursion
10330 (skip-chars-forward sig-re)
10331 (point)))))
10332 (if (not (member v1 verilog-keywords))
10333 (save-excursion
10334 (setq verilog-sk-signal v1)
10335 (verilog-beg-of-defun)
10336 (verilog-end-of-statement)
10337 (verilog-forward-syntactic-ws)
10338 (verilog-sk-def-reg)
10339 (message "signal at point is %s" v1))
10340 (message "object at point (%s) is a keyword" v1))))
10341
10342 (define-skeleton verilog-sk-wire
10343 "Insert a wire definition."
10344 ()
10345 > "wire [" '(verilog-sk-datadef))
10346
10347 (define-skeleton verilog-sk-reg
10348 "Insert a reg definition."
10349 ()
10350 > "reg [" '(verilog-sk-datadef))
10351
10352 (define-skeleton verilog-sk-assign
10353 "Insert a skeleton assign statement."
10354 ()
10355 > "assign " '(verilog-sk-prompt-name) " = " _ ";" \n)
10356
10357 (define-skeleton verilog-sk-while
10358 "Insert a skeleton while loop statement."
10359 ()
10360 > "while (" '(verilog-sk-prompt-condition) ") begin" \n
10361 > _ \n
10362 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
10363
10364 (define-skeleton verilog-sk-repeat
10365 "Insert a skeleton repeat loop statement."
10366 ()
10367 > "repeat (" '(verilog-sk-prompt-condition) ") begin" \n
10368 > _ \n
10369 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
10370
10371 (define-skeleton verilog-sk-for
10372 "Insert a skeleton while loop statement."
10373 ()
10374 > "for ("
10375 '(verilog-sk-prompt-init) "; "
10376 '(verilog-sk-prompt-condition) "; "
10377 '(verilog-sk-prompt-inc)
10378 ") begin" \n
10379 > _ \n
10380 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil))
10381
10382 (define-skeleton verilog-sk-comment
10383 "Inserts three comment lines, making a display comment."
10384 ()
10385 > "/*\n"
10386 > "* " _ \n
10387 > "*/")
10388
10389 (define-skeleton verilog-sk-state-machine
10390 "Insert a state machine definition."
10391 "Name of state variable: "
10392 '(setq input "state")
10393 > "// State registers for " str | -23 \n
10394 '(setq verilog-sk-state str)
10395 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-state ", next_" verilog-sk-state ?; \n
10396 '(setq input nil)
10397 > \n
10398 > "// State FF for " verilog-sk-state \n
10399 > "always @ ( " (read-string "clock:" "posedge clk") " or " (verilog-sk-prompt-reset) " ) begin" \n
10400 > "if ( " verilog-sk-reset " ) " verilog-sk-state " = 0; else" \n
10401 > verilog-sk-state " = next_" verilog-sk-state ?; \n
10402 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil)
10403 > \n
10404 > "// Next State Logic for " verilog-sk-state \n
10405 > "always @ ( /*AUTOSENSE*/ ) begin\n"
10406 > "case (" '(verilog-sk-prompt-state-selector) ") " \n
10407 > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n )
10408 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)
10409 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil))
10410 \f
10411
10412 ;;
10413 ;; Include file loading with mouse/return event
10414 ;;
10415 ;; idea & first impl.: M. Rouat (eldo-mode.el)
10416 ;; second (emacs/xemacs) impl.: G. Van der Plas (spice-mode.el)
10417
10418 (if (featurep 'xemacs)
10419 (require 'overlay)
10420 (require 'lucid)) ;; what else can we do ??
10421
10422 (defconst verilog-include-file-regexp
10423 "^`include\\s-+\"\\([^\n\"]*\\)\""
10424 "Regexp that matches the include file.")
10425
10426 (defvar verilog-mode-mouse-map
10427 (let ((map (make-sparse-keymap))) ; as described in info pages, make a map
10428 (set-keymap-parent map verilog-mode-map)
10429 ;; mouse button bindings
10430 (define-key map "\r" 'verilog-load-file-at-point)
10431 (if (featurep 'xemacs)
10432 (define-key map 'button2 'verilog-load-file-at-mouse);ffap-at-mouse ?
10433 (define-key map [mouse-2] 'verilog-load-file-at-mouse))
10434 (if (featurep 'xemacs)
10435 (define-key map 'Sh-button2 'mouse-yank) ; you wanna paste don't you ?
10436 (define-key map [S-mouse-2] 'mouse-yank-at-click))
10437 map)
10438 "Map containing mouse bindings for `verilog-mode'.")
10439
10440
10441 (defun verilog-colorize-include-files (beg end old-len)
10442 "This function colorizes included files when the mouse passes over them.
10443 Clicking on the middle-mouse button loads them in a buffer (as in dired)."
10444 (save-excursion
10445 (save-match-data
10446 (let (end-point)
10447 (goto-char end)
10448 (setq end-point (verilog-get-end-of-line))
10449 (goto-char beg)
10450 (beginning-of-line) ; scan entire line !
10451 ;; delete overlays existing on this line
10452 (let ((overlays (overlays-in (point) end-point)))
10453 (while overlays
10454 (if (and
10455 (overlay-get (car overlays) 'detachable)
10456 (overlay-get (car overlays) 'verilog-include-file))
10457 (delete-overlay (car overlays)))
10458 (setq overlays (cdr overlays)))) ; let
10459 ;; make new ones, could reuse deleted one ?
10460 (while (search-forward-regexp verilog-include-file-regexp end-point t)
10461 (let (ov)
10462 (goto-char (match-beginning 1))
10463 (setq ov (make-overlay (match-beginning 1) (match-end 1)))
10464 (overlay-put ov 'start-closed 't)
10465 (overlay-put ov 'end-closed 't)
10466 (overlay-put ov 'evaporate 't)
10467 (overlay-put ov 'verilog-include-file 't)
10468 (overlay-put ov 'mouse-face 'highlight)
10469 (overlay-put ov 'local-map verilog-mode-mouse-map)))))))
10470
10471
10472 (defun verilog-colorize-include-files-buffer ()
10473 "Colorize an include file."
10474 (interactive)
10475 ;; delete overlays
10476 (let ((overlays (overlays-in (point-min) (point-max))))
10477 (while overlays
10478 (if (and
10479 (overlay-get (car overlays) 'detachable)
10480 (overlay-get (car overlays) 'verilog-include-file))
10481 (delete-overlay (car overlays)))
10482 (setq overlays (cdr overlays)))) ; let
10483 ;; remake overlays
10484 (verilog-colorize-include-files (point-min) (point-max) nil))
10485
10486 ;; ffap-at-mouse isn't useful for Verilog mode. It uses library paths.
10487 ;; so define this function to do more or less the same as ffap-at-mouse
10488 ;; but first resolve filename...
10489 (defun verilog-load-file-at-mouse (event)
10490 "Load file under button 2 click's EVENT.
10491 Files are checked based on `verilog-library-directories'."
10492 (interactive "@e")
10493 (save-excursion ;; implement a Verilog specific ffap-at-mouse
10494 (mouse-set-point event)
10495 (beginning-of-line)
10496 (if (looking-at verilog-include-file-regexp)
10497 (if (and (car (verilog-library-filenames
10498 (match-string 1) (buffer-file-name)))
10499 (file-readable-p (car (verilog-library-filenames
10500 (match-string 1) (buffer-file-name)))))
10501 (find-file (car (verilog-library-filenames
10502 (match-string 1) (buffer-file-name))))
10503 (progn
10504 (message
10505 "File '%s' isn't readable, use shift-mouse2 to paste in this field"
10506 (match-string 1)))))))
10507
10508 ;; ffap isn't useable for Verilog mode. It uses library paths.
10509 ;; so define this function to do more or less the same as ffap
10510 ;; but first resolve filename...
10511 (defun verilog-load-file-at-point ()
10512 "Load file under point.
10513 Files are checked based on `verilog-library-directories'."
10514 (interactive)
10515 (save-excursion ;; implement a Verilog specific ffap
10516 (beginning-of-line)
10517 (if (looking-at verilog-include-file-regexp)
10518 (if (and
10519 (car (verilog-library-filenames
10520 (match-string 1) (buffer-file-name)))
10521 (file-readable-p (car (verilog-library-filenames
10522 (match-string 1) (buffer-file-name)))))
10523 (find-file (car (verilog-library-filenames
10524 (match-string 1) (buffer-file-name))))))))
10525
10526
10527 ;;
10528 ;; Bug reporting
10529 ;;
10530
10531 (defun verilog-faq ()
10532 "Tell the user their current version, and where to get the FAQ etc."
10533 (interactive)
10534 (with-output-to-temp-buffer "*verilog-mode help*"
10535 (princ (format "You are using verilog-mode %s\n" verilog-mode-version))
10536 (princ "\n")
10537 (princ "For new releases, see http://www.verilog.com\n")
10538 (princ "\n")
10539 (princ "For frequently asked questions, see http://www.veripool.org/verilog-mode-faq.html\n")
10540 (princ "\n")
10541 (princ "To submit a bug, use M-x verilog-submit-bug-report\n")
10542 (princ "\n")))
10543
10544 (autoload 'reporter-submit-bug-report "reporter")
10545 (defvar reporter-prompt-for-summary-p)
10546
10547 (defun verilog-submit-bug-report ()
10548 "Submit via mail a bug report on verilog-mode.el."
10549 (interactive)
10550 (let ((reporter-prompt-for-summary-p t))
10551 (reporter-submit-bug-report
10552 "mac@verilog.com"
10553 (concat "verilog-mode v" verilog-mode-version)
10554 '(
10555 verilog-align-ifelse
10556 verilog-auto-endcomments
10557 verilog-auto-hook
10558 verilog-auto-indent-on-newline
10559 verilog-auto-inst-vector
10560 verilog-auto-inst-template-numbers
10561 verilog-auto-lineup
10562 verilog-auto-newline
10563 verilog-auto-save-policy
10564 verilog-auto-sense-defines-constant
10565 verilog-auto-sense-include-inputs
10566 verilog-before-auto-hook
10567 verilog-case-indent
10568 verilog-cexp-indent
10569 verilog-compiler
10570 verilog-coverage
10571 verilog-highlight-translate-off
10572 verilog-indent-begin-after-if
10573 verilog-indent-declaration-macros
10574 verilog-indent-level
10575 verilog-indent-level-behavioral
10576 verilog-indent-level-declaration
10577 verilog-indent-level-directive
10578 verilog-indent-level-module
10579 verilog-indent-lists
10580 verilog-library-flags
10581 verilog-library-directories
10582 verilog-library-extensions
10583 verilog-library-files
10584 verilog-linter
10585 verilog-minimum-comment-distance
10586 verilog-mode-hook
10587 verilog-simulator
10588 verilog-tab-always-indent
10589 verilog-tab-to-comment
10590 )
10591 nil nil
10592 (concat "Hi Mac,
10593
10594 I want to report a bug. I've read the `Bugs' section of `Info' on
10595 Emacs, so I know how to make a clear and unambiguous report. To get
10596 to that Info section, I typed
10597
10598 M-x info RET m " invocation-name " RET m bugs RET
10599
10600 Before I go further, I want to say that Verilog mode has changed my life.
10601 I save so much time, my files are colored nicely, my co workers respect
10602 my coding ability... until now. I'd really appreciate anything you
10603 could do to help me out with this minor deficiency in the product.
10604
10605 If you have bugs with the AUTO functions, please CC the AUTOAUTHOR Wilson
10606 Snyder (wsnyder@wsnyder.org) and/or see http://www.veripool.org.
10607 You may also want to look at the Verilog-Mode FAQ, see
10608 http://www.veripool.org/verilog-mode-faq.html.
10609
10610 To reproduce the bug, start a fresh Emacs via " invocation-name "
10611 -no-init-file -no-site-file'. In a new buffer, in Verilog mode, type
10612 the code included below.
10613
10614 Given those lines, I expected [[Fill in here]] to happen;
10615 but instead, [[Fill in here]] happens!.
10616
10617 == The code: =="))))
10618
10619 (provide 'verilog-mode)
10620
10621 ;; Local Variables:
10622 ;; checkdoc-permit-comma-termination-flag:t
10623 ;; checkdoc-force-docstrings-flag:nil
10624 ;; End:
10625
10626 ;; arch-tag: 87923725-57b3-41b5-9494-be21118c6a6f
10627 ;;; verilog-mode.el ends here