Mercurial > emacs
annotate lisp/progmodes/verilog-mode.el @ 91266:3cd59392b3ec
(Vfont_encoding_charset_alist): New variable.
(syms_of_fontset): DEFVAR it.
(reorder_font_vector): Optimize for the case of no need of
reordring.
(fontset_find_font): Likewise.
(face_for_char): Map the charset property by
Vfont_encoding_charset_alist.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 21 Dec 2007 01:37:31 +0000 |
parents | 52d2889ab3d8 |
children | d3e3c91e18f6 34b619baa980 |
rev | line source |
---|---|
79545 | 1 ;; verilog-mode.el --- major mode for editing verilog source in Emacs |
79551 | 2 |
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, | |
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc. | |
79545 | 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.com | |
12 ;; Keywords: languages | |
13 | |
79551 | 14 ;; This file is part of GNU Emacs. |
15 | |
16 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
79545 | 17 ;; it under the terms of the GNU General Public License as published by |
79551 | 18 ;; the Free Software Foundation; either version 3, or (at your option) |
19 ;; any later version. | |
20 | |
21 ;; GNU Emacs is distributed in the hope that it will be useful, | |
79545 | 22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 ;; GNU General Public License for more details. | |
25 | |
26 ;; You should have received a copy of the GNU General Public License | |
79551 | 27 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
28 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
29 ;; Boston, MA 02110-1301, USA. | |
79545 | 30 |
31 ;;; Commentary: | |
32 | |
33 ;; This mode borrows heavily from the Pascal-mode and the cc-mode of emacs | |
34 | |
35 ;; USAGE | |
36 ;; ===== | |
37 | |
38 ;; A major mode for editing Verilog HDL source code. When you have | |
39 ;; entered Verilog mode, you may get more info by pressing C-h m. You | |
40 ;; may also get online help describing various functions by: C-h f | |
41 ;; <Name of function you want described> | |
42 | |
43 ;; KNOWN BUGS / BUG REPORTS | |
44 ;; ======================= | |
45 | |
46 ;; Verilog is a rapidly evolving language, and hence this mode is | |
47 ;; under continuous development. Hence this is beta code, and likely | |
48 ;; has bugs. Please report any and all bugs to me at mac@verilog.com. | |
49 ;; Please use verilog-submit-bug-report to submit a report; type C-c | |
50 ;; C-b to invoke this and as a result I will have a much easier time | |
51 ;; of reproducing the bug you find, and hence fixing it. | |
52 | |
53 ;; INSTALLING THE MODE | |
54 ;; =================== | |
55 | |
56 ;; An older version of this mode may be already installed as a part of | |
57 ;; your environment, and one method of updating would be to update | |
58 ;; your emacs environment. Sometimes this is difficult for local | |
59 ;; political/control reasons, and hence you can always install a | |
60 ;; private copy (or even a shared copy) which overrides the system | |
61 ;; default. | |
62 | |
63 ;; You can get step by step help in installing this file by going to | |
64 ;; <http://www.verilog.com/emacs_install.html> | |
65 | |
66 ;; The short list of installation instructions are: To set up | |
67 ;; automatic verilog mode, put this file in your load path, and put | |
68 ;; the following in code (please un comment it first!) in your | |
69 ;; .emacs, or in your site's site-load.el | |
70 | |
71 ; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t ) | |
72 ; (setq auto-mode-alist (cons '("\\.v\\'" . verilog-mode) auto-mode-alist)) | |
73 ; (setq auto-mode-alist (cons '("\\.dv\\'" . verilog-mode) auto-mode-alist)) | |
74 | |
75 ;; If you want to customize Verilog mode to fit your needs better, | |
76 ;; you may add these lines (the values of the variables presented | |
77 ;; here are the defaults). Note also that if you use an emacs that | |
78 ;; supports custom, it's probably better to use the custom menu to | |
79 ;; edit these. | |
80 ;; | |
81 ;; Be sure to examine at the help for verilog-auto, and the other | |
82 ;; verilog-auto-* functions for some major coding time savers. | |
83 ;; | |
84 ; ;; User customization for Verilog mode | |
85 ; (setq verilog-indent-level 3 | |
86 ; verilog-indent-level-module 3 | |
87 ; verilog-indent-level-declaration 3 | |
88 ; verilog-indent-level-behavioral 3 | |
89 ; verilog-indent-level-directive 1 | |
90 ; verilog-case-indent 2 | |
91 ; verilog-auto-newline t | |
92 ; verilog-auto-indent-on-newline t | |
93 ; verilog-tab-always-indent t | |
94 ; verilog-auto-endcomments t | |
95 ; verilog-minimum-comment-distance 40 | |
96 ; verilog-indent-begin-after-if t | |
97 ; verilog-auto-lineup '(all) | |
98 ; verilog-highlight-p1800-keywords nil | |
99 ; verilog-linter "my_lint_shell_command" | |
100 ; ) | |
101 | |
102 ;; | |
103 | |
104 ;;; History: | |
105 ;; | |
106 ;; | |
107 ;;; Code: | |
108 | |
109 ;; This variable will always hold the version number of the mode | |
79546 | 110 (defconst verilog-mode-version "377" |
79545 | 111 "Version of this verilog mode.") |
79546 | 112 (defconst verilog-mode-release-date "2007-12-07" |
79545 | 113 "Version of this verilog mode.") |
114 | |
115 (defun verilog-version () | |
116 "Inform caller of the version of this file." | |
117 (interactive) | |
118 (message (concat "Using verilog-mode version " verilog-mode-version) )) | |
119 | |
120 ;; Insure we have certain packages, and deal with it if we don't | |
79546 | 121 (eval-when-compile |
122 (condition-case nil | |
123 (require 'imenu) | |
124 (error nil)) | |
125 (condition-case nil | |
126 (require 'reporter) | |
127 (error nil)) | |
128 (condition-case nil | |
129 (require 'easymenu) | |
130 (error nil)) | |
131 (condition-case nil | |
132 (require 'regexp-opt) | |
133 (error nil)) | |
134 (condition-case nil | |
135 (load "skeleton") ;; bug in 19.28 through 19.30 skeleton.el, not provided. | |
136 (error nil)) | |
137 (condition-case nil | |
138 (require 'vc) | |
139 (error nil)) | |
140 (condition-case nil | |
141 (if (fboundp 'when) | |
142 nil ;; fab | |
143 (defmacro when (cond &rest body) | |
144 (list 'if cond (cons 'progn body)))) | |
145 (error nil)) | |
146 (condition-case nil | |
147 (if (fboundp 'unless) | |
148 nil ;; fab | |
149 (defmacro unless (cond &rest body) | |
150 (cons 'if (cons cond (cons nil body))))) | |
151 (error nil)) | |
152 (condition-case nil | |
153 (if (fboundp 'store-match-data) | |
154 nil ;; fab | |
155 (defmacro store-match-data (&rest args) nil)) | |
156 (error nil)) | |
79555
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
157 (if (featurep 'xemacs) |
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
158 (condition-case nil |
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
159 (if (boundp 'current-menubar) |
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
160 nil ;; great |
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
161 (progn |
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
162 (defmacro add-submenu (&rest args) nil)) |
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
163 ) |
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
164 (error nil))) |
79546 | 165 (condition-case nil |
166 (if (fboundp 'zmacs-activate-region) | |
167 nil ;; great | |
168 (defmacro zmacs-activate-region (&rest args) nil)) | |
169 (error nil)) | |
170 (condition-case nil | |
171 (if (fboundp 'char-before) | |
172 nil ;; great | |
173 (defmacro char-before (&rest body) | |
174 (char-after (1- (point))))) | |
175 (error nil)) | |
176 ;; Requires to define variables that would be "free" warnings | |
177 (condition-case nil | |
178 (require 'font-lock) | |
179 (error nil)) | |
180 (condition-case nil | |
181 (require 'compile) | |
182 (error nil)) | |
183 (condition-case nil | |
184 (require 'custom) | |
185 (error nil)) | |
186 (condition-case nil | |
187 (require 'dinotrace) | |
188 (error nil)) | |
189 (condition-case nil | |
190 (if (fboundp 'dinotrace-unannotate-all) | |
191 nil ;; great | |
192 (defun dinotrace-unannotate-all (&rest args) nil)) | |
193 (error nil)) | |
194 (condition-case nil | |
195 (if (fboundp 'customize-apropos) | |
196 nil ;; great | |
197 (defun customize-apropos (&rest args) nil)) | |
198 (error nil)) | |
199 (condition-case nil | |
200 (if (fboundp 'match-string-no-properties) | |
201 nil ;; great | |
202 (defsubst match-string-no-properties (num &optional string) | |
203 "Return string of text matched by last search, without text properties. | |
79545 | 204 NUM specifies which parenthesized expression in the last regexp. |
205 Value is nil if NUMth pair didn't match, or there were less than NUM pairs. | |
206 Zero means the entire text matched by the whole regexp or whole string. | |
207 STRING should be given if the last search was by `string-match' on STRING." | |
79546 | 208 (if (match-beginning num) |
209 (if string | |
210 (let ((result | |
211 (substring string (match-beginning num) (match-end num)))) | |
212 (set-text-properties 0 (length result) nil result) | |
213 result) | |
214 (buffer-substring-no-properties (match-beginning num) | |
215 (match-end num) | |
216 (current-buffer) | |
217 ))))) | |
218 (error nil)) | |
219 (if (and (featurep 'custom) (fboundp 'custom-declare-variable)) | |
220 nil ;; We've got what we needed | |
221 ;; We have the old custom-library, hack around it! | |
222 (defmacro defgroup (&rest args) nil) | |
223 (defmacro customize (&rest args) | |
224 (message "Sorry, Customize is not available with this version of emacs")) | |
225 (defmacro defcustom (var value doc &rest args) | |
226 `(defvar ,var ,value ,doc)) | |
227 ) | |
228 (if (fboundp 'defface) | |
229 nil ; great! | |
230 (defmacro defface (var values doc &rest args) | |
231 `(make-face ,var)) | |
232 ) | |
233 | |
234 (if (and (featurep 'custom) (fboundp 'customize-group)) | |
235 nil ;; We've got what we needed | |
236 ;; We have an intermediate custom-library, hack around it! | |
237 (defmacro customize-group (var &rest args) | |
238 `(customize ,var)) | |
239 ) | |
240 | |
241 ) | |
79545 | 242 ;; Provide a regular expression optimization routine, using regexp-opt |
243 ;; if provided by the user's elisp libraries | |
244 (eval-and-compile | |
245 (if (fboundp 'regexp-opt) | |
246 ;; regexp-opt is defined, does it take 3 or 2 arguments? | |
247 (if (fboundp 'function-max-args) | |
79546 | 248 (let ((args (function-max-args `regexp-opt))) |
249 (cond | |
250 ((eq args 3) ;; It takes 3 | |
79545 | 251 (condition-case nil ; Hide this defun from emacses |
252 ;with just a two input regexp | |
253 (defun verilog-regexp-opt (a b) | |
254 "Deal with differing number of required arguments for `regexp-opt'. | |
255 Call 'regexp-opt' on A and B." | |
256 (regexp-opt a b 't) | |
257 ) | |
258 (error nil)) | |
259 ) | |
79546 | 260 ((eq args 2) ;; It takes 2 |
79545 | 261 (defun verilog-regexp-opt (a b) |
262 "Call 'regexp-opt' on A and B." | |
263 (regexp-opt a b)) | |
264 ) | |
79546 | 265 (t nil))) |
79545 | 266 ;; We can't tell; assume it takes 2 |
267 (defun verilog-regexp-opt (a b) | |
268 "Call 'regexp-opt' on A and B." | |
269 (regexp-opt a b)) | |
270 ) | |
271 ;; There is no regexp-opt, provide our own | |
272 (defun verilog-regexp-opt (strings &optional paren shy) | |
273 (let ((open (if paren "\\(" "")) (close (if paren "\\)" ""))) | |
274 (concat open (mapconcat 'regexp-quote strings "\\|") close))) | |
275 )) | |
276 | |
79555
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
277 (eval-when-compile |
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
278 (defun verilog-regexp-words (a) |
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
279 "Call 'regexp-opt' with word delimiters for the words A." |
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
280 (concat "\\<" (verilog-regexp-opt a t) "\\>"))) |
79545 | 281 |
282 (defun verilog-customize () | |
283 "Link to customize screen for Verilog." | |
284 (interactive) | |
285 (customize-group 'verilog-mode)) | |
286 | |
287 (defun verilog-font-customize () | |
288 "Link to customize fonts used for Verilog." | |
289 (interactive) | |
290 (customize-apropos "font-lock-*" 'faces)) | |
291 | |
292 (defgroup verilog-mode nil | |
293 "Facilitates easy editing of Verilog source text" | |
294 :group 'languages) | |
295 | |
296 ; (defgroup verilog-mode-fonts nil | |
297 ; "Facilitates easy customization fonts used in Verilog source text" | |
298 ; :link '(customize-apropos "font-lock-*" 'faces) | |
299 ; :group 'verilog-mode) | |
300 | |
301 (defgroup verilog-mode-indent nil | |
302 "Customize indentation and highlighting of verilog source text" | |
303 :group 'verilog-mode) | |
304 | |
305 (defgroup verilog-mode-actions nil | |
306 "Customize actions on verilog source text" | |
307 :group 'verilog-mode) | |
308 | |
309 (defgroup verilog-mode-auto nil | |
310 "Customize AUTO actions when expanding verilog source text" | |
311 :group 'verilog-mode) | |
312 | |
313 (defcustom verilog-linter | |
314 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'" | |
315 "*Unix program and arguments to call to run a lint checker on verilog source. | |
316 Depending on the `verilog-set-compile-command', this may be invoked when | |
317 you type \\[compile]. When the compile completes, \\[next-error] will take | |
318 you to the next lint error." | |
319 :type 'string | |
320 :group 'verilog-mode-actions) | |
321 | |
322 (defcustom verilog-coverage | |
323 "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'" | |
324 "*Program and arguments to use to annotate for coverage verilog source. | |
325 Depending on the `verilog-set-compile-command', this may be invoked when | |
326 you type \\[compile]. When the compile completes, \\[next-error] will take | |
327 you to the next lint error." | |
328 :type 'string | |
329 :group 'verilog-mode-actions) | |
330 | |
331 (defcustom verilog-simulator | |
332 "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'" | |
333 "*Program and arguments to use to interpret verilog source. | |
334 Depending on the `verilog-set-compile-command', this may be invoked when | |
335 you type \\[compile]. When the compile completes, \\[next-error] will take | |
336 you to the next lint error." | |
337 :type 'string | |
338 :group 'verilog-mode-actions) | |
339 | |
340 (defcustom verilog-compiler | |
341 "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'" | |
342 "*Program and arguments to use to compile verilog source. | |
343 Depending on the `verilog-set-compile-command', this may be invoked when | |
344 you type \\[compile]. When the compile completes, \\[next-error] will take | |
345 you to the next lint error." | |
346 :type 'string | |
347 :group 'verilog-mode-actions) | |
348 | |
349 (defvar verilog-tool 'verilog-linter | |
350 "Which tool to use for building compiler-command. | |
351 Either nil, `verilog-linter, `verilog-coverage, `verilog-simulator, or | |
352 `verilog-compiler. Alternatively use the \"Choose Compilation Action\" | |
353 menu. See `verilog-set-compile-command' for more information.") | |
354 | |
355 (defcustom verilog-highlight-translate-off nil | |
356 "*Non-nil means background-highlight code excluded from translation. | |
357 That is, all code between \"// synopsys translate_off\" and | |
358 \"// synopsys translate_on\" is highlighted using a different background color | |
359 \(face `verilog-font-lock-translate-off-face'). | |
360 | |
361 Note: This will slow down on-the-fly fontification (and thus editing). | |
362 | |
363 Note: Activate the new setting in a Verilog buffer by re-fontifying it (menu | |
364 entry \"Fontify Buffer\"). XEmacs: turn off and on font locking." | |
365 :type 'boolean | |
366 :group 'verilog-mode-indent) | |
367 | |
368 (defcustom verilog-indent-level 3 | |
369 "*Indentation of Verilog statements with respect to containing block." | |
370 :group 'verilog-mode-indent | |
371 :type 'integer) | |
372 | |
373 (defcustom verilog-indent-level-module 3 | |
374 "*Indentation of Module level Verilog statements. (eg always, initial) | |
375 Set to 0 to get initial and always statements lined up on the left side of | |
376 your screen." | |
377 :group 'verilog-mode-indent | |
378 :type 'integer) | |
379 | |
380 (defcustom verilog-indent-level-declaration 3 | |
381 "*Indentation of declarations with respect to containing block. | |
382 Set to 0 to get them list right under containing block." | |
383 :group 'verilog-mode-indent | |
384 :type 'integer) | |
385 | |
386 (defcustom verilog-indent-declaration-macros nil | |
387 "*How to treat macro expansions in a declaration. | |
388 If nil, indent as: | |
389 input [31:0] a; | |
390 input `CP; | |
391 output c; | |
392 If non nil, treat as: | |
393 input [31:0] a; | |
394 input `CP ; | |
395 output c;" | |
396 :group 'verilog-mode-indent | |
397 :type 'boolean) | |
398 | |
399 (defcustom verilog-indent-lists t | |
400 "*How to treat indenting items in a list. | |
401 If t (the default), indent as: | |
402 always @( posedge a or | |
403 reset ) begin | |
404 | |
405 If nil, treat as: | |
406 always @( posedge a or | |
407 reset ) begin" | |
408 :group 'verilog-mode-indent | |
409 :type 'boolean) | |
410 | |
411 (defcustom verilog-indent-level-behavioral 3 | |
412 "*Absolute indentation of first begin in a task or function block. | |
413 Set to 0 to get such code to start at the left side of the screen." | |
414 :group 'verilog-mode-indent | |
415 :type 'integer) | |
416 | |
417 (defcustom verilog-indent-level-directive 1 | |
418 "*Indentation to add to each level of `ifdef declarations. | |
419 Set to 0 to have all directives start at the left side of the screen." | |
420 :group 'verilog-mode-indent | |
421 :type 'integer) | |
422 | |
423 (defcustom verilog-cexp-indent 2 | |
424 "*Indentation of Verilog statements split across lines." | |
425 :group 'verilog-mode-indent | |
426 :type 'integer) | |
427 | |
428 (defcustom verilog-case-indent 2 | |
429 "*Indentation for case statements." | |
430 :group 'verilog-mode-indent | |
431 :type 'integer) | |
432 | |
433 (defcustom verilog-auto-newline t | |
434 "*True means automatically newline after semicolons." | |
435 :group 'verilog-mode-indent | |
436 :type 'boolean) | |
437 | |
438 (defcustom verilog-auto-indent-on-newline t | |
439 "*True means automatically indent line after newline." | |
440 :group 'verilog-mode-indent | |
441 :type 'boolean) | |
442 | |
443 (defcustom verilog-tab-always-indent t | |
444 "*True means TAB should always re-indent the current line. | |
445 Nil means TAB will only reindent when at the beginning of the line." | |
446 :group 'verilog-mode-indent | |
447 :type 'boolean) | |
448 | |
449 (defcustom verilog-tab-to-comment nil | |
450 "*True means TAB moves to the right hand column in preparation for a comment." | |
451 :group 'verilog-mode-actions | |
452 :type 'boolean) | |
453 | |
454 (defcustom verilog-indent-begin-after-if t | |
455 "*If true, indent begin statements following if, else, while, for and repeat. | |
456 Otherwise, line them up." | |
457 :group 'verilog-mode-indent | |
458 :type 'boolean ) | |
459 | |
460 | |
461 (defcustom verilog-align-ifelse nil | |
462 "*If true, align `else' under matching `if'. | |
463 Otherwise else is lined up with first character on line holding matching if." | |
464 :group 'verilog-mode-indent | |
465 :type 'boolean ) | |
466 | |
467 (defcustom verilog-minimum-comment-distance 10 | |
468 "*Minimum distance (in lines) between begin and end required before a comment. | |
469 Setting this variable to zero results in every end acquiring a comment; the | |
470 default avoids too many redundant comments in tight quarters" | |
471 :group 'verilog-mode-indent | |
472 :type 'integer) | |
473 | |
474 (defcustom verilog-auto-lineup '(declaration) | |
475 "*Algorithm for lining up statements on multiple lines. | |
476 | |
477 If this list contains the symbol 'all', then all line ups described below | |
478 are done. | |
479 | |
480 If this list contains the symbol 'declaration', then declarations are lined up | |
481 with any preceding declarations, taking into account widths and the like, so | |
482 for example the code: | |
483 reg [31:0] a; | |
484 reg b; | |
485 would become | |
486 reg [31:0] a; | |
487 reg b; | |
488 | |
489 If this list contains the symbol 'assignment', then assignments are lined up | |
490 with any preceding assignments, so for example the code | |
491 a_long_variable = b + c; | |
492 d = e + f; | |
493 would become | |
494 a_long_variable = b + c; | |
495 d = e + f;" | |
496 | |
497 ;; The following is not implemented: | |
498 ;If this list contains the symbol 'case', then case items are lined up | |
499 ;with any preceding case items, so for example the code | |
500 ; case (a) begin | |
501 ; a_long_state : a = 3; | |
502 ; b: a = 4; | |
503 ; endcase | |
504 ;would become | |
505 ; case (a) begin | |
506 ; a_long_state : a = 3; | |
507 ; b : a = 4; | |
508 ; endcase | |
509 ; | |
510 | |
511 :group 'verilog-mode-indent | |
512 :type 'list ) | |
513 | |
514 (defcustom verilog-highlight-p1800-keywords nil | |
515 "*If true highlight words newly reserved by IEEE-1800 in | |
516 verilog-font-lock-p1800-face in order to gently suggest changing where | |
517 these words are used as variables to something else. Nil means highlight | |
518 these words as appropriate for the SystemVerilog IEEE-1800 standard. Note | |
519 that changing this will require restarting emacs to see the effect as font | |
520 color choices are cached by emacs" | |
521 :group 'verilog-mode-indent | |
522 :type 'boolean) | |
523 | |
524 (defcustom verilog-auto-endcomments t | |
525 "*True means insert a comment /* ... */ after 'end's. | |
526 The name of the function or case will be set between the braces." | |
527 :group 'verilog-mode-actions | |
528 :type 'boolean ) | |
529 | |
530 (defcustom verilog-auto-read-includes nil | |
531 "*True means to automatically read includes before AUTOs. | |
532 This will do a `verilog-read-defines' and `verilog-read-includes' before | |
533 each AUTO expansion. This makes it easier to embed defines and includes, | |
534 but can result in very slow reading times if there are many or large | |
535 include files." | |
536 :group 'verilog-mode-actions | |
537 :type 'boolean ) | |
538 | |
539 (defcustom verilog-auto-save-policy nil | |
540 "*Non-nil indicates action to take when saving a Verilog buffer with AUTOs. | |
541 A value of `force' will always do a \\[verilog-auto] automatically if | |
542 needed on every save. A value of `detect' will do \\[verilog-auto] | |
543 automatically when it thinks necessary. A value of `ask' will query the | |
544 user when it thinks updating is needed. | |
545 | |
546 You should not rely on the 'ask or 'detect policies, they are safeguards | |
547 only. They do not detect when AUTOINSTs need to be updated because a | |
548 sub-module's port list has changed." | |
549 :group 'verilog-mode-actions | |
550 :type '(choice (const nil) (const ask) (const detect) (const force))) | |
551 | |
552 (defcustom verilog-auto-star-expand t | |
553 "*Non-nil indicates to expand a SystemVerilog .* instance ports. | |
554 They will be expanded in the same way as if there was a AUTOINST in the | |
555 instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'." | |
556 :group 'verilog-mode-actions | |
557 :type 'boolean) | |
558 | |
559 (defcustom verilog-auto-star-save nil | |
560 "*Non-nil indicates to save to disk SystemVerilog .* instance expansions. | |
561 Nil indicates direct connections will be removed before saving. Only | |
562 meaningful to those created due to `verilog-auto-star-expand' being set. | |
563 | |
564 Instead of setting this, you may want to use /*AUTOINST*/, which will | |
565 always be saved." | |
566 :group 'verilog-mode-actions | |
567 :type 'boolean) | |
568 | |
569 (defvar verilog-auto-update-tick nil | |
570 "Modification tick at which autos were last performed.") | |
571 | |
572 (defvar verilog-auto-last-file-locals nil | |
573 "Text from file-local-variables during last evaluation.") | |
574 | |
575 (defvar verilog-error-regexp-add-didit nil) | |
576 (defvar verilog-error-regexp nil) | |
577 (setq verilog-error-regexp-add-didit nil | |
578 verilog-error-regexp | |
579 '( | |
580 ; SureLint | |
581 ;; ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2) | |
582 ; Most SureFire tools | |
583 ("\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\), \\(line \\|\\)\\([0-9]+\\):" 2 4 ) | |
584 ("\ | |
585 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\ | |
586 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5) | |
587 ; xsim | |
588 ; Error! in file /homes/mac/Axis/Xsim/test.v at line 13 [OBJ_NOT_DECLARED] | |
589 ("\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3) | |
590 ; vcs | |
591 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3) | |
592 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2) | |
593 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3) | |
594 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2) | |
595 ; Verilator | |
596 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4) | |
597 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4) | |
598 ; vxl | |
599 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3) | |
600 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 1 2) ; vxl | |
601 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 1 2) | |
602 ; nc-verilog | |
603 (".*\\*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 1 2) | |
604 ; Leda | |
605 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 1 2) | |
606 ) | |
607 ; "*List of regexps for verilog compilers, like verilint. See compilation-error-regexp-alist for the formatting." | |
608 ) | |
609 | |
610 (defvar verilog-error-font-lock-keywords | |
611 '( | |
612 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t) | |
613 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t) | |
614 | |
615 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t) | |
616 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t) | |
617 | |
618 ("\ | |
619 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\ | |
620 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t) | |
621 ("\ | |
622 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\ | |
623 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t) | |
624 | |
625 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t) | |
626 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t) | |
627 | |
628 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t) | |
629 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t) | |
630 | |
631 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t) | |
632 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t) | |
633 | |
634 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t) | |
635 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t) | |
636 | |
637 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t) | |
638 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t) | |
639 ; vxl | |
640 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t) | |
641 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t) | |
642 | |
643 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 1 bold t) | |
644 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 2 bold t) | |
645 | |
646 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 1 bold t) | |
647 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 2 bold t) | |
648 ; nc-verilog | |
649 (".*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 1 bold t) | |
650 (".*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t) | |
651 ; Leda | |
652 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 1 bold t) | |
653 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 2 bold t) | |
654 ) | |
655 "*Keywords to also highlight in Verilog *compilation* buffers." | |
656 ) | |
657 | |
658 (defcustom verilog-library-flags '("") | |
659 "*List of standard Verilog arguments to use for /*AUTOINST*/. | |
660 These arguments are used to find files for `verilog-auto', and match | |
661 the flags accepted by a standard Verilog-XL simulator. | |
662 | |
663 -f filename Reads more `verilog-library-flags' from the filename. | |
664 +incdir+dir Adds the directory to `verilog-library-directories'. | |
665 -Idir Adds the directory to `verilog-library-directories'. | |
666 -y dir Adds the directory to `verilog-library-directories'. | |
667 +libext+.v Adds the extensions to `verilog-library-extensions'. | |
668 -v filename Adds the filename to `verilog-library-files'. | |
669 | |
670 filename Adds the filename to `verilog-library-files'. | |
671 This is not recommended, -v is a better choice. | |
672 | |
673 You might want these defined in each file; put at the *END* of your file | |
674 something like: | |
675 | |
676 // Local Variables: | |
677 // verilog-library-flags:(\"-y dir -y otherdir\") | |
678 // End: | |
679 | |
680 Verilog-mode attempts to detect changes to this local variable, but they | |
681 are only insured to be correct when the file is first visited. Thus if you | |
682 have problems, use \\[find-alternate-file] RET to have these take effect. | |
683 | |
684 See also the variables mentioned above." | |
685 :group 'verilog-mode-auto | |
686 :type '(repeat string)) | |
687 | |
688 (defcustom verilog-library-directories '(".") | |
689 "*List of directories when looking for files for /*AUTOINST*/. | |
690 The directory may be relative to the current file, or absolute. | |
691 Environment variables are also expanded in the directory names. | |
692 Having at least the current directory is a good idea. | |
693 | |
694 You might want these defined in each file; put at the *END* of your file | |
695 something like: | |
696 | |
697 // Local Variables: | |
698 // verilog-library-directories:(\".\" \"subdir\" \"subdir2\") | |
699 // End: | |
700 | |
701 Verilog-mode attempts to detect changes to this local variable, but they | |
702 are only insured to be correct when the file is first visited. Thus if you | |
703 have problems, use \\[find-alternate-file] RET to have these take effect. | |
704 | |
705 See also `verilog-library-flags', `verilog-library-files' | |
706 and `verilog-library-extensions'." | |
707 :group 'verilog-mode-auto | |
708 :type '(repeat file)) | |
709 | |
710 (defcustom verilog-library-files '() | |
711 "*List of files to search for modules when looking for AUTOINST files. | |
712 This is a complete path, usually to a technology file with many standard | |
713 cells defined in it. | |
714 | |
715 You might want these defined in each file; put at the *END* of your file | |
716 something like: | |
717 | |
718 // Local Variables: | |
719 // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\") | |
720 // End: | |
721 | |
722 Verilog-mode attempts to detect changes to this local variable, but they | |
723 are only insured to be correct when the file is first visited. Thus if you | |
724 have problems, use \\[find-alternate-file] RET to have these take effect. | |
725 | |
726 See also `verilog-library-flags', `verilog-library-directories'." | |
727 :group 'verilog-mode-auto | |
728 :type '(repeat directory)) | |
729 | |
730 (defcustom verilog-library-extensions '(".v") | |
731 "*List of extensions to use when looking for files for /*AUTOINST*/. | |
732 See also `verilog-library-flags', `verilog-library-directories'." | |
733 :type '(repeat string) | |
734 :group 'verilog-mode-auto) | |
735 | |
736 (defcustom verilog-active-low-regexp nil | |
737 "*If set, treat signals matching this regexp as active low. | |
738 This is used for AUTORESET and AUTOTIEOFF. For proper behavior, | |
739 you will probably also need `verilog-auto-reset-widths' set." | |
740 :group 'verilog-mode-auto | |
741 :type 'string) | |
742 | |
743 (defcustom verilog-auto-sense-include-inputs nil | |
744 "*If true, AUTOSENSE should include all inputs. | |
745 If nil, only inputs that are NOT output signals in the same block are | |
746 included." | |
747 :type 'boolean | |
748 :group 'verilog-mode-auto) | |
749 | |
750 (defcustom verilog-auto-sense-defines-constant nil | |
751 "*If true, AUTOSENSE should assume all defines represent constants. | |
752 When true, the defines will not be included in sensitivity lists. To | |
753 maintain compatibility with other sites, this should be set at the bottom | |
754 of each verilog file that requires it, rather than being set globally." | |
755 :type 'boolean | |
756 :group 'verilog-mode-auto) | |
757 | |
758 (defcustom verilog-auto-reset-widths t | |
759 "*If true, AUTORESET should determine the width of signals. | |
760 This is then used to set the width of the zero (32'h0 for example). This | |
761 is required by some lint tools that aren't smart enough to ignore widths of | |
762 the constant zero. This may result in ugly code when parameters determine | |
763 the MSB or LSB of a signal inside a AUTORESET." | |
764 :type 'boolean | |
765 :group 'verilog-mode-auto) | |
766 | |
767 (defcustom verilog-assignment-delay "" | |
768 "*Text used for delays in delayed assignments. Add a trailing space if set." | |
769 :type 'string | |
770 :group 'verilog-mode-auto) | |
771 | |
772 (defcustom verilog-auto-inst-vector t | |
773 "*If true, when creating default ports with AUTOINST, use bus subscripts. | |
774 If nil, skip the subscript when it matches the entire bus as declared in | |
775 the module (AUTOWIRE signals always are subscripted, you must manually | |
776 declare the wire to have the subscripts removed.) Nil may speed up some | |
777 simulators, but is less general and harder to read, so avoid." | |
778 :group 'verilog-mode-auto | |
779 :type 'boolean ) | |
780 | |
781 (defcustom verilog-auto-inst-template-numbers nil | |
782 "*If true, when creating templated ports with AUTOINST, add a comment. | |
783 The comment will add the line number of the template that was used for that | |
784 port declaration. Setting this aids in debugging, but nil is suggested for | |
785 regular use to prevent large numbers of merge conflicts." | |
786 :group 'verilog-mode-auto | |
787 :type 'boolean ) | |
788 | |
789 (defvar verilog-auto-inst-column 40 | |
790 "Column number for first part of auto-inst.") | |
791 | |
792 (defcustom verilog-auto-input-ignore-regexp nil | |
793 "*If set, when creating AUTOINPUT list, ignore signals matching this regexp. | |
794 See the \\[verilog-faq] for examples on using this." | |
795 :group 'verilog-mode-auto | |
796 :type 'string ) | |
797 | |
798 (defcustom verilog-auto-inout-ignore-regexp nil | |
799 "*If set, when creating AUTOINOUT list, ignore signals matching this regexp. | |
800 See the \\[verilog-faq] for examples on using this." | |
801 :group 'verilog-mode-auto | |
802 :type 'string ) | |
803 | |
804 (defcustom verilog-auto-output-ignore-regexp nil | |
805 "*If set, when creating AUTOOUTPUT list, ignore signals matching this regexp. | |
806 See the \\[verilog-faq] for examples on using this." | |
807 :group 'verilog-mode-auto | |
808 :type 'string ) | |
809 | |
810 (defcustom verilog-auto-unused-ignore-regexp nil | |
811 "*If set, when creating AUTOUNUSED list, ignore signals matching this regexp. | |
812 See the \\[verilog-faq] for examples on using this." | |
813 :group 'verilog-mode-auto | |
814 :type 'string ) | |
815 | |
816 (defcustom verilog-typedef-regexp nil | |
817 "*If non-nil, regular expression that matches Verilog-2001 typedef names. | |
818 For example, \"_t$\" matches typedefs named with _t, as in the C language." | |
819 :group 'verilog-mode-auto | |
820 :type 'string ) | |
821 | |
822 (defcustom verilog-mode-hook 'verilog-set-compile-command | |
823 "*Hook (List of functions) run after verilog mode is loaded." | |
824 :type 'hook | |
825 :group 'verilog-mode) | |
826 | |
827 (defcustom verilog-auto-hook nil | |
828 "*Hook run after `verilog-mode' updates AUTOs." | |
829 :type 'hook | |
830 :group 'verilog-mode-auto) | |
831 | |
832 (defcustom verilog-before-auto-hook nil | |
833 "*Hook run before `verilog-mode' updates AUTOs." | |
834 :type 'hook | |
835 :group 'verilog-mode-auto) | |
836 | |
837 (defcustom verilog-delete-auto-hook nil | |
838 "*Hook run after `verilog-mode' deletes AUTOs." | |
839 :type 'hook | |
840 :group 'verilog-mode-auto) | |
841 | |
842 (defcustom verilog-before-delete-auto-hook nil | |
843 "*Hook run before `verilog-mode' deletes AUTOs." | |
844 :type 'hook | |
845 :group 'verilog-mode-auto) | |
846 | |
847 (defcustom verilog-getopt-flags-hook nil | |
848 "*Hook run after `verilog-getopt-flags' determines the Verilog option lists." | |
849 :type 'hook | |
850 :group 'verilog-mode-auto) | |
851 | |
852 (defcustom verilog-before-getopt-flags-hook nil | |
853 "*Hook run before `verilog-getopt-flags' determines the Verilog option lists." | |
854 :type 'hook | |
855 :group 'verilog-mode-auto) | |
856 | |
857 (defvar verilog-imenu-generic-expression | |
858 '((nil "^\\s-*\\(\\(m\\(odule\\|acromodule\\)\\)\\|primitive\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 4) | |
859 ("*Vars*" "^\\s-*\\(reg\\|wire\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3)) | |
860 "Imenu expression for Verilog-mode. See `imenu-generic-expression'.") | |
861 | |
862 ;; | |
863 ;; provide a verilog-header function. | |
864 ;; Customization variables: | |
865 ;; | |
866 (defvar verilog-date-scientific-format nil | |
867 "*If non-nil, dates are written in scientific format (e.g. 1997/09/17). | |
868 If nil, in European format (e.g. 17.09.1997). The brain-dead American | |
869 format (e.g. 09/17/1997) is not supported.") | |
870 | |
871 (defvar verilog-company nil | |
872 "*Default name of Company for verilog header. | |
873 If set will become buffer local.") | |
874 | |
875 (defvar verilog-project nil | |
876 "*Default name of Project for verilog header. | |
877 If set will become buffer local.") | |
878 | |
79549
d9595ed9b084
* progmodes/verilog-mode.el (verilog-mode-map): Fix typo.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79547
diff
changeset
|
879 (defvar verilog-mode-map |
79546 | 880 (let ((map (make-sparse-keymap))) |
881 (define-key map ";" 'electric-verilog-semi) | |
882 (define-key map [(control 59)] 'electric-verilog-semi-with-comment) | |
883 (define-key map ":" 'electric-verilog-colon) | |
884 ;;(define-key map "=" 'electric-verilog-equal) | |
885 (define-key map "\`" 'electric-verilog-tick) | |
886 (define-key map "\t" 'electric-verilog-tab) | |
887 (define-key map "\r" 'electric-verilog-terminate-line) | |
888 ;; backspace/delete key bindings | |
889 (define-key map [backspace] 'backward-delete-char-untabify) | |
890 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable | |
891 (define-key map [delete] 'delete-char) | |
892 (define-key map [(meta delete)] 'kill-word)) | |
893 (define-key map "\M-\C-b" 'electric-verilog-backward-sexp) | |
894 (define-key map "\M-\C-f" 'electric-verilog-forward-sexp) | |
895 (define-key map "\M-\r" `electric-verilog-terminate-and-indent) | |
896 (define-key map "\M-\t" 'verilog-complete-word) | |
897 (define-key map "\M-?" 'verilog-show-completions) | |
898 (define-key map [(meta control h)] 'verilog-mark-defun) | |
899 (define-key map "\C-c\`" 'verilog-lint-off) | |
900 (define-key map "\C-c\*" 'verilog-delete-auto-star-implicit) | |
901 (define-key map "\C-c\C-r" 'verilog-label-be) | |
902 (define-key map "\C-c\C-i" 'verilog-pretty-declarations) | |
903 (define-key map "\C-c=" 'verilog-pretty-expr) | |
904 (define-key map "\C-c\C-b" 'verilog-submit-bug-report) | |
905 (define-key map "\M-*" 'verilog-star-comment) | |
906 (define-key map "\C-c\C-c" 'verilog-comment-region) | |
907 (define-key map "\C-c\C-u" 'verilog-uncomment-region) | |
908 (define-key map "\M-\C-a" 'verilog-beg-of-defun) | |
909 (define-key map "\M-\C-e" 'verilog-end-of-defun) | |
910 (define-key map "\C-c\C-d" 'verilog-goto-defun) | |
911 (define-key map "\C-c\C-k" 'verilog-delete-auto) | |
912 (define-key map "\C-c\C-a" 'verilog-auto) | |
913 (define-key map "\C-c\C-s" 'verilog-auto-save-compile) | |
914 (define-key map "\C-c\C-z" 'verilog-inject-auto) | |
915 (define-key map "\C-c\C-e" 'verilog-expand-vector) | |
79550
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
916 (define-key map "\C-c\C-h" 'verilog-header) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
917 map) |
79545 | 918 "Keymap used in Verilog mode.") |
919 | |
920 ;; menus | |
921 (defvar verilog-xemacs-menu | |
922 '("Verilog" | |
923 ("Choose Compilation Action" | |
924 ["None" | |
925 (progn | |
926 (setq verilog-tool nil) | |
927 (verilog-set-compile-command)) | |
928 :style radio | |
929 :selected (equal verilog-tool nil)] | |
930 ["Lint" | |
931 (progn | |
932 (setq verilog-tool 'verilog-linter) | |
933 (verilog-set-compile-command)) | |
934 :style radio | |
935 :selected (equal verilog-tool `verilog-linter)] | |
936 ["Coverage" | |
937 (progn | |
938 (setq verilog-tool 'verilog-coverage) | |
939 (verilog-set-compile-command)) | |
940 :style radio | |
941 :selected (equal verilog-tool `verilog-coverage)] | |
942 ["Simulator" | |
943 (progn | |
944 (setq verilog-tool 'verilog-simulator) | |
945 (verilog-set-compile-command)) | |
946 :style radio | |
947 :selected (equal verilog-tool `verilog-simulator)] | |
948 ["Compiler" | |
949 (progn | |
950 (setq verilog-tool 'verilog-compiler) | |
951 (verilog-set-compile-command)) | |
952 :style radio | |
953 :selected (equal verilog-tool `verilog-compiler)] | |
954 ) | |
955 ("Move" | |
956 ["Beginning of function" verilog-beg-of-defun t] | |
957 ["End of function" verilog-end-of-defun t] | |
958 ["Mark function" verilog-mark-defun t] | |
959 ["Goto function/module" verilog-goto-defun t] | |
960 ["Move to beginning of block" electric-verilog-backward-sexp t] | |
961 ["Move to end of block" electric-verilog-forward-sexp t] | |
962 ) | |
963 ("Comments" | |
964 ["Comment Region" verilog-comment-region t] | |
965 ["UnComment Region" verilog-uncomment-region t] | |
966 ["Multi-line comment insert" verilog-star-comment t] | |
967 ["Lint error to comment" verilog-lint-off t] | |
968 ) | |
969 "----" | |
970 ["Compile" compile t] | |
971 ["AUTO, Save, Compile" verilog-auto-save-compile t] | |
972 ["Next Compile Error" next-error t] | |
973 ["Ignore Lint Warning at point" verilog-lint-off t] | |
974 "----" | |
975 ["Line up declarations around point" verilog-pretty-declarations t] | |
976 ["Line up equations around point" verilog-pretty-expr t] | |
977 ["Redo/insert comments on every end" verilog-label-be t] | |
978 ["Expand [x:y] vector line" verilog-expand-vector t] | |
979 ["Insert begin-end block" verilog-insert-block t] | |
980 ["Complete word" verilog-complete-word t] | |
981 "----" | |
982 ["Recompute AUTOs" verilog-auto t] | |
983 ["Kill AUTOs" verilog-delete-auto t] | |
984 ["Inject AUTOs" verilog-inject-auto t] | |
985 ("AUTO Help..." | |
986 ["AUTO General" (describe-function 'verilog-auto) t] | |
987 ["AUTO Library Flags" (describe-variable 'verilog-library-flags) t] | |
988 ["AUTO Library Path" (describe-variable 'verilog-library-directories) t] | |
989 ["AUTO Library Files" (describe-variable 'verilog-library-files) t] | |
990 ["AUTO Library Extensions" (describe-variable 'verilog-library-extensions) t] | |
991 ["AUTO `define Reading" (describe-function 'verilog-read-defines) t] | |
992 ["AUTO `include Reading" (describe-function 'verilog-read-includes) t] | |
993 ["AUTOARG" (describe-function 'verilog-auto-arg) t] | |
994 ["AUTOASCIIENUM" (describe-function 'verilog-auto-ascii-enum) t] | |
995 ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module) t] | |
996 ["AUTOINOUT" (describe-function 'verilog-auto-inout) t] | |
997 ["AUTOINPUT" (describe-function 'verilog-auto-input) t] | |
998 ["AUTOINST" (describe-function 'verilog-auto-inst) t] | |
999 ["AUTOINST (.*)" (describe-function 'verilog-auto-star) t] | |
1000 ["AUTOINSTPARAM" (describe-function 'verilog-auto-inst-param) t] | |
1001 ["AUTOOUTPUT" (describe-function 'verilog-auto-output) t] | |
1002 ["AUTOOUTPUTEVERY" (describe-function 'verilog-auto-output-every) t] | |
1003 ["AUTOREG" (describe-function 'verilog-auto-reg) t] | |
1004 ["AUTOREGINPUT" (describe-function 'verilog-auto-reg-input) t] | |
1005 ["AUTORESET" (describe-function 'verilog-auto-reset) t] | |
1006 ["AUTOSENSE" (describe-function 'verilog-auto-sense) t] | |
1007 ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff) t] | |
1008 ["AUTOUNUSED" (describe-function 'verilog-auto-unused) t] | |
1009 ["AUTOWIRE" (describe-function 'verilog-auto-wire) t] | |
1010 ) | |
1011 "----" | |
1012 ["Submit bug report" verilog-submit-bug-report t] | |
1013 ["Version and FAQ" verilog-faq t] | |
1014 ["Customize Verilog Mode..." verilog-customize t] | |
1015 ["Customize Verilog Fonts & Colors" verilog-font-customize t] | |
1016 ) | |
1017 "Emacs menu for VERILOG mode." | |
1018 ) | |
1019 (defvar verilog-statement-menu | |
1020 '("Statements" | |
1021 ["Header" verilog-sk-header t] | |
1022 ["Comment" verilog-sk-comment t] | |
1023 "----" | |
1024 ["Module" verilog-sk-module t] | |
1025 ["Primitive" verilog-sk-primitive t] | |
1026 "----" | |
1027 ["Input" verilog-sk-input t] | |
1028 ["Output" verilog-sk-output t] | |
1029 ["Inout" verilog-sk-inout t] | |
1030 ["Wire" verilog-sk-wire t] | |
1031 ["Reg" verilog-sk-reg t] | |
1032 ["Define thing under point as a register" verilog-sk-define-signal t] | |
1033 "----" | |
1034 ["Initial" verilog-sk-initial t] | |
1035 ["Always" verilog-sk-always t] | |
1036 ["Function" verilog-sk-function t] | |
1037 ["Task" verilog-sk-task t] | |
1038 ["Specify" verilog-sk-specify t] | |
1039 ["Generate" verilog-sk-generate t] | |
1040 "----" | |
1041 ["Begin" verilog-sk-begin t] | |
1042 ["If" verilog-sk-if t] | |
1043 ["(if) else" verilog-sk-else-if t] | |
1044 ["For" verilog-sk-for t] | |
1045 ["While" verilog-sk-while t] | |
1046 ["Fork" verilog-sk-fork t] | |
1047 ["Repeat" verilog-sk-repeat t] | |
1048 ["Case" verilog-sk-case t] | |
1049 ["Casex" verilog-sk-casex t] | |
1050 ["Casez" verilog-sk-casez t] | |
1051 ) | |
1052 "Menu for statement templates in Verilog." | |
1053 ) | |
1054 | |
1055 (easy-menu-define verilog-menu verilog-mode-map "Menu for Verilog mode" | |
1056 verilog-xemacs-menu) | |
1057 (easy-menu-define verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog." | |
1058 verilog-statement-menu) | |
1059 | |
1060 (defvar verilog-mode-abbrev-table nil | |
1061 "Abbrev table in use in Verilog-mode buffers.") | |
1062 | |
1063 (define-abbrev-table 'verilog-mode-abbrev-table ()) | |
1064 | |
79547
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1065 ;; |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1066 ;; Macros |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1067 ;; |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1068 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1069 (defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1070 "Replace occurrences of FROM-STRING with TO-STRING. |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1071 FIXEDCASE and LITERAL as in `replace-match`. STRING is what to replace. |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1072 The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\") |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1073 will break, as the o's continuously replace. xa -> x works ok though." |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1074 ;; Hopefully soon to a emacs built-in |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1075 (let ((start 0)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1076 (while (string-match from-string string start) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1077 (setq string (replace-match to-string fixedcase literal string) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1078 start (min (length string) (match-end 0)))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1079 string)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1080 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1081 (defsubst verilog-string-remove-spaces (string) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1082 "Remove spaces surrounding STRING." |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1083 (save-match-data |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1084 (setq string (verilog-string-replace-matches "^\\s-+" "" nil nil string)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1085 (setq string (verilog-string-replace-matches "\\s-+$" "" nil nil string)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1086 string)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1087 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1088 (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1089 ; checkdoc-params: (REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1090 "Like `re-search-forward', but skips over match in comments or strings." |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1091 (store-match-data '(nil nil)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1092 (while (and |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1093 (re-search-forward REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1094 (and (verilog-skip-forward-comment-or-string) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1095 (progn |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1096 (store-match-data '(nil nil)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1097 (if BOUND |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1098 (< (point) BOUND) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1099 t) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1100 )))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1101 (match-end 0)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1102 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1103 (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1104 ; checkdoc-params: (REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1105 "Like `re-search-backward', but skips over match in comments or strings." |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1106 (store-match-data '(nil nil)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1107 (while (and |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1108 (re-search-backward REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1109 (and (verilog-skip-backward-comment-or-string) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1110 (progn |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1111 (store-match-data '(nil nil)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1112 (if BOUND |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1113 (> (point) BOUND) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1114 t) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1115 )))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1116 (match-end 0)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1117 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1118 (defsubst verilog-re-search-forward-quick (regexp bound noerror) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1119 "Like `verilog-re-search-forward', including use of REGEXP BOUND and NOERROR, |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1120 but trashes match data and is faster for REGEXP that doesn't match often. |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1121 This may at some point use text properties to ignore comments, |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1122 so there may be a large up front penalty for the first search." |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1123 (let (pt) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1124 (while (and (not pt) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1125 (re-search-forward regexp bound noerror)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1126 (if (not (verilog-inside-comment-p)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1127 (setq pt (match-end 0)))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1128 pt)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1129 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1130 (defsubst verilog-re-search-backward-quick (regexp bound noerror) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1131 ; checkdoc-params: (REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1132 "Like `verilog-re-search-backward', including use of REGEXP BOUND and NOERROR, |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1133 but trashes match data and is faster for REGEXP that doesn't match often. |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1134 This may at some point use text properties to ignore comments, |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1135 so there may be a large up front penalty for the first search." |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1136 (let (pt) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1137 (while (and (not pt) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1138 (re-search-backward regexp bound noerror)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1139 (if (not (verilog-inside-comment-p)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1140 (setq pt (match-end 0)))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1141 pt)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1142 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1143 (defsubst verilog-get-beg-of-line (&optional arg) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1144 (save-excursion |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1145 (beginning-of-line arg) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1146 (point))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1147 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1148 (defsubst verilog-get-end-of-line (&optional arg) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1149 (save-excursion |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1150 (end-of-line arg) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1151 (point))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1152 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1153 (defsubst verilog-within-string () |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1154 (save-excursion |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1155 (nth 3 (parse-partial-sexp (verilog-get-beg-of-line) (point))))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1156 |
79545 | 1157 ;; compilation program |
1158 (defun verilog-set-compile-command () | |
1159 "Function to compute shell command to compile verilog. | |
1160 | |
1161 This reads `verilog-tool' and sets `compile-command'. This specifies the | |
1162 program that executes when you type \\[compile] or | |
1163 \\[verilog-auto-save-compile]. | |
1164 | |
1165 By default `verilog-tool' uses a Makefile if one exists in the current | |
1166 directory. If not, it is set to the `verilog-linter', `verilog-coverage', | |
1167 `verilog-simulator', or `verilog-compiler' variables, as selected with the | |
1168 Verilog -> \"Choose Compilation Action\" menu. | |
1169 | |
1170 You should set `verilog-tool' or the other variables to the path and | |
1171 arguments for your Verilog simulator. For example: | |
1172 \"vcs -p123 -O\" | |
1173 or a string like: | |
1174 \"(cd /tmp; surecov %s)\". | |
1175 | |
1176 In the former case, the path to the current buffer is concat'ed to the | |
1177 value of `verilog-tool'; in the later, the path to the current buffer is | |
1178 substituted for the %s. | |
1179 | |
1180 Where __FILE__ appears in the string, the buffer-file-name of the current | |
1181 buffer, without the directory portion, will be substituted." | |
1182 (interactive) | |
1183 (cond | |
1184 ((or (file-exists-p "makefile") ;If there is a makefile, use it | |
1185 (file-exists-p "Makefile")) | |
1186 (make-local-variable 'compile-command) | |
1187 (setq compile-command "make ")) | |
1188 (t | |
1189 (make-local-variable 'compile-command) | |
1190 (setq compile-command | |
1191 (if verilog-tool | |
1192 (if (string-match "%s" (eval verilog-tool)) | |
1193 (format (eval verilog-tool) (or buffer-file-name "")) | |
1194 (concat (eval verilog-tool) " " (or buffer-file-name ""))) | |
1195 "")))) | |
1196 (verilog-modify-compile-command)) | |
1197 | |
1198 (defun verilog-modify-compile-command () | |
1199 "Replace meta-information in `compile-command'. | |
1200 Where __FILE__ appears in the string, the current buffer's file-name, | |
1201 without the directory portion, will be substituted." | |
1202 (when (and | |
1203 (stringp compile-command) | |
1204 (string-match "\\b__FILE__\\b" compile-command)) | |
1205 (make-local-variable 'compile-command) | |
1206 (setq compile-command | |
1207 (verilog-string-replace-matches | |
1208 "\\b__FILE__\\b" (file-name-nondirectory (buffer-file-name)) | |
1209 t t compile-command)))) | |
1210 | |
1211 (defun verilog-error-regexp-add () | |
1212 "Add the messages to the `compilation-error-regexp-alist'. | |
1213 Called by `compilation-mode-hook'. This allows \\[next-error] to find the errors." | |
1214 (if (not verilog-error-regexp-add-didit) | |
1215 (progn | |
1216 (setq verilog-error-regexp-add-didit t) | |
1217 (setq-default compilation-error-regexp-alist | |
1218 (append verilog-error-regexp | |
1219 (default-value 'compilation-error-regexp-alist))) | |
1220 ;; Could be buffer local at this point; maybe also in let; change all three | |
1221 (setq compilation-error-regexp-alist (default-value 'compilation-error-regexp-alist)) | |
1222 (set (make-local-variable 'compilation-error-regexp-alist) | |
1223 (default-value 'compilation-error-regexp-alist)) | |
1224 ))) | |
1225 | |
1226 (add-hook 'compilation-mode-hook 'verilog-error-regexp-add) | |
1227 | |
1228 (defconst verilog-directive-re | |
1229 ;; "`case" "`default" "`define" "`define" "`else" "`endfor" "`endif" | |
1230 ;; "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef" | |
1231 ;; "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale" | |
1232 ;; "`time_scale" "`undef" "`while" | |
1233 "\\<`\\(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\\)\\>") | |
1234 | |
1235 (defconst verilog-directive-begin | |
1236 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>") | |
1237 | |
1238 (defconst verilog-directive-middle | |
1239 "\\<`\\(else\\|default\\|case\\)\\>") | |
1240 | |
1241 (defconst verilog-directive-end | |
1242 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>") | |
1243 | |
1244 (defconst verilog-directive-re-1 | |
1245 (concat "[ \t]*" verilog-directive-re)) | |
1246 | |
1247 ;; | |
1248 ;; Regular expressions used to calculate indent, etc. | |
1249 ;; | |
1250 (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>") | |
1251 (defconst verilog-case-re "\\(\\<case[xz]?\\>\\|\\<randcase\\>\\)") | |
1252 ;; Want to match | |
1253 ;; aa : | |
1254 ;; aa,bb : | |
1255 ;; a[34:32] : | |
1256 ;; a, | |
1257 ;; b : | |
1258 | |
1259 (defconst verilog-no-indent-begin-re | |
1260 "\\<\\(if\\|else\\|while\\|for\\|repeat\\|always\\|always_comb\\|always_ff\\|always_latch\\)\\>") | |
1261 | |
1262 (defconst verilog-ends-re | |
1263 ;; Parenthesis indicate type of keyword found | |
1264 (concat | |
1265 "\\(\\<else\\>\\)\\|" ; 1 | |
1266 "\\(\\<if\\>\\)\\|" ; 2 | |
1267 "\\(\\<end\\>\\)\\|" ; 3 | |
1268 "\\(\\<endcase\\>\\)\\|" ; 4 | |
1269 "\\(\\<endfunction\\>\\)\\|" ; 5 | |
1270 "\\(\\<endtask\\>\\)\\|" ; 6 | |
1271 "\\(\\<endspecify\\>\\)\\|" ; 7 | |
1272 "\\(\\<endtable\\>\\)\\|" ; 8 | |
1273 "\\(\\<endgenerate\\>\\)\\|" ; 9 | |
1274 "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10 | |
1275 "\\(\\<endclass\\>\\)\\|" ; 11 | |
1276 "\\(\\<endgroup\\>\\)" ; 12 | |
1277 )) | |
1278 | |
1279 (defconst verilog-auto-end-comment-lines-re | |
1280 ;; Matches to names in this list cause auto-end-commentation | |
1281 (concat "\\(" | |
1282 verilog-directive-re "\\)\\|\\(" | |
1283 (eval-when-compile | |
1284 (verilog-regexp-words | |
1285 `( "begin" | |
1286 "else" | |
1287 "end" | |
1288 "endcase" | |
1289 "endclass" | |
1290 "endclocking" | |
1291 "endgroup" | |
1292 "endfunction" | |
1293 "endmodule" | |
1294 "endprogram" | |
1295 "endprimitive" | |
1296 "endinterface" | |
1297 "endpackage" | |
1298 "endsequence" | |
1299 "endspecify" | |
1300 "endtable" | |
1301 "endtask" | |
1302 "join" | |
1303 "join_any" | |
1304 "join_none" | |
1305 "module" | |
1306 "macromodule" | |
1307 "primitive" | |
1308 "interface" | |
1309 "package"))) | |
1310 "\\)")) | |
1311 | |
1312 ;;; NOTE: verilog-leap-to-head expects that verilog-end-block-re and | |
1313 ;;; verilog-end-block-ordered-re matches exactly the same strings. | |
1314 (defconst verilog-end-block-ordered-re | |
1315 ;; Parenthesis indicate type of keyword found | |
1316 (concat "\\(\\<endcase\\>\\)\\|" ; 1 | |
1317 "\\(\\<end\\>\\)\\|" ; 2 | |
1318 "\\(\\<end" ; 3, but not used | |
1319 "\\(" ; 4, but not used | |
1320 "\\(function\\)\\|" ; 5 | |
1321 "\\(task\\)\\|" ; 6 | |
1322 "\\(module\\)\\|" ; 7 | |
1323 "\\(primitive\\)\\|" ; 8 | |
1324 "\\(interface\\)\\|" ; 9 | |
1325 "\\(package\\)\\|" ; 10 | |
1326 "\\(class\\)\\|" ; 11 | |
1327 "\\(group\\)\\|" ; 12 | |
1328 "\\(program\\)\\|" ; 13 | |
1329 "\\(sequence\\)\\|" ; 14 | |
1330 "\\(clocking\\)\\|" ; 15 | |
1331 "\\)\\>\\)")) | |
1332 (defconst verilog-end-block-re | |
1333 (eval-when-compile | |
1334 (verilog-regexp-words | |
1335 | |
1336 `("end" ;; closes begin | |
1337 "endcase" ;; closes any of case, casex casez or randcase | |
1338 "join" "join_any" "join_none" ;; closes fork | |
1339 "endclass" | |
1340 "endtable" | |
1341 "endspecify" | |
1342 "endfunction" | |
1343 "endgenerate" | |
1344 "endtask" | |
1345 "endgroup" | |
1346 "endproperty" | |
1347 "endinterface" | |
1348 "endpackage" | |
1349 "endprogram" | |
1350 "endsequence" | |
1351 "endclocking" | |
1352 ) | |
1353 ))) | |
1354 | |
1355 | |
1356 (defconst verilog-endcomment-reason-re | |
1357 ;; Parenthesis indicate type of keyword found | |
1358 (concat | |
1359 "\\(\\<fork\\>\\)\\|" | |
1360 "\\(\\<begin\\>\\)\\|" | |
1361 "\\(\\<if\\>\\)\\|" | |
1362 "\\(\\<clocking\\>\\)\\|" | |
1363 "\\(\\<else\\>\\)\\|" | |
1364 "\\(\\<end\\>.*\\<else\\>\\)\\|" | |
1365 "\\(\\<task\\>\\)\\|" | |
1366 "\\(\\<function\\>\\)\\|" | |
1367 "\\(\\<initial\\>\\)\\|" | |
1368 "\\(\\<interface\\>\\)\\|" | |
1369 "\\(\\<package\\>\\)\\|" | |
1370 "\\(\\<final\\>\\)\\|" | |
1371 "\\(\\<always\\>\\(\[ \t\]*@\\)?\\)\\|" | |
1372 "\\(\\<always_comb\\>\\(\[ \t\]*@\\)?\\)\\|" | |
1373 "\\(\\<always_ff\\>\\(\[ \t\]*@\\)?\\)\\|" | |
1374 "\\(\\<always_latch\\>\\(\[ \t\]*@\\)?\\)\\|" | |
1375 "\\(@\\)\\|" | |
1376 "\\(\\<while\\>\\)\\|" | |
1377 "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|" | |
1378 "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|" | |
1379 "#")) | |
1380 | |
1381 (defconst verilog-named-block-re "begin[ \t]*:") | |
1382 | |
1383 ;; These words begin a block which can occur inside a module which should be indented, | |
1384 ;; and closed with the respective word from the end-block list | |
1385 | |
1386 (defconst verilog-beg-block-re | |
1387 (eval-when-compile | |
1388 (verilog-regexp-words | |
1389 `("begin" | |
1390 "case" "casex" "casez" "randcase" | |
1391 "clocking" | |
1392 "generate" | |
1393 "fork" | |
1394 "function" | |
1395 "property" | |
1396 "specify" | |
1397 "table" | |
1398 "task" | |
1399 )))) | |
1400 ;; These are the same words, in a specific order in the regular | |
1401 ;; expression so that matching will work nicely for | |
1402 ;; verilog-forward-sexp and verilog-calc-indent | |
1403 | |
1404 (defconst verilog-beg-block-re-ordered | |
1405 ( concat "\\<" | |
1406 "\\(begin\\)" ;1 | |
1407 "\\|\\(randcase\\|\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)" ; 2 | |
1408 ;; "\\|\\(randcase\\|case[xz]?\\)" ; 2 | |
1409 "\\|\\(fork\\)" ;3 | |
1410 "\\|\\(class\\)" ;4 | |
1411 "\\|\\(table\\)" ;5 | |
1412 "\\|\\(specify\\)" ;6 | |
1413 "\\|\\(function\\)" ;7 | |
1414 "\\|\\(task\\)" ;8 | |
1415 "\\|\\(generate\\)" ;9 | |
1416 "\\|\\(covergroup\\)" ;10 | |
1417 "\\|\\(property\\)" ;11 | |
1418 "\\|\\(\\(rand\\)?sequence\\)" ;12 | |
1419 "\\|\\(clocking\\)" ;13 | |
1420 "\\>")) | |
1421 | |
1422 (defconst verilog-end-block-ordered-rry | |
1423 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" | |
1424 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)" | |
1425 "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" | |
1426 "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" | |
1427 "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" | |
1428 "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" | |
1429 "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" | |
1430 "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" | |
1431 "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" | |
1432 "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" | |
1433 "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" | |
1434 "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" | |
1435 "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" | |
1436 ] ) | |
1437 | |
1438 (defconst verilog-nameable-item-re | |
1439 (eval-when-compile | |
1440 (verilog-regexp-words | |
1441 `("begin" | |
1442 "fork" | |
1443 "join" "join_any" "join_none" | |
1444 "end" | |
1445 "endcase" | |
1446 "endconfig" | |
1447 "endclass" | |
1448 "endclocking" | |
1449 "endfunction" | |
1450 "endgenerate" | |
1451 "endmodule" | |
1452 "endprimative" | |
1453 "endinterface" | |
1454 "endpackage" | |
1455 "endspecify" | |
1456 "endtable" | |
1457 "endtask" ) | |
1458 ))) | |
1459 | |
1460 (defconst verilog-declaration-opener | |
1461 (eval-when-compile | |
1462 (verilog-regexp-words | |
1463 `("module" "begin" "task" "function")))) | |
1464 | |
1465 (defconst verilog-declaration-prefix-re | |
1466 (eval-when-compile | |
1467 (verilog-regexp-words | |
1468 `( | |
1469 ;; port direction | |
79546 | 1470 "inout" "input" "output" "ref" |
79545 | 1471 ;; changeableness |
1472 "const" "static" "protected" "local" | |
1473 ;; parameters | |
79546 | 1474 "localparam" "parameter" "var" |
79545 | 1475 ;; type creation |
1476 "typedef" | |
1477 )))) | |
1478 (defconst verilog-declaration-core-re | |
1479 (eval-when-compile | |
1480 (verilog-regexp-words | |
1481 `( | |
1482 ;; integer_atom_type | |
1483 "byte" "shortint" "int" "longint" "integer" "time" | |
1484 ;; integer_vector_type | |
1485 "bit" "logic" "reg" | |
1486 ;; non_integer_type | |
1487 "shortreal" "real" "realtime" | |
1488 ;; net_type | |
1489 "supply0" "supply1" "tri" "triand" "trior" "trireg" "tri0" "tri1" "uwire" "wire" "wand" "wor" | |
1490 ;; misc | |
1491 "string" "event" "chandle" "virtual" "enum" "genvar" | |
1492 "struct" "union" | |
1493 ;; builtin classes | |
79546 | 1494 "mailbox" "semaphore" |
79545 | 1495 )))) |
79546 | 1496 (defconst verilog-declaration-re |
79545 | 1497 (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re)) |
1498 (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+") | |
1499 (defconst verilog-optional-signed-re "\\s-*\\(signed\\)?") | |
1500 (defconst verilog-optional-signed-range-re | |
1501 (concat | |
1502 "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?")) | |
1503 (defconst verilog-macroexp-re "`\\sw+") | |
1504 | |
1505 (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)") | |
1506 (defconst verilog-declaration-re-2-no-macro | |
1507 (concat "\\s-*" verilog-declaration-re | |
1508 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)" | |
1509 "\\)?")) | |
1510 (defconst verilog-declaration-re-2-macro | |
1511 (concat "\\s-*" verilog-declaration-re | |
1512 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)" | |
1513 "\\|\\(" verilog-macroexp-re "\\)" | |
1514 "\\)?")) | |
1515 (defconst verilog-declaration-re-1-macro | |
1516 (concat "^" verilog-declaration-re-2-macro)) | |
1517 | |
1518 (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro)) | |
1519 | |
1520 (defconst verilog-defun-re | |
1521 (eval-when-compile (verilog-regexp-words `("macromodule" "module" "class" "program" "interface" "package" "primitive" "config")))) | |
1522 (defconst verilog-end-defun-re | |
1523 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig")))) | |
1524 (defconst verilog-zero-indent-re | |
1525 (concat verilog-defun-re "\\|" verilog-end-defun-re)) | |
1526 | |
1527 (defconst verilog-behavioral-block-beg-re | |
1528 (concat "\\(\\<initial\\>\\|\\<final\\>\\|\\<always\\>\\|\\<always_comb\\>\\|\\<always_ff\\>\\|" | |
1529 "\\<always_latch\\>\\|\\<function\\>\\|\\<task\\>\\)")) | |
1530 | |
1531 (defconst verilog-indent-re | |
1532 (eval-when-compile | |
1533 (verilog-regexp-words | |
1534 `( | |
1535 "{" | |
1536 "always" "always_latch" "always_ff" "always_comb" | |
1537 "begin" "end" | |
1538 ; "unique" "priority" | |
1539 "case" "casex" "casez" "randcase" "endcase" | |
1540 "class" "endclass" | |
1541 "clocking" "endclocking" | |
1542 "config" "endconfig" | |
1543 "covergroup" "endgroup" | |
1544 "fork" "join" "join_any" "join_none" | |
1545 "function" "endfunction" | |
1546 "final" | |
1547 "generate" "endgenerate" | |
1548 "initial" | |
1549 "interface" "endinterface" | |
1550 "module" "macromodule" "endmodule" | |
1551 "package" "endpackage" | |
1552 "primitive" "endprimative" | |
1553 "program" "endprogram" | |
1554 "property" "endproperty" | |
1555 "sequence" "randsequence" "endsequence" | |
1556 "specify" "endspecify" | |
1557 "table" "endtable" | |
1558 "task" "endtask" | |
1559 "`case" | |
1560 "`default" | |
1561 "`define" "`undef" | |
1562 "`if" "`ifdef" "`ifndef" "`else" "`endif" | |
1563 "`while" "`endwhile" | |
1564 "`for" "`endfor" | |
1565 "`format" | |
1566 "`include" | |
1567 "`let" | |
1568 "`protect" "`endprotect" | |
1569 "`switch" "`endswitch" | |
1570 "`timescale" | |
1571 "`time_scale" | |
1572 )))) | |
1573 | |
1574 (defconst verilog-defun-level-re | |
1575 (eval-when-compile | |
1576 (verilog-regexp-words | |
1577 `( | |
1578 "module" "macromodule" "primitive" "class" "program" "initial" "final" "always" "always_comb" | |
1579 "always_ff" "always_latch" "endtask" "endfunction" "interface" "package" | |
1580 "config")))) | |
1581 | |
1582 (defconst verilog-defun-level-not-generate-re | |
1583 (eval-when-compile | |
1584 (verilog-regexp-words | |
1585 `( | |
1586 "module" "macromodule" "primitive" "class" "program" "interface" "package" "config")))) | |
1587 | |
1588 (defconst verilog-cpp-level-re | |
1589 (eval-when-compile | |
1590 (verilog-regexp-words | |
1591 `( | |
1592 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass" | |
1593 )))) | |
1594 (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?") | |
1595 (defconst verilog-extended-complete-re | |
1596 (concat "\\(\\<extern\\s-+\\|\\<virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)" | |
1597 "\\|\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)" | |
1598 "\\|" verilog-extended-case-re )) | |
1599 (defconst verilog-basic-complete-re | |
1600 (eval-when-compile | |
1601 (verilog-regexp-words | |
1602 `( | |
1603 "always" "assign" "always_latch" "always_ff" "always_comb" "constraint" | |
1604 "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while" | |
1605 "if" "for" "forever" "foreach" "else" "parameter" "do" | |
1606 )))) | |
1607 (defconst verilog-complete-reg | |
1608 (concat | |
1609 verilog-extended-complete-re | |
1610 "\\|" | |
1611 verilog-basic-complete-re)) | |
1612 | |
1613 (defconst verilog-end-statement-re | |
1614 (concat "\\(" verilog-beg-block-re "\\)\\|\\(" | |
1615 verilog-end-block-re "\\)")) | |
1616 | |
1617 (defconst verilog-endcase-re | |
1618 (concat verilog-case-re "\\|" | |
1619 "\\(endcase\\)\\|" | |
1620 verilog-defun-re | |
1621 )) | |
1622 | |
1623 (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----" | |
1624 "String used to mark beginning of excluded text.") | |
1625 (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */" | |
1626 "String used to mark end of excluded text.") | |
1627 (defconst verilog-preprocessor-re | |
1628 (eval-when-compile | |
1629 (verilog-regexp-words | |
1630 `( | |
1631 "`define" "`include" "`ifdef" "`ifndef" "`if" "`endif" "`else" | |
1632 )))) | |
1633 | |
1634 (defconst verilog-keywords | |
1635 '( "`case" "`default" "`define" "`else" "`endfor" "`endif" | |
1636 "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef" | |
1637 "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale" | |
1638 "`time_scale" "`undef" "`while" | |
1639 | |
1640 "after" "alias" "always" "always_comb" "always_ff" "always_latch" "and" | |
1641 "assert" "assign" "assume" "automatic" "before" "begin" "bind" | |
1642 "bins" "binsof" "bit" "break" "buf" "bufif0" "bufif1" "byte" | |
1643 "case" "casex" "casez" "cell" "chandle" "class" "clocking" "cmos" | |
1644 "config" "const" "constraint" "context" "continue" "cover" | |
1645 "covergroup" "coverpoint" "cross" "deassign" "default" "defparam" | |
1646 "design" "disable" "dist" "do" "edge" "else" "end" "endcase" | |
1647 "endclass" "endclocking" "endconfig" "endfunction" "endgenerate" | |
1648 "endgroup" "endinterface" "endmodule" "endpackage" "endprimitive" | |
1649 "endprogram" "endproperty" "endspecify" "endsequence" "endtable" | |
1650 "endtask" "enum" "event" "expect" "export" "extends" "extern" | |
1651 "final" "first_match" "for" "force" "foreach" "forever" "fork" | |
1652 "forkjoin" "function" "generate" "genvar" "highz0" "highz1" "if" | |
1653 "iff" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir" | |
1654 "include" "initial" "inout" "input" "inside" "instance" "int" | |
1655 "integer" "interface" "intersect" "join" "join_any" "join_none" | |
1656 "large" "liblist" "library" "local" "localparam" "logic" | |
1657 "longint" "macromodule" "mailbox" "matches" "medium" "modport" "module" | |
1658 "nand" "negedge" "new" "nmos" "nor" "noshowcancelled" "not" | |
1659 "notif0" "notif1" "null" "or" "output" "package" "packed" | |
1660 "parameter" "pmos" "posedge" "primitive" "priority" "program" | |
1661 "property" "protected" "pull0" "pull1" "pulldown" "pullup" | |
1662 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc" | |
1663 "randcase" "randsequence" "rcmos" "real" "realtime" "ref" "reg" | |
1664 "release" "repeat" "return" "rnmos" "rpmos" "rtran" "rtranif0" | |
1665 "rtranif1" "scalared" "semaphore" "sequence" "shortint" "shortreal" | |
1666 "showcancelled" "signed" "small" "solve" "specify" "specparam" | |
1667 "static" "string" "strong0" "strong1" "struct" "super" "supply0" | |
1668 "supply1" "table" "tagged" "task" "this" "throughout" "time" | |
1669 "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri" | |
1670 "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union" | |
1671 "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void" | |
1672 "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard" | |
1673 "wire" "with" "within" "wor" "xnor" "xor" | |
1674 ) | |
1675 "List of Verilog keywords.") | |
1676 | |
1677 | |
1678 (defconst verilog-emacs-features | |
1679 ;; Documentation at the bottom | |
1680 (let ((major (and (boundp 'emacs-major-version) | |
1681 emacs-major-version)) | |
1682 (minor (and (boundp 'emacs-minor-version) | |
1683 emacs-minor-version)) | |
1684 flavor comments flock-syntax) | |
1685 ;; figure out version numbers if not already discovered | |
1686 (and (or (not major) (not minor)) | |
1687 (string-match "\\([0-9]+\\).\\([0-9]+\\)" emacs-version) | |
1688 (setq major (string-to-int (substring emacs-version | |
1689 (match-beginning 1) | |
1690 (match-end 1))) | |
1691 minor (string-to-int (substring emacs-version | |
1692 (match-beginning 2) | |
1693 (match-end 2))))) | |
1694 (if (not (and major minor)) | |
1695 (error "Cannot figure out the major and minor version numbers")) | |
1696 ;; calculate the major version | |
1697 (cond | |
1698 ((= major 4) (setq major 'v18)) ;Epoch 4 | |
1699 ((= major 18) (setq major 'v18)) ;Emacs 18 | |
1700 ((= major 19) (setq major 'v19 ;Emacs 19 | |
1701 flavor (if (or (string-match "Lucid" emacs-version) | |
1702 (string-match "XEmacs" emacs-version)) | |
1703 'XEmacs 'FSF))) | |
1704 ((> major 19) (setq major 'v20 | |
1705 flavor (if (or (string-match "Lucid" emacs-version) | |
1706 (string-match "XEmacs" emacs-version)) | |
1707 'XEmacs 'FSF))) | |
1708 ;; I don't know | |
1709 (t (error "Cannot recognize major version number: %s" major))) | |
1710 ;; XEmacs 19 uses 8-bit modify-syntax-entry flags, as do all | |
1711 ;; patched Emacs 19, Emacs 18, Epoch 4's. Only Emacs 19 uses a | |
1712 ;; 1-bit flag. Let's be as smart as we can about figuring this | |
1713 ;; out. | |
1714 (if (or (eq major 'v20) (eq major 'v19)) | |
1715 (let ((table (copy-syntax-table))) | |
1716 (modify-syntax-entry ?a ". 12345678" table) | |
1717 (cond | |
1718 ;; XEmacs pre 20 and Emacs pre 19.30 use vectors for syntax tables. | |
1719 ((vectorp table) | |
1720 (if (= (logand (lsh (aref table ?a) -16) 255) 255) | |
1721 (setq comments '8-bit) | |
1722 (setq comments '1-bit))) | |
1723 ;; XEmacs 20 is known to be 8-bit | |
1724 ((eq flavor 'XEmacs) (setq comments '8-bit)) | |
1725 ;; Emacs 19.30 and beyond are known to be 1-bit | |
1726 ((eq flavor 'FSF) (setq comments '1-bit)) | |
1727 ;; Don't know what this is | |
1728 (t (error "Couldn't figure out syntax table format")) | |
1729 )) | |
1730 ;; Emacs 18 has no support for dual comments | |
1731 (setq comments 'no-dual-comments)) | |
1732 ;; determine whether to use old or new font lock syntax | |
1733 ;; We can assume 8-bit syntax table emacsen support new syntax, otherwise | |
1734 ;; look for version > 19.30 | |
1735 (setq flock-syntax | |
1736 (if (or (equal comments '8-bit) | |
1737 (equal major 'v20) | |
1738 (and (equal major 'v19) (> minor 30))) | |
1739 'flock-syntax-after-1930 | |
1740 'flock-syntax-before-1930)) | |
1741 ;; lets do some minimal sanity checking. | |
1742 (if (or | |
1743 ;; Emacs before 19.6 had bugs | |
1744 (and (eq major 'v19) (eq flavor 'XEmacs) (< minor 6)) | |
1745 ;; Emacs 19 before 19.21 has known bugs | |
1746 (and (eq major 'v19) (eq flavor 'FSF) (< minor 21)) | |
1747 ) | |
1748 (with-output-to-temp-buffer "*verilog-mode warnings*" | |
1749 (print (format | |
1750 "The version of Emacs that you are running, %s, | |
1751 has known bugs in its syntax parsing routines which will affect the | |
1752 performance of verilog-mode. You should strongly consider upgrading to the | |
1753 latest available version. verilog-mode may continue to work, after a | |
1754 fashion, but strange indentation errors could be encountered." | |
1755 emacs-version)))) | |
1756 ;; Emacs 18, with no patch is not too good | |
1757 (if (and (eq major 'v18) (eq comments 'no-dual-comments)) | |
1758 (with-output-to-temp-buffer "*verilog-mode warnings*" | |
1759 (print (format | |
1760 "The version of Emacs 18 you are running, %s, | |
1761 has known deficiencies in its ability to handle the dual verilog | |
79546 | 1762 \(and C++) comments, (e.g. the // and /* */ comments). This will |
79545 | 1763 not be much of a problem for you if you only use the /* */ comments, |
1764 but you really should strongly consider upgrading to one of the latest | |
1765 Emacs 19's. In Emacs 18, you may also experience performance degradations. | |
1766 Emacs 19 has some new built-in routines which will speed things up for you. | |
1767 Because of these inherent problems, verilog-mode is not supported | |
1768 on emacs-18." | |
1769 emacs-version)))) | |
1770 ;; Emacs 18 with the syntax patches are no longer supported | |
1771 (if (and (eq major 'v18) (not (eq comments 'no-dual-comments))) | |
1772 (with-output-to-temp-buffer "*verilog-mode warnings*" | |
1773 (print (format | |
1774 "You are running a syntax patched Emacs 18 variant. While this should | |
1775 work for you, you may want to consider upgrading to Emacs 19. | |
1776 The syntax patches are no longer supported either for verilog-mode.")))) | |
1777 (list major comments flock-syntax)) | |
1778 "A list of features extant in the Emacs you are using. | |
1779 There are many flavors of Emacs out there, each with different | |
1780 features supporting those needed by `verilog-mode'. Here's the current | |
1781 supported list, along with the values for this variable: | |
1782 | |
1783 Vanilla Emacs 18/Epoch 4: (v18 no-dual-comments flock-syntax-before-1930) | |
1784 Emacs 18/Epoch 4 (patch2): (v18 8-bit flock-syntax-after-1930) | |
1785 XEmacs (formerly Lucid) 19: (v19 8-bit flock-syntax-after-1930) | |
1786 XEmacs 20: (v20 8-bit flock-syntax-after-1930) | |
1787 Emacs 19.1-19.30: (v19 8-bit flock-syntax-before-1930) | |
1788 Emacs 19.31-19.xx: (v19 8-bit flock-syntax-after-1930) | |
1789 Emacs20 : (v20 1-bit flock-syntax-after-1930).") | |
1790 | |
1791 (defconst verilog-comment-start-regexp "//\\|/\\*" | |
1792 "Dual comment value for `comment-start-regexp'.") | |
1793 | |
1794 (defun verilog-populate-syntax-table (table) | |
1795 "Populate the syntax TABLE." | |
1796 (modify-syntax-entry ?\\ "\\" table) | |
1797 (modify-syntax-entry ?+ "." table) | |
1798 (modify-syntax-entry ?- "." table) | |
1799 (modify-syntax-entry ?= "." table) | |
1800 (modify-syntax-entry ?% "." table) | |
1801 (modify-syntax-entry ?< "." table) | |
1802 (modify-syntax-entry ?> "." table) | |
1803 (modify-syntax-entry ?& "." table) | |
1804 (modify-syntax-entry ?| "." table) | |
1805 (modify-syntax-entry ?` "w" table) | |
1806 (modify-syntax-entry ?_ "w" table) | |
1807 (modify-syntax-entry ?\' "." table) | |
1808 ) | |
1809 | |
1810 (defun verilog-setup-dual-comments (table) | |
1811 "Set up TABLE to handle block and line style comments." | |
1812 (cond | |
1813 ((memq '8-bit verilog-emacs-features) | |
1814 ;; XEmacs (formerly Lucid) has the best implementation | |
1815 (modify-syntax-entry ?/ ". 1456" table) | |
1816 (modify-syntax-entry ?* ". 23" table) | |
1817 (modify-syntax-entry ?\n "> b" table) | |
1818 ) | |
1819 ((memq '1-bit verilog-emacs-features) | |
1820 ;; Emacs 19 does things differently, but we can work with it | |
1821 (modify-syntax-entry ?/ ". 124b" table) | |
1822 (modify-syntax-entry ?* ". 23" table) | |
1823 (modify-syntax-entry ?\n "> b" table) | |
1824 ) | |
1825 )) | |
1826 | |
1827 (defvar verilog-mode-syntax-table nil | |
1828 "Syntax table used in `verilog-mode' buffers.") | |
1829 | |
1830 (defconst verilog-font-lock-keywords nil | |
1831 "Default highlighting for Verilog mode.") | |
1832 | |
1833 (defconst verilog-font-lock-keywords-1 nil | |
1834 "Subdued level highlighting for Verilog mode.") | |
1835 | |
1836 (defconst verilog-font-lock-keywords-2 nil | |
1837 "Medium level highlighting for Verilog mode. | |
1838 See also `verilog-font-lock-extra-types'.") | |
1839 | |
1840 (defconst verilog-font-lock-keywords-3 nil | |
1841 "Gaudy level highlighting for Verilog mode. | |
1842 See also `verilog-font-lock-extra-types'.") | |
1843 (defvar verilog-font-lock-translate-off-face | |
1844 'verilog-font-lock-translate-off-face | |
1845 "Font to use for translated off regions.") | |
1846 (defface verilog-font-lock-translate-off-face | |
1847 '((((class color) | |
1848 (background light)) | |
1849 (:background "gray90" :italic t )) | |
1850 (((class color) | |
1851 (background dark)) | |
1852 (:background "gray10" :italic t )) | |
1853 (((class grayscale) (background light)) | |
1854 (:foreground "DimGray" :italic t)) | |
1855 (((class grayscale) (background dark)) | |
1856 (:foreground "LightGray" :italic t)) | |
1857 (t (:italis t))) | |
1858 "Font lock mode face used to background highlight translate-off regions." | |
1859 :group 'font-lock-highlighting-faces) | |
1860 | |
1861 (defvar verilog-font-lock-p1800-face | |
1862 'verilog-font-lock-p1800-face | |
1863 "Font to use for p1800 keywords.") | |
1864 (defface verilog-font-lock-p1800-face | |
1865 '((((class color) | |
1866 (background light)) | |
1867 (:foreground "DarkOrange3" :bold t )) | |
1868 (((class color) | |
1869 (background dark)) | |
1870 (:foreground "orange1" :bold t )) | |
1871 (t (:italic t))) | |
1872 "Font lock mode face used to highlight P1800 keywords." | |
1873 :group 'font-lock-highlighting-faces) | |
1874 | |
1875 (defvar verilog-font-lock-ams-face | |
1876 'verilog-font-lock-ams-face | |
1877 "Font to use for Analog/Mixed Signal keywords.") | |
1878 (defface verilog-font-lock-ams-face | |
1879 '((((class color) | |
1880 (background light)) | |
1881 (:foreground "Purple" :bold t )) | |
1882 (((class color) | |
1883 (background dark)) | |
1884 (:foreground "orange1" :bold t )) | |
1885 (t (:italic t))) | |
1886 "Font lock mode face used to highlight AMS keywords." | |
1887 :group 'font-lock-highlighting-faces) | |
1888 | |
1889 (let* ((verilog-type-font-keywords | |
1890 (eval-when-compile | |
1891 (verilog-regexp-opt | |
1892 '( | |
1893 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam" | |
1894 "event" "genvar" "inout" "input" "integer" "localparam" | |
1895 "logic" "mailbox" "nand" "nmos" "not" "notif0" "notif1" "or" | |
1896 "output" "parameter" "pmos" "pull0" "pull1" "pullup" | |
1897 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" | |
1898 "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply" | |
1899 "supply0" "supply1" "time" "tran" "tranif0" "tranif1" | |
1900 "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef" | |
1901 "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor" | |
1902 ) nil ))) | |
1903 | |
1904 (verilog-pragma-keywords | |
1905 (eval-when-compile | |
1906 (verilog-regexp-opt | |
1907 '("surefire" "synopsys" "rtl_synthesis" "verilint" ) nil | |
1908 ))) | |
1909 | |
1910 (verilog-p1800-keywords | |
1911 (eval-when-compile | |
1912 (verilog-regexp-opt | |
1913 '("alias" "assert" "assume" "automatic" "before" "bind" | |
1914 "bins" "binsof" "break" "byte" "cell" "chandle" "class" | |
1915 "clocking" "config" "const" "constraint" "context" "continue" | |
1916 "cover" "covergroup" "coverpoint" "cross" "deassign" "design" | |
1917 "dist" "do" "edge" "endclass" "endclocking" "endconfig" | |
1918 "endgroup" "endprogram" "endproperty" "endsequence" "enum" | |
1919 "expect" "export" "extends" "extern" "first_match" "foreach" | |
1920 "forkjoin" "genvar" "highz0" "highz1" "ifnone" "ignore_bins" | |
1921 "illegal_bins" "import" "incdir" "include" "inside" "instance" | |
1922 "int" "intersect" "large" "liblist" "library" "local" "longint" | |
1923 "matches" "medium" "modport" "new" "noshowcancelled" "null" | |
1924 "packed" "program" "property" "protected" "pull0" "pull1" | |
1925 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc" | |
1926 "randcase" "randsequence" "ref" "release" "return" "scalared" | |
1927 "sequence" "shortint" "shortreal" "showcancelled" "small" "solve" | |
1928 "specparam" "static" "string" "strong0" "strong1" "struct" | |
1929 "super" "tagged" "this" "throughout" "timeprecision" "timeunit" | |
1930 "type" "union" "unsigned" "use" "var" "virtual" "void" | |
1931 "wait_order" "weak0" "weak1" "wildcard" "with" "within" | |
1932 ) nil ))) | |
1933 | |
1934 (verilog-ams-keywords | |
1935 (eval-when-compile | |
1936 (verilog-regexp-opt | |
1937 '("above" "abs" "absdelay" "acos" "acosh" "ac_stim" | |
1938 "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh" | |
1939 "branch" "ceil" "connectmodule" "connectrules" "cos" "cosh" "ddt" | |
1940 "ddx" "discipline" "driver_update" "enddiscipline" "endconnectrules" | |
1941 "endnature" "endparamset" "exclude" "exp" "final_step" "flicker_noise" | |
1942 "floor" "flow" "from" "ground" "hypot" "idt" "idtmod" "inf" | |
1943 "initial_step" "laplace_nd" "laplace_np" "laplace_zd" "laplace_zp" | |
1944 "last_crossing" "limexp" "ln" "log" "max" "min" "nature" | |
1945 "net_resolution" "noise_table" "paramset" "potential" "pow" "sin" | |
1946 "sinh" "slew" "sqrt" "tan" "tanh" "timer" "transition" "white_noise" | |
1947 "wreal" "zi_nd" "zi_np" "zi_zd" ) nil ))) | |
1948 | |
1949 (verilog-font-keywords | |
1950 (eval-when-compile | |
1951 (verilog-regexp-opt | |
1952 '( | |
1953 "assign" "begin" "case" "casex" "casez" "randcase" "deassign" | |
1954 "default" "disable" "else" "end" "endcase" "endfunction" | |
1955 "endgenerate" "endinterface" "endmodule" "endprimitive" | |
1956 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break" | |
1957 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial" | |
1958 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge" | |
1959 "package" "endpackage" "always" "always_comb" "always_ff" | |
1960 "always_latch" "posedge" "primitive" "priority" "release" | |
1961 "repeat" "specify" "table" "task" "unique" "wait" "while" | |
1962 "class" "program" "endclass" "endprogram" | |
1963 ) nil )))) | |
1964 | |
1965 (setq verilog-font-lock-keywords | |
1966 (list | |
1967 ;; Fontify all builtin keywords | |
1968 (concat "\\<\\(" verilog-font-keywords "\\|" | |
1969 ;; And user/system tasks and functions | |
1970 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*" | |
1971 "\\)\\>") | |
1972 ;; Fontify all types | |
1973 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>") | |
1974 'font-lock-type-face) | |
1975 ;; Fontify IEEE-P1800 keywords appropriately | |
1976 (if verilog-highlight-p1800-keywords | |
1977 (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>") | |
1978 'verilog-font-lock-p1800-face) | |
1979 (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>") | |
1980 'font-lock-type-face)) | |
1981 ;; Fontify Verilog-AMS keywords | |
1982 (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>") | |
1983 'verilog-font-lock-ams-face) | |
1984 )) | |
1985 | |
1986 (setq verilog-font-lock-keywords-1 | |
1987 (append verilog-font-lock-keywords | |
1988 (list | |
1989 ;; Fontify module definitions | |
1990 (list | |
1991 "\\<\\(\\(macro\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)" | |
1992 '(1 font-lock-keyword-face) | |
1993 '(3 font-lock-function-name-face 'prepend)) | |
1994 ;; Fontify function definitions | |
1995 (list | |
1996 (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" ) | |
1997 '(1 font-lock-keyword-face) | |
1998 '(3 font-lock-reference-face prepend) | |
1999 ) | |
2000 '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)" | |
2001 (1 font-lock-keyword-face) | |
2002 (2 font-lock-reference-face append) | |
2003 ) | |
2004 '("\\<function\\>\\s-+\\(\\sw+\\)" | |
2005 1 'font-lock-reference-face append) | |
2006 ))) | |
2007 | |
2008 (setq verilog-font-lock-keywords-2 | |
2009 (append verilog-font-lock-keywords-1 | |
2010 (list | |
2011 ;; Fontify pragmas | |
2012 (concat "\\(//\\s-*" verilog-pragma-keywords "\\s-.*\\)") | |
2013 ;; Fontify escaped names | |
2014 '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face) | |
2015 ;; Fontify macro definitions/ uses | |
2016 '("`\\s-*[A-Za-z][A-Za-z0-9_]*" 0 (if (boundp 'font-lock-preprocessor-face) | |
2017 'font-lock-preprocessor-face | |
2018 'font-lock-type-face)) | |
2019 ;; Fontify delays/numbers | |
2020 '("\\(@\\)\\|\\(#\\s-*\\(\\(\[0-9_.\]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)" | |
2021 0 font-lock-type-face append) | |
2022 ;; Fontify instantiation names | |
2023 '("\\([A-Za-z][A-Za-z0-9_]+\\)\\s-*(" 1 font-lock-function-name-face) | |
2024 | |
2025 ))) | |
2026 | |
2027 (setq verilog-font-lock-keywords-3 | |
2028 (append verilog-font-lock-keywords-2 | |
2029 (when verilog-highlight-translate-off | |
2030 (list | |
2031 ;; Fontify things in translate off regions | |
2032 '(verilog-match-translate-off (0 'verilog-font-lock-translate-off-face prepend)) | |
2033 ))) | |
2034 ) | |
2035 ) | |
2036 | |
2037 | |
2038 | |
2039 (defun verilog-inside-comment-p () | |
2040 "Check if point inside a nested comment." | |
2041 (save-excursion | |
2042 (let ((st-point (point)) hitbeg) | |
2043 (or (search-backward "//" (verilog-get-beg-of-line) t) | |
2044 (if (progn | |
2045 ;; This is for tricky case //*, we keep searching if /* is proceeded by // on same line | |
2046 (while (and (setq hitbeg (search-backward "/*" nil t)) | |
2047 (progn (forward-char 1) (search-backward "//" (verilog-get-beg-of-line) t)))) | |
2048 hitbeg) | |
2049 (not (search-forward "*/" st-point t))))))) | |
2050 | |
2051 (defun verilog-declaration-end () | |
2052 (search-forward ";")) | |
2053 | |
2054 (defun verilog-point-text (&optional pointnum) | |
2055 "Return text describing where POINTNUM or current point is (for errors). | |
2056 Use filename, if current buffer being edited shorten to just buffer name." | |
2057 (concat (or (and (equal (window-buffer (selected-window)) (current-buffer)) | |
2058 (buffer-name)) | |
2059 buffer-file-name | |
2060 (buffer-name)) | |
2061 ":" (int-to-string (count-lines (point-min) (or pointnum (point)))))) | |
2062 | |
2063 (defun electric-verilog-backward-sexp () | |
2064 "Move backward over a sexp." | |
2065 (interactive) | |
2066 ;; before that see if we are in a comment | |
2067 (verilog-backward-sexp) | |
2068 ) | |
2069 (defun electric-verilog-forward-sexp () | |
2070 "Move backward over a sexp." | |
2071 (interactive) | |
2072 ;; before that see if we are in a comment | |
2073 (verilog-forward-sexp) | |
2074 ) | |
2075 ;;;used by hs-minor-mode | |
2076 (defun verilog-forward-sexp-function (arg) | |
2077 (if (< arg 0) | |
2078 (verilog-backward-sexp) | |
2079 (verilog-forward-sexp))) | |
2080 | |
2081 | |
2082 (defun verilog-backward-sexp () | |
2083 (let ((reg) | |
2084 (elsec 1) | |
2085 (found nil) | |
2086 (st (point)) | |
2087 ) | |
2088 (if (not (looking-at "\\<")) | |
2089 (forward-word -1)) | |
2090 (cond | |
2091 ((verilog-skip-backward-comment-or-string) | |
2092 ) | |
2093 ((looking-at "\\<else\\>") | |
2094 (setq reg (concat | |
2095 verilog-end-block-re | |
2096 "\\|\\(\\<else\\>\\)" | |
2097 "\\|\\(\\<if\\>\\)" | |
2098 )) | |
2099 (while (and (not found) | |
2100 (verilog-re-search-backward reg nil 'move)) | |
2101 (cond | |
2102 ((match-end 1) ; matched verilog-end-block-re | |
2103 ; try to leap back to matching outward block by striding across | |
2104 ; indent level changing tokens then immediately | |
2105 ; previous line governs indentation. | |
2106 (verilog-leap-to-head)) | |
2107 ((match-end 2) ; else, we're in deep | |
2108 (setq elsec (1+ elsec))) | |
2109 ((match-end 3) ; found it | |
2110 (setq elsec (1- elsec)) | |
2111 (if (= 0 elsec) | |
2112 ;; Now previous line describes syntax | |
2113 (setq found 't) | |
2114 )) | |
2115 ) | |
2116 ) | |
2117 ) | |
2118 ((looking-at verilog-end-block-re) | |
2119 (verilog-leap-to-head)) | |
2120 ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)\\|\\(\\<endclass\\>\\)\\|\\(\\<endprogram\\>\\)\\|\\(\\<endinterface\\>\\)\\|\\(\\<endpackage\\>\\)") | |
2121 (cond | |
2122 ((match-end 1) | |
2123 (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move)) | |
2124 ((match-end 2) | |
2125 (verilog-re-search-backward "\\<primitive\\>" nil 'move)) | |
2126 ((match-end 3) | |
2127 (verilog-re-search-backward "\\<class\\>" nil 'move)) | |
2128 ((match-end 4) | |
2129 (verilog-re-search-backward "\\<program\\>" nil 'move)) | |
2130 ((match-end 5) | |
2131 (verilog-re-search-backward "\\<interface\\>" nil 'move)) | |
2132 ((match-end 6) | |
2133 (verilog-re-search-backward "\\<package\\>" nil 'move)) | |
2134 (t | |
2135 (goto-char st) | |
2136 (backward-sexp 1)))) | |
2137 (t | |
2138 (goto-char st) | |
2139 (backward-sexp)) | |
2140 ) ;; cond | |
2141 )) | |
2142 | |
2143 (defun verilog-forward-sexp () | |
2144 (let ((reg) | |
2145 (md 2) | |
2146 (st (point))) | |
2147 (if (not (looking-at "\\<")) | |
2148 (forward-word -1)) | |
2149 (cond | |
2150 ((verilog-skip-forward-comment-or-string) | |
2151 (verilog-forward-syntactic-ws) | |
2152 ) | |
2153 ((looking-at verilog-beg-block-re-ordered);; begin|case|fork|class|table|specify|function|task|generate|covergroup|property|sequence|clocking | |
2154 (cond | |
2155 ((match-end 1) ; end | |
2156 ;; Search forward for matching begin | |
2157 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" )) | |
2158 ((match-end 2) ; endcase | |
2159 ;; Search forward for matching case | |
2160 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ) | |
2161 ) | |
2162 ((match-end 3) ; join | |
2163 ;; Search forward for matching fork | |
2164 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )) | |
2165 ((match-end 4) ; endclass | |
2166 ;; Search forward for matching class | |
2167 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" )) | |
2168 ((match-end 5) ; endtable | |
2169 ;; Search forward for matching table | |
2170 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )) | |
2171 ((match-end 6) ; endspecify | |
2172 ;; Search forward for matching specify | |
2173 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )) | |
2174 ((match-end 7) ; endfunction | |
2175 ;; Search forward for matching function | |
2176 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )) | |
2177 ((match-end 8) ; endtask | |
2178 ;; Search forward for matching task | |
2179 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" )) | |
2180 ((match-end 9) ; endgenerate | |
2181 ;; Search forward for matching generate | |
2182 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" )) | |
2183 ((match-end 10) ; endgroup | |
2184 ;; Search forward for matching covergroup | |
2185 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )) | |
2186 ((match-end 11) ; endproperty | |
2187 ;; Search forward for matching property | |
2188 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" )) | |
2189 ((match-end 12) ; endsequence | |
2190 ;; Search forward for matching sequence | |
2191 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ) | |
2192 (setq md 3) ; 3 to get to endsequence in the reg above | |
2193 ) | |
2194 ((match-end 13) ; endclocking | |
2195 ;; Search forward for matching clocking | |
2196 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )) | |
2197 ) | |
2198 (if (forward-word 1) | |
2199 (catch 'skip | |
2200 (let ((nest 1)) | |
2201 (while (verilog-re-search-forward reg nil 'move) | |
2202 (cond | |
2203 ((match-end md) ; the closer in reg, so we are climbing out | |
2204 (setq nest (1- nest)) | |
2205 (if (= 0 nest) ; we are out! | |
2206 (throw 'skip 1))) | |
2207 ((match-end 1) ; the opener in reg, so we are deeper now | |
2208 (setq nest (1+ nest))))) | |
2209 ))) | |
2210 ) | |
2211 ((looking-at (concat | |
2212 "\\(\\<\\(macro\\)?module\\>\\)\\|" | |
2213 "\\(\\<primitive\\>\\)\\|" | |
2214 "\\(\\<class\\>\\)\\|" | |
2215 "\\(\\<program\\>\\)\\|" | |
2216 "\\(\\<interface\\>\\)\\|" | |
2217 "\\(\\<package\\>\\)")) | |
2218 (cond | |
2219 ((match-end 1) | |
2220 (verilog-re-search-forward "\\<endmodule\\>" nil 'move)) | |
2221 ((match-end 2) | |
2222 (verilog-re-search-forward "\\<endprimitive\\>" nil 'move)) | |
2223 ((match-end 3) | |
2224 (verilog-re-search-forward "\\<endclass\\>" nil 'move)) | |
2225 ((match-end 4) | |
2226 (verilog-re-search-forward "\\<endprogram\\>" nil 'move)) | |
2227 ((match-end 5) | |
2228 (verilog-re-search-forward "\\<endinterface\\>" nil 'move)) | |
2229 ((match-end 6) | |
2230 (verilog-re-search-forward "\\<endpackage\\>" nil 'move)) | |
2231 (t | |
2232 (goto-char st) | |
2233 (if (= (following-char) ?\) ) | |
2234 (forward-char 1) | |
2235 (forward-sexp 1))))) | |
2236 (t | |
2237 (goto-char st) | |
2238 (if (= (following-char) ?\) ) | |
2239 (forward-char 1) | |
2240 (forward-sexp 1))) | |
2241 ) ;; cond | |
2242 )) | |
2243 | |
2244 (defun verilog-declaration-beg () | |
2245 (verilog-re-search-backward verilog-declaration-re (bobp) t)) | |
2246 | |
2247 (require 'font-lock) | |
2248 (defvar verilog-need-fld 1) | |
2249 (defvar font-lock-defaults-alist nil) ;In case we are XEmacs | |
2250 | |
2251 (defun verilog-font-lock-init () | |
2252 "Initialize fontification." | |
2253 ;; highlight keywords and standardized types, attributes, enumeration | |
2254 ;; values, and subprograms | |
2255 (setq verilog-font-lock-keywords-3 | |
2256 (append verilog-font-lock-keywords-2 | |
2257 (when verilog-highlight-translate-off | |
2258 (list | |
2259 ;; Fontify things in translate off regions | |
2260 '(verilog-match-translate-off (0 'verilog-font-lock-translate-off-face prepend)) | |
2261 )) | |
2262 ) | |
2263 ) | |
2264 (put 'verilog-mode 'font-lock-defaults | |
2265 '((verilog-font-lock-keywords | |
2266 verilog-font-lock-keywords-1 | |
2267 verilog-font-lock-keywords-2 | |
2268 verilog-font-lock-keywords-3 | |
2269 ) | |
2270 nil ;; nil means highlight strings & comments as well as keywords | |
2271 nil ;; nil means keywords must match case | |
2272 nil ;; syntax table handled elsewhere | |
2273 verilog-beg-of-defun ;; function to move to beginning of reasonable region to highlight | |
2274 )) | |
2275 (if verilog-need-fld | |
2276 (let ((verilog-mode-defaults | |
2277 '((verilog-font-lock-keywords | |
2278 verilog-font-lock-keywords-1 | |
2279 verilog-font-lock-keywords-2 | |
2280 verilog-font-lock-keywords-3 | |
2281 ) | |
2282 nil ;; nil means highlight strings & comments as well as keywords | |
2283 nil ;; nil means keywords must match case | |
2284 nil ;; syntax table handled elsewhere | |
2285 verilog-beg-of-defun ;; function to move to beginning of reasonable region to highlight | |
2286 ))) | |
2287 (setq font-lock-defaults-alist | |
2288 (append | |
2289 font-lock-defaults-alist | |
2290 (list (cons 'verilog-mode verilog-mode-defaults)))) | |
2291 (setq verilog-need-fld 0)))) | |
2292 | |
2293 ;; initialize fontification for Verilog Mode | |
2294 (verilog-font-lock-init) | |
2295 ;; start up message | |
2296 (defconst verilog-startup-message-lines | |
2297 '("Please use \\[verilog-submit-bug-report] to report bugs." | |
2298 "Visit http://www.verilog.com to check for updates" | |
2299 )) | |
2300 (defconst verilog-startup-message-displayed t) | |
2301 (defun verilog-display-startup-message () | |
2302 (if (not verilog-startup-message-displayed) | |
2303 (if (sit-for 5) | |
2304 (let ((lines verilog-startup-message-lines)) | |
2305 (message "verilog-mode version %s, released %s; type \\[describe-mode] for help" | |
2306 verilog-mode-version verilog-mode-release-date) | |
2307 (setq verilog-startup-message-displayed t) | |
2308 (while (and (sit-for 4) lines) | |
2309 (message (substitute-command-keys (car lines))) | |
2310 (setq lines (cdr lines))))) | |
2311 (message ""))) | |
2312 ;; | |
2313 ;; | |
2314 ;; Mode | |
2315 ;; | |
2316 (defvar verilog-which-tool 1) | |
79546 | 2317 ;;;###autoload |
79545 | 2318 (defun verilog-mode () |
2319 "Major mode for editing Verilog code. | |
2320 \\<verilog-mode-map> | |
2321 See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how | |
2322 AUTOs can improve coding efficiency. | |
2323 | |
2324 Use \\[verilog-faq] for a pointer to frequently asked questions. | |
2325 | |
2326 NEWLINE, TAB indents for Verilog code. | |
2327 Delete converts tabs to spaces as it moves back. | |
2328 | |
2329 Supports highlighting. | |
2330 | |
2331 Turning on Verilog mode calls the value of the variable `verilog-mode-hook' | |
2332 with no args, if that value is non-nil. | |
2333 | |
2334 Variables controlling indentation/edit style: | |
2335 | |
2336 variable `verilog-indent-level' (default 3) | |
2337 Indentation of Verilog statements with respect to containing block. | |
2338 `verilog-indent-level-module' (default 3) | |
2339 Absolute indentation of Module level Verilog statements. | |
2340 Set to 0 to get initial and always statements lined up | |
2341 on the left side of your screen. | |
2342 `verilog-indent-level-declaration' (default 3) | |
2343 Indentation of declarations with respect to containing block. | |
2344 Set to 0 to get them list right under containing block. | |
2345 `verilog-indent-level-behavioral' (default 3) | |
2346 Indentation of first begin in a task or function block | |
2347 Set to 0 to get such code to lined up underneath the task or function keyword | |
2348 `verilog-indent-level-directive' (default 1) | |
2349 Indentation of `ifdef/`endif blocks | |
2350 `verilog-cexp-indent' (default 1) | |
2351 Indentation of Verilog statements broken across lines i.e.: | |
2352 if (a) | |
2353 begin | |
2354 `verilog-case-indent' (default 2) | |
2355 Indentation for case statements. | |
2356 `verilog-auto-newline' (default nil) | |
2357 Non-nil means automatically newline after semicolons and the punctuation | |
2358 mark after an end. | |
2359 `verilog-auto-indent-on-newline' (default t) | |
2360 Non-nil means automatically indent line after newline | |
2361 `verilog-tab-always-indent' (default t) | |
2362 Non-nil means TAB in Verilog mode should always reindent the current line, | |
2363 regardless of where in the line point is when the TAB command is used. | |
2364 `verilog-indent-begin-after-if' (default t) | |
2365 Non-nil means to indent begin statements following a preceding | |
2366 if, else, while, for and repeat statements, if any. otherwise, | |
2367 the begin is lined up with the preceding token. If t, you get: | |
2368 if (a) | |
2369 begin // amount of indent based on `verilog-cexp-indent' | |
2370 otherwise you get: | |
2371 if (a) | |
2372 begin | |
2373 `verilog-auto-endcomments' (default t) | |
2374 Non-nil means a comment /* ... */ is set after the ends which ends | |
2375 cases, tasks, functions and modules. | |
2376 The type and name of the object will be set between the braces. | |
2377 `verilog-minimum-comment-distance' (default 10) | |
2378 Minimum distance (in lines) between begin and end required before a comment | |
2379 will be inserted. Setting this variable to zero results in every | |
2380 end acquiring a comment; the default avoids too many redundant | |
2381 comments in tight quarters. | |
2382 `verilog-auto-lineup' (default `(all)) | |
2383 List of contexts where auto lineup of code should be done. | |
2384 | |
2385 Variables controlling other actions: | |
2386 | |
2387 `verilog-linter' (default surelint) | |
2388 Unix program to call to run the lint checker. This is the default | |
2389 command for \\[compile-command] and \\[verilog-auto-save-compile]. | |
2390 | |
2391 See \\[customize] for the complete list of variables. | |
2392 | |
2393 AUTO expansion functions are, in part: | |
2394 | |
2395 \\[verilog-auto] Expand AUTO statements. | |
2396 \\[verilog-delete-auto] Remove the AUTOs. | |
2397 \\[verilog-inject-auto] Insert AUTOs for the first time. | |
2398 | |
2399 Some other functions are: | |
2400 | |
2401 \\[verilog-complete-word] Complete word with appropriate possibilities. | |
2402 \\[verilog-mark-defun] Mark function. | |
2403 \\[verilog-beg-of-defun] Move to beginning of current function. | |
2404 \\[verilog-end-of-defun] Move to end of current function. | |
2405 \\[verilog-label-be] Label matching begin ... end, fork ... join, etc statements. | |
2406 | |
2407 \\[verilog-comment-region] Put marked area in a comment. | |
2408 \\[verilog-uncomment-region] Uncomment an area commented with \\[verilog-comment-region]. | |
2409 \\[verilog-insert-block] Insert begin ... end;. | |
2410 \\[verilog-star-comment] Insert /* ... */. | |
2411 | |
2412 \\[verilog-sk-always] Insert a always @(AS) begin .. end block. | |
2413 \\[verilog-sk-begin] Insert a begin .. end block. | |
2414 \\[verilog-sk-case] Insert a case block, prompting for details. | |
2415 \\[verilog-sk-for] Insert a for (...) begin .. end block, prompting for details. | |
2416 \\[verilog-sk-generate] Insert a generate .. endgenerate block. | |
2417 \\[verilog-sk-header] Insert a nice header block at the top of file. | |
2418 \\[verilog-sk-initial] Insert an initial begin .. end block. | |
2419 \\[verilog-sk-fork] Insert a fork begin .. end .. join block. | |
2420 \\[verilog-sk-module] Insert a module .. (/*AUTOARG*/);.. endmodule block. | |
2421 \\[verilog-sk-primitive] Insert a primitive .. (.. );.. endprimitive block. | |
2422 \\[verilog-sk-repeat] Insert a repeat (..) begin .. end block. | |
2423 \\[verilog-sk-specify] Insert a specify .. endspecify block. | |
2424 \\[verilog-sk-task] Insert a task .. begin .. end endtask block. | |
2425 \\[verilog-sk-while] Insert a while (...) begin .. end block, prompting for details. | |
2426 \\[verilog-sk-casex] Insert a casex (...) item: begin.. end endcase block, prompting for details. | |
2427 \\[verilog-sk-casez] Insert a casez (...) item: begin.. end endcase block, prompting for details. | |
2428 \\[verilog-sk-if] Insert an if (..) begin .. end block. | |
2429 \\[verilog-sk-else-if] Insert an else if (..) begin .. end block. | |
2430 \\[verilog-sk-comment] Insert a comment block. | |
2431 \\[verilog-sk-assign] Insert an assign .. = ..; statement. | |
2432 \\[verilog-sk-function] Insert a function .. begin .. end endfunction block. | |
2433 \\[verilog-sk-input] Insert an input declaration, prompting for details. | |
2434 \\[verilog-sk-output] Insert an output declaration, prompting for details. | |
2435 \\[verilog-sk-state-machine] Insert a state machine definition, prompting for details. | |
2436 \\[verilog-sk-inout] Insert an inout declaration, prompting for details. | |
2437 \\[verilog-sk-wire] Insert a wire declaration, prompting for details. | |
2438 \\[verilog-sk-reg] Insert a register declaration, prompting for details. | |
2439 \\[verilog-sk-define-signal] Define signal under point as a register at the top of the module. | |
2440 | |
2441 All key bindings can be seen in a Verilog-buffer with \\[describe-bindings]. | |
2442 Key bindings specific to `verilog-mode-map' are: | |
2443 | |
2444 \\{verilog-mode-map}" | |
2445 (interactive) | |
2446 (kill-all-local-variables) | |
2447 (use-local-map verilog-mode-map) | |
2448 (setq major-mode 'verilog-mode) | |
2449 (setq mode-name "Verilog") | |
2450 (setq local-abbrev-table verilog-mode-abbrev-table) | |
2451 (setq verilog-mode-syntax-table (make-syntax-table)) | |
2452 (verilog-populate-syntax-table verilog-mode-syntax-table) | |
79546 | 2453 (set (make-local-variable 'beginning-of-defun-function) |
2454 'verilog-beg-of-defun) | |
2455 (set (make-local-variable 'end-of-defun-function) | |
2456 'verilog-end-of-defun) | |
79545 | 2457 ;; add extra comment syntax |
2458 (verilog-setup-dual-comments verilog-mode-syntax-table) | |
2459 (set-syntax-table verilog-mode-syntax-table) | |
2460 (make-local-variable 'indent-line-function) | |
2461 (setq indent-line-function 'verilog-indent-line-relative) | |
2462 (setq comment-indent-function 'verilog-comment-indent) | |
2463 (make-local-variable 'parse-sexp-ignore-comments) | |
2464 (setq parse-sexp-ignore-comments nil) | |
2465 (make-local-variable 'comment-start) | |
2466 (make-local-variable 'comment-end) | |
2467 (make-local-variable 'comment-multi-line) | |
2468 (make-local-variable 'comment-start-skip) | |
2469 (setq comment-start "// " | |
2470 comment-end "" | |
2471 comment-start-skip "/\\*+ *\\|// *" | |
2472 comment-multi-line nil) | |
2473 ;; Set up for compilation | |
2474 (setq verilog-which-tool 1) | |
2475 (setq verilog-tool 'verilog-linter) | |
2476 (verilog-set-compile-command) | |
2477 (when (boundp 'hack-local-variables-hook) ;; Also modify any file-local-variables | |
2478 (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t)) | |
2479 | |
2480 ;; Setting up menus | |
79546 | 2481 (when (featurep 'xemacs) |
2482 (when (and current-menubar | |
2483 (not (assoc "Verilog" current-menubar))) | |
2484 ;; (set-buffer-menubar (copy-sequence current-menubar)) | |
2485 (add-submenu nil verilog-xemacs-menu) | |
2486 (add-submenu nil verilog-stmt-menu) | |
2487 )) | |
79545 | 2488 ;; Stuff for GNU emacs |
2489 (make-local-variable 'font-lock-defaults) | |
2490 ;;------------------------------------------------------------ | |
2491 ;; now hook in 'verilog-colorize-include-files (eldo-mode.el&spice-mode.el) | |
2492 ;; all buffer local: | |
2493 (make-local-hook 'font-lock-mode-hook) | |
2494 (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in emacs 20 | |
2495 (add-hook 'font-lock-mode-hook 'verilog-colorize-include-files-buffer t t) | |
2496 (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-colorize-include-files-buffer t t) ; not in emacs 20 | |
2497 (make-local-hook 'after-change-functions) | |
2498 (add-hook 'after-change-functions 'verilog-colorize-include-files t t) | |
2499 | |
2500 ;; Tell imenu how to handle verilog. | |
2501 (make-local-variable 'imenu-generic-expression) | |
2502 (setq imenu-generic-expression verilog-imenu-generic-expression) | |
2503 ;; hideshow support | |
2504 (unless (assq 'verilog-mode hs-special-modes-alist) | |
2505 (setq hs-special-modes-alist | |
2506 (cons '(verilog-mode-mode "\\<begin\\>" "\\<end\\>" nil | |
2507 verilog-forward-sexp-function) | |
2508 hs-special-modes-alist))) | |
2509 ;; Display version splash information. | |
2510 (verilog-display-startup-message) | |
2511 | |
2512 ;; Stuff for autos | |
2513 (add-hook 'write-contents-hooks 'verilog-auto-save-check) ; already local | |
2514 ;; (verilog-auto-reeval-locals t) ; Save locals in case user changes them | |
2515 ;; (verilog-getopt-flags) | |
2516 (run-hooks 'verilog-mode-hook)) | |
2517 | |
2518 | |
2519 ;; | |
2520 ;; Electric functions | |
2521 ;; | |
2522 (defun electric-verilog-terminate-line (&optional arg) | |
2523 "Terminate line and indent next line. | |
2524 With optional ARG, remove existing end of line comments." | |
2525 (interactive) | |
2526 ;; before that see if we are in a comment | |
2527 (let ((state | |
2528 (save-excursion | |
2529 (parse-partial-sexp (point-min) (point))))) | |
2530 (cond | |
2531 ((nth 7 state) ; Inside // comment | |
2532 (if (eolp) | |
2533 (progn | |
2534 (delete-horizontal-space) | |
2535 (newline)) | |
2536 (progn | |
2537 (newline) | |
2538 (insert-string "// ") | |
2539 (beginning-of-line))) | |
2540 (verilog-indent-line)) | |
2541 ((nth 4 state) ; Inside any comment (hence /**/) | |
2542 (newline) | |
2543 (verilog-more-comment)) | |
2544 ((eolp) | |
2545 ;; First, check if current line should be indented | |
2546 (if (save-excursion | |
2547 (delete-horizontal-space) | |
2548 (beginning-of-line) | |
2549 (skip-chars-forward " \t") | |
2550 (if (looking-at verilog-auto-end-comment-lines-re) | |
2551 (let ((indent-str (verilog-indent-line))) | |
2552 ;; Maybe we should set some endcomments | |
2553 (if verilog-auto-endcomments | |
2554 (verilog-set-auto-endcomments indent-str arg)) | |
2555 (end-of-line) | |
2556 (delete-horizontal-space) | |
2557 (if arg | |
2558 () | |
2559 (newline)) | |
2560 nil) | |
2561 (progn | |
2562 (end-of-line) | |
2563 (delete-horizontal-space) | |
2564 't | |
2565 ) | |
2566 ) | |
2567 ) | |
2568 ;; see if we should line up assignments | |
2569 (progn | |
2570 (if (or (memq 'all verilog-auto-lineup) | |
2571 (memq 'assignments verilog-auto-lineup)) | |
2572 (verilog-pretty-expr) | |
2573 ) | |
2574 (newline) | |
2575 ) | |
2576 (forward-line 1) | |
2577 ) | |
2578 ;; Indent next line | |
2579 (if verilog-auto-indent-on-newline | |
2580 (verilog-indent-line)) | |
2581 ) | |
2582 (t | |
2583 (newline)) | |
2584 ))) | |
2585 | |
2586 (defun electric-verilog-terminate-and-indent () | |
2587 "Insert a newline and indent for the next statement." | |
2588 (interactive) | |
2589 (electric-verilog-terminate-line 1)) | |
2590 | |
2591 (defun electric-verilog-semi () | |
2592 "Insert `;' character and reindent the line." | |
2593 (interactive) | |
2594 (insert last-command-char) | |
2595 | |
2596 (if (or (verilog-in-comment-or-string-p) | |
2597 (verilog-in-escaped-name-p)) | |
2598 () | |
2599 (save-excursion | |
2600 (beginning-of-line) | |
2601 (verilog-forward-ws&directives) | |
2602 (verilog-indent-line) | |
2603 ) | |
2604 (if (and verilog-auto-newline | |
2605 (not (verilog-parenthesis-depth))) | |
2606 (electric-verilog-terminate-line)))) | |
2607 | |
2608 (defun electric-verilog-semi-with-comment () | |
2609 "Insert `;' character, reindent the line and indent for comment." | |
2610 (interactive) | |
2611 (insert "\;") | |
2612 (save-excursion | |
2613 (beginning-of-line) | |
2614 (verilog-indent-line)) | |
2615 (indent-for-comment)) | |
2616 | |
2617 (defun electric-verilog-colon () | |
2618 "Insert `:' and do all indentations except line indent on this line." | |
2619 (interactive) | |
2620 (insert last-command-char) | |
2621 ;; Do nothing if within string. | |
2622 (if (or | |
2623 (verilog-within-string) | |
2624 (not (verilog-in-case-region-p))) | |
2625 () | |
2626 (save-excursion | |
2627 (let ((p (point)) | |
2628 (lim (progn (verilog-beg-of-statement) (point)))) | |
2629 (goto-char p) | |
2630 (verilog-backward-case-item lim) | |
2631 (verilog-indent-line))) | |
2632 ;; (let ((verilog-tab-always-indent nil)) | |
2633 ;; (verilog-indent-line)) | |
2634 )) | |
2635 | |
2636 ;;(defun electric-verilog-equal () | |
2637 ;; "Insert `=', and do indentation if within block." | |
2638 ;; (interactive) | |
2639 ;; (insert last-command-char) | |
2640 ;; Could auto line up expressions, but not yet | |
2641 ;; (if (eq (car (verilog-calculate-indent)) 'block) | |
2642 ;; (let ((verilog-tab-always-indent nil)) | |
2643 ;; (verilog-indent-command))) | |
2644 ;; ) | |
2645 | |
2646 (defun electric-verilog-tick () | |
2647 "Insert back-tick, and indent to column 0 if this is a CPP directive." | |
2648 (interactive) | |
2649 (insert last-command-char) | |
2650 (save-excursion | |
2651 (if (progn | |
2652 (beginning-of-line) | |
2653 (looking-at verilog-directive-re-1)) | |
2654 (verilog-indent-line)))) | |
2655 | |
2656 (defun electric-verilog-tab () | |
2657 "Function called when TAB is pressed in Verilog mode." | |
2658 (interactive) | |
2659 ;; If verilog-tab-always-indent, indent the beginning of the line. | |
2660 (if (or verilog-tab-always-indent | |
2661 (save-excursion | |
2662 (skip-chars-backward " \t") | |
2663 (bolp))) | |
2664 (let* ((oldpnt (point)) | |
2665 (boi-point | |
2666 (save-excursion | |
2667 (beginning-of-line) | |
2668 (skip-chars-forward " \t") | |
2669 (verilog-indent-line) | |
2670 (back-to-indentation) | |
2671 (point)))) | |
2672 (if (< (point) boi-point) | |
2673 (back-to-indentation) | |
2674 (cond ((not verilog-tab-to-comment)) | |
2675 ((not (eolp)) | |
2676 (end-of-line)) | |
2677 (t | |
2678 (indent-for-comment) | |
2679 (when (and (eolp) (= oldpnt (point))) | |
2680 ; kill existing comment | |
2681 (beginning-of-line) | |
2682 (re-search-forward comment-start-skip oldpnt 'move) | |
2683 (goto-char (match-beginning 0)) | |
2684 (skip-chars-backward " \t") | |
2685 (kill-region (point) oldpnt) | |
2686 )))) | |
2687 ) | |
2688 (progn (insert "\t")))) | |
2689 | |
2690 | |
2691 | |
2692 ;; | |
2693 ;; Interactive functions | |
2694 ;; | |
2695 | |
2696 (defun verilog-indent-buffer () | |
2697 "Indent-region the entire buffer as Verilog code. | |
2698 To call this from the command line, see \\[verilog-batch-indent]." | |
2699 (interactive) | |
2700 (verilog-mode) | |
2701 (indent-region (point-min) (point-max) nil)) | |
2702 | |
2703 (defun verilog-insert-block () | |
2704 "Insert Verilog begin ... end; block in the code with right indentation." | |
2705 (interactive) | |
2706 (verilog-indent-line) | |
2707 (insert "begin") | |
2708 (electric-verilog-terminate-line) | |
2709 (save-excursion | |
2710 (electric-verilog-terminate-line) | |
2711 (insert "end") | |
2712 (beginning-of-line) | |
2713 (verilog-indent-line))) | |
2714 | |
2715 (defun verilog-star-comment () | |
2716 "Insert Verilog star comment at point." | |
2717 (interactive) | |
2718 (verilog-indent-line) | |
2719 (insert "/*") | |
2720 (save-excursion | |
2721 (newline) | |
2722 (insert " */")) | |
2723 (newline) | |
2724 (insert " * ")) | |
2725 | |
2726 (defun verilog-insert-indices (MAX) | |
2727 "Insert a set of indices at into the rectangle. | |
2728 The upper left corner is defined by the current point. Indices always | |
2729 begin with 0 and extend to the MAX - 1. If no prefix arg is given, the | |
2730 user is prompted for a value. The indices are surrounded by square brackets | |
79546 | 2731 \[]. For example, the following code with the point located after the first |
79545 | 2732 'a' gives: |
2733 | |
2734 a = b a[ 0] = b | |
2735 a = b a[ 1] = b | |
2736 a = b a[ 2] = b | |
2737 a = b a[ 3] = b | |
2738 a = b ==> insert-indices ==> a[ 4] = b | |
2739 a = b a[ 5] = b | |
2740 a = b a[ 6] = b | |
2741 a = b a[ 7] = b | |
2742 a = b a[ 8] = b" | |
2743 | |
2744 (interactive "NMAX?") | |
2745 (save-excursion | |
2746 (let ((n 0)) | |
2747 (while (< n MAX) | |
2748 (save-excursion | |
2749 (insert (format "[%3d]" n))) | |
2750 (next-line 1) | |
2751 (setq n (1+ n)))))) | |
2752 | |
2753 | |
2754 (defun verilog-generate-numbers (MAX) | |
2755 "Insert a set of generated numbers into a rectangle. | |
2756 The upper left corner is defined by point. The numbers are padded to three | |
2757 digits, starting with 000 and extending to (MAX - 1). If no prefix argument | |
2758 is supplied, then the user is prompted for the MAX number. consider the | |
2759 following code fragment: | |
2760 | |
2761 buf buf buf buf000 | |
2762 buf buf buf buf001 | |
2763 buf buf buf buf002 | |
2764 buf buf buf buf003 | |
2765 buf buf ==> insert-indices ==> buf buf004 | |
2766 buf buf buf buf005 | |
2767 buf buf buf buf006 | |
2768 buf buf buf buf007 | |
2769 buf buf buf buf008" | |
2770 | |
2771 (interactive "NMAX?") | |
2772 (save-excursion | |
2773 (let ((n 0)) | |
2774 (while (< n MAX) | |
2775 (save-excursion | |
2776 (insert (format "%3.3d" n))) | |
2777 (next-line 1) | |
2778 (setq n (1+ n)))))) | |
2779 | |
2780 (defun verilog-mark-defun () | |
2781 "Mark the current verilog function (or procedure). | |
2782 This puts the mark at the end, and point at the beginning." | |
2783 (interactive) | |
2784 (push-mark (point)) | |
2785 (verilog-end-of-defun) | |
2786 (push-mark (point)) | |
2787 (verilog-beg-of-defun) | |
2788 (zmacs-activate-region)) | |
2789 | |
2790 (defun verilog-comment-region (start end) | |
2791 ; checkdoc-params: (start end) | |
2792 "Put the region into a Verilog comment. | |
2793 The comments that are in this area are \"deformed\": | |
2794 `*)' becomes `!(*' and `}' becomes `!{'. | |
2795 These deformed comments are returned to normal if you use | |
2796 \\[verilog-uncomment-region] to undo the commenting. | |
2797 | |
2798 The commented area starts with `verilog-exclude-str-start', and ends with | |
2799 `verilog-exclude-str-end'. But if you change these variables, | |
2800 \\[verilog-uncomment-region] won't recognize the comments." | |
2801 (interactive "r") | |
2802 (save-excursion | |
2803 ;; Insert start and endcomments | |
2804 (goto-char end) | |
2805 (if (and (save-excursion (skip-chars-forward " \t") (eolp)) | |
2806 (not (save-excursion (skip-chars-backward " \t") (bolp)))) | |
2807 (forward-line 1) | |
2808 (beginning-of-line)) | |
2809 (insert verilog-exclude-str-end) | |
2810 (setq end (point)) | |
2811 (newline) | |
2812 (goto-char start) | |
2813 (beginning-of-line) | |
2814 (insert verilog-exclude-str-start) | |
2815 (newline) | |
2816 ;; Replace end-comments within commented area | |
2817 (goto-char end) | |
2818 (save-excursion | |
2819 (while (re-search-backward "\\*/" start t) | |
2820 (replace-match "*-/" t t))) | |
2821 (save-excursion | |
2822 (let ((s+1 (1+ start))) | |
2823 (while (re-search-backward "/\\*" s+1 t) | |
2824 (replace-match "/-*" t t)))) | |
2825 )) | |
2826 | |
2827 (defun verilog-uncomment-region () | |
2828 "Uncomment a commented area; change deformed comments back to normal. | |
2829 This command does nothing if the pointer is not in a commented | |
2830 area. See also `verilog-comment-region'." | |
2831 (interactive) | |
2832 (save-excursion | |
2833 (let ((start (point)) | |
2834 (end (point))) | |
2835 ;; Find the boundaries of the comment | |
2836 (save-excursion | |
2837 (setq start (progn (search-backward verilog-exclude-str-start nil t) | |
2838 (point))) | |
2839 (setq end (progn (search-forward verilog-exclude-str-end nil t) | |
2840 (point)))) | |
2841 ;; Check if we're really inside a comment | |
2842 (if (or (equal start (point)) (<= end (point))) | |
2843 (message "Not standing within commented area.") | |
2844 (progn | |
2845 ;; Remove endcomment | |
2846 (goto-char end) | |
2847 (beginning-of-line) | |
2848 (let ((pos (point))) | |
2849 (end-of-line) | |
2850 (delete-region pos (1+ (point)))) | |
2851 ;; Change comments back to normal | |
2852 (save-excursion | |
2853 (while (re-search-backward "\\*-/" start t) | |
2854 (replace-match "*/" t t))) | |
2855 (save-excursion | |
2856 (while (re-search-backward "/-\\*" start t) | |
2857 (replace-match "/*" t t))) | |
2858 ;; Remove start comment | |
2859 (goto-char start) | |
2860 (beginning-of-line) | |
2861 (let ((pos (point))) | |
2862 (end-of-line) | |
2863 (delete-region pos (1+ (point))))))))) | |
2864 | |
2865 (defun verilog-beg-of-defun () | |
2866 "Move backward to the beginning of the current function or procedure." | |
2867 (interactive) | |
2868 (verilog-re-search-backward verilog-defun-re nil 'move)) | |
2869 | |
2870 (defun verilog-end-of-defun () | |
2871 "Move forward to the end of the current function or procedure." | |
2872 (interactive) | |
2873 (verilog-re-search-forward verilog-end-defun-re nil 'move)) | |
2874 | |
2875 (defun verilog-get-beg-of-defun (&optional warn) | |
2876 (save-excursion | |
2877 (cond ((verilog-re-search-forward-quick verilog-defun-re nil t) | |
2878 (point)) | |
2879 (t | |
2880 (error "%s: Can't find module beginning" (verilog-point-text)) | |
2881 (point-max))))) | |
2882 (defun verilog-get-end-of-defun (&optional warn) | |
2883 (save-excursion | |
2884 (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t) | |
2885 (point)) | |
2886 (t | |
2887 (error "%s: Can't find endmodule" (verilog-point-text)) | |
2888 (point-max))))) | |
2889 | |
2890 (defun verilog-label-be (&optional arg) | |
2891 "Label matching begin ... end, fork ... join and case ... endcase statements. | |
2892 With ARG, first kill any existing labels." | |
2893 (interactive) | |
2894 (let ((cnt 0) | |
2895 (oldpos (point)) | |
2896 (b (progn | |
2897 (verilog-beg-of-defun) | |
2898 (point-marker))) | |
2899 (e (progn | |
2900 (verilog-end-of-defun) | |
2901 (point-marker))) | |
2902 ) | |
2903 (goto-char (marker-position b)) | |
2904 (if (> (- e b) 200) | |
2905 (message "Relabeling module...")) | |
2906 (while (and | |
2907 (> (marker-position e) (point)) | |
2908 (verilog-re-search-forward | |
2909 (concat | |
2910 "\\<end\\(\\(function\\)\\|\\(task\\)\\|\\(module\\)\\|\\(primitive\\)\\|\\(interface\\)\\|\\(package\\)\\|\\(case\\)\\)?\\>" | |
2911 "\\|\\(`endif\\)\\|\\(`else\\)") | |
2912 nil 'move)) | |
2913 (goto-char (match-beginning 0)) | |
2914 (let ((indent-str (verilog-indent-line))) | |
2915 (verilog-set-auto-endcomments indent-str 't) | |
2916 (end-of-line) | |
2917 (delete-horizontal-space) | |
2918 ) | |
2919 (setq cnt (1+ cnt)) | |
2920 (if (= 9 (% cnt 10)) | |
2921 (message "%d..." cnt)) | |
2922 ) | |
2923 (goto-char oldpos) | |
2924 (if (or | |
2925 (> (- e b) 200) | |
2926 (> cnt 20)) | |
2927 (message "%d lines auto commented" cnt)) | |
2928 )) | |
2929 | |
2930 (defun verilog-beg-of-statement () | |
2931 "Move backward to beginning of statement." | |
2932 (interactive) | |
2933 ;; Move back token by token until we see the end | |
2934 ;; of some ealier line. | |
2935 (while | |
2936 ;; If the current point does not begin a new | |
2937 ;; statement, as in the character ahead of us is a ';', or SOF | |
2938 ;; or the string after us unambiguosly starts a statement, | |
2939 ;; or the token before us unambiguously ends a statement, | |
2940 ;; then move back a token and test again. | |
2941 (not (or | |
2942 (bolp) | |
2943 (= (preceding-char) ?\;) | |
2944 (not (or | |
2945 (looking-at "\\<") | |
2946 (forward-word -1))) | |
2947 (and | |
2948 (looking-at verilog-extended-complete-re) | |
2949 (not (save-excursion | |
2950 (verilog-backward-token) | |
2951 (looking-at verilog-extended-complete-re))) | |
2952 ) | |
2953 (looking-at verilog-basic-complete-re) | |
2954 (save-excursion | |
2955 (verilog-backward-token) | |
2956 (or | |
2957 (looking-at verilog-end-block-re) | |
2958 (looking-at verilog-preprocessor-re))) | |
2959 )) | |
2960 (verilog-backward-syntactic-ws) | |
2961 (verilog-backward-token)) | |
2962 ;; Now point is where the previous line ended. | |
2963 (verilog-forward-syntactic-ws)) | |
2964 | |
2965 (defun verilog-beg-of-statement-1 () | |
2966 "Move backward to beginning of statement." | |
2967 (interactive) | |
2968 (let ((pt (point))) | |
2969 | |
2970 (while (and (not (looking-at verilog-complete-reg)) | |
2971 (setq pt (point)) | |
2972 (verilog-backward-token) | |
2973 (not (looking-at verilog-complete-reg)) | |
2974 (verilog-backward-syntactic-ws) | |
2975 (setq pt (point)) | |
2976 (not (bolp)) | |
2977 (not (= (preceding-char) ?\;)))) | |
2978 (goto-char pt) | |
2979 (verilog-forward-ws&directives))) | |
2980 | |
2981 (defun verilog-end-of-statement () | |
2982 "Move forward to end of current statement." | |
2983 (interactive) | |
2984 (let ((nest 0) pos) | |
2985 (or (looking-at verilog-beg-block-re) | |
2986 ;; Skip to end of statement | |
2987 (setq pos (catch 'found | |
2988 (while t | |
2989 (forward-sexp 1) | |
2990 (verilog-skip-forward-comment-or-string) | |
2991 (cond ((looking-at "[ \t]*;") | |
2992 (skip-chars-forward "^;") | |
2993 (forward-char 1) | |
2994 (throw 'found (point))) | |
2995 ((save-excursion | |
2996 (forward-sexp -1) | |
2997 (looking-at verilog-beg-block-re)) | |
2998 (goto-char (match-beginning 0)) | |
2999 (throw 'found nil)) | |
3000 ((looking-at "[ \t]*)") | |
79546 | 3001 (throw 'found (point))) |
79545 | 3002 ((eobp) |
3003 (throw 'found (point)))))))) | |
3004 (if (not pos) | |
3005 ;; Skip a whole block | |
3006 (catch 'found | |
3007 (while t | |
3008 (verilog-re-search-forward verilog-end-statement-re nil 'move) | |
3009 (setq nest (if (match-end 1) | |
3010 (1+ nest) | |
3011 (1- nest))) | |
3012 (cond ((eobp) | |
3013 (throw 'found (point))) | |
3014 ((= 0 nest) | |
3015 (throw 'found (verilog-end-of-statement)))))) | |
3016 pos))) | |
3017 | |
3018 (defun verilog-in-case-region-p () | |
3019 "Return TRUE if in a case region; | |
3020 more specifically, point @ in the line foo : @ begin" | |
3021 (interactive) | |
3022 (save-excursion | |
3023 (if (and | |
3024 (progn (verilog-forward-syntactic-ws) | |
3025 (looking-at "\\<begin\\>")) | |
3026 (progn (verilog-backward-syntactic-ws) | |
3027 (= (preceding-char) ?\:))) | |
3028 (catch 'found | |
3029 (let ((nest 1)) | |
3030 (while t | |
3031 (verilog-re-search-backward | |
3032 (concat "\\(\\<module\\>\\)\\|\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|" | |
3033 "\\(\\<endcase\\>\\)\\>") | |
3034 nil 'move) | |
3035 (cond | |
3036 ((match-end 3) | |
3037 (setq nest (1+ nest))) | |
3038 ((match-end 2) | |
3039 (if (= nest 1) | |
3040 (throw 'found 1)) | |
3041 (setq nest (1- nest))) | |
3042 (t | |
3043 (throw 'found (= nest 0))) | |
3044 )))) | |
3045 nil))) | |
3046 (defun verilog-in-struct-region-p () | |
3047 "Return TRUE if in a struct region; | |
3048 more specifically, in a list after a struct|union keyword" | |
3049 (interactive) | |
3050 (save-excursion | |
3051 (let* ((state (parse-partial-sexp (point-min) (point))) | |
3052 (depth (nth 0 state))) | |
3053 (if depth | |
3054 (progn (backward-up-list depth) | |
3055 (verilog-beg-of-statement) | |
3056 (looking-at "\\<typedef\\>?\\s-*\\<struct\\|union\\>") | |
3057 ) | |
3058 ) | |
3059 ) | |
3060 ) | |
3061 ) | |
3062 | |
3063 (defun verilog-in-generate-region-p () | |
3064 "Return TRUE if in a generate region; | |
3065 more specifically, after a generate and before an endgenerate" | |
3066 (interactive) | |
3067 (let ((lim (save-excursion (verilog-beg-of-defun) (point))) | |
3068 (nest 1) | |
3069 ) | |
3070 (save-excursion | |
3071 (while (and | |
3072 (/= nest 0) | |
3073 (verilog-re-search-backward "\\<\\(generate\\)\\|\\(endgenerate\\)\\>" lim 'move) | |
3074 (cond | |
3075 ((match-end 1) ; generate | |
3076 (setq nest (1- nest))) | |
3077 ((match-end 2) ; endgenerate | |
3078 (setq nest (1+ nest))) | |
3079 )) | |
3080 )) | |
3081 (= nest 0) )) ; return nest | |
3082 | |
3083 (defun verilog-in-fork-region-p () | |
3084 "Return true if between a fork and join." | |
3085 (interactive) | |
3086 (let ((lim (save-excursion (verilog-beg-of-defun) (point))) | |
3087 (nest 1) | |
3088 ) | |
3089 (save-excursion | |
3090 (while (and | |
3091 (/= nest 0) | |
3092 (verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\(_any\\|_none\\)?\\)\\>" lim 'move) | |
3093 (cond | |
3094 ((match-end 1) ; fork | |
3095 (setq nest (1- nest))) | |
3096 ((match-end 2) ; join | |
3097 (setq nest (1+ nest))) | |
3098 )) | |
3099 )) | |
3100 (= nest 0) )) ; return nest | |
3101 | |
3102 (defun verilog-backward-case-item (lim) | |
3103 "Skip backward to nearest enclosing case item. | |
3104 Limit search to point LIM." | |
3105 (interactive) | |
3106 (let ((str 'nil) | |
3107 (lim1 | |
3108 (progn | |
3109 (save-excursion | |
3110 (verilog-re-search-backward verilog-endcomment-reason-re | |
3111 lim 'move) | |
3112 (point))))) | |
3113 ;; Try to find the real : | |
3114 (if (save-excursion (search-backward ":" lim1 t)) | |
3115 (let ((colon 0) | |
3116 b e ) | |
3117 (while | |
3118 (and | |
3119 (< colon 1) | |
3120 (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)" | |
3121 lim1 'move)) | |
3122 (cond | |
3123 ((match-end 1) ;; [ | |
3124 (setq colon (1+ colon)) | |
3125 (if (>= colon 0) | |
3126 (error "%s: unbalanced [" (verilog-point-text)))) | |
3127 ((match-end 2) ;; ] | |
3128 (setq colon (1- colon))) | |
3129 | |
3130 ((match-end 3) ;; : | |
3131 (setq colon (1+ colon))) | |
3132 )) | |
3133 ;; Skip back to beginning of case item | |
3134 (skip-chars-backward "\t ") | |
3135 (verilog-skip-backward-comment-or-string) | |
3136 (setq e (point)) | |
3137 (setq b | |
3138 (progn | |
3139 (if | |
3140 (verilog-re-search-backward | |
3141 "\\<\\(case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move) | |
3142 (progn | |
3143 (cond | |
3144 ((match-end 1) | |
3145 (goto-char (match-end 1)) | |
3146 (verilog-forward-ws&directives) | |
3147 (if (looking-at "(") | |
3148 (progn | |
3149 (forward-sexp) | |
3150 (verilog-forward-ws&directives))) | |
3151 (point)) | |
3152 (t | |
3153 (goto-char (match-end 0)) | |
3154 (verilog-forward-ws&directives) | |
3155 (point)) | |
3156 )) | |
3157 (error "Malformed case item") | |
3158 ))) | |
3159 (setq str (buffer-substring b e)) | |
3160 (if | |
3161 (setq e | |
3162 (string-match | |
3163 "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str)) | |
3164 (setq str (concat (substring str 0 e) "..."))) | |
3165 str) | |
3166 'nil))) | |
3167 | |
3168 | |
3169 ;; | |
3170 ;; Other functions | |
3171 ;; | |
3172 | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3173 (defun verilog-kill-existing-comment () |
79545 | 3174 "Kill auto comment on this line." |
3175 (save-excursion | |
3176 (let* ( | |
3177 (e (progn | |
3178 (end-of-line) | |
3179 (point))) | |
3180 (b (progn | |
3181 (beginning-of-line) | |
3182 (search-forward "//" e t)))) | |
3183 (if b | |
3184 (delete-region (- b 2) e))))) | |
3185 | |
3186 (defconst verilog-directive-nest-re | |
3187 (concat "\\(`else\\>\\)\\|" | |
3188 "\\(`endif\\>\\)\\|" | |
3189 "\\(`if\\>\\)\\|" | |
3190 "\\(`ifdef\\>\\)\\|" | |
3191 "\\(`ifndef\\>\\)")) | |
3192 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment) | |
3193 "Add ending comment with given INDENT-STR. | |
3194 With KILL-EXISTING-COMMENT, remove what was there before. | |
3195 Insert `// case: 7 ' or `// NAME ' on this line if appropriate. | |
3196 Insert `// case expr ' if this line ends a case block. | |
3197 Insert `// ifdef FOO ' if this line ends code conditional on FOO. | |
3198 Insert `// NAME ' if this line ends a function, task, module, primitive or interface named NAME." | |
3199 (save-excursion | |
3200 (cond | |
3201 (; Comment close preprocessor directives | |
3202 (and | |
3203 (looking-at "\\(`endif\\)\\|\\(`else\\)") | |
3204 (or kill-existing-comment | |
3205 (not (save-excursion | |
3206 (end-of-line) | |
3207 (search-backward "//" (verilog-get-beg-of-line) t))))) | |
3208 (let ((nest 1) b e | |
3209 m | |
3210 (else (if (match-end 2) "!" " ")) | |
3211 ) | |
3212 (end-of-line) | |
3213 (if kill-existing-comment | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3214 (verilog-kill-existing-comment)) |
79545 | 3215 (delete-horizontal-space) |
3216 (save-excursion | |
3217 (backward-sexp 1) | |
3218 (while (and (/= nest 0) | |
3219 (verilog-re-search-backward verilog-directive-nest-re nil 'move)) | |
3220 (cond | |
3221 ((match-end 1) ; `else | |
3222 (if (= nest 1) | |
3223 (setq else "!"))) | |
3224 ((match-end 2) ; `endif | |
3225 (setq nest (1+ nest))) | |
3226 ((match-end 3) ; `if | |
3227 (setq nest (1- nest))) | |
3228 ((match-end 4) ; `ifdef | |
3229 (setq nest (1- nest))) | |
3230 ((match-end 5) ; `ifndef | |
3231 (setq nest (1- nest))) | |
3232 )) | |
3233 (if (match-end 0) | |
3234 (setq | |
3235 m (buffer-substring | |
3236 (match-beginning 0) | |
3237 (match-end 0)) | |
3238 b (progn | |
3239 (skip-chars-forward "^ \t") | |
3240 (verilog-forward-syntactic-ws) | |
3241 (point)) | |
3242 e (progn | |
3243 (skip-chars-forward "a-zA-Z0-9_") | |
3244 (point) | |
3245 )))) | |
3246 (if b | |
3247 (if (> (count-lines (point) b) verilog-minimum-comment-distance) | |
3248 (insert (concat " // " else m " " (buffer-substring b e)))) | |
3249 (progn | |
3250 (insert " // unmatched `else or `endif") | |
3251 (ding 't)) | |
3252 ))) | |
3253 | |
3254 (; Comment close case/class/function/task/module and named block | |
3255 (and (looking-at "\\<end") | |
3256 (or kill-existing-comment | |
3257 (not (save-excursion | |
3258 (end-of-line) | |
3259 (search-backward "//" (verilog-get-beg-of-line) t))))) | |
3260 (let ((type (car indent-str))) | |
3261 (unless (eq type 'declaration) | |
3262 (unless (looking-at (concat "\\(" verilog-end-block-ordered-re "\\)[ \t]*:")) ;; ignore named ends | |
3263 (if (looking-at verilog-end-block-ordered-re) | |
3264 (cond | |
3265 (;- This is a case block; search back for the start of this case | |
3266 (match-end 1) ;; of verilog-end-block-ordered-re | |
3267 | |
3268 (let ((err 't) | |
3269 (str "UNMATCHED!!")) | |
3270 (save-excursion | |
3271 (verilog-leap-to-head) | |
3272 (cond | |
3273 ((looking-at "\\<randcase\\>") | |
3274 (setq str "randcase") | |
3275 (setq err nil) | |
3276 ) | |
3277 ((match-end 0) | |
3278 (goto-char (match-end 1)) | |
3279 (if nil | |
3280 (let (s f) | |
3281 (setq s (match-beginning 1)) | |
3282 (setq f (progn (end-of-line) | |
3283 (point))) | |
3284 (setq str (buffer-substring s f))) | |
3285 (setq err nil)) | |
3286 (setq str (concat (buffer-substring (match-beginning 1) (match-end 1)) | |
3287 " " | |
3288 (verilog-get-expr)))))) | |
3289 (end-of-line) | |
3290 (if kill-existing-comment | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3291 (verilog-kill-existing-comment)) |
79545 | 3292 (delete-horizontal-space) |
3293 (insert (concat " // " str )) | |
3294 (if err (ding 't)) | |
3295 )) | |
3296 | |
3297 (;- This is a begin..end block | |
3298 (match-end 2) ;; of verilog-end-block-ordered-re | |
3299 (let ((str " // UNMATCHED !!") | |
3300 (err 't) | |
3301 (here (point)) | |
3302 there | |
3303 cntx | |
3304 ) | |
3305 (save-excursion | |
3306 (verilog-leap-to-head) | |
3307 (setq there (point)) | |
3308 (if (not (match-end 0)) | |
3309 (progn | |
3310 (goto-char here) | |
3311 (end-of-line) | |
3312 (if kill-existing-comment | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3313 (verilog-kill-existing-comment)) |
79545 | 3314 (delete-horizontal-space) |
3315 (insert str) | |
3316 (ding 't) | |
3317 ) | |
3318 (let ((lim | |
3319 (save-excursion (verilog-beg-of-defun) (point))) | |
3320 (here (point)) | |
3321 ) | |
3322 (cond | |
3323 (;-- handle named block differently | |
3324 (looking-at verilog-named-block-re) | |
3325 (search-forward ":") | |
3326 (setq there (point)) | |
3327 (setq str (verilog-get-expr)) | |
3328 (setq err nil) | |
3329 (setq str (concat " // block: " str ))) | |
3330 | |
3331 ((verilog-in-case-region-p) ;-- handle case item differently | |
3332 (goto-char here) | |
3333 (setq str (verilog-backward-case-item lim)) | |
3334 (setq there (point)) | |
3335 (setq err nil) | |
3336 (setq str (concat " // case: " str ))) | |
3337 | |
3338 (;- try to find "reason" for this begin | |
3339 (cond | |
3340 (; | |
3341 (eq here (progn | |
3342 (verilog-backward-token) | |
3343 (verilog-beg-of-statement-1) | |
3344 (point))) | |
3345 (setq err nil) | |
3346 (setq str "")) | |
3347 ((looking-at verilog-endcomment-reason-re) | |
3348 (setq there (match-end 0)) | |
3349 (setq cntx (concat | |
3350 (buffer-substring (match-beginning 0) (match-end 0)) " ")) | |
3351 (cond | |
3352 (;- begin | |
3353 (match-end 2) | |
3354 (setq err nil) | |
3355 (save-excursion | |
3356 (if (and (verilog-continued-line) | |
3357 (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>")) | |
3358 (progn | |
3359 (goto-char (match-end 0)) | |
3360 (setq there (point)) | |
3361 (setq str | |
3362 (concat " // " | |
3363 (buffer-substring (match-beginning 0) (match-end 0)) " " | |
3364 (verilog-get-expr)))) | |
3365 (setq str "")))) | |
3366 | |
3367 (;- else | |
3368 (match-end 4) | |
3369 (let ((nest 0) | |
3370 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)") | |
3371 ) | |
3372 (catch 'skip | |
3373 (while (verilog-re-search-backward reg nil 'move) | |
3374 (cond | |
3375 ((match-end 1) ; begin | |
3376 (setq nest (1- nest))) | |
3377 ((match-end 2) ; end | |
3378 (setq nest (1+ nest))) | |
3379 ((match-end 3) | |
3380 (if (= 0 nest) | |
3381 (progn | |
3382 (goto-char (match-end 0)) | |
3383 (setq there (point)) | |
3384 (setq err nil) | |
3385 (setq str (verilog-get-expr)) | |
3386 (setq str (concat " // else: !if" str )) | |
3387 (throw 'skip 1)) | |
3388 ))) | |
3389 )))) | |
3390 | |
3391 (;- end else | |
3392 (match-end 5) | |
3393 (goto-char there) | |
3394 (let ((nest 0) | |
3395 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)") | |
3396 ) | |
3397 (catch 'skip | |
3398 (while (verilog-re-search-backward reg nil 'move) | |
3399 (cond | |
3400 ((match-end 1) ; begin | |
3401 (setq nest (1- nest))) | |
3402 ((match-end 2) ; end | |
3403 (setq nest (1+ nest))) | |
3404 ((match-end 3) | |
3405 (if (= 0 nest) | |
3406 (progn | |
3407 (goto-char (match-end 0)) | |
3408 (setq there (point)) | |
3409 (setq err nil) | |
3410 (setq str (verilog-get-expr)) | |
3411 (setq str (concat " // else: !if" str )) | |
3412 (throw 'skip 1)) | |
3413 ))) | |
3414 )))) | |
3415 | |
3416 (;- task/function/initial et cetera | |
3417 t | |
3418 (match-end 0) | |
3419 (goto-char (match-end 0)) | |
3420 (setq there (point)) | |
3421 (setq err nil) | |
3422 (setq str (verilog-get-expr)) | |
3423 (setq str (concat " // " cntx str ))) | |
3424 | |
3425 (;-- otherwise... | |
3426 (setq str " // auto-endcomment confused ")) | |
3427 )) | |
3428 | |
3429 ((and | |
3430 (verilog-in-case-region-p) ;-- handle case item differently | |
3431 (progn | |
3432 (setq there (point)) | |
3433 (goto-char here) | |
3434 (setq str (verilog-backward-case-item lim)))) | |
3435 (setq err nil) | |
3436 (setq str (concat " // case: " str ))) | |
3437 | |
3438 ((verilog-in-fork-region-p) | |
3439 (setq err nil) | |
3440 (setq str " // fork branch" )) | |
3441 | |
3442 ((looking-at "\\<end\\>") | |
3443 ;; HERE | |
3444 (forward-word 1) | |
3445 (verilog-forward-syntactic-ws) | |
3446 (setq err nil) | |
3447 (setq str (verilog-get-expr)) | |
3448 (setq str (concat " // " cntx str ))) | |
3449 | |
3450 )))) | |
3451 (goto-char here) | |
3452 (end-of-line) | |
3453 (if kill-existing-comment | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3454 (verilog-kill-existing-comment)) |
79545 | 3455 (delete-horizontal-space) |
3456 (if (or err | |
3457 (> (count-lines here there) verilog-minimum-comment-distance)) | |
3458 (insert str)) | |
3459 (if err (ding 't)) | |
3460 )))) | |
3461 (;- this is endclass, which can be nested | |
3462 (match-end 11) ;; of verilog-end-block-ordered-re | |
3463 ;;(goto-char there) | |
3464 (let ((nest 0) | |
3465 ( reg "\\<\\(class\\)\\|\\(endclass\\)\\|\\(package\\|primitive\\|\\(macro\\)?module\\)\\>") | |
3466 string | |
3467 ) | |
3468 (save-excursion | |
3469 (catch 'skip | |
3470 (while (verilog-re-search-backward reg nil 'move) | |
3471 (cond | |
3472 ((match-end 3) ; endclass | |
3473 (ding 't) | |
3474 (setq string "unmatched endclass") | |
3475 (throw 'skip 1)) | |
3476 | |
3477 ((match-end 2) ; endclass | |
3478 (setq nest (1+ nest))) | |
3479 | |
3480 ((match-end 1) ; class | |
3481 (setq nest (1- nest)) | |
3482 (if (< nest 0) | |
3483 (progn | |
3484 (goto-char (match-end 0)) | |
3485 (let (b e) | |
3486 (setq b (progn | |
3487 (skip-chars-forward "^ \t") | |
3488 (verilog-forward-ws&directives) | |
3489 (point)) | |
3490 e (progn | |
3491 (skip-chars-forward "a-zA-Z0-9_") | |
3492 (point))) | |
3493 (setq string (buffer-substring b e))) | |
3494 (throw 'skip 1)))) | |
3495 )))) | |
3496 (end-of-line) | |
3497 (insert (concat " // " string ))) | |
3498 ) | |
3499 | |
3500 (;- this is end{function,generate,task,module,primitive,table,generate} | |
3501 ;- which can not be nested. | |
3502 t | |
3503 (let (string reg (width nil)) | |
3504 (end-of-line) | |
3505 (if kill-existing-comment | |
3506 (save-match-data | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3507 (verilog-kill-existing-comment))) |
79545 | 3508 (delete-horizontal-space) |
3509 (backward-sexp) | |
3510 (cond | |
3511 ((match-end 5) ;; of verilog-end-block-ordered-re | |
3512 (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)") | |
3513 (setq width "\\(\\s-*\\(\\[[^]]*\\]\\)\\|\\(real\\(time\\)?\\)\\|\\(integer\\)\\|\\(time\\)\\)?") | |
3514 ) | |
3515 ((match-end 6) ;; of verilog-end-block-ordered-re | |
3516 (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)")) | |
3517 ((match-end 7) ;; of verilog-end-block-ordered-re | |
3518 (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>")) | |
3519 ((match-end 8) ;; of verilog-end-block-ordered-re | |
3520 (setq reg "\\(\\<primitive\\>\\)\\|\\(\\<\\(endprimitive\\|package\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3521 ((match-end 9) ;; of verilog-end-block-ordered-re | |
3522 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<\\(endinterface\\|package\\|primitive\\|\\(macro\\)?module\\)\\>\\)")) | |
3523 ((match-end 10) ;; of verilog-end-block-ordered-re | |
3524 (setq reg "\\(\\<package\\>\\)\\|\\(\\<\\(endpackage\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3525 ((match-end 11) ;; of verilog-end-block-ordered-re | |
3526 (setq reg "\\(\\<class\\>\\)\\|\\(\\<\\(endclass\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3527 ((match-end 12) ;; of verilog-end-block-ordered-re | |
3528 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<\\(endcovergroup\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3529 ((match-end 13) ;; of verilog-end-block-ordered-re | |
3530 (setq reg "\\(\\<program\\>\\)\\|\\(\\<\\(endprogram\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3531 ((match-end 14) ;; of verilog-end-block-ordered-re | |
3532 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<\\(endsequence\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3533 ((match-end 15) ;; of verilog-end-block-ordered-re | |
3534 (setq reg "\\(\\<clocking\\>\\)\\|\\<endclocking\\>")) | |
3535 | |
3536 (t (error "Problem in verilog-set-auto-endcomments")) | |
3537 ) | |
3538 (let (b e) | |
3539 (save-excursion | |
3540 (verilog-re-search-backward reg nil 'move) | |
3541 (cond | |
3542 ((match-end 1) | |
3543 (setq b (progn | |
3544 (skip-chars-forward "^ \t") | |
3545 (verilog-forward-ws&directives) | |
3546 (if (and width (looking-at width)) | |
3547 (progn | |
3548 (goto-char (match-end 0)) | |
3549 (verilog-forward-ws&directives) | |
3550 )) | |
3551 (point)) | |
3552 e (progn | |
3553 (skip-chars-forward "a-zA-Z0-9_") | |
3554 (point))) | |
3555 (setq string (buffer-substring b e))) | |
3556 (t | |
3557 (ding 't) | |
3558 (setq string "unmatched end(function|task|module|primitive|interface|package|class|clocking)"))))) | |
3559 (end-of-line) | |
3560 (insert (concat " // " string ))) | |
3561 )))))))))) | |
3562 | |
3563 (defun verilog-get-expr() | |
3564 "Grab expression at point, e.g, case ( a | b & (c ^d))" | |
3565 (let* ((b (progn | |
3566 (verilog-forward-syntactic-ws) | |
3567 (skip-chars-forward " \t") | |
3568 (point))) | |
3569 (e (let ((par 1)) | |
3570 (cond | |
3571 ((looking-at "@") | |
3572 (forward-char 1) | |
3573 (verilog-forward-syntactic-ws) | |
3574 (if (looking-at "(") | |
3575 (progn | |
3576 (forward-char 1) | |
3577 (while (and (/= par 0) | |
3578 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move)) | |
3579 (cond | |
3580 ((match-end 1) | |
3581 (setq par (1+ par))) | |
3582 ((match-end 2) | |
3583 (setq par (1- par))))))) | |
3584 (point)) | |
3585 ((looking-at "(") | |
3586 (forward-char 1) | |
3587 (while (and (/= par 0) | |
3588 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move)) | |
3589 (cond | |
3590 ((match-end 1) | |
3591 (setq par (1+ par))) | |
3592 ((match-end 2) | |
3593 (setq par (1- par))))) | |
3594 (point)) | |
3595 ((looking-at "\\[") | |
3596 (forward-char 1) | |
3597 (while (and (/= par 0) | |
3598 (verilog-re-search-forward "\\(\\[\\)\\|\\(\\]\\)" nil 'move)) | |
3599 (cond | |
3600 ((match-end 1) | |
3601 (setq par (1+ par))) | |
3602 ((match-end 2) | |
3603 (setq par (1- par))))) | |
3604 (verilog-forward-syntactic-ws) | |
3605 (skip-chars-forward "^ \t\n\f") | |
3606 (point)) | |
3607 ((looking-at "/[/\\*]") | |
3608 b) | |
3609 ('t | |
3610 (skip-chars-forward "^: \t\n\f") | |
3611 (point) | |
3612 )))) | |
3613 (str (buffer-substring b e))) | |
3614 (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str)) | |
3615 (setq str (concat (substring str 0 e) "..."))) | |
3616 str)) | |
3617 | |
3618 (defun verilog-expand-vector () | |
3619 "Take a signal vector on the current line and expand it to multiple lines. | |
3620 Useful for creating tri's and other expanded fields." | |
3621 (interactive) | |
3622 (verilog-expand-vector-internal "[" "]")) | |
3623 | |
3624 (defun verilog-expand-vector-internal (bra ket) | |
3625 "Given BRA, the start brace and KET, the end brace, expand one line into many lines." | |
3626 (save-excursion | |
3627 (forward-line 0) | |
3628 (let ((signal-string (buffer-substring (point) | |
3629 (progn | |
3630 (end-of-line) (point))))) | |
3631 (if (string-match (concat "\\(.*\\)" | |
3632 (regexp-quote bra) | |
3633 "\\([0-9]*\\)\\(:[0-9]*\\|\\)\\(::[0-9---]*\\|\\)" | |
3634 (regexp-quote ket) | |
3635 "\\(.*\\)$") signal-string) | |
3636 (let* ((sig-head (match-string 1 signal-string)) | |
3637 (vec-start (string-to-int (match-string 2 signal-string))) | |
3638 (vec-end (if (= (match-beginning 3) (match-end 3)) | |
3639 vec-start | |
3640 (string-to-int (substring signal-string (1+ (match-beginning 3)) (match-end 3))))) | |
3641 (vec-range (if (= (match-beginning 4) (match-end 4)) | |
3642 1 | |
3643 (string-to-int (substring signal-string (+ 2 (match-beginning 4)) (match-end 4))))) | |
3644 (sig-tail (match-string 5 signal-string)) | |
3645 vec) | |
3646 ;; Decode vectors | |
3647 (setq vec nil) | |
3648 (if (< vec-range 0) | |
3649 (let ((tmp vec-start)) | |
3650 (setq vec-start vec-end | |
3651 vec-end tmp | |
3652 vec-range (- vec-range)))) | |
3653 (if (< vec-end vec-start) | |
3654 (while (<= vec-end vec-start) | |
3655 (setq vec (append vec (list vec-start))) | |
3656 (setq vec-start (- vec-start vec-range))) | |
3657 (while (<= vec-start vec-end) | |
3658 (setq vec (append vec (list vec-start))) | |
3659 (setq vec-start (+ vec-start vec-range)))) | |
3660 ;; | |
3661 ;; Delete current line | |
3662 (delete-region (point) (progn (forward-line 0) (point))) | |
3663 ;; | |
3664 ;; Expand vector | |
3665 (while vec | |
3666 (insert (concat sig-head bra (int-to-string (car vec)) ket sig-tail "\n")) | |
3667 (setq vec (cdr vec))) | |
3668 (delete-char -1) | |
3669 ;; | |
3670 ))))) | |
3671 | |
3672 (defun verilog-strip-comments () | |
3673 "Strip all comments from the verilog code." | |
3674 (interactive) | |
3675 (goto-char (point-min)) | |
3676 (while (re-search-forward "//" nil t) | |
3677 (if (verilog-within-string) | |
3678 (re-search-forward "\"" nil t) | |
3679 (if (verilog-in-star-comment-p) | |
3680 (re-search-forward "\*/" nil t) | |
3681 (let ((bpt (- (point) 2))) | |
3682 (end-of-line) | |
3683 (delete-region bpt (point)))))) | |
3684 ;; | |
3685 (goto-char (point-min)) | |
3686 (while (re-search-forward "/\\*" nil t) | |
3687 (if (verilog-within-string) | |
3688 (re-search-forward "\"" nil t) | |
3689 (let ((bpt (- (point) 2))) | |
3690 (re-search-forward "\\*/") | |
3691 (delete-region bpt (point)))))) | |
3692 | |
3693 (defun verilog-one-line () | |
3694 "Convert structural verilog instances to occupy one line." | |
3695 (interactive) | |
3696 (goto-char (point-min)) | |
3697 (while (re-search-forward "\\([^;]\\)[ \t]*\n[ \t]*" nil t) | |
3698 (replace-match "\\1 " nil nil))) | |
3699 | |
3700 (defun verilog-linter-name () | |
3701 "Return name of linter, either surelint or verilint." | |
3702 (let ((compile-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil | |
3703 compile-command)) | |
3704 (lint-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil | |
3705 verilog-linter))) | |
3706 (cond ((equal compile-word1 "surelint") `surelint) | |
3707 ((equal compile-word1 "verilint") `verilint) | |
3708 ((equal lint-word1 "surelint") `surelint) | |
3709 ((equal lint-word1 "verilint") `verilint) | |
3710 (t `surelint)))) ;; back compatibility | |
3711 | |
3712 (defun verilog-lint-off () | |
3713 "Convert a Verilog linter warning line into a disable statement. | |
3714 For example: | |
3715 pci_bfm_null.v, line 46: Unused input: pci_rst_ | |
3716 becomes a comment for the appropriate tool. | |
3717 | |
3718 The first word of the `compile-command' or `verilog-linter' | |
3719 variables are used to determine which product is being used. | |
3720 | |
3721 See \\[verilog-surelint-off] and \\[verilog-verilint-off]." | |
3722 (interactive) | |
3723 (let ((linter (verilog-linter-name))) | |
3724 (cond ((equal linter `surelint) | |
3725 (verilog-surelint-off)) | |
3726 ((equal linter `verilint) | |
3727 (verilog-verilint-off)) | |
3728 (t (error "Linter name not set"))))) | |
3729 | |
3730 (defun verilog-surelint-off () | |
3731 "Convert a SureLint warning line into a disable statement. | |
3732 Run from Verilog source window; assumes there is a *compile* buffer | |
3733 with point set appropriately. | |
3734 | |
3735 For example: | |
3736 WARNING [STD-UDDONX]: xx.v, line 8: output out is never assigned. | |
3737 becomes: | |
3738 // surefire lint_line_off UDDONX" | |
3739 (interactive) | |
3740 (save-excursion | |
3741 (switch-to-buffer compilation-last-buffer) | |
3742 (beginning-of-line) | |
3743 (when | |
3744 (looking-at "\\(INFO\\|WARNING\\|ERROR\\) \\[[^-]+-\\([^]]+\\)\\]: \\([^,]+\\), line \\([0-9]+\\): \\(.*\\)$") | |
3745 (let* ((code (match-string 2)) | |
3746 (file (match-string 3)) | |
3747 (line (match-string 4)) | |
3748 (buffer (get-file-buffer file)) | |
3749 dir filename) | |
3750 (unless buffer | |
3751 (progn | |
3752 (setq buffer | |
3753 (and (file-exists-p file) | |
3754 (find-file-noselect file))) | |
3755 (or buffer | |
3756 (let* ((pop-up-windows t)) | |
3757 (let ((name (expand-file-name | |
3758 (read-file-name | |
3759 (format "Find this error in: (default %s) " | |
3760 file) | |
3761 dir file t)))) | |
3762 (if (file-directory-p name) | |
3763 (setq name (expand-file-name filename name))) | |
3764 (setq buffer | |
3765 (and (file-exists-p name) | |
3766 (find-file-noselect name)))))))) | |
3767 (switch-to-buffer buffer) | |
3768 (goto-line (string-to-number line)) | |
3769 (end-of-line) | |
3770 (catch 'already | |
3771 (cond | |
3772 ((verilog-in-slash-comment-p) | |
3773 (re-search-backward "//") | |
3774 (cond | |
3775 ((looking-at "// surefire lint_off_line ") | |
3776 (goto-char (match-end 0)) | |
3777 (let ((lim (save-excursion (end-of-line) (point)))) | |
3778 (if (re-search-forward code lim 'move) | |
3779 (throw 'already t) | |
3780 (insert-string (concat " " code))))) | |
3781 (t | |
3782 ))) | |
3783 ((verilog-in-star-comment-p) | |
3784 (re-search-backward "/\*") | |
3785 (insert-string (format " // surefire lint_off_line %6s" code )) | |
3786 ) | |
3787 (t | |
3788 (insert-string (format " // surefire lint_off_line %6s" code )) | |
3789 ))))))) | |
3790 | |
3791 (defun verilog-verilint-off () | |
3792 "Convert a Verilint warning line into a disable statement. | |
3793 | |
3794 For example: | |
3795 (W240) pci_bfm_null.v, line 46: Unused input: pci_rst_ | |
3796 becomes: | |
3797 //Verilint 240 off // WARNING: Unused input" | |
3798 (interactive) | |
3799 (save-excursion | |
3800 (beginning-of-line) | |
3801 (when (looking-at "\\(.*\\)([WE]\\([0-9A-Z]+\\)).*,\\s +line\\s +[0-9]+:\\s +\\([^:\n]+\\):?.*$") | |
3802 (replace-match (format | |
3803 ;; %3s makes numbers 1-999 line up nicely | |
3804 "\\1//Verilint %3s off // WARNING: \\3" | |
3805 (match-string 2))) | |
3806 (beginning-of-line) | |
3807 (verilog-indent-line)))) | |
3808 | |
3809 (defun verilog-auto-save-compile () | |
3810 "Update automatics with \\[verilog-auto], save the buffer, and compile." | |
3811 (interactive) | |
3812 (verilog-auto) ; Always do it for safety | |
3813 (save-buffer) | |
3814 (compile compile-command)) | |
3815 | |
3816 | |
3817 | |
3818 ;; | |
3819 ;; Batch | |
3820 ;; | |
3821 | |
3822 (defmacro verilog-batch-error-wrapper (&rest body) | |
3823 "Execute BODY and add error prefix to any errors found. | |
3824 This lets programs calling batch mode to easily extract error messages." | |
79546 | 3825 `(condition-case err |
3826 (progn ,@body) | |
3827 (error | |
3828 (error "%%Error: %s%s" (error-message-string err) | |
3829 (if (featurep 'xemacs) "\n" ""))))) ;; xemacs forgets to add a newline | |
79545 | 3830 |
3831 (defun verilog-batch-execute-func (funref) | |
3832 "Internal processing of a batch command, running FUNREF on all command arguments." | |
3833 (verilog-batch-error-wrapper | |
3834 ;; General globals needed | |
3835 (setq make-backup-files nil) | |
3836 (setq-default make-backup-files nil) | |
3837 (setq enable-local-variables t) | |
3838 (setq enable-local-eval t) | |
3839 ;; Make sure any sub-files we read get proper mode | |
3840 (setq default-major-mode `verilog-mode) | |
3841 ;; Ditto files already read in | |
3842 (mapcar '(lambda (buf) | |
3843 (when (buffer-file-name buf) | |
3844 (save-excursion | |
3845 (set-buffer buf) | |
3846 (verilog-mode)))) | |
3847 (buffer-list)) | |
3848 ;; Process the files | |
3849 (mapcar '(lambda (buf) | |
3850 (when (buffer-file-name buf) | |
3851 (save-excursion | |
3852 (if (not (file-exists-p (buffer-file-name buf))) | |
3853 (error (concat "File not found: " (buffer-file-name buf)))) | |
3854 (message (concat "Processing " (buffer-file-name buf))) | |
3855 (set-buffer buf) | |
3856 (funcall funref) | |
3857 (save-buffer)))) | |
3858 (buffer-list)))) | |
3859 | |
3860 (defun verilog-batch-auto () | |
3861 "For use with --batch, perform automatic expansions as a stand-alone tool. | |
3862 This sets up the appropriate Verilog-Mode environment, updates automatics | |
3863 with \\[verilog-auto] on all command-line files, and saves the buffers. | |
3864 For proper results, multiple filenames need to be passed on the command | |
3865 line in bottom-up order." | |
3866 (unless noninteractive | |
3867 (error "Use verilog-batch-auto only with --batch")) ;; Otherwise we'd mess up buffer modes | |
3868 (verilog-batch-execute-func `verilog-auto)) | |
3869 | |
3870 (defun verilog-batch-delete-auto () | |
3871 "For use with --batch, perform automatic deletion as a stand-alone tool. | |
3872 This sets up the appropriate Verilog-Mode environment, deletes automatics | |
3873 with \\[verilog-delete-auto] on all command-line files, and saves the buffers." | |
3874 (unless noninteractive | |
3875 (error "Use verilog-batch-delete-auto only with --batch")) ;; Otherwise we'd mess up buffer modes | |
3876 (verilog-batch-execute-func `verilog-delete-auto)) | |
3877 | |
3878 (defun verilog-batch-inject-auto () | |
3879 "For use with --batch, perform automatic injection as a stand-alone tool. | |
3880 This sets up the appropriate Verilog-Mode environment, injects new automatics | |
3881 with \\[verilog-inject-auto] on all command-line files, and saves the buffers. | |
3882 For proper results, multiple filenames need to be passed on the command | |
3883 line in bottom-up order." | |
3884 (unless noninteractive | |
3885 (error "Use verilog-batch-inject-auto only with --batch")) ;; Otherwise we'd mess up buffer modes | |
3886 (verilog-batch-execute-func `verilog-inject-auto)) | |
3887 | |
3888 (defun verilog-batch-indent () | |
3889 "For use with --batch, reindent an a entire file as a stand-alone tool. | |
3890 This sets up the appropriate Verilog-Mode environment, calls | |
3891 \\[verilog-indent-buffer] on all command-line files, and saves the buffers." | |
3892 (unless noninteractive | |
3893 (error "Use verilog-batch-indent only with --batch")) ;; Otherwise we'd mess up buffer modes | |
3894 (verilog-batch-execute-func `verilog-indent-buffer)) | |
3895 | |
3896 | |
3897 ;; | |
3898 ;; Indentation | |
3899 ;; | |
3900 (defconst verilog-indent-alist | |
3901 '((block . (+ ind verilog-indent-level)) | |
3902 (case . (+ ind verilog-case-indent)) | |
3903 (cparenexp . (+ ind verilog-indent-level)) | |
3904 (cexp . (+ ind verilog-cexp-indent)) | |
3905 (defun . verilog-indent-level-module) | |
3906 (declaration . verilog-indent-level-declaration) | |
3907 (directive . (verilog-calculate-indent-directive)) | |
3908 (tf . verilog-indent-level) | |
3909 (behavioral . (+ verilog-indent-level-behavioral verilog-indent-level-module)) | |
3910 (statement . ind) | |
3911 (cpp . 0) | |
3912 (comment . (verilog-comment-indent)) | |
3913 (unknown . 3) | |
3914 (string . 0))) | |
3915 | |
3916 (defun verilog-continued-line-1 (lim) | |
3917 "Return true if this is a continued line. | |
3918 Set point to where line starts. Limit search to point LIM." | |
3919 (let ((continued 't)) | |
3920 (if (eq 0 (forward-line -1)) | |
3921 (progn | |
3922 (end-of-line) | |
3923 (verilog-backward-ws&directives lim) | |
3924 (if (bobp) | |
3925 (setq continued nil) | |
3926 (setq continued (verilog-backward-token)))) | |
3927 (setq continued nil)) | |
3928 continued)) | |
3929 | |
3930 (defun verilog-calculate-indent () | |
3931 "Calculate the indent of the current Verilog line. | |
3932 Examine previous lines. Once a line is found that is definitive as to the | |
3933 type of the current line, return that lines' indent level and its | |
3934 type. Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)." | |
3935 (save-excursion | |
3936 (let* ((starting_position (point)) | |
3937 (par 0) | |
3938 (begin (looking-at "[ \t]*begin\\>")) | |
3939 (lim (save-excursion (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil t))) | |
3940 (type (catch 'nesting | |
3941 ;; Keep working backwards until we can figure out | |
3942 ;; what type of statement this is. | |
3943 ;; Basically we need to figure out | |
3944 ;; 1) if this is a continuation of the previous line; | |
3945 ;; 2) are we in a block scope (begin..end) | |
3946 | |
3947 ;; if we are in a comment, done. | |
3948 (if (verilog-in-star-comment-p) | |
3949 (throw 'nesting 'comment)) | |
3950 | |
3951 ;; if we have a directive, done. | |
3952 (if (save-excursion (beginning-of-line) (looking-at verilog-directive-re-1)) | |
3953 (throw 'nesting 'directive)) | |
3954 | |
3955 ;; unless we are in the newfangled coverpoint or constraint blocks | |
3956 ;; if we are in a parenthesized list, and the user likes to indent these, return. | |
3957 (if (and | |
3958 verilog-indent-lists | |
3959 (not (verilog-in-coverage)) | |
3960 (verilog-in-paren)) | |
3961 (progn (setq par 1) | |
3962 (throw 'nesting 'block)) | |
3963 ) | |
3964 | |
3965 ;; See if we are continuing a previous line | |
3966 (while t | |
3967 ;; trap out if we crawl off the top of the buffer | |
3968 (if (bobp) (throw 'nesting 'cpp)) | |
3969 | |
3970 (if (verilog-continued-line-1 lim) | |
3971 (let ((sp (point))) | |
3972 (if (and | |
3973 (not (looking-at verilog-complete-reg)) | |
3974 (verilog-continued-line-1 lim)) | |
3975 (progn (goto-char sp) | |
3976 (throw 'nesting 'cexp)) | |
3977 | |
3978 (goto-char sp)) | |
3979 | |
3980 (if (and begin | |
3981 (not verilog-indent-begin-after-if) | |
3982 (looking-at verilog-no-indent-begin-re)) | |
3983 (progn | |
3984 (beginning-of-line) | |
3985 (skip-chars-forward " \t") | |
3986 (throw 'nesting 'statement)) | |
3987 (progn | |
3988 (throw 'nesting 'cexp)))) | |
3989 ;; not a continued line | |
3990 (goto-char starting_position)) | |
3991 | |
3992 (if (looking-at "\\<else\\>") | |
3993 ;; search back for governing if, striding across begin..end pairs | |
3994 ;; appropriately | |
3995 (let ((elsec 1)) | |
3996 (while (verilog-re-search-backward verilog-ends-re nil 'move) | |
3997 (cond | |
3998 ((match-end 1) ; else, we're in deep | |
3999 (setq elsec (1+ elsec))) | |
4000 ((match-end 2) ; if | |
4001 (setq elsec (1- elsec)) | |
4002 (if (= 0 elsec) | |
4003 (if verilog-align-ifelse | |
4004 (throw 'nesting 'statement) | |
4005 (progn ;; back up to first word on this line | |
4006 (beginning-of-line) | |
4007 (verilog-forward-syntactic-ws) | |
4008 (throw 'nesting 'statement))))) | |
4009 (t ; endblock | |
4010 ; try to leap back to matching outward block by striding across | |
4011 ; indent level changing tokens then immediately | |
4012 ; previous line governs indentation. | |
4013 (let (( reg) (nest 1)) | |
4014 ;; verilog-ends => else|if|end|join(_any|_none|)|endcase|endclass|endtable|endspecify|endfunction|endtask|endgenerate|endgroup | |
4015 (cond | |
4016 ((match-end 3) ; end | |
4017 ;; Search back for matching begin | |
4018 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" )) | |
4019 ((match-end 4) ; endcase | |
4020 ;; Search back for matching case | |
4021 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )) | |
4022 ((match-end 5) ; endfunction | |
4023 ;; Search back for matching function | |
4024 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )) | |
4025 ((match-end 6) ; endtask | |
4026 ;; Search back for matching task | |
4027 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" )) | |
4028 ((match-end 7) ; endspecify | |
4029 ;; Search back for matching specify | |
4030 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )) | |
4031 ((match-end 8) ; endtable | |
4032 ;; Search back for matching table | |
4033 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )) | |
4034 ((match-end 9) ; endgenerate | |
4035 ;; Search back for matching generate | |
4036 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" )) | |
4037 ((match-end 10) ; joins | |
4038 ;; Search back for matching fork | |
4039 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|none\\)?\\>\\)" )) | |
4040 ((match-end 11) ; class | |
4041 ;; Search back for matching class | |
4042 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" )) | |
4043 ((match-end 12) ; covergroup | |
4044 ;; Search back for matching covergroup | |
4045 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )) | |
4046 ) | |
4047 (catch 'skip | |
4048 (while (verilog-re-search-backward reg nil 'move) | |
4049 (cond | |
4050 ((match-end 1) ; begin | |
4051 (setq nest (1- nest)) | |
4052 (if (= 0 nest) | |
4053 (throw 'skip 1))) | |
4054 ((match-end 2) ; end | |
4055 (setq nest (1+ nest))))) | |
4056 ) | |
4057 )) | |
4058 )))) | |
4059 (throw 'nesting (verilog-calc-1)) | |
4060 ) | |
4061 );; catch nesting | |
4062 );; type | |
4063 ) | |
4064 ;; Return type of block and indent level. | |
4065 (if (not type) | |
4066 (setq type 'cpp)) | |
4067 (if (> par 0) ; Unclosed Parenthesis | |
4068 (list 'cparenexp par) | |
4069 (cond | |
4070 ((eq type 'case) | |
4071 (list type (verilog-case-indent-level))) | |
4072 ((eq type 'statement) | |
4073 (list type (current-column))) | |
4074 ((eq type 'defun) | |
4075 (list type 0)) | |
4076 (t | |
4077 (list type (verilog-current-indent-level))))) | |
4078 ))) | |
4079 (defun verilog-wai () | |
4080 "Show matching nesting block for debugging." | |
4081 (interactive) | |
4082 (save-excursion | |
4083 (let ((nesting (verilog-calc-1))) | |
4084 (message "You are at nesting %s" nesting)))) | |
4085 | |
4086 (defun verilog-calc-1 () | |
4087 (catch 'nesting | |
4088 (while (verilog-re-search-backward (concat "\\({\\|}\\|" verilog-indent-re "\\)") nil 'move) | |
4089 (cond | |
4090 ((equal (char-after) ?\{) | |
4091 (if (verilog-at-constraint-p) | |
4092 (throw 'nesting 'block) | |
4093 )) | |
4094 ((equal (char-after) ?\}) | |
4095 | |
4096 (let ((there (verilog-at-close-constraint-p))) | |
4097 (if there (goto-char there)))) | |
4098 | |
4099 ((looking-at verilog-beg-block-re-ordered) | |
4100 (cond | |
4101 ((match-end 2) ; *sigh* could be "unique case" or "priority casex" | |
4102 (let ((here (point))) | |
4103 (verilog-beg-of-statement) | |
4104 (if (looking-at verilog-extended-case-re) | |
4105 (throw 'nesting 'case) | |
4106 (goto-char here))) | |
4107 (throw 'nesting 'case)) | |
4108 | |
4109 ;; need to consider typedef struct here... | |
4110 ((looking-at "\\<class\\|struct\\|function\\|task\\|property\\>") | |
4111 ; *sigh* These words have an optional prefix: | |
4112 ; extern {virtual|protected}? function a(); | |
4113 ; assert property (p_1); | |
4114 ; typedef class foo; | |
4115 ; and we don't want to confuse this with | |
4116 ; function a(); | |
4117 ; property | |
4118 ; ... | |
4119 ; endfunction | |
4120 (let ((here (point))) | |
4121 (save-excursion | |
4122 (verilog-beg-of-statement) | |
4123 (if (= (point) here) | |
4124 (throw 'nesting 'block)) | |
4125 ))) | |
4126 (t (throw 'nesting 'block)))) | |
4127 | |
4128 ((looking-at verilog-end-block-re) | |
4129 (verilog-leap-to-head) | |
4130 (if (verilog-in-case-region-p) | |
4131 (progn | |
4132 (verilog-leap-to-case-head) | |
4133 (if (looking-at verilog-case-re) | |
4134 (throw 'nesting 'case))))) | |
4135 | |
4136 ((looking-at (if (verilog-in-generate-region-p) | |
4137 verilog-defun-level-not-generate-re | |
4138 verilog-defun-level-re)) | |
4139 (throw 'nesting 'defun)) | |
4140 | |
4141 ((looking-at verilog-cpp-level-re) | |
4142 (throw 'nesting 'cpp)) | |
4143 | |
4144 ((bobp) | |
4145 (throw 'nesting 'cpp)) | |
4146 )) | |
4147 (throw 'nesting 'cpp) | |
4148 ) | |
4149 ) | |
4150 | |
4151 (defun verilog-calculate-indent-directive () | |
4152 "Return indentation level for directive. | |
4153 For speed, the searcher looks at the last directive, not the indent | |
4154 of the appropriate enclosing block." | |
4155 (let ((base -1) ;; Indent of the line that determines our indentation | |
4156 (ind 0) ;; Relative offset caused by other directives (like `endif on same line as `else) | |
4157 ) | |
4158 ;; Start at current location, scan back for another directive | |
4159 | |
4160 (save-excursion | |
4161 (beginning-of-line) | |
4162 (while (and (< base 0) | |
4163 (verilog-re-search-backward verilog-directive-re nil t)) | |
4164 (cond ((save-excursion (skip-chars-backward " \t") (bolp)) | |
4165 (setq base (current-indentation)) | |
4166 )) | |
4167 (cond ((and (looking-at verilog-directive-end) (< base 0)) ;; Only matters when not at BOL | |
4168 (setq ind (- ind verilog-indent-level-directive))) | |
4169 ((and (looking-at verilog-directive-middle) (>= base 0)) ;; Only matters when at BOL | |
4170 (setq ind (+ ind verilog-indent-level-directive))) | |
4171 ((looking-at verilog-directive-begin) | |
4172 (setq ind (+ ind verilog-indent-level-directive))))) | |
4173 ;; Adjust indent to starting indent of critical line | |
4174 (setq ind (max 0 (+ ind base)))) | |
4175 | |
4176 (save-excursion | |
4177 (beginning-of-line) | |
4178 (skip-chars-forward " \t") | |
4179 (cond ((or (looking-at verilog-directive-middle) | |
4180 (looking-at verilog-directive-end)) | |
4181 (setq ind (max 0 (- ind verilog-indent-level-directive)))))) | |
4182 ind)) | |
4183 | |
4184 (defun verilog-leap-to-case-head () | |
4185 (let ((nest 1)) | |
4186 (while (/= 0 nest) | |
4187 (verilog-re-search-backward "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" nil 'move) | |
4188 (cond | |
4189 ((match-end 1) | |
4190 (setq nest (1- nest))) | |
4191 ((match-end 2) | |
4192 (setq nest (1+ nest))) | |
4193 ((bobp) | |
4194 (ding 't) | |
4195 (setq nest 0)))))) | |
4196 | |
4197 (defun verilog-leap-to-head () | |
4198 "Move point to the head of this block; jump from end to matching begin, | |
4199 from endcase to matching case, and so on." | |
4200 (let ((reg nil) | |
4201 snest | |
4202 (nest 1)) | |
4203 (cond | |
4204 ((looking-at "\\<end\\>") | |
4205 ;; 1: Search back for matching begin | |
4206 (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|" | |
4207 "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))) | |
4208 ((looking-at "\\<endcase\\>") | |
4209 ;; 2: Search back for matching case | |
4210 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)" )) | |
4211 ((looking-at "\\<join\\(_any\\|_none\\)?\\>") | |
4212 ;; 3: Search back for matching fork | |
4213 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )) | |
4214 ((looking-at "\\<endclass\\>") | |
4215 ;; 4: Search back for matching class | |
4216 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" )) | |
4217 ((looking-at "\\<endtable\\>") | |
4218 ;; 5: Search back for matching table | |
4219 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )) | |
4220 ((looking-at "\\<endspecify\\>") | |
4221 ;; 6: Search back for matching specify | |
4222 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )) | |
4223 ((looking-at "\\<endfunction\\>") | |
4224 ;; 7: Search back for matching function | |
4225 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )) | |
4226 ((looking-at "\\<endgenerate\\>") | |
4227 ;; 8: Search back for matching generate | |
4228 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" )) | |
4229 ((looking-at "\\<endtask\\>") | |
4230 ;; 9: Search back for matching task | |
4231 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" )) | |
4232 ((looking-at "\\<endgroup\\>") | |
4233 ;; 10: Search back for matching covergroup | |
4234 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )) | |
4235 ((looking-at "\\<endproperty\\>") | |
4236 ;; 11: Search back for matching property | |
4237 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" )) | |
4238 ((looking-at "\\<endinterface\\>") | |
4239 ;; 12: Search back for matching interface | |
4240 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" )) | |
4241 ((looking-at "\\<endsequence\\>") | |
4242 ;; 12: Search back for matching sequence | |
4243 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )) | |
4244 ((looking-at "\\<endclocking\\>") | |
4245 ;; 12: Search back for matching clocking | |
4246 (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" )) | |
4247 ) | |
4248 (if reg | |
4249 (catch 'skip | |
4250 (let (sreg) | |
4251 (while (verilog-re-search-backward reg nil 'move) | |
4252 (cond | |
4253 ((match-end 1) ; begin | |
4254 (setq nest (1- nest)) | |
4255 (if (= 0 nest) | |
4256 ;; Now previous line describes syntax | |
4257 (throw 'skip 1)) | |
4258 (if (and snest | |
4259 (= snest nest)) | |
4260 (setq reg sreg))) | |
4261 ((match-end 2) ; end | |
4262 (setq nest (1+ nest))) | |
4263 ((match-end 3) | |
4264 ;; endcase, jump to case | |
4265 (setq snest nest) | |
4266 (setq nest (1+ nest)) | |
4267 (setq sreg reg) | |
4268 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )) | |
4269 ((match-end 4) | |
4270 ;; join, jump to fork | |
4271 (setq snest nest) | |
4272 (setq nest (1+ nest)) | |
4273 (setq sreg reg) | |
4274 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )) | |
4275 ))))))) | |
4276 | |
4277 (defun verilog-continued-line () | |
4278 "Return true if this is a continued line. | |
4279 Set point to where line starts" | |
4280 (let ((continued 't)) | |
4281 (if (eq 0 (forward-line -1)) | |
4282 (progn | |
4283 (end-of-line) | |
4284 (verilog-backward-ws&directives) | |
4285 (if (bobp) | |
4286 (setq continued nil) | |
4287 (while (and continued | |
4288 (save-excursion | |
4289 (skip-chars-backward " \t") | |
4290 (not (bolp)))) | |
4291 (setq continued (verilog-backward-token)) | |
4292 ) ;; while | |
4293 )) | |
4294 (setq continued nil)) | |
4295 continued)) | |
4296 | |
4297 (defun verilog-backward-token () | |
4298 "Step backward token, returning true if we are now at an end of line token." | |
4299 (interactive) | |
4300 (verilog-backward-syntactic-ws) | |
4301 (cond | |
4302 ((bolp) | |
4303 nil) | |
4304 (;-- Anything ending in a ; is complete | |
4305 (= (preceding-char) ?\;) | |
4306 nil) | |
4307 (; If a "}" is prefixed by a ";", then this is a complete statement | |
4308 ; i.e.: constraint foo { a = b; } | |
4309 (= (preceding-char) ?\}) | |
4310 (progn | |
4311 (backward-char) | |
4312 (verilog-at-close-constraint-p)) | |
4313 ) | |
4314 (;-- constraint foo { a = b } | |
4315 ; is a complete statement. *sigh* | |
4316 (= (preceding-char) ?\{) | |
4317 (progn | |
4318 (backward-char) | |
4319 (not (verilog-at-constraint-p))) | |
4320 ) | |
4321 (;-- Could be 'case (foo)' or 'always @(bar)' which is complete | |
4322 ; also could be simply '@(foo)' | |
4323 ; or foo u1 #(a=8) | |
4324 ; (b, ... which ISN'T complete | |
4325 ;;;; Do we need this??? | |
4326 (= (preceding-char) ?\)) | |
4327 (progn | |
4328 (backward-char) | |
4329 (backward-up-list 1) | |
4330 (verilog-backward-syntactic-ws) | |
4331 (let ((back (point))) | |
4332 (forward-word -1) | |
4333 (cond | |
4334 ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>") | |
4335 (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]"))) | |
4336 (t | |
4337 (goto-char back) | |
4338 (cond | |
4339 ((= (preceding-char) ?\@) | |
4340 (backward-char) | |
4341 (save-excursion | |
4342 (verilog-backward-token) | |
4343 (not (looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|initial\\|while\\)\\>")))) | |
4344 ((= (preceding-char) ?\#) | |
4345 (backward-char) | |
4346 ) | |
4347 (t t)) | |
4348 ))))) | |
4349 | |
4350 (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete | |
4351 t | |
4352 (forward-word -1) | |
4353 (cond | |
4354 ((looking-at "\\<else\\>") | |
4355 t) | |
4356 ((looking-at verilog-indent-re) | |
4357 nil) | |
4358 (t | |
4359 (let | |
4360 ((back (point))) | |
4361 (verilog-backward-syntactic-ws) | |
4362 (cond | |
4363 ((= (preceding-char) ?\:) | |
4364 (backward-char) | |
4365 (verilog-backward-syntactic-ws) | |
4366 (backward-sexp) | |
4367 (if (looking-at verilog-nameable-item-re ) | |
4368 nil | |
4369 t) | |
4370 ) | |
4371 ((= (preceding-char) ?\#) | |
4372 (backward-char) | |
4373 t) | |
4374 ((= (preceding-char) ?\`) | |
4375 (backward-char) | |
4376 t) | |
4377 | |
4378 (t | |
4379 (goto-char back) | |
4380 t) | |
4381 ))))))) | |
4382 | |
4383 (defun verilog-backward-syntactic-ws (&optional bound) | |
4384 "Backward skip over syntactic whitespace for Emacs 19. | |
4385 Optional BOUND limits search." | |
4386 (save-restriction | |
4387 (let* ((bound (or bound (point-min))) (here bound) ) | |
4388 (if (< bound (point)) | |
4389 (progn | |
4390 (narrow-to-region bound (point)) | |
4391 (while (/= here (point)) | |
4392 (setq here (point)) | |
4393 (verilog-skip-backward-comments) | |
4394 ))) | |
4395 )) | |
4396 t) | |
4397 | |
4398 (defun verilog-forward-syntactic-ws (&optional bound) | |
4399 "Forward skip over syntactic whitespace for Emacs 19. | |
4400 Optional BOUND limits search." | |
4401 (save-restriction | |
4402 (let* ((bound (or bound (point-max))) | |
4403 (here bound) | |
4404 ) | |
4405 (if (> bound (point)) | |
4406 (progn | |
4407 (narrow-to-region (point) bound) | |
4408 (while (/= here (point)) | |
4409 (setq here (point)) | |
4410 (forward-comment (buffer-size)) | |
4411 ))) | |
4412 ))) | |
4413 | |
4414 (defun verilog-backward-ws&directives (&optional bound) | |
4415 "Backward skip over syntactic whitespace and compiler directives for Emacs 19. | |
4416 Optional BOUND limits search." | |
4417 (save-restriction | |
4418 (let* ((bound (or bound (point-min))) | |
4419 (here bound) | |
4420 (p nil) ) | |
4421 (if (< bound (point)) | |
4422 (progn | |
4423 (let ((state | |
4424 (save-excursion | |
4425 (parse-partial-sexp (point-min) (point))))) | |
4426 (cond | |
4427 ((nth 7 state) ;; in // comment | |
4428 (verilog-re-search-backward "//" nil 'move) | |
4429 (skip-chars-backward "/")) | |
4430 ((nth 4 state) ;; in /* */ comment | |
4431 (verilog-re-search-backward "/\*" nil 'move)))) | |
4432 (narrow-to-region bound (point)) | |
4433 (while (/= here (point)) | |
4434 (setq here (point)) | |
4435 (verilog-skip-backward-comments) | |
4436 (setq p | |
4437 (save-excursion | |
4438 (beginning-of-line) | |
4439 (cond | |
4440 ((verilog-within-translate-off) | |
4441 (verilog-back-to-start-translate-off (point-min))) | |
4442 ((looking-at verilog-directive-re-1) | |
4443 (point)) | |
4444 (t | |
4445 nil)))) | |
4446 (if p (goto-char p)) | |
4447 ))) | |
4448 ))) | |
4449 | |
4450 (defun verilog-forward-ws&directives (&optional bound) | |
4451 "Forward skip over syntactic whitespace and compiler directives for Emacs 19. | |
4452 Optional BOUND limits search." | |
4453 (save-restriction | |
4454 (let* ((bound (or bound (point-max))) | |
4455 (here bound) | |
4456 jump | |
4457 ) | |
4458 (if (> bound (point)) | |
4459 (progn | |
4460 (let ((state | |
4461 (save-excursion | |
4462 (parse-partial-sexp (point-min) (point))))) | |
4463 (cond | |
4464 ((nth 7 state) ;; in // comment | |
4465 (verilog-re-search-forward "//" nil 'move)) | |
4466 ((nth 4 state) ;; in /* */ comment | |
4467 (verilog-re-search-forward "/\*" nil 'move)))) | |
4468 (narrow-to-region (point) bound) | |
4469 (while (/= here (point)) | |
4470 (setq here (point) | |
4471 jump nil) | |
4472 (forward-comment (buffer-size)) | |
4473 (save-excursion | |
4474 (beginning-of-line) | |
4475 (if (looking-at verilog-directive-re-1) | |
4476 (setq jump t))) | |
4477 (if jump | |
4478 (beginning-of-line 2)) | |
4479 ))) | |
4480 ))) | |
4481 | |
4482 (defun verilog-in-comment-p () | |
4483 "Return true if in a star or // comment." | |
4484 (let ((state | |
4485 (save-excursion | |
4486 (parse-partial-sexp (point-min) (point))))) | |
4487 (or (nth 4 state) (nth 7 state)))) | |
4488 | |
4489 (defun verilog-in-star-comment-p () | |
4490 "Return true if in a star comment." | |
4491 (let ((state | |
4492 (save-excursion | |
4493 (parse-partial-sexp (point-min) (point))))) | |
4494 (and | |
4495 (nth 4 state) ; t if in a comment of style a // or b /**/ | |
4496 (not | |
4497 (nth 7 state) ; t if in a comment of style b /**/ | |
4498 )))) | |
4499 | |
4500 (defun verilog-in-slash-comment-p () | |
4501 "Return true if in a slash comment." | |
4502 (let ((state | |
4503 (save-excursion | |
4504 (parse-partial-sexp (point-min) (point))))) | |
4505 (nth 7 state))) | |
4506 | |
4507 (defun verilog-in-comment-or-string-p () | |
4508 "Return true if in a string or comment." | |
4509 (let ((state | |
4510 (save-excursion | |
4511 (parse-partial-sexp (point-min) (point))))) | |
4512 (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment) | |
4513 | |
4514 (defun verilog-in-escaped-name-p () | |
4515 "Return true if in an escaped name." | |
4516 (save-excursion | |
4517 (backward-char) | |
4518 (skip-chars-backward "^ \t\n\f") | |
4519 (if (equal (char-after (point) ) ?\\ ) | |
4520 t | |
4521 nil))) | |
4522 | |
4523 (defun verilog-in-paren () | |
4524 "Return true if in a parenthetical expression." | |
4525 (let ((state | |
4526 (save-excursion | |
4527 (parse-partial-sexp (point-min) (point))))) | |
4528 (> (nth 0 state) 0 ))) | |
4529 | |
4530 (defun verilog-in-coverage () | |
4531 "Return true if in a constraint or coverpoint expression." | |
4532 (interactive) | |
4533 (save-excursion | |
4534 (if (verilog-in-paren) | |
4535 (progn | |
4536 (backward-up-list 1) | |
4537 (verilog-at-constraint-p) | |
4538 ) | |
4539 nil))) | |
4540 (defun verilog-at-close-constraint-p () | |
4541 "If at the } that closes a constraint or covergroup, return true." | |
4542 (if (and | |
4543 (equal (char-after) ?\}) | |
4544 (verilog-in-paren)) | |
4545 | |
4546 (save-excursion | |
4547 (verilog-backward-ws&directives) | |
4548 (if (equal (char-before) ?\;) | |
4549 (point) | |
4550 nil)))) | |
4551 | |
4552 (defun verilog-at-constraint-p () | |
4553 "If at the { of a constraint or coverpoint definition, return true, moving point to constraint." | |
4554 (if (save-excursion | |
4555 (and | |
4556 (equal (char-after) ?\{) | |
4557 (forward-list) | |
4558 (progn (backward-char 1) | |
4559 (verilog-backward-ws&directives) | |
4560 (equal (char-before) ?\;)) | |
4561 )) | |
4562 ;; maybe | |
4563 (verilog-re-search-backward "\\<constraint\\|coverpoint\\|cross\\>" nil 'move) | |
4564 ;; not | |
4565 nil | |
4566 ) | |
4567 ) | |
4568 | |
4569 (defun verilog-parenthesis-depth () | |
4570 "Return non zero if in parenthetical-expression." | |
4571 (save-excursion | |
4572 (nth 1 (parse-partial-sexp (point-min) (point))))) | |
4573 | |
4574 | |
4575 (defun verilog-skip-forward-comment-or-string () | |
4576 "Return true if in a string or comment." | |
4577 (let ((state | |
4578 (save-excursion | |
4579 (parse-partial-sexp (point-min) (point))))) | |
4580 (cond | |
4581 ((nth 3 state) ;Inside string | |
4582 (goto-char (nth 3 state)) | |
4583 t) | |
4584 ((nth 7 state) ;Inside // comment | |
4585 (forward-line 1) | |
4586 t) | |
4587 ((nth 4 state) ;Inside any comment (hence /**/) | |
4588 (search-forward "*/")) | |
4589 (t | |
4590 nil)))) | |
4591 | |
4592 (defun verilog-skip-backward-comment-or-string () | |
4593 "Return true if in a string or comment." | |
4594 (let ((state | |
4595 (save-excursion | |
4596 (parse-partial-sexp (point-min) (point))))) | |
4597 (cond | |
4598 ((nth 3 state) ;Inside string | |
4599 (search-backward "\"") | |
4600 t) | |
4601 ((nth 7 state) ;Inside // comment | |
4602 (search-backward "//") | |
4603 (skip-chars-backward "/") | |
4604 t) | |
4605 ((nth 4 state) ;Inside /* */ comment | |
4606 (search-backward "/*") | |
4607 t) | |
4608 (t | |
4609 nil)))) | |
4610 | |
4611 (defun verilog-skip-backward-comments () | |
4612 "Return true if a comment was skipped." | |
4613 (let ((more t)) | |
4614 (while more | |
4615 (setq more | |
4616 (let ((state | |
4617 (save-excursion | |
4618 (parse-partial-sexp (point-min) (point))))) | |
4619 (cond | |
4620 ((nth 7 state) ;Inside // comment | |
4621 (search-backward "//") | |
4622 (skip-chars-backward "/") | |
4623 (skip-chars-backward " \t\n\f") | |
4624 t) | |
4625 ((nth 4 state) ;Inside /* */ comment | |
4626 (search-backward "/*") | |
4627 (skip-chars-backward " \t\n\f") | |
4628 t) | |
4629 ((and (not (bobp)) | |
4630 (= (char-before) ?\/) | |
4631 (= (char-before (1- (point))) ?\*) | |
4632 ) | |
4633 (goto-char (- (point) 2)) | |
4634 t) | |
4635 (t | |
4636 (skip-chars-backward " \t\n\f") | |
4637 nil))))))) | |
4638 | |
4639 (defun verilog-skip-forward-comment-p () | |
4640 "If in comment, move to end and return true." | |
4641 (let (state) | |
4642 (progn | |
4643 (setq state | |
4644 (save-excursion | |
4645 (parse-partial-sexp (point-min) (point)))) | |
4646 (cond | |
4647 ((nth 3 state) | |
4648 t) | |
4649 ((nth 7 state) ;Inside // comment | |
4650 (end-of-line) | |
4651 (forward-char 1) | |
4652 t) | |
4653 ((nth 4 state) ;Inside any comment | |
4654 t) | |
4655 (t | |
4656 nil))))) | |
4657 | |
4658 (defun verilog-indent-line-relative () | |
4659 "Cheap version of indent line. | |
4660 Only look at a few lines to determine indent level." | |
4661 (interactive) | |
4662 (let ((indent-str) | |
4663 (sp (point))) | |
4664 (if (looking-at "^[ \t]*$") | |
4665 (cond ;- A blank line; No need to be too smart. | |
4666 ((bobp) | |
4667 (setq indent-str (list 'cpp 0))) | |
4668 ((verilog-continued-line) | |
4669 (let ((sp1 (point))) | |
4670 (if (verilog-continued-line) | |
4671 (progn (goto-char sp) | |
4672 (setq indent-str (list 'statement (verilog-current-indent-level)))) | |
4673 (goto-char sp1) | |
4674 (setq indent-str (list 'block (verilog-current-indent-level))))) | |
4675 (goto-char sp)) | |
4676 ((goto-char sp) | |
4677 (setq indent-str (verilog-calculate-indent)))) | |
4678 (progn (skip-chars-forward " \t") | |
4679 (setq indent-str (verilog-calculate-indent)))) | |
4680 (verilog-do-indent indent-str))) | |
4681 | |
4682 (defun verilog-indent-line () | |
4683 "Indent for special part of code." | |
4684 (verilog-do-indent (verilog-calculate-indent))) | |
4685 | |
4686 (defun verilog-do-indent (indent-str) | |
4687 (let ((type (car indent-str)) | |
4688 (ind (car (cdr indent-str)))) | |
4689 (cond | |
4690 (; handle continued exp | |
4691 (eq type 'cexp) | |
4692 (let ((here (point))) | |
4693 (verilog-backward-syntactic-ws) | |
4694 (cond | |
4695 ((or | |
4696 (= (preceding-char) ?\,) | |
4697 (= (preceding-char) ?\]) | |
4698 (save-excursion | |
4699 (verilog-beg-of-statement-1) | |
4700 (looking-at verilog-declaration-re))) | |
4701 (let* ( fst | |
4702 (val | |
4703 (save-excursion | |
4704 (backward-char 1) | |
4705 (verilog-beg-of-statement-1) | |
4706 (setq fst (point)) | |
4707 (if (looking-at verilog-declaration-re) | |
4708 (progn ;; we have multiple words | |
4709 (goto-char (match-end 0)) | |
4710 (skip-chars-forward " \t") | |
4711 (cond | |
4712 ((and verilog-indent-declaration-macros | |
4713 (= (following-char) ?\`)) | |
4714 (progn | |
4715 (forward-char 1) | |
4716 (forward-word 1) | |
4717 (skip-chars-forward " \t"))) | |
4718 ((= (following-char) ?\[) | |
4719 (progn | |
4720 (forward-char 1) | |
4721 (backward-up-list -1) | |
4722 (skip-chars-forward " \t"))) | |
4723 ) | |
4724 (current-column)) | |
4725 (progn | |
4726 (goto-char fst) | |
4727 (+ (current-column) verilog-cexp-indent)) | |
4728 )))) | |
4729 (goto-char here) | |
4730 (indent-line-to val)) | |
4731 ) | |
4732 ((= (preceding-char) ?\) ) | |
4733 (goto-char here) | |
4734 (let ((val (eval (cdr (assoc type verilog-indent-alist))))) | |
4735 (indent-line-to val))) | |
4736 (t | |
4737 (goto-char here) | |
4738 (let ((val)) | |
4739 (verilog-beg-of-statement-1) | |
4740 (if (and (< (point) here) | |
4741 (verilog-re-search-forward "=[ \\t]*" here 'move)) | |
4742 (setq val (current-column)) | |
4743 (setq val (eval (cdr (assoc type verilog-indent-alist))))) | |
4744 (goto-char here) | |
4745 (indent-line-to val))) | |
4746 ))) | |
4747 | |
4748 (; handle inside parenthetical expressions | |
4749 (eq type 'cparenexp) | |
4750 (let ((val (save-excursion | |
4751 (backward-up-list 1) | |
4752 (forward-char 1) | |
4753 (skip-chars-forward " \t") | |
4754 (current-column)))) | |
4755 (indent-line-to val) | |
4756 (if (and (not (verilog-in-struct-region-p)) | |
4757 (looking-at verilog-declaration-re)) | |
4758 (verilog-indent-declaration ind)) | |
4759 )) | |
4760 | |
4761 (;-- Handle the ends | |
4762 (or | |
4763 (looking-at verilog-end-block-re ) | |
4764 (verilog-at-close-constraint-p)) | |
4765 (let ((val (if (eq type 'statement) | |
4766 (- ind verilog-indent-level) | |
4767 ind))) | |
4768 (indent-line-to val))) | |
4769 | |
4770 (;-- Case -- maybe line 'em up | |
4771 (and (eq type 'case) (not (looking-at "^[ \t]*$"))) | |
4772 (progn | |
4773 (cond | |
4774 ((looking-at "\\<endcase\\>") | |
4775 (indent-line-to ind)) | |
4776 (t | |
4777 (let ((val (eval (cdr (assoc type verilog-indent-alist))))) | |
4778 (indent-line-to val)))))) | |
4779 | |
4780 (;-- defun | |
4781 (and (eq type 'defun) | |
4782 (looking-at verilog-zero-indent-re)) | |
4783 (indent-line-to 0)) | |
4784 | |
4785 (;-- declaration | |
4786 (and (or | |
4787 (eq type 'defun) | |
4788 (eq type 'block)) | |
4789 (looking-at verilog-declaration-re)) | |
4790 (verilog-indent-declaration ind)) | |
4791 | |
4792 (;-- Everything else | |
4793 t | |
4794 (let ((val (eval (cdr (assoc type verilog-indent-alist))))) | |
4795 (indent-line-to val))) | |
4796 ) | |
4797 (if (looking-at "[ \t]+$") | |
4798 (skip-chars-forward " \t")) | |
4799 indent-str ; Return indent data | |
4800 )) | |
4801 | |
4802 (defun verilog-current-indent-level () | |
4803 "Return the indent-level the current statement has." | |
4804 (save-excursion | |
4805 (let (par-pos) | |
4806 (beginning-of-line) | |
4807 (setq par-pos (verilog-parenthesis-depth)) | |
4808 (while par-pos | |
4809 (goto-char par-pos) | |
4810 (beginning-of-line) | |
4811 (setq par-pos (verilog-parenthesis-depth))) | |
4812 (skip-chars-forward " \t") | |
4813 (current-column)))) | |
4814 | |
4815 (defun verilog-case-indent-level () | |
4816 "Return the indent-level the current statement has. | |
4817 Do not count named blocks or case-statements." | |
4818 (save-excursion | |
4819 (skip-chars-forward " \t") | |
4820 (cond | |
4821 ((looking-at verilog-named-block-re) | |
4822 (current-column)) | |
4823 ((and (not (looking-at verilog-case-re)) | |
4824 (looking-at "^[^:;]+[ \t]*:")) | |
4825 (verilog-re-search-forward ":" nil t) | |
4826 (skip-chars-forward " \t") | |
4827 (current-column)) | |
4828 (t | |
4829 (current-column))))) | |
4830 | |
4831 (defun verilog-indent-comment () | |
4832 "Indent current line as comment." | |
4833 (let* ((stcol | |
4834 (cond | |
4835 ((verilog-in-star-comment-p) | |
4836 (save-excursion | |
4837 (re-search-backward "/\\*" nil t) | |
4838 (1+(current-column)))) | |
4839 (comment-column | |
4840 comment-column ) | |
4841 (t | |
4842 (save-excursion | |
4843 (re-search-backward "//" nil t) | |
4844 (current-column))) | |
4845 ))) | |
4846 (indent-line-to stcol) | |
4847 stcol)) | |
4848 | |
4849 (defun verilog-more-comment () | |
4850 "Make more comment lines like the previous." | |
4851 (let* ((star 0) | |
4852 (stcol | |
4853 (cond | |
4854 ((verilog-in-star-comment-p) | |
4855 (save-excursion | |
4856 (setq star 1) | |
4857 (re-search-backward "/\\*" nil t) | |
4858 (1+(current-column)))) | |
4859 (comment-column | |
4860 comment-column ) | |
4861 (t | |
4862 (save-excursion | |
4863 (re-search-backward "//" nil t) | |
4864 (current-column))) | |
4865 ))) | |
4866 (progn | |
4867 (indent-to stcol) | |
4868 (if (and star | |
4869 (save-excursion | |
4870 (forward-line -1) | |
4871 (skip-chars-forward " \t") | |
4872 (looking-at "\*"))) | |
4873 (insert "* "))))) | |
4874 | |
4875 (defun verilog-comment-indent (&optional arg) | |
4876 "Return the column number the line should be indented to. | |
4877 ARG is ignored, for `comment-indent-function' compatibility." | |
4878 (cond | |
4879 ((verilog-in-star-comment-p) | |
4880 (save-excursion | |
4881 (re-search-backward "/\\*" nil t) | |
4882 (1+(current-column)))) | |
4883 ( comment-column | |
4884 comment-column ) | |
4885 (t | |
4886 (save-excursion | |
4887 (re-search-backward "//" nil t) | |
4888 (current-column))))) | |
4889 | |
4890 ;; | |
4891 | |
4892 (defun verilog-pretty-declarations () | |
4893 "Line up declarations around point." | |
4894 (interactive) | |
4895 (save-excursion | |
4896 (if (progn | |
4897 (verilog-beg-of-statement-1) | |
4898 (looking-at verilog-declaration-re)) | |
4899 (let* ((m1 (make-marker)) | |
4900 (e) (r) | |
4901 (here (point)) | |
4902 ;; Start of declaration range | |
4903 (start | |
4904 (progn | |
4905 (verilog-beg-of-statement-1) | |
4906 (while (looking-at verilog-declaration-re) | |
4907 (beginning-of-line) | |
4908 (setq e (point)) | |
4909 (verilog-backward-syntactic-ws) | |
4910 (backward-char) | |
4911 (verilog-beg-of-statement-1)) ;Ack, need to grok `define | |
4912 e)) | |
4913 ;; End of declaration range | |
4914 (end | |
4915 (progn | |
4916 (goto-char here) | |
4917 (verilog-end-of-statement) | |
4918 (setq e (point)) ;Might be on last line | |
4919 (verilog-forward-syntactic-ws) | |
4920 (while (looking-at verilog-declaration-re) | |
4921 (beginning-of-line) | |
4922 (verilog-end-of-statement) | |
4923 (setq e (point)) | |
4924 (verilog-forward-syntactic-ws)) | |
4925 e)) | |
4926 (edpos (set-marker (make-marker) end)) | |
4927 (ind) | |
4928 (base-ind | |
4929 (progn | |
4930 (goto-char start) | |
4931 (verilog-do-indent (verilog-calculate-indent)) | |
4932 (verilog-forward-ws&directives) | |
4933 (current-column))) | |
4934 ) | |
4935 (goto-char end) | |
4936 (goto-char start) | |
4937 (if (> (- end start) 100) | |
4938 (message "Lining up declarations..(please stand by)")) | |
4939 ;; Get the beginning of line indent first | |
4940 (while (progn (setq e (marker-position edpos)) | |
4941 (< (point) e)) | |
4942 (cond | |
4943 ( (save-excursion (skip-chars-backward " \t") | |
4944 (bolp)) | |
4945 (verilog-forward-ws&directives) | |
4946 (indent-line-to base-ind) | |
4947 (verilog-forward-ws&directives) | |
4948 (verilog-re-search-forward "[ \t\n\f]" e 'move) | |
4949 ) | |
4950 (t | |
4951 (just-one-space) | |
4952 (verilog-re-search-forward "[ \t\n\f]" e 'move) | |
4953 ) | |
4954 ) | |
4955 ) | |
4956 ;;(forward-line)) | |
4957 ;; Now find biggest prefix | |
4958 (setq ind (verilog-get-lineup-indent start edpos)) | |
4959 ;; Now indent each line. | |
4960 (goto-char start) | |
4961 (while (progn (setq e (marker-position edpos)) | |
4962 (setq r (- e (point))) | |
4963 (> r 0)) | |
4964 (setq e (point)) | |
4965 (message "%d" r) | |
4966 (cond | |
4967 ((or (and verilog-indent-declaration-macros | |
4968 (looking-at verilog-declaration-re-1-macro)) | |
4969 (looking-at verilog-declaration-re-1-no-macro)) | |
4970 (let ((p (match-end 0))) | |
4971 (set-marker m1 p) | |
4972 (if (verilog-re-search-forward "[[#`]" p 'move) | |
4973 (progn | |
4974 (forward-char -1) | |
4975 (just-one-space) | |
4976 (goto-char (marker-position m1)) | |
4977 (just-one-space) | |
4978 (indent-to ind)) | |
4979 (progn | |
4980 (just-one-space) | |
4981 (indent-to ind)) | |
4982 ))) | |
4983 ((verilog-continued-line-1 start) | |
4984 (goto-char e) | |
4985 (indent-line-to ind)) | |
4986 (t ; Must be comment or white space | |
4987 (goto-char e) | |
4988 (verilog-forward-ws&directives) | |
4989 (forward-line -1)) | |
4990 ) | |
4991 (forward-line 1)) | |
4992 (message ""))))) | |
4993 | |
4994 (defun verilog-pretty-expr (&optional myre) | |
4995 "Line up expressions around point." | |
4996 (interactive "sRegular Expression: ((<|:)?=) ") | |
4997 (save-excursion | |
4998 (if (or (eq myre nil) | |
4999 (string-equal myre "")) | |
5000 (setq myre "\\(<\\|:\\)?=")) | |
5001 ; (setq myre (concat "\\(^[^;" myre "]*\\)\\([" myre "]\\)")) | |
5002 (setq myre (concat "\\(^[^;#:?=]*\\)\\([" myre "]\\)")) | |
5003 (beginning-of-line) | |
5004 (if (and (not (looking-at (concat "^\\s-*" verilog-complete-reg))) | |
5005 (looking-at myre)) | |
5006 (let* ((here (point)) | |
5007 (e) (r) | |
5008 (start | |
5009 (progn | |
5010 (beginning-of-line) | |
5011 (setq e (point)) | |
5012 (verilog-backward-syntactic-ws) | |
5013 (beginning-of-line) | |
5014 (while (and (not (looking-at (concat "^\\s-*" verilog-complete-reg))) | |
5015 (looking-at myre) | |
5016 (not (bobp)) | |
5017 ) | |
5018 (setq e (point)) | |
5019 (verilog-backward-syntactic-ws) | |
5020 (beginning-of-line) | |
5021 ) ;Ack, need to grok `define | |
5022 e)) | |
5023 (end | |
5024 (progn | |
5025 (goto-char here) | |
5026 (end-of-line) | |
5027 (setq e (point)) ;Might be on last line | |
5028 (verilog-forward-syntactic-ws) | |
5029 (beginning-of-line) | |
5030 (while (and (not(looking-at (concat "^\\s-*" verilog-complete-reg))) | |
5031 (looking-at myre)) | |
5032 (end-of-line) | |
5033 (setq e (point)) | |
5034 (verilog-forward-syntactic-ws) | |
5035 (beginning-of-line) | |
5036 ) | |
5037 e)) | |
5038 (edpos (set-marker (make-marker) end)) | |
5039 (ind) | |
5040 ) | |
5041 (goto-char start) | |
5042 (verilog-do-indent (verilog-calculate-indent)) | |
5043 (if (> (- end start) 100) | |
5044 (message "Lining up expressions..(please stand by)")) | |
5045 | |
5046 ;; Set indent to minimum throughout region | |
5047 (while (< (point) (marker-position edpos)) | |
5048 (beginning-of-line) | |
5049 (verilog-just-one-space myre) | |
5050 (end-of-line) | |
5051 (verilog-forward-syntactic-ws) | |
5052 ) | |
5053 | |
5054 ;; Now find biggest prefix | |
5055 (setq ind (verilog-get-lineup-indent-2 myre start edpos)) | |
5056 | |
5057 ;; Now indent each line. | |
5058 (goto-char start) | |
5059 (while (progn (setq e (marker-position edpos)) | |
5060 (setq r (- e (point))) | |
5061 (> r 0)) | |
5062 (setq e (point)) | |
5063 (message "%d" r) | |
5064 (cond | |
5065 ((looking-at myre) | |
5066 (goto-char (match-end 1)) | |
5067 (if (eq (char-after) ?=) | |
5068 (indent-to (1+ ind)) ; line up the = of the <= with surrounding = | |
5069 (indent-to ind) | |
5070 ) | |
5071 ) | |
5072 ((verilog-continued-line-1 start) | |
5073 (goto-char e) | |
5074 (indent-line-to ind)) | |
5075 (t ; Must be comment or white space | |
5076 (goto-char e) | |
5077 (verilog-forward-ws&directives) | |
5078 (forward-line -1)) | |
5079 ) | |
5080 (forward-line 1)) | |
5081 (message "") | |
5082 )))) | |
5083 | |
5084 (defun verilog-just-one-space (myre) | |
5085 "Remove extra spaces around regular expression MYRE." | |
5086 (interactive) | |
5087 (if (and (not(looking-at verilog-complete-reg)) | |
5088 (looking-at myre)) | |
5089 (let ((p1 (match-end 1)) | |
5090 (p2 (match-end 2))) | |
5091 (progn | |
5092 (goto-char p2) | |
5093 (if (looking-at "\\s-") (just-one-space) ) | |
5094 (goto-char p1) | |
5095 (forward-char -1) | |
5096 (if (looking-at "\\s-") (just-one-space)) | |
5097 ) | |
5098 )) | |
5099 (message "")) | |
5100 | |
5101 (defun verilog-indent-declaration (baseind) | |
5102 "Indent current lines as declaration. | |
5103 Line up the variable names based on previous declaration's indentation. | |
5104 BASEIND is the base indent to offset everything." | |
5105 (interactive) | |
5106 (let ((pos (point-marker)) | |
5107 (lim (save-excursion | |
5108 ;; (verilog-re-search-backward verilog-declaration-opener nil 'move) | |
5109 (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)\\|\\(\\<task\\>\\)" nil 'move) | |
5110 (point))) | |
5111 (ind) | |
5112 (val) | |
5113 (m1 (make-marker)) | |
5114 ) | |
5115 (setq val (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist))))) | |
5116 (indent-line-to val) | |
5117 | |
5118 ;; Use previous declaration (in this module) as template. | |
5119 (if (or (memq 'all verilog-auto-lineup) | |
5120 (memq 'declaration verilog-auto-lineup)) | |
79546 | 5121 (if (verilog-re-search-backward |
79545 | 5122 (or (and verilog-indent-declaration-macros |
5123 verilog-declaration-re-1-macro) | |
5124 verilog-declaration-re-1-no-macro) lim t) | |
5125 (progn | |
5126 (goto-char (match-end 0)) | |
5127 (skip-chars-forward " \t") | |
5128 (setq ind (current-column)) | |
5129 (goto-char pos) | |
5130 (setq val (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist))))) | |
5131 (indent-line-to val) | |
5132 (if (and verilog-indent-declaration-macros | |
5133 (looking-at verilog-declaration-re-2-macro)) | |
5134 (let ((p (match-end 0))) | |
5135 (set-marker m1 p) | |
5136 (if (verilog-re-search-forward "[[#`]" p 'move) | |
5137 (progn | |
5138 (forward-char -1) | |
5139 (just-one-space) | |
5140 (goto-char (marker-position m1)) | |
5141 (just-one-space) | |
5142 (indent-to ind) | |
5143 ) | |
5144 (if (/= (current-column) ind) | |
5145 (progn | |
5146 (just-one-space) | |
5147 (indent-to ind)) | |
5148 ))) | |
5149 (if (looking-at verilog-declaration-re-2-no-macro) | |
5150 (let ((p (match-end 0))) | |
5151 (set-marker m1 p) | |
5152 (if (verilog-re-search-forward "[[`#]" p 'move) | |
5153 (progn | |
5154 (forward-char -1) | |
5155 (just-one-space) | |
5156 (goto-char (marker-position m1)) | |
5157 (just-one-space) | |
5158 (indent-to ind)) | |
5159 (if (/= (current-column) ind) | |
5160 (progn | |
5161 (just-one-space) | |
5162 (indent-to ind)) | |
5163 ))) | |
5164 ))) | |
5165 ) | |
5166 ) | |
5167 (goto-char pos) | |
5168 ) | |
5169 ) | |
5170 | |
5171 (defun verilog-get-lineup-indent (b edpos) | |
5172 "Return the indent level that will line up several lines within the region. | |
5173 Region is defined by B and EDPOS." | |
5174 (save-excursion | |
5175 (let ((ind 0) e) | |
5176 (goto-char b) | |
5177 ;; Get rightmost position | |
5178 (while (progn (setq e (marker-position edpos)) | |
5179 (< (point) e)) | |
79546 | 5180 (if (verilog-re-search-forward |
79545 | 5181 (or (and verilog-indent-declaration-macros |
5182 verilog-declaration-re-1-macro) | |
5183 verilog-declaration-re-1-no-macro) e 'move) | |
5184 (progn | |
5185 (goto-char (match-end 0)) | |
5186 (verilog-backward-syntactic-ws) | |
5187 (if (> (current-column) ind) | |
5188 (setq ind (current-column))) | |
5189 (goto-char (match-end 0))))) | |
5190 (if (> ind 0) | |
5191 (1+ ind) | |
5192 ;; No lineup-string found | |
5193 (goto-char b) | |
5194 (end-of-line) | |
5195 (skip-chars-backward " \t") | |
5196 (1+ (current-column)))))) | |
5197 | |
5198 (defun verilog-get-lineup-indent-2 (myre b edpos) | |
5199 "Return the indent level that will line up several lines within the region." | |
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 myre e 'move) | |
5207 (progn | |
5208 (goto-char (match-end 0)) | |
5209 (verilog-backward-syntactic-ws) | |
5210 (if (> (current-column) ind) | |
5211 (setq ind (current-column))) | |
5212 (goto-char (match-end 0))))) | |
5213 (if (> ind 0) | |
5214 (1+ ind) | |
5215 ;; No lineup-string found | |
5216 (goto-char b) | |
5217 (end-of-line) | |
5218 (skip-chars-backward " \t") | |
5219 (1+ (current-column)))))) | |
5220 | |
5221 (defun verilog-comment-depth (type val) | |
5222 "A useful mode debugging aide. TYPE and VAL are comments for insertion." | |
5223 (save-excursion | |
5224 (let | |
5225 ((b (prog2 | |
5226 (beginning-of-line) | |
5227 (point-marker) | |
5228 (end-of-line))) | |
5229 (e (point-marker))) | |
5230 (if (re-search-backward " /\\* \[#-\]# \[a-zA-Z\]+ \[0-9\]+ ## \\*/" b t) | |
5231 (progn | |
5232 (replace-match " /* -# ## */") | |
5233 (end-of-line)) | |
5234 (progn | |
5235 (end-of-line) | |
5236 (insert " /* ## ## */")))) | |
5237 (backward-char 6) | |
5238 (insert | |
5239 (format "%s %d" type val)))) | |
5240 | |
5241 ;; | |
5242 ;; | |
5243 ;; Completion | |
5244 ;; | |
5245 (defvar verilog-str nil) | |
5246 (defvar verilog-all nil) | |
5247 (defvar verilog-pred nil) | |
5248 (defvar verilog-buffer-to-use nil) | |
5249 (defvar verilog-flag nil) | |
5250 (defvar verilog-toggle-completions nil | |
5251 "*True means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one. | |
5252 Repeated use of \\[verilog-complete-word] will show you all of them. | |
5253 Normally, when there is more than one possible completion, | |
5254 it displays a list of all possible completions.") | |
5255 | |
5256 | |
5257 (defvar verilog-type-keywords | |
5258 '( | |
5259 "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input" | |
5260 "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0" | |
5261 "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pullup" | |
5262 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0" | |
5263 "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1" | |
5264 "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor" | |
5265 ) | |
5266 "*Keywords for types used when completing a word in a declaration or parmlist. | |
5267 \(eg. integer, real, reg...)") | |
5268 | |
5269 (defvar verilog-cpp-keywords | |
5270 '("module" "macromodule" "primitive" "timescale" "define" "ifdef" "ifndef" "else" | |
5271 "endif") | |
5272 "*Keywords to complete when at first word of a line in declarative scope. | |
5273 \(eg. initial, always, begin, assign.) | |
5274 The procedures and variables defined within the Verilog program | |
5275 will be completed runtime and should not be added to this list.") | |
5276 | |
5277 (defvar verilog-defun-keywords | |
5278 (append | |
5279 '( | |
5280 "always" "always_comb" "always_ff" "always_latch" "assign" | |
5281 "begin" "end" "generate" "endgenerate" "module" "endmodule" | |
5282 "specify" "endspecify" "function" "endfunction" "initial" "final" | |
5283 "task" "endtask" "primitive" "endprimitive" | |
5284 ) | |
5285 verilog-type-keywords) | |
5286 "*Keywords to complete when at first word of a line in declarative scope. | |
5287 \(eg. initial, always, begin, assign.) | |
5288 The procedures and variables defined within the Verilog program | |
5289 will be completed runtime and should not be added to this list.") | |
5290 | |
5291 (defvar verilog-block-keywords | |
5292 '( | |
5293 "begin" "break" "case" "continue" "else" "end" "endfunction" | |
5294 "endgenerate" "endinterface" "endpackage" "endspecify" "endtask" | |
5295 "for" "fork" "if" "join" "join_any" "join_none" "repeat" "return" | |
5296 "while") | |
5297 "*Keywords to complete when at first word of a line in behavioral scope. | |
5298 \(eg. begin, if, then, else, for, fork.) | |
5299 The procedures and variables defined within the Verilog program | |
5300 will be completed runtime and should not be added to this list.") | |
5301 | |
5302 (defvar verilog-tf-keywords | |
5303 '("begin" "break" "fork" "join" "join_any" "join_none" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat") | |
5304 "*Keywords to complete when at first word of a line in a task or function. | |
5305 \(eg. begin, if, then, else, for, fork.) | |
5306 The procedures and variables defined within the Verilog program | |
5307 will be completed runtime and should not be added to this list.") | |
5308 | |
5309 (defvar verilog-case-keywords | |
5310 '("begin" "fork" "join" "join_any" "join_none" "case" "end" "endcase" "if" "else" "for" "repeat") | |
5311 "*Keywords to complete when at first word of a line in case scope. | |
5312 \(eg. begin, if, then, else, for, fork.) | |
5313 The procedures and variables defined within the Verilog program | |
5314 will be completed runtime and should not be added to this list.") | |
5315 | |
5316 (defvar verilog-separator-keywords | |
5317 '("else" "then" "begin") | |
5318 "*Keywords to complete when NOT standing at the first word of a statement. | |
5319 \(eg. else, then.) | |
5320 Variables and function names defined within the | |
5321 Verilog program are completed runtime and should not be added to this list.") | |
5322 | |
5323 (defun verilog-string-diff (str1 str2) | |
5324 "Return index of first letter where STR1 and STR2 differs." | |
5325 (catch 'done | |
5326 (let ((diff 0)) | |
5327 (while t | |
5328 (if (or (> (1+ diff) (length str1)) | |
5329 (> (1+ diff) (length str2))) | |
5330 (throw 'done diff)) | |
5331 (or (equal (aref str1 diff) (aref str2 diff)) | |
5332 (throw 'done diff)) | |
5333 (setq diff (1+ diff)))))) | |
5334 | |
5335 ;; Calculate all possible completions for functions if argument is `function', | |
5336 ;; completions for procedures if argument is `procedure' or both functions and | |
5337 ;; procedures otherwise. | |
5338 | |
5339 (defun verilog-func-completion (type) | |
5340 "Build regular expression for module/task/function names. | |
5341 TYPE is 'module, 'tf for task or function, or t if unknown." | |
5342 (if (string= verilog-str "") | |
5343 (setq verilog-str "[a-zA-Z_]")) | |
5344 (let ((verilog-str (concat (cond | |
5345 ((eq type 'module) "\\<\\(module\\)\\s +") | |
5346 ((eq type 'tf) "\\<\\(task\\|function\\)\\s +") | |
5347 (t "\\<\\(task\\|function\\|module\\)\\s +")) | |
5348 "\\<\\(" verilog-str "[a-zA-Z0-9_.]*\\)\\>")) | |
5349 match) | |
5350 | |
5351 (if (not (looking-at verilog-defun-re)) | |
5352 (verilog-re-search-backward verilog-defun-re nil t)) | |
5353 (forward-char 1) | |
5354 | |
5355 ;; Search through all reachable functions | |
5356 (goto-char (point-min)) | |
5357 (while (verilog-re-search-forward verilog-str (point-max) t) | |
5358 (progn (setq match (buffer-substring (match-beginning 2) | |
5359 (match-end 2))) | |
5360 (if (or (null verilog-pred) | |
5361 (funcall verilog-pred match)) | |
5362 (setq verilog-all (cons match verilog-all))))) | |
5363 (if (match-beginning 0) | |
5364 (goto-char (match-beginning 0))))) | |
5365 | |
5366 (defun verilog-get-completion-decl (end) | |
5367 "Macro for searching through current declaration (var, type or const) | |
5368 for matches of `str' and adding the occurrence tp `all' through point END." | |
5369 (let ((re (or (and verilog-indent-declaration-macros | |
5370 verilog-declaration-re-2-macro) | |
5371 verilog-declaration-re-2-no-macro)) | |
5372 decl-end match) | |
5373 ;; Traverse lines | |
5374 (while (and (< (point) end) | |
5375 (verilog-re-search-forward re end t)) | |
5376 ;; Traverse current line | |
5377 (setq decl-end (save-excursion (verilog-declaration-end))) | |
5378 (while (and (verilog-re-search-forward verilog-symbol-re decl-end t) | |
5379 (not (match-end 1))) | |
5380 (setq match (buffer-substring (match-beginning 0) (match-end 0))) | |
5381 (if (string-match (concat "\\<" verilog-str) match) | |
5382 (if (or (null verilog-pred) | |
5383 (funcall verilog-pred match)) | |
5384 (setq verilog-all (cons match verilog-all))))) | |
5385 (forward-line 1) | |
5386 ) | |
5387 ) | |
5388 verilog-all | |
5389 ) | |
5390 | |
5391 (defun verilog-type-completion () | |
5392 "Calculate all possible completions for types." | |
5393 (let ((start (point)) | |
5394 goon) | |
5395 ;; Search for all reachable type declarations | |
5396 (while (or (verilog-beg-of-defun) | |
5397 (setq goon (not goon))) | |
5398 (save-excursion | |
5399 (if (and (< start (prog1 (save-excursion (verilog-end-of-defun) | |
5400 (point)) | |
5401 (forward-char 1))) | |
5402 (verilog-re-search-forward | |
5403 "\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>" | |
5404 start t) | |
5405 (not (match-end 1))) | |
5406 ;; Check current type declaration | |
5407 (verilog-get-completion-decl start)))))) | |
5408 | |
5409 (defun verilog-var-completion () | |
5410 "Calculate all possible completions for variables (or constants)." | |
5411 (let ((start (point))) | |
5412 ;; Search for all reachable var declarations | |
5413 (verilog-beg-of-defun) | |
5414 (save-excursion | |
5415 ;; Check var declarations | |
5416 (verilog-get-completion-decl start)))) | |
5417 | |
5418 (defun verilog-keyword-completion (keyword-list) | |
5419 "Give list of all possible completions of keywords in KEYWORD-LIST." | |
5420 (mapcar '(lambda (s) | |
5421 (if (string-match (concat "\\<" verilog-str) s) | |
5422 (if (or (null verilog-pred) | |
5423 (funcall verilog-pred s)) | |
5424 (setq verilog-all (cons s verilog-all))))) | |
5425 keyword-list)) | |
5426 | |
5427 | |
5428 (defun verilog-completion (verilog-str verilog-pred verilog-flag) | |
5429 "Function passed to `completing-read', `try-completion' or `all-completions'. | |
5430 Called to get completion on VERILOG-STR. If VERILOG-PRED is non-nil, it | |
5431 must be a function to be called for every match to check if this should | |
5432 really be a match. If VERILOG-FLAG is t, the function returns a list of all | |
5433 possible completions. If VERILOG-FLAG is nil it returns a string, the | |
5434 longest possible completion, or t if STR is an exact match. If VERILOG-FLAG | |
5435 is 'lambda, the function returns t if STR is an exact match, nil | |
5436 otherwise." | |
5437 (save-excursion | |
5438 (let ((verilog-all nil)) | |
5439 ;; Set buffer to use for searching labels. This should be set | |
5440 ;; within functions which use verilog-completions | |
5441 (set-buffer verilog-buffer-to-use) | |
5442 | |
5443 ;; Determine what should be completed | |
5444 (let ((state (car (verilog-calculate-indent)))) | |
5445 (cond ((eq state 'defun) | |
5446 (save-excursion (verilog-var-completion)) | |
5447 (verilog-func-completion 'module) | |
5448 (verilog-keyword-completion verilog-defun-keywords)) | |
5449 | |
5450 ((eq state 'behavioral) | |
5451 (save-excursion (verilog-var-completion)) | |
5452 (verilog-func-completion 'module) | |
5453 (verilog-keyword-completion verilog-defun-keywords)) | |
5454 | |
5455 ((eq state 'block) | |
5456 (save-excursion (verilog-var-completion)) | |
5457 (verilog-func-completion 'tf) | |
5458 (verilog-keyword-completion verilog-block-keywords)) | |
5459 | |
5460 ((eq state 'case) | |
5461 (save-excursion (verilog-var-completion)) | |
5462 (verilog-func-completion 'tf) | |
5463 (verilog-keyword-completion verilog-case-keywords)) | |
5464 | |
5465 ((eq state 'tf) | |
5466 (save-excursion (verilog-var-completion)) | |
5467 (verilog-func-completion 'tf) | |
5468 (verilog-keyword-completion verilog-tf-keywords)) | |
5469 | |
5470 ((eq state 'cpp) | |
5471 (save-excursion (verilog-var-completion)) | |
5472 (verilog-keyword-completion verilog-cpp-keywords)) | |
5473 | |
5474 ((eq state 'cparenexp) | |
5475 (save-excursion (verilog-var-completion))) | |
5476 | |
5477 (t;--Anywhere else | |
5478 (save-excursion (verilog-var-completion)) | |
5479 (verilog-func-completion 'both) | |
5480 (verilog-keyword-completion verilog-separator-keywords)))) | |
5481 | |
5482 ;; Now we have built a list of all matches. Give response to caller | |
5483 (verilog-completion-response)))) | |
5484 | |
5485 (defun verilog-completion-response () | |
5486 (cond ((or (equal verilog-flag 'lambda) (null verilog-flag)) | |
5487 ;; This was not called by all-completions | |
5488 (if (null verilog-all) | |
5489 ;; Return nil if there was no matching label | |
5490 nil | |
5491 ;; Get longest string common in the labels | |
5492 (let* ((elm (cdr verilog-all)) | |
5493 (match (car verilog-all)) | |
5494 (min (length match)) | |
5495 tmp) | |
5496 (if (string= match verilog-str) | |
5497 ;; Return t if first match was an exact match | |
5498 (setq match t) | |
5499 (while (not (null elm)) | |
5500 ;; Find longest common string | |
5501 (if (< (setq tmp (verilog-string-diff match (car elm))) min) | |
5502 (progn | |
5503 (setq min tmp) | |
5504 (setq match (substring match 0 min)))) | |
5505 ;; Terminate with match=t if this is an exact match | |
5506 (if (string= (car elm) verilog-str) | |
5507 (progn | |
5508 (setq match t) | |
5509 (setq elm nil)) | |
5510 (setq elm (cdr elm))))) | |
5511 ;; If this is a test just for exact match, return nil ot t | |
5512 (if (and (equal verilog-flag 'lambda) (not (equal match 't))) | |
5513 nil | |
5514 match)))) | |
5515 ;; If flag is t, this was called by all-completions. Return | |
5516 ;; list of all possible completions | |
5517 (verilog-flag | |
5518 verilog-all))) | |
5519 | |
5520 (defvar verilog-last-word-numb 0) | |
5521 (defvar verilog-last-word-shown nil) | |
5522 (defvar verilog-last-completions nil) | |
5523 | |
5524 (defun verilog-complete-word () | |
5525 "Complete word at current point. | |
5526 \(See also `verilog-toggle-completions', `verilog-type-keywords', | |
5527 and `verilog-separator-keywords'.)" | |
5528 (interactive) | |
5529 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point))) | |
5530 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))) | |
5531 (verilog-str (buffer-substring b e)) | |
5532 ;; The following variable is used in verilog-completion | |
5533 (verilog-buffer-to-use (current-buffer)) | |
5534 (allcomp (if (and verilog-toggle-completions | |
5535 (string= verilog-last-word-shown verilog-str)) | |
5536 verilog-last-completions | |
5537 (all-completions verilog-str 'verilog-completion))) | |
5538 (match (if verilog-toggle-completions | |
5539 "" (try-completion | |
5540 verilog-str (mapcar '(lambda (elm) | |
5541 (cons elm 0)) allcomp))))) | |
5542 ;; Delete old string | |
5543 (delete-region b e) | |
5544 | |
5545 ;; Toggle-completions inserts whole labels | |
5546 (if verilog-toggle-completions | |
5547 (progn | |
5548 ;; Update entry number in list | |
5549 (setq verilog-last-completions allcomp | |
5550 verilog-last-word-numb | |
5551 (if (>= verilog-last-word-numb (1- (length allcomp))) | |
5552 0 | |
5553 (1+ verilog-last-word-numb))) | |
5554 (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb)) | |
5555 ;; Display next match or same string if no match was found | |
5556 (if (not (null allcomp)) | |
5557 (insert "" verilog-last-word-shown) | |
5558 (insert "" verilog-str) | |
5559 (message "(No match)"))) | |
5560 ;; The other form of completion does not necessarily do that. | |
5561 | |
5562 ;; Insert match if found, or the original string if no match | |
5563 (if (or (null match) (equal match 't)) | |
5564 (progn (insert "" verilog-str) | |
5565 (message "(No match)")) | |
5566 (insert "" match)) | |
5567 ;; Give message about current status of completion | |
5568 (cond ((equal match 't) | |
5569 (if (not (null (cdr allcomp))) | |
5570 (message "(Complete but not unique)") | |
5571 (message "(Sole completion)"))) | |
5572 ;; Display buffer if the current completion didn't help | |
5573 ;; on completing the label. | |
5574 ((and (not (null (cdr allcomp))) (= (length verilog-str) | |
5575 (length match))) | |
5576 (with-output-to-temp-buffer "*Completions*" | |
5577 (display-completion-list allcomp)) | |
5578 ;; Wait for a key press. Then delete *Completion* window | |
5579 (momentary-string-display "" (point)) | |
5580 (delete-window (get-buffer-window (get-buffer "*Completions*"))) | |
5581 ))))) | |
5582 | |
5583 (defun verilog-show-completions () | |
5584 "Show all possible completions at current point." | |
5585 (interactive) | |
5586 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point))) | |
5587 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))) | |
5588 (verilog-str (buffer-substring b e)) | |
5589 ;; The following variable is used in verilog-completion | |
5590 (verilog-buffer-to-use (current-buffer)) | |
5591 (allcomp (if (and verilog-toggle-completions | |
5592 (string= verilog-last-word-shown verilog-str)) | |
5593 verilog-last-completions | |
5594 (all-completions verilog-str 'verilog-completion)))) | |
5595 ;; Show possible completions in a temporary buffer. | |
5596 (with-output-to-temp-buffer "*Completions*" | |
5597 (display-completion-list allcomp)) | |
5598 ;; Wait for a key press. Then delete *Completion* window | |
5599 (momentary-string-display "" (point)) | |
5600 (delete-window (get-buffer-window (get-buffer "*Completions*"))))) | |
5601 | |
5602 | |
5603 (defun verilog-get-default-symbol () | |
5604 "Return symbol around current point as a string." | |
5605 (save-excursion | |
5606 (buffer-substring (progn | |
5607 (skip-chars-backward " \t") | |
5608 (skip-chars-backward "a-zA-Z0-9_") | |
5609 (point)) | |
5610 (progn | |
5611 (skip-chars-forward "a-zA-Z0-9_") | |
5612 (point))))) | |
5613 | |
5614 (defun verilog-build-defun-re (str &optional arg) | |
5615 "Return function/task/module starting with STR as regular expression. | |
5616 With optional second ARG non-nil, STR is the complete name of the instruction." | |
5617 (if arg | |
5618 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "\\)\\>") | |
5619 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>"))) | |
5620 | |
5621 (defun verilog-comp-defun (verilog-str verilog-pred verilog-flag) | |
5622 "Function passed to `completing-read', `try-completion' or `all-completions'. | |
5623 Returns a completion on any function name based on VERILOG-STR prefix. If | |
5624 VERILOG-PRED is non-nil, it must be a function to be called for every match | |
5625 to check if this should really be a match. If VERILOG-FLAG is t, the | |
5626 function returns a list of all possible completions. If it is nil it | |
5627 returns a string, the longest possible completion, or t if VERILOG-STR is | |
5628 an exact match. If VERILOG-FLAG is 'lambda, the function returns t if | |
5629 VERILOG-STR is an exact match, nil otherwise." | |
5630 (save-excursion | |
5631 (let ((verilog-all nil) | |
5632 match) | |
5633 | |
5634 ;; Set buffer to use for searching labels. This should be set | |
5635 ;; within functions which use verilog-completions | |
5636 (set-buffer verilog-buffer-to-use) | |
5637 | |
5638 (let ((verilog-str verilog-str)) | |
5639 ;; Build regular expression for functions | |
5640 (if (string= verilog-str "") | |
5641 (setq verilog-str (verilog-build-defun-re "[a-zA-Z_]")) | |
5642 (setq verilog-str (verilog-build-defun-re verilog-str))) | |
5643 (goto-char (point-min)) | |
5644 | |
5645 ;; Build a list of all possible completions | |
5646 (while (verilog-re-search-forward verilog-str nil t) | |
5647 (setq match (buffer-substring (match-beginning 2) (match-end 2))) | |
5648 (if (or (null verilog-pred) | |
5649 (funcall verilog-pred match)) | |
5650 (setq verilog-all (cons match verilog-all))))) | |
5651 | |
5652 ;; Now we have built a list of all matches. Give response to caller | |
5653 (verilog-completion-response)))) | |
5654 | |
5655 (defun verilog-goto-defun () | |
5656 "Move to specified Verilog module/task/function. | |
5657 The default is a name found in the buffer around point. | |
5658 If search fails, other files are checked based on | |
5659 `verilog-library-flags'." | |
5660 (interactive) | |
5661 (let* ((default (verilog-get-default-symbol)) | |
5662 ;; The following variable is used in verilog-comp-function | |
5663 (verilog-buffer-to-use (current-buffer)) | |
5664 (label (if (not (string= default "")) | |
5665 ;; Do completion with default | |
5666 (completing-read (concat "Label: (default " default ") ") | |
5667 'verilog-comp-defun nil nil "") | |
5668 ;; There is no default value. Complete without it | |
5669 (completing-read "Label: " | |
5670 'verilog-comp-defun nil nil ""))) | |
5671 pt) | |
5672 ;; If there was no response on prompt, use default value | |
5673 (if (string= label "") | |
5674 (setq label default)) | |
5675 ;; Goto right place in buffer if label is not an empty string | |
5676 (or (string= label "") | |
5677 (progn | |
5678 (save-excursion | |
5679 (goto-char (point-min)) | |
5680 (setq pt (re-search-forward (verilog-build-defun-re label t) nil t))) | |
5681 (when pt | |
5682 (goto-char pt) | |
5683 (beginning-of-line)) | |
5684 pt) | |
5685 (verilog-goto-defun-file label) | |
5686 ))) | |
5687 | |
5688 ;; Eliminate compile warning | |
5689 (eval-when-compile | |
5690 (if (not (boundp 'occur-pos-list)) | |
5691 (defvar occur-pos-list nil "Backward compatibility occur positions."))) | |
5692 | |
5693 (defun verilog-showscopes () | |
5694 "List all scopes in this module." | |
5695 (interactive) | |
5696 (let ((buffer (current-buffer)) | |
5697 (linenum 1) | |
5698 (nlines 0) | |
5699 (first 1) | |
5700 (prevpos (point-min)) | |
5701 (final-context-start (make-marker)) | |
5702 (regexp "\\(module\\s-+\\w+\\s-*(\\)\\|\\(\\w+\\s-+\\w+\\s-*(\\)") | |
5703 ) | |
5704 (with-output-to-temp-buffer "*Occur*" | |
5705 (save-excursion | |
5706 (message (format "Searching for %s ..." regexp)) | |
5707 ;; Find next match, but give up if prev match was at end of buffer. | |
5708 (while (and (not (= prevpos (point-max))) | |
5709 (verilog-re-search-forward regexp nil t)) | |
5710 (goto-char (match-beginning 0)) | |
5711 (beginning-of-line) | |
5712 (save-match-data | |
5713 (setq linenum (+ linenum (count-lines prevpos (point))))) | |
5714 (setq prevpos (point)) | |
5715 (goto-char (match-end 0)) | |
5716 (let* ((start (save-excursion | |
5717 (goto-char (match-beginning 0)) | |
5718 (forward-line (if (< nlines 0) nlines (- nlines))) | |
5719 (point))) | |
5720 (end (save-excursion | |
5721 (goto-char (match-end 0)) | |
5722 (if (> nlines 0) | |
5723 (forward-line (1+ nlines)) | |
5724 (forward-line 1)) | |
5725 (point))) | |
5726 (tag (format "%3d" linenum)) | |
5727 (empty (make-string (length tag) ?\ )) | |
5728 tem) | |
5729 (save-excursion | |
5730 (setq tem (make-marker)) | |
5731 (set-marker tem (point)) | |
5732 (set-buffer standard-output) | |
5733 (setq occur-pos-list (cons tem occur-pos-list)) | |
5734 (or first (zerop nlines) | |
5735 (insert "--------\n")) | |
5736 (setq first nil) | |
5737 (insert-buffer-substring buffer start end) | |
5738 (backward-char (- end start)) | |
5739 (setq tem (if (< nlines 0) (- nlines) nlines)) | |
5740 (while (> tem 0) | |
5741 (insert empty ?:) | |
5742 (forward-line 1) | |
5743 (setq tem (1- tem))) | |
5744 (let ((this-linenum linenum)) | |
5745 (set-marker final-context-start | |
5746 (+ (point) (- (match-end 0) (match-beginning 0)))) | |
5747 (while (< (point) final-context-start) | |
5748 (if (null tag) | |
5749 (setq tag (format "%3d" this-linenum))) | |
5750 (insert tag ?:))))))) | |
5751 (set-buffer-modified-p nil)))) | |
5752 | |
5753 | |
5754 ;; Highlight helper functions | |
5755 (defconst verilog-directive-regexp "\\(translate\\|coverage\\|lint\\)_") | |
5756 (defun verilog-within-translate-off () | |
5757 "Return point if within translate-off region, else nil." | |
5758 (and (save-excursion | |
5759 (re-search-backward | |
5760 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>") | |
5761 nil t)) | |
5762 (equal "off" (match-string 2)) | |
5763 (point))) | |
5764 | |
5765 (defun verilog-start-translate-off (limit) | |
5766 "Return point before translate-off directive if before LIMIT, else nil." | |
5767 (when (re-search-forward | |
5768 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>") | |
5769 limit t) | |
5770 (match-beginning 0))) | |
5771 | |
5772 (defun verilog-back-to-start-translate-off (limit) | |
5773 "Return point before translate-off directive if before LIMIT, else nil." | |
5774 (when (re-search-backward | |
5775 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>") | |
5776 limit t) | |
5777 (match-beginning 0))) | |
5778 | |
5779 (defun verilog-end-translate-off (limit) | |
5780 "Return point after translate-on directive if before LIMIT, else nil." | |
5781 | |
5782 (re-search-forward (concat | |
5783 "//\\s-*.*\\s-*" verilog-directive-regexp "on\\>") limit t)) | |
5784 | |
5785 (defun verilog-match-translate-off (limit) | |
5786 "Match a translate-off block, setting `match-data' and returning t, else nil. | |
5787 Bound search by LIMIT." | |
5788 (when (< (point) limit) | |
5789 (let ((start (or (verilog-within-translate-off) | |
5790 (verilog-start-translate-off limit))) | |
5791 (case-fold-search t)) | |
5792 (when start | |
5793 (let ((end (or (verilog-end-translate-off limit) limit))) | |
5794 (set-match-data (list start end)) | |
5795 (goto-char end)))))) | |
5796 | |
5797 (defun verilog-font-lock-match-item (limit) | |
5798 "Match, and move over, any declaration item after point. | |
5799 Bound search by LIMIT. Adapted from | |
5800 `font-lock-match-c-style-declaration-item-and-skip-to-next'." | |
5801 (condition-case nil | |
5802 (save-restriction | |
5803 (narrow-to-region (point-min) limit) | |
5804 ;; match item | |
5805 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)") | |
5806 (save-match-data | |
5807 (goto-char (match-end 1)) | |
5808 ;; move to next item | |
5809 (if (looking-at "\\(\\s-*,\\)") | |
5810 (goto-char (match-end 1)) | |
5811 (end-of-line) t)))) | |
5812 (error nil))) | |
5813 | |
5814 | |
5815 ;; Added by Subbu Meiyappan for Header | |
5816 | |
5817 (defun verilog-header () | |
5818 "Insert a standard Verilog file header." | |
5819 (interactive) | |
5820 (let ((start (point))) | |
5821 (insert "\ | |
5822 //----------------------------------------------------------------------------- | |
5823 // Title : <title> | |
5824 // Project : <project> | |
5825 //----------------------------------------------------------------------------- | |
5826 // File : <filename> | |
5827 // Author : <author> | |
5828 // Created : <credate> | |
5829 // Last modified : <moddate> | |
5830 //----------------------------------------------------------------------------- | |
5831 // Description : | |
5832 // <description> | |
5833 //----------------------------------------------------------------------------- | |
5834 // Copyright (c) <copydate> by <company> This model is the confidential and | |
5835 // proprietary property of <company> and the possession or use of this | |
5836 // file requires a written license from <company>. | |
5837 //------------------------------------------------------------------------------ | |
5838 // Modification history : | |
5839 // <modhist> | |
5840 //----------------------------------------------------------------------------- | |
5841 | |
5842 ") | |
5843 (goto-char start) | |
5844 (search-forward "<filename>") | |
5845 (replace-match (buffer-name) t t) | |
5846 (search-forward "<author>") (replace-match "" t t) | |
5847 (insert (user-full-name)) | |
5848 (insert " <" (user-login-name) "@" (system-name) ">") | |
5849 (search-forward "<credate>") (replace-match "" t t) | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
5850 (verilog-insert-date) |
79545 | 5851 (search-forward "<moddate>") (replace-match "" t t) |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
5852 (verilog-insert-date) |
79545 | 5853 (search-forward "<copydate>") (replace-match "" t t) |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
5854 (verilog-insert-year) |
79545 | 5855 (search-forward "<modhist>") (replace-match "" t t) |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
5856 (verilog-insert-date) |
79545 | 5857 (insert " : created") |
5858 (goto-char start) | |
5859 (let (string) | |
5860 (setq string (read-string "title: ")) | |
5861 (search-forward "<title>") | |
5862 (replace-match string t t) | |
5863 (setq string (read-string "project: " verilog-project)) | |
5864 (make-variable-buffer-local 'verilog-project) | |
5865 (setq verilog-project string) | |
5866 (search-forward "<project>") | |
5867 (replace-match string t t) | |
5868 (setq string (read-string "Company: " verilog-company)) | |
5869 (make-variable-buffer-local 'verilog-company) | |
5870 (setq verilog-company string) | |
5871 (search-forward "<company>") | |
5872 (replace-match string t t) | |
5873 (search-forward "<company>") | |
5874 (replace-match string t t) | |
5875 (search-forward "<company>") | |
5876 (replace-match string t t) | |
5877 (search-backward "<description>") | |
5878 (replace-match "" t t) | |
5879 ))) | |
5880 | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
5881 ;; verilog-header Uses the verilog-insert-date function |
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
5882 |
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
5883 (defun verilog-insert-date () |
79545 | 5884 "Insert date from the system." |
5885 (interactive) | |
5886 (let ((timpos)) | |
5887 (setq timpos (point)) | |
5888 (if verilog-date-scientific-format | |
5889 (shell-command "date \"+@%Y/%m/%d\"" t) | |
5890 (shell-command "date \"+@%d.%m.%Y\"" t)) | |
5891 (search-forward "@") | |
5892 (delete-region timpos (point)) | |
5893 (end-of-line)) | |
5894 (delete-char 1)) | |
5895 | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
5896 (defun verilog-insert-year () |
79545 | 5897 "Insert year from the system." |
5898 (interactive) | |
5899 (let ((timpos)) | |
5900 (setq timpos (point)) | |
5901 (shell-command "date \"+@%Y\"" t) | |
5902 (search-forward "@") | |
5903 (delete-region timpos (point)) | |
5904 (end-of-line)) | |
5905 (delete-char 1)) | |
5906 | |
5907 | |
5908 ;; | |
5909 ;; Signal list parsing | |
5910 ;; | |
5911 | |
5912 ;; Elements of a signal list | |
5913 (defsubst verilog-sig-name (sig) | |
5914 (car sig)) | |
5915 (defsubst verilog-sig-bits (sig) | |
5916 (nth 1 sig)) | |
5917 (defsubst verilog-sig-comment (sig) | |
5918 (nth 2 sig)) | |
5919 (defsubst verilog-sig-memory (sig) | |
5920 (nth 3 sig)) | |
5921 (defsubst verilog-sig-enum (sig) | |
5922 (nth 4 sig)) | |
5923 (defsubst verilog-sig-signed (sig) | |
5924 (nth 5 sig)) | |
5925 (defsubst verilog-sig-type (sig) | |
5926 (nth 6 sig)) | |
5927 (defsubst verilog-sig-multidim (sig) | |
5928 (nth 7 sig)) | |
5929 (defsubst verilog-sig-multidim-string (sig) | |
5930 (if (verilog-sig-multidim sig) | |
5931 (let ((str "") (args (verilog-sig-multidim sig))) | |
5932 (while args | |
5933 (setq str (concat str (car args))) | |
5934 (setq args (cdr args))) | |
5935 str))) | |
5936 (defsubst verilog-sig-width (sig) | |
5937 (verilog-make-width-expression (verilog-sig-bits sig))) | |
5938 | |
5939 (defsubst verilog-alw-get-inputs (sigs) | |
5940 (nth 2 sigs)) | |
5941 (defsubst verilog-alw-get-outputs (sigs) | |
5942 (nth 0 sigs)) | |
5943 (defsubst verilog-alw-get-uses-delayed (sigs) | |
5944 (nth 3 sigs)) | |
5945 | |
5946 (defun verilog-signals-not-in (in-list not-list) | |
5947 "Return list of signals in IN-LIST that aren't also in NOT-LIST, | |
5948 and also remove any duplicates in IN-LIST. | |
5949 Signals must be in standard (base vector) form." | |
5950 (let (out-list) | |
5951 (while in-list | |
5952 (if (not (or (assoc (car (car in-list)) not-list) | |
5953 (assoc (car (car in-list)) out-list))) | |
5954 (setq out-list (cons (car in-list) out-list))) | |
5955 (setq in-list (cdr in-list))) | |
5956 (nreverse out-list))) | |
5957 ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" ""))) | |
5958 | |
5959 (defun verilog-signals-in (in-list other-list) | |
5960 "Return list of signals in IN-LIST that are also in OTHER-LIST. | |
5961 Signals must be in standard (base vector) form." | |
5962 (let (out-list) | |
5963 (while in-list | |
5964 (if (assoc (car (car in-list)) other-list) | |
5965 (setq out-list (cons (car in-list) out-list))) | |
5966 (setq in-list (cdr in-list))) | |
5967 (nreverse out-list))) | |
5968 ;;(verilog-signals-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" ""))) | |
5969 | |
5970 (defun verilog-signals-memory (in-list) | |
5971 "Return list of signals in IN-LIST that are memoried (multidimensional)." | |
5972 (let (out-list) | |
5973 (while in-list | |
5974 (if (nth 3 (car in-list)) | |
5975 (setq out-list (cons (car in-list) out-list))) | |
5976 (setq in-list (cdr in-list))) | |
5977 out-list)) | |
5978 ;;(verilog-signals-memory '(("A" nil nil "[3:0]")) '(("B" nil nil nil))) | |
5979 | |
5980 (defun verilog-signals-sort-compare (a b) | |
5981 "Compare signal A and B for sorting." | |
5982 (string< (car a) (car b))) | |
5983 | |
5984 (defun verilog-signals-not-params (in-list) | |
5985 "Return list of signals in IN-LIST that aren't parameters or numeric constants." | |
5986 (let (out-list) | |
5987 (while in-list | |
5988 (unless (boundp (intern (concat "vh-" (car (car in-list))))) | |
5989 (setq out-list (cons (car in-list) out-list))) | |
5990 (setq in-list (cdr in-list))) | |
5991 (nreverse out-list))) | |
5992 | |
5993 (defun verilog-signals-combine-bus (in-list) | |
5994 "Return a list of signals in IN-LIST, with busses combined. | |
5995 Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]." | |
5996 (let (combo buswarn | |
5997 out-list | |
5998 sig highbit lowbit ; Temp information about current signal | |
5999 sv-name sv-highbit sv-lowbit ; Details about signal we are forming | |
6000 sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring | |
6001 bus) | |
6002 ;; Shove signals so duplicated signals will be adjacent | |
6003 (setq in-list (sort in-list `verilog-signals-sort-compare)) | |
6004 (while in-list | |
6005 (setq sig (car in-list)) | |
6006 ;; No current signal; form from existing details | |
6007 (unless sv-name | |
6008 (setq sv-name (verilog-sig-name sig) | |
6009 sv-highbit nil | |
6010 sv-busstring nil | |
6011 sv-comment (verilog-sig-comment sig) | |
6012 sv-memory (verilog-sig-memory sig) | |
6013 sv-enum (verilog-sig-enum sig) | |
6014 sv-signed (verilog-sig-signed sig) | |
6015 sv-type (verilog-sig-type sig) | |
6016 sv-multidim (verilog-sig-multidim sig) | |
6017 combo "" | |
6018 buswarn "" | |
6019 )) | |
6020 ;; Extract bus details | |
6021 (setq bus (verilog-sig-bits sig)) | |
6022 (cond ((and bus | |
6023 (or (and (string-match "\\[\\([0-9]+\\):\\([0-9]+\\)\\]" bus) | |
6024 (setq highbit (string-to-int (match-string 1 bus)) | |
6025 lowbit (string-to-int (match-string 2 bus)))) | |
6026 (and (string-match "\\[\\([0-9]+\\)\\]" bus) | |
6027 (setq highbit (string-to-int (match-string 1 bus)) | |
6028 lowbit highbit)))) | |
6029 ;; Combine bits in bus | |
6030 (if sv-highbit | |
6031 (setq sv-highbit (max highbit sv-highbit) | |
6032 sv-lowbit (min lowbit sv-lowbit)) | |
6033 (setq sv-highbit highbit | |
6034 sv-lowbit lowbit))) | |
6035 (bus | |
6036 ;; String, probably something like `preproc:0 | |
6037 (setq sv-busstring bus))) | |
6038 ;; Peek ahead to next signal | |
6039 (setq in-list (cdr in-list)) | |
6040 (setq sig (car in-list)) | |
6041 (cond ((and sig (equal sv-name (verilog-sig-name sig))) | |
6042 ;; Combine with this signal | |
6043 (when (and sv-busstring (not (equal sv-busstring (verilog-sig-bits sig)))) | |
6044 (when nil ;; Debugging | |
6045 (message (concat "Warning, can't merge into single bus " | |
6046 sv-name bus | |
6047 ", the AUTOs may be wrong"))) | |
6048 (setq buswarn ", Couldn't Merge")) | |
6049 (if (verilog-sig-comment sig) (setq combo ", ...")) | |
6050 (setq sv-memory (or sv-memory (verilog-sig-memory sig)) | |
6051 sv-enum (or sv-enum (verilog-sig-enum sig)) | |
6052 sv-signed (or sv-signed (verilog-sig-signed sig)) | |
6053 sv-type (or sv-type (verilog-sig-type sig)) | |
6054 sv-multidim (or sv-multidim (verilog-sig-multidim sig)))) | |
6055 ;; Doesn't match next signal, add to queue, zero in prep for next | |
6056 ;; Note sig may also be nil for the last signal in the list | |
6057 (t | |
6058 (setq out-list | |
6059 (cons (list sv-name | |
6060 (or sv-busstring | |
6061 (if sv-highbit | |
6062 (concat "[" (int-to-string sv-highbit) ":" (int-to-string sv-lowbit) "]"))) | |
6063 (concat sv-comment combo buswarn) | |
6064 sv-memory sv-enum sv-signed sv-type sv-multidim) | |
6065 out-list) | |
6066 sv-name nil))) | |
6067 ) | |
6068 ;; | |
6069 out-list)) | |
6070 | |
6071 (defun verilog-sig-tieoff (sig &optional no-width) | |
6072 "Return tieoff expression for given SIGNAL, with appropriate width. | |
6073 Ignore width if optional NO-WIDTH is set." | |
6074 (let* ((width (if no-width nil (verilog-sig-width sig)))) | |
6075 (concat | |
6076 (if (and verilog-active-low-regexp | |
6077 (string-match verilog-active-low-regexp (verilog-sig-name sig))) | |
6078 "~" "") | |
6079 (cond ((not width) | |
6080 "0") | |
6081 ((string-match "^[0-9]+$" width) | |
6082 (concat width (if (verilog-sig-signed sig) "'sh0" "'h0"))) | |
6083 (t | |
6084 (concat "{" width "{1'b0}}")))))) | |
6085 | |
6086 ;; | |
6087 ;; Port/Wire/Etc Reading | |
6088 ;; | |
6089 | |
6090 (defun verilog-read-inst-backward-name () | |
6091 "Internal. Move point back to beginning of inst-name." | |
6092 (verilog-backward-open-paren) | |
6093 (let (done) | |
6094 (while (not done) | |
6095 (verilog-re-search-backward-quick "\\()\\|\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil) ; ] isn't word boundary | |
6096 (cond ((looking-at ")") | |
6097 (verilog-backward-open-paren)) | |
6098 (t (setq done t))))) | |
6099 (while (looking-at "\\]") | |
6100 (verilog-backward-open-bracket) | |
6101 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil)) | |
6102 (skip-chars-backward "a-zA-Z0-9`_$")) | |
6103 | |
6104 (defun verilog-read-inst-module () | |
6105 "Return module_name when point is inside instantiation." | |
6106 (save-excursion | |
6107 (verilog-read-inst-backward-name) | |
6108 ;; Skip over instantiation name | |
6109 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary | |
6110 ;; Check for parameterized instantiations | |
6111 (when (looking-at ")") | |
6112 (verilog-backward-open-paren) | |
6113 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil)) | |
6114 (skip-chars-backward "a-zA-Z0-9'_$") | |
6115 (looking-at "[a-zA-Z0-9`_\$]+") | |
6116 ;; Important: don't use match string, this must work with emacs 19 font-lock on | |
6117 (buffer-substring-no-properties (match-beginning 0) (match-end 0)))) | |
6118 | |
6119 (defun verilog-read-inst-name () | |
6120 "Return instance_name when point is inside instantiation." | |
6121 (save-excursion | |
6122 (verilog-read-inst-backward-name) | |
6123 (looking-at "[a-zA-Z0-9`_\$]+") | |
6124 ;; Important: don't use match string, this must work with emacs 19 font-lock on | |
6125 (buffer-substring-no-properties (match-beginning 0) (match-end 0)))) | |
6126 | |
6127 (defun verilog-read-module-name () | |
6128 "Return module name when after its ( or ;." | |
6129 (save-excursion | |
6130 (re-search-backward "[(;]") | |
6131 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil) | |
6132 (skip-chars-backward "a-zA-Z0-9`_$") | |
6133 (looking-at "[a-zA-Z0-9`_\$]+") | |
6134 ;; Important: don't use match string, this must work with emacs 19 font-lock on | |
6135 (buffer-substring-no-properties (match-beginning 0) (match-end 0)))) | |
6136 | |
6137 (defun verilog-read-auto-params (num-param &optional max-param) | |
6138 "Return parameter list inside auto. | |
6139 Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters." | |
6140 (let ((olist)) | |
6141 (save-excursion | |
6142 ;; /*AUTOPUNT("parameter", "parameter")*/ | |
6143 (search-backward "(") | |
6144 (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?") | |
6145 (setq olist (cons (match-string 1) olist)) | |
6146 (goto-char (match-end 0)))) | |
6147 (or (eq nil num-param) | |
6148 (<= num-param (length olist)) | |
6149 (error "%s: Expected %d parameters" (verilog-point-text) num-param)) | |
6150 (if (eq max-param nil) (setq max-param num-param)) | |
6151 (or (eq nil max-param) | |
6152 (>= max-param (length olist)) | |
6153 (error "%s: Expected <= %d parameters" (verilog-point-text) max-param)) | |
6154 (nreverse olist))) | |
6155 | |
6156 (defun verilog-read-decls () | |
6157 "Compute signal declaration information for the current module at point. | |
6158 Return a array of [outputs inouts inputs wire reg assign const]." | |
6159 (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max))) | |
6160 (functask 0) (paren 0) (sig-paren 0) | |
6161 sigs-in sigs-out sigs-inout sigs-wire sigs-reg sigs-assign sigs-const sigs-gparam | |
6162 vec expect-signal keywd newsig rvalue enum io signed typedefed multidim) | |
6163 (save-excursion | |
6164 (verilog-beg-of-defun) | |
6165 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point)) | |
6166 (while (< (point) end-mod-point) | |
6167 ;;(if dbg (setq dbg (cons (format "Pt %s Vec %s Kwd'%s'\n" (point) vec keywd) dbg))) | |
6168 (cond | |
6169 ((looking-at "//") | |
6170 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") | |
6171 (setq enum (match-string 1))) | |
6172 (search-forward "\n")) | |
6173 ((looking-at "/\\*") | |
6174 (forward-char 2) | |
6175 (if (looking-at "[^*]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") | |
6176 (setq enum (match-string 1))) | |
6177 (or (search-forward "*/") | |
6178 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point)))) | |
6179 ((looking-at "(\\*") | |
6180 (forward-char 2) | |
6181 (or (looking-at "\\s-*)") ; It's a "always @ (*)" | |
6182 (search-forward "*)") | |
6183 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point)))) | |
6184 ((eq ?\" (following-char)) | |
6185 (or (re-search-forward "[^\\]\"" nil t) ;; don't forward-char first, since we look for a non backslash first | |
6186 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point)))) | |
6187 ((eq ?\; (following-char)) | |
6188 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil) | |
6189 (forward-char 1)) | |
6190 ((eq ?= (following-char)) | |
6191 (setq rvalue t newsig nil) | |
6192 (forward-char 1)) | |
6193 ((and (or rvalue sig-paren) | |
6194 (cond ((and (eq ?, (following-char)) | |
6195 (eq paren sig-paren)) | |
6196 (setq rvalue nil) | |
6197 (forward-char 1) | |
6198 t) | |
6199 ;; ,'s can occur inside {} & funcs | |
6200 ((looking-at "[{(]") | |
6201 (setq paren (1+ paren)) | |
6202 (forward-char 1) | |
6203 t) | |
6204 ((looking-at "[})]") | |
6205 (setq paren (1- paren)) | |
6206 (forward-char 1) | |
6207 (when (< paren sig-paren) | |
6208 (setq expect-signal nil)) ; ) that ends variables inside v2k arg list | |
6209 t) | |
6210 ))) | |
6211 ((looking-at "\\s-*\\(\\[[^]]+\\]\\)") | |
6212 (goto-char (match-end 0)) | |
6213 (cond (newsig ; Memory, not just width. Patch last signal added's memory (nth 3) | |
6214 (setcar (cdr (cdr (cdr newsig))) (match-string 1))) | |
6215 (vec ;; Multidimensional | |
6216 (setq multidim (cons vec multidim)) | |
6217 (setq vec (verilog-string-replace-matches | |
6218 "\\s-+" "" nil nil (match-string 1)))) | |
6219 (t ;; Bit width | |
6220 (setq vec (verilog-string-replace-matches | |
6221 "\\s-+" "" nil nil (match-string 1)))))) | |
6222 ;; Normal or escaped identifier -- note we remember the \ if escaped | |
6223 ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)") | |
6224 (goto-char (match-end 0)) | |
6225 (setq keywd (match-string 1)) | |
6226 (when (string-match "^\\\\" keywd) | |
6227 (setq keywd (concat keywd " "))) ;; Escaped ID needs space at end | |
6228 (cond ((equal keywd "input") | |
6229 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren | |
6230 expect-signal 'sigs-in io t)) | |
6231 ((equal keywd "output") | |
6232 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren | |
6233 expect-signal 'sigs-out io t)) | |
6234 ((equal keywd "inout") | |
6235 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren | |
6236 expect-signal 'sigs-inout io t)) | |
6237 ((or (equal keywd "wire") | |
6238 (equal keywd "tri") | |
6239 (equal keywd "tri0") | |
6240 (equal keywd "tri1")) | |
6241 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren | |
6242 expect-signal 'sigs-wire))) | |
6243 ((or (equal keywd "reg") | |
6244 (equal keywd "trireg")) | |
6245 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren | |
6246 expect-signal 'sigs-reg))) | |
6247 ((equal keywd "assign") | |
6248 (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren | |
6249 expect-signal 'sigs-assign)) | |
6250 ((or (equal keywd "supply0") | |
6251 (equal keywd "supply1") | |
6252 (equal keywd "supply") | |
6253 (equal keywd "localparam")) | |
6254 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren | |
6255 expect-signal 'sigs-const))) | |
6256 ((or (equal keywd "parameter")) | |
6257 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren | |
6258 expect-signal 'sigs-gparam))) | |
6259 ((equal keywd "signed") | |
6260 (setq signed "signed")) | |
6261 ((or (equal keywd "function") | |
6262 (equal keywd "task")) | |
6263 (setq functask (1+ functask))) | |
6264 ((or (equal keywd "endfunction") | |
6265 (equal keywd "endtask")) | |
6266 (setq functask (1- functask))) | |
6267 ((or (equal keywd "`ifdef") | |
6268 (equal keywd "`ifndef")) | |
6269 (setq rvalue t)) | |
6270 ((verilog-typedef-name-p keywd) | |
6271 (setq typedefed keywd)) | |
6272 ((and expect-signal | |
6273 (eq functask 0) | |
6274 (not rvalue) | |
6275 (eq paren sig-paren) | |
6276 (not (member keywd verilog-keywords))) | |
6277 ;; Add new signal to expect-signal's variable | |
6278 (setq newsig (list keywd vec nil nil enum signed typedefed multidim)) | |
6279 (set expect-signal (cons newsig | |
6280 (symbol-value expect-signal)))))) | |
6281 (t | |
6282 (forward-char 1))) | |
6283 (skip-syntax-forward " ")) | |
6284 ;; Return arguments | |
6285 (vector (nreverse sigs-out) | |
6286 (nreverse sigs-inout) | |
6287 (nreverse sigs-in) | |
6288 (nreverse sigs-wire) | |
6289 (nreverse sigs-reg) | |
6290 (nreverse sigs-assign) | |
6291 (nreverse sigs-const) | |
6292 (nreverse sigs-gparam) | |
6293 )))) | |
6294 | |
6295 (defvar sigs-in nil) ; Prevent compile warning | |
6296 (defvar sigs-inout nil) ; Prevent compile warning | |
6297 (defvar sigs-out nil) ; Prevent compile warning | |
6298 | |
6299 (defun verilog-read-sub-decls-sig (submodi comment port sig vec multidim) | |
6300 "For verilog-read-sub-decls-line, add a signal." | |
6301 (let (portdata) | |
6302 (when sig | |
6303 (setq port (verilog-symbol-detick-denumber port)) | |
6304 (setq sig (verilog-symbol-detick-denumber sig)) | |
6305 (if sig (setq sig (verilog-string-replace-matches "^[---+~!|&]+" "" nil nil sig))) | |
6306 (if vec (setq vec (verilog-symbol-detick-denumber vec))) | |
6307 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim))) | |
6308 (unless (or (not sig) | |
6309 (equal sig "")) ;; Ignore .foo(1'b1) assignments | |
6310 (cond ((setq portdata (assoc port (verilog-modi-get-inouts submodi))) | |
6311 (setq sigs-inout (cons (list sig vec (concat "To/From " comment) nil nil | |
6312 (verilog-sig-signed portdata) | |
6313 (verilog-sig-type portdata) | |
6314 multidim) | |
6315 sigs-inout))) | |
6316 ((setq portdata (assoc port (verilog-modi-get-outputs submodi))) | |
6317 (setq sigs-out (cons (list sig vec (concat "From " comment) nil nil | |
6318 (verilog-sig-signed portdata) | |
6319 (verilog-sig-type portdata) | |
6320 multidim) | |
6321 sigs-out))) | |
6322 ((setq portdata (assoc port (verilog-modi-get-inputs submodi))) | |
6323 (setq sigs-in (cons (list sig vec (concat "To " comment) nil nil | |
6324 (verilog-sig-signed portdata) | |
6325 (verilog-sig-type portdata) | |
6326 multidim) | |
6327 sigs-in))) | |
6328 ;; (t -- warning pin isn't defined.) ; Leave for lint tool | |
6329 ))))) | |
6330 | |
6331 (defun verilog-read-sub-decls-line (submodi comment) | |
6332 "For read-sub-decls, read lines of port defs until none match anymore. | |
6333 Return the list of signals found, using submodi to look up each port." | |
6334 (let (done port sig vec multidim) | |
6335 (save-excursion | |
6336 (forward-line 1) | |
6337 (while (not done) | |
6338 ;; Get port name | |
6339 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*") | |
6340 (setq port (match-string 1)) | |
6341 (goto-char (match-end 0))) | |
6342 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*") | |
6343 (setq port (concat (match-string 1) " ")) ;; escaped id's need trailing space | |
6344 (goto-char (match-end 0))) | |
6345 ((looking-at "\\s-*\\.[^(]*(") | |
6346 (setq port nil) ;; skip this line | |
6347 (goto-char (match-end 0))) | |
6348 (t | |
6349 (setq port nil done t))) ;; Unknown, ignore rest of line | |
6350 ;; Get signal name | |
6351 (when port | |
6352 (setq multidim nil) | |
6353 (cond ((looking-at "\\(\\\\[^ \t\n\f]*\\)\\s-*)") | |
6354 (setq sig (concat (match-string 1) " ") ;; escaped id's need trailing space | |
6355 vec nil)) | |
6356 ; We intentionally ignore (non-escaped) signals with .s in them | |
6357 ; this prevents AUTOWIRE etc from noticing hierarchical sigs. | |
6358 ((looking-at "\\([^[({).]*\\)\\s-*)") | |
6359 (setq sig (verilog-string-remove-spaces (match-string 1)) | |
6360 vec nil)) | |
6361 ((looking-at "\\([^[({).]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)") | |
6362 (setq sig (verilog-string-remove-spaces (match-string 1)) | |
6363 vec (match-string 2))) | |
6364 ((looking-at "\\([^[({).]*\\)\\s-*/\\*\\(\\[[^*]+\\]\\)\\*/\\s-*)") | |
6365 (setq sig (verilog-string-remove-spaces (match-string 1)) | |
6366 vec nil) | |
6367 (let ((parse (match-string 2))) | |
6368 (while (string-match "^\\(\\[[^]]+\\]\\)\\(.*\\)$" parse) | |
6369 (when vec (setq multidim (cons vec multidim))) | |
6370 (setq vec (match-string 1 parse)) | |
6371 (setq parse (match-string 2 parse))))) | |
6372 ((looking-at "{\\(.*\\)}.*\\s-*)") | |
6373 (let ((mlst (split-string (match-string 1) ",")) | |
6374 mstr) | |
6375 (while (setq mstr (pop mlst)) | |
6376 ;;(unless noninteractive (message "sig: %s " mstr)) | |
6377 (cond | |
6378 ((string-match "\\(['`a-zA-Z0-9_$]+\\)\\s-*$" mstr) | |
6379 (setq sig (verilog-string-remove-spaces (match-string 1 mstr)) | |
6380 vec nil) | |
6381 ;;(unless noninteractive (message "concat sig1: %s %s" mstr (match-string 1 mstr))) | |
6382 ) | |
6383 ((string-match "\\([^[({).]+\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*" mstr) | |
6384 (setq sig (verilog-string-remove-spaces (match-string 1 mstr)) | |
6385 vec (match-string 2 mstr)) | |
6386 ;;(unless noninteractive (message "concat sig2: '%s' '%s' '%s'" mstr (match-string 1 mstr) (match-string 2 mstr))) | |
6387 ) | |
6388 (t | |
6389 (setq sig nil))) | |
6390 ;; Process signals | |
6391 (verilog-read-sub-decls-sig submodi comment port sig vec multidim)))) | |
6392 (t | |
6393 (setq sig nil))) | |
6394 ;; Process signals | |
6395 (verilog-read-sub-decls-sig submodi comment port sig vec multidim)) | |
6396 ;; | |
6397 (forward-line 1))))) | |
6398 | |
6399 (defun verilog-read-sub-decls () | |
6400 "Internally parse signals going to modules under this module. | |
6401 Return a array of [ outputs inouts inputs ] signals for modules that are | |
6402 instantiated in this module. For example if declare A A (.B(SIG)) and SIG | |
6403 is a output, then SIG will be included in the list. | |
6404 | |
6405 This only works on instantiations created with /*AUTOINST*/ converted by | |
6406 \\[verilog-auto-inst]. Otherwise, it would have to read in the whole | |
6407 component library to determine connectivity of the design. | |
6408 | |
6409 One work around for this problem is to manually create // Inputs and // | |
6410 Outputs comments above subcell signals, for example: | |
6411 | |
6412 module1 instance1x ( | |
6413 // Outputs | |
6414 .out (out), | |
6415 // Inputs | |
6416 .in (in));" | |
6417 (save-excursion | |
6418 (let ((end-mod-point (verilog-get-end-of-defun t)) | |
6419 st-point end-inst-point | |
6420 ;; below 3 modified by verilog-read-sub-decls-line | |
6421 sigs-out sigs-inout sigs-in) | |
6422 (verilog-beg-of-defun) | |
6423 (while (re-search-forward "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t) | |
6424 (save-excursion | |
6425 (goto-char (match-beginning 0)) | |
6426 (unless (verilog-inside-comment-p) | |
6427 ;; Attempt to snarf a comment | |
6428 (let* ((submod (verilog-read-inst-module)) | |
6429 (inst (verilog-read-inst-name)) | |
6430 (comment (concat inst " of " submod ".v")) submodi) | |
6431 (when (setq submodi (verilog-modi-lookup submod t)) | |
6432 ;; This could have used a list created by verilog-auto-inst | |
6433 ;; However I want it to be runnable even on user's manually added signals | |
6434 (verilog-backward-open-paren) | |
6435 (setq end-inst-point (save-excursion (forward-sexp 1) (point)) | |
6436 st-point (point)) | |
6437 (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t) | |
6438 (verilog-read-sub-decls-line submodi comment)) ;; Modifies sigs-out | |
6439 (goto-char st-point) | |
6440 (while (re-search-forward "\\s *// Inouts" end-inst-point t) | |
6441 (verilog-read-sub-decls-line submodi comment)) ;; Modifies sigs-inout | |
6442 (goto-char st-point) | |
6443 (while (re-search-forward "\\s *// Inputs" end-inst-point t) | |
6444 (verilog-read-sub-decls-line submodi comment)) ;; Modifies sigs-in | |
6445 ))))) | |
6446 ;; Combine duplicate bits | |
6447 ;;(setq rr (vector sigs-out sigs-inout sigs-in)) | |
6448 (vector (verilog-signals-combine-bus (nreverse sigs-out)) | |
6449 (verilog-signals-combine-bus (nreverse sigs-inout)) | |
6450 (verilog-signals-combine-bus (nreverse sigs-in)))))) | |
6451 | |
6452 (defun verilog-read-inst-pins () | |
6453 "Return a array of [ pins ] for the current instantiation at point. | |
6454 For example if declare A A (.B(SIG)) then B will be included in the list." | |
6455 (save-excursion | |
6456 (let ((end-mod-point (point)) ;; presume at /*AUTOINST*/ point | |
6457 pins pin) | |
6458 (verilog-backward-open-paren) | |
6459 (while (re-search-forward "\\.\\([^(,) \t\n\f]*\\)\\s-*" end-mod-point t) | |
6460 (setq pin (match-string 1)) | |
6461 (unless (verilog-inside-comment-p) | |
6462 (setq pins (cons (list pin) pins)) | |
6463 (when (looking-at "(") | |
6464 (forward-sexp 1)))) | |
6465 (vector pins)))) | |
6466 | |
6467 (defun verilog-read-arg-pins () | |
6468 "Return a array of [ pins ] for the current argument declaration at point." | |
6469 (save-excursion | |
6470 (let ((end-mod-point (point)) ;; presume at /*AUTOARG*/ point | |
6471 pins pin) | |
6472 (verilog-backward-open-paren) | |
6473 (while (re-search-forward "\\([a-zA-Z0-9$_.%`]+\\)" end-mod-point t) | |
6474 (setq pin (match-string 1)) | |
6475 (unless (verilog-inside-comment-p) | |
6476 (setq pins (cons (list pin) pins)))) | |
6477 (vector pins)))) | |
6478 | |
6479 (defun verilog-read-auto-constants (beg end-mod-point) | |
6480 "Return a list of AUTO_CONSTANTs used in the region from BEG to END-MOD-POINT." | |
6481 ;; Insert new | |
6482 (save-excursion | |
6483 (let (sig-list tpl-end-pt) | |
6484 (goto-char beg) | |
6485 (while (re-search-forward "\\<AUTO_CONSTANT" end-mod-point t) | |
6486 (if (not (looking-at "\\s *(")) | |
6487 (error "%s: Missing () after AUTO_CONSTANT" (verilog-point-text))) | |
6488 (search-forward "(" end-mod-point) | |
6489 (setq tpl-end-pt (save-excursion | |
6490 (backward-char 1) | |
6491 (forward-sexp 1) ;; Moves to paren that closes argdecl's | |
6492 (backward-char 1) | |
6493 (point))) | |
6494 (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t) | |
6495 (setq sig-list (cons (list (match-string 1) nil nil) sig-list)))) | |
6496 sig-list))) | |
6497 | |
6498 (defun verilog-read-auto-lisp (start end) | |
6499 "Look for and evaluate a AUTO_LISP between START and END." | |
6500 (save-excursion | |
6501 (goto-char start) | |
6502 (while (re-search-forward "\\<AUTO_LISP(" end t) | |
6503 (backward-char) | |
6504 (let* ((beg-pt (prog1 (point) | |
6505 (forward-sexp 1))) ;; Closing paren | |
6506 (end-pt (point))) | |
6507 (eval-region beg-pt end-pt nil))))) | |
6508 | |
6509 (eval-when-compile | |
6510 ;; These are passed in a let, not global | |
6511 (if (not (boundp 'sigs-in)) | |
6512 (defvar sigs-in nil) (defvar sigs-out nil) | |
6513 (defvar got-sig nil) (defvar got-rvalue nil) (defvar uses-delayed nil))) | |
6514 | |
6515 (defun verilog-read-always-signals-recurse | |
6516 (exit-keywd rvalue ignore-next) | |
6517 "Recursive routine for parentheses/bracket matching. | |
6518 EXIT-KEYWD is expression to stop at, nil if top level. | |
6519 RVALUE is true if at right hand side of equal. | |
6520 IGNORE-NEXT is true to ignore next token, fake from inside case statement." | |
6521 (let* ((semi-rvalue (equal "endcase" exit-keywd)) ;; true if after a ; we are looking for rvalue | |
6522 keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-rvalue end-else-check) | |
6523 ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue ignore-next)))) | |
6524 (while (not (or (eobp) gotend)) | |
6525 (cond | |
6526 ((looking-at "//") | |
6527 (search-forward "\n")) | |
6528 ((looking-at "/\\*") | |
6529 (or (search-forward "*/") | |
6530 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point)))) | |
6531 ((looking-at "(\\*") | |
6532 (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)" | |
6533 (search-forward "*)") | |
6534 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point)))) | |
6535 (t (setq keywd (buffer-substring-no-properties | |
6536 (point) | |
6537 (save-excursion (when (eq 0 (skip-chars-forward "a-zA-Z0-9$_.%`")) | |
6538 (forward-char 1)) | |
6539 (point))) | |
6540 sig-last-tolk sig-tolk | |
6541 sig-tolk nil) | |
6542 ;;(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)))) | |
6543 (cond | |
6544 ((equal keywd "\"") | |
6545 (or (re-search-forward "[^\\]\"" nil t) | |
6546 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point)))) | |
6547 ;; else at top level loop, keep parsing | |
6548 ((and end-else-check (equal keywd "else")) | |
6549 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else %s\n" keywd)))) | |
6550 ;; no forward movement, want to see else in lower loop | |
6551 (setq end-else-check nil)) | |
6552 ;; End at top level loop | |
6553 ((and end-else-check (looking-at "[^ \t\n\f]")) | |
6554 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else-other %s\n" keywd)))) | |
6555 (setq gotend t)) | |
6556 ;; Final statement? | |
6557 ((and exit-keywd (equal keywd exit-keywd)) | |
6558 (setq gotend t) | |
6559 (forward-char (length keywd))) | |
6560 ;; Standard tokens... | |
6561 ((equal keywd ";") | |
6562 (setq ignore-next nil rvalue semi-rvalue) | |
6563 ;; Final statement at top level loop? | |
6564 (when (not exit-keywd) | |
6565 ;;(if dbg (setq dbg (concat dbg (format "\ttop-end-check %s\n" keywd)))) | |
6566 (setq end-else-check t)) | |
6567 (forward-char 1)) | |
6568 ((equal keywd "'") | |
6569 (if (looking-at "'s?[hdxbo][0-9a-fA-F_xz? \t]*") | |
6570 (goto-char (match-end 0)) | |
6571 (forward-char 1))) | |
6572 ((equal keywd ":") ;; Case statement, begin/end label, x?y:z | |
6573 (cond ((equal "endcase" exit-keywd) ;; case x: y=z; statement next | |
6574 (setq ignore-next nil rvalue nil)) | |
6575 ((equal "?" exit-keywd) ;; x?y:z rvalue | |
6576 ) ;; NOP | |
6577 (got-sig ;; label: statement | |
6578 (setq ignore-next nil rvalue semi-rvalue got-sig nil)) | |
6579 ((not rvalue) ;; begin label | |
6580 (setq ignore-next t rvalue nil))) | |
6581 (forward-char 1)) | |
6582 ((equal keywd "=") | |
6583 (if (eq (char-before) ?< ) | |
6584 (setq uses-delayed 1)) | |
6585 (setq ignore-next nil rvalue t) | |
6586 (forward-char 1)) | |
6587 ((equal keywd "?") | |
6588 (forward-char 1) | |
6589 (verilog-read-always-signals-recurse ":" rvalue nil)) | |
6590 ((equal keywd "[") | |
6591 (forward-char 1) | |
6592 (verilog-read-always-signals-recurse "]" t nil)) | |
6593 ((equal keywd "(") | |
6594 (forward-char 1) | |
6595 (cond (sig-last-tolk ;; Function call; zap last signal | |
6596 (setq got-sig nil))) | |
6597 (cond ((equal last-keywd "for") | |
6598 (verilog-read-always-signals-recurse ";" nil nil) | |
6599 (verilog-read-always-signals-recurse ";" t nil) | |
6600 (verilog-read-always-signals-recurse ")" nil nil)) | |
6601 (t (verilog-read-always-signals-recurse ")" t nil)))) | |
6602 ((equal keywd "begin") | |
6603 (skip-syntax-forward "w_") | |
6604 (verilog-read-always-signals-recurse "end" nil nil) | |
6605 ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd)))) | |
6606 (setq ignore-next nil rvalue semi-rvalue) | |
6607 (if (not exit-keywd) (setq end-else-check t))) | |
6608 ((or (equal keywd "case") | |
6609 (equal keywd "casex") | |
6610 (equal keywd "casez")) | |
6611 (skip-syntax-forward "w_") | |
6612 (verilog-read-always-signals-recurse "endcase" t nil) | |
6613 (setq ignore-next nil rvalue semi-rvalue) | |
6614 (if (not exit-keywd) (setq gotend t))) ;; top level begin/end | |
6615 ((string-match "^[$`a-zA-Z_]" keywd) ;; not exactly word constituent | |
6616 (cond ((or (equal keywd "`ifdef") | |
6617 (equal keywd "`ifndef")) | |
6618 (setq ignore-next t)) | |
6619 ((or ignore-next | |
6620 (member keywd verilog-keywords) | |
6621 (string-match "^\\$" keywd)) ;; PLI task | |
6622 (setq ignore-next nil)) | |
6623 (t | |
6624 (setq keywd (verilog-symbol-detick-denumber keywd)) | |
6625 (when got-sig | |
6626 (if got-rvalue (setq sigs-in (cons got-sig sigs-in)) | |
6627 (setq sigs-out (cons got-sig sigs-out))) | |
6628 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S rv=%S\n" got-sig got-rvalue)))) | |
6629 ) | |
6630 (setq got-rvalue rvalue | |
6631 got-sig (if (or (not keywd) | |
6632 (assoc keywd (if got-rvalue sigs-in sigs-out))) | |
6633 nil (list keywd nil nil)) | |
6634 sig-tolk t))) | |
6635 (skip-chars-forward "a-zA-Z0-9$_.%`")) | |
6636 (t | |
6637 (forward-char 1))) | |
6638 ;; End of non-comment token | |
6639 (setq last-keywd keywd) | |
6640 )) | |
6641 (skip-syntax-forward " ")) | |
6642 ;; Append the final pending signal | |
6643 (when got-sig | |
6644 (if got-rvalue (setq sigs-in (cons got-sig sigs-in)) | |
6645 (setq sigs-out (cons got-sig sigs-out))) | |
6646 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S rv=%S\n" got-sig got-rvalue)))) | |
6647 (setq got-sig nil)) | |
6648 ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd)))) | |
6649 )) | |
6650 | |
6651 (defun verilog-read-always-signals () | |
6652 "Parse always block at point and return list of (outputs inout inputs)." | |
6653 ;; Insert new | |
6654 (save-excursion | |
6655 (let* (;;(dbg "") | |
6656 sigs-in sigs-out | |
6657 uses-delayed) ;; Found signal/rvalue; push if not function | |
6658 (search-forward ")") | |
6659 (verilog-read-always-signals-recurse nil nil nil) | |
6660 ;;(if dbg (save-excursion (set-buffer (get-buffer-create "*vl-dbg*")) (delete-region (point-min) (point-max)) (insert dbg) (setq dbg ""))) | |
6661 ;; Return what was found | |
6662 (list sigs-out nil sigs-in uses-delayed)))) | |
6663 | |
6664 (defun verilog-read-instants () | |
6665 "Parse module at point and return list of ( ( file instance ) ... )." | |
6666 (verilog-beg-of-defun) | |
6667 (let* ((end-mod-point (verilog-get-end-of-defun t)) | |
6668 (state nil) | |
6669 (instants-list nil)) | |
6670 (save-excursion | |
6671 (while (< (point) end-mod-point) | |
6672 ;; Stay at level 0, no comments | |
6673 (while (progn | |
6674 (setq state (parse-partial-sexp (point) end-mod-point 0 t nil)) | |
6675 (or (> (car state) 0) ; in parens | |
6676 (nth 5 state) ; comment | |
6677 )) | |
6678 (forward-line 1)) | |
6679 (beginning-of-line) | |
6680 (if (looking-at "^\\s-*\\([a-zA-Z0-9`_$]+\\)\\s-+\\([a-zA-Z0-9`_$]+\\)\\s-*(") | |
6681 ;;(if (looking-at "^\\(.+\\)$") | |
6682 (let ((module (match-string 1)) | |
6683 (instant (match-string 2))) | |
6684 (if (not (member module verilog-keywords)) | |
6685 (setq instants-list (cons (list module instant) instants-list))))) | |
6686 (forward-line 1) | |
6687 )) | |
6688 instants-list)) | |
6689 | |
6690 | |
6691 (defun verilog-read-auto-template (module) | |
6692 "Look for a auto_template for the instantiation of the given MODULE. | |
6693 If found returns the signal name connections. Return REGEXP and | |
6694 list of ( (signal_name connection_name)... )" | |
6695 (save-excursion | |
6696 ;; Find beginning | |
6697 (let ((tpl-regexp "\\([0-9]+\\)") | |
6698 (lineno 0) | |
6699 (templateno 0) | |
6700 tpl-sig-list tpl-wild-list tpl-end-pt rep) | |
6701 (cond ((or | |
6702 (re-search-backward (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t) | |
6703 (progn | |
6704 (goto-char (point-min)) | |
6705 (re-search-forward (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t))) | |
6706 (goto-char (match-end 0)) | |
6707 ;; Parse "REGEXP" | |
6708 ;; We reserve @"..." for future lisp expressions that evaluate once-per-AUTOINST | |
6709 (when (looking-at "\\s-*\"\\([^\"]*)\\)\"") | |
6710 (setq tpl-regexp (match-string 1)) | |
6711 (goto-char (match-end 0))) | |
6712 (search-forward "(") | |
6713 ;; Parse lines in the template | |
6714 (when verilog-auto-inst-template-numbers | |
6715 (save-excursion | |
6716 (goto-char (point-min)) | |
6717 (while (search-forward "AUTO_TEMPLATE" nil t) | |
6718 (setq templateno (1+ templateno))))) | |
6719 (setq tpl-end-pt (save-excursion | |
6720 (backward-char 1) | |
6721 (forward-sexp 1) ;; Moves to paren that closes argdecl's | |
6722 (backward-char 1) | |
6723 (point))) | |
6724 ;; | |
6725 (while (< (point) tpl-end-pt) | |
6726 (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)") | |
6727 (setq tpl-sig-list (cons (list | |
6728 (match-string-no-properties 1) | |
6729 (match-string-no-properties 2) | |
6730 templateno lineno) | |
6731 tpl-sig-list)) | |
6732 (goto-char (match-end 0))) | |
6733 ;; Regexp form?? | |
6734 ((looking-at | |
6735 ;; Regexp bug in xemacs disallows ][ inside [], and wants + last | |
6736 "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]+\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)") | |
6737 (setq rep (match-string-no-properties 3)) | |
6738 (goto-char (match-end 0)) | |
6739 (setq tpl-wild-list | |
6740 (cons (list | |
6741 (concat "^" | |
6742 (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil | |
6743 (match-string 1)) | |
6744 "$") | |
6745 rep | |
6746 templateno lineno) | |
6747 tpl-wild-list))) | |
6748 ((looking-at "[ \t\f]+") | |
6749 (goto-char (match-end 0))) | |
6750 ((looking-at "\n") | |
6751 (setq lineno (1+ lineno)) | |
6752 (goto-char (match-end 0))) | |
6753 ((looking-at "//") | |
6754 (search-forward "\n")) | |
6755 ((looking-at "/\\*") | |
6756 (forward-char 2) | |
6757 (or (search-forward "*/") | |
6758 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point)))) | |
6759 (t | |
6760 (error "%s: AUTO_TEMPLATE parsing error: %s" | |
6761 (verilog-point-text) | |
6762 (progn (looking-at ".*$") (match-string 0)))) | |
6763 )) | |
6764 ;; Return | |
6765 (vector tpl-regexp | |
6766 (list tpl-sig-list tpl-wild-list))) | |
6767 ;; If no template found | |
6768 (t (vector tpl-regexp nil)))))) | |
6769 ;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry")) | |
6770 | |
6771 (defun verilog-set-define (defname defvalue &optional buffer enumname) | |
6772 "Set the definition DEFNAME to the DEFVALUE in the given BUFFER. | |
6773 Optionally associate it with the specified enumeration ENUMNAME." | |
6774 (save-excursion | |
6775 (set-buffer (or buffer (current-buffer))) | |
6776 (let ((mac (intern (concat "vh-" defname)))) | |
6777 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1) | |
6778 ;; Need to define to a constant if no value given | |
6779 (set (make-variable-buffer-local mac) | |
6780 (if (equal defvalue "") "1" defvalue))) | |
6781 (if enumname | |
6782 (let ((enumvar (intern (concat "venum-" enumname)))) | |
6783 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1) | |
6784 (make-variable-buffer-local enumvar) | |
6785 (add-to-list enumvar defname))) | |
6786 )) | |
6787 | |
6788 (defun verilog-read-defines (&optional filename recurse subcall) | |
6789 "Read `defines and parameters for the current file, or optional FILENAME. | |
6790 If the filename is provided, `verilog-library-flags' will be used to | |
6791 resolve it. If optional RECURSE is non-nil, recurse through `includes. | |
6792 | |
6793 Parameters must be simple assignments to constants, or have their own | |
6794 \"parameter\" label rather than a list of parameters. Thus: | |
6795 | |
6796 parameter X = 5, Y = 10; // Ok | |
6797 parameter X = {1'b1, 2'h2}; // Ok | |
6798 parameter X = {1'b1, 2'h2}, Y = 10; // Bad, make into 2 parameter lines | |
6799 | |
6800 Defines must be simple text substitutions, one on a line, starting | |
6801 at the beginning of the line. Any ifdefs or multiline comments around the | |
6802 define are ignored. | |
6803 | |
6804 Defines are stored inside Emacs variables using the name vh-{definename}. | |
6805 | |
6806 This function is useful for setting vh-* variables. The file variables | |
6807 feature can be used to set defines that `verilog-mode' can see; put at the | |
6808 *END* of your file something like: | |
6809 | |
6810 // Local Variables: | |
6811 // vh-macro:\"macro_definition\" | |
6812 // End: | |
6813 | |
6814 If macros are defined earlier in the same file and you want their values, | |
6815 you can read them automatically (provided `enable-local-eval' is on): | |
6816 | |
6817 // Local Variables: | |
6818 // eval:(verilog-read-defines) | |
6819 // eval:(verilog-read-defines \"group_standard_includes.v\") | |
6820 // End: | |
6821 | |
6822 Note these are only read when the file is first visited, you must use | |
6823 \\[find-alternate-file] RET to have these take effect after editing them! | |
6824 | |
6825 If you want to disable the \"Process `eval' or hook local variables\" | |
6826 warning message, you need to add to your .emacs file: | |
6827 | |
6828 (setq enable-local-eval t)" | |
6829 (let ((origbuf (current-buffer))) | |
6830 (save-excursion | |
6831 (unless subcall (verilog-getopt-flags)) | |
6832 (when filename | |
6833 (let ((fns (verilog-library-filenames filename (buffer-file-name)))) | |
6834 (if fns | |
6835 (set-buffer (find-file-noselect (car fns))) | |
6836 (error (concat (verilog-point-text) | |
6837 ": Can't find verilog-read-defines file: " filename))))) | |
6838 (when recurse | |
6839 (goto-char (point-min)) | |
6840 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t) | |
6841 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string-no-properties 1)))) | |
6842 (unless (verilog-inside-comment-p) | |
6843 (verilog-read-defines inc recurse t))))) | |
6844 ;; Read `defines | |
6845 ;; note we don't use verilog-re... it's faster this way, and that | |
6846 ;; function has problems when comments are at the end of the define | |
6847 (goto-char (point-min)) | |
6848 (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t) | |
6849 (let ((defname (match-string-no-properties 1)) | |
6850 (defvalue (match-string-no-properties 2))) | |
6851 (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue)) | |
6852 (verilog-set-define defname defvalue origbuf))) | |
6853 ;; Hack: Read parameters | |
6854 (goto-char (point-min)) | |
6855 (while (re-search-forward | |
6856 "^\\s-*\\(parameter\\|localparam\\)\\(\\(\\s-*\\[[^]]*\\]\\|\\)\\s-+\\([a-zA-Z0-9_$]+\\)\\s-*=\\s-*\\([^;,]*\\),?\\|\\)\\s-*" nil t) | |
6857 (let ((var (match-string-no-properties 4)) | |
6858 (val (match-string-no-properties 5)) | |
6859 enumname) | |
6860 ;; The primary way of getting defines is verilog-read-decls | |
6861 ;; However, that isn't called yet for included files, so we'll add another scheme | |
6862 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") | |
6863 (setq enumname (match-string-no-properties 1))) | |
6864 (if var | |
6865 (verilog-set-define var val origbuf enumname)) | |
6866 (forward-comment 999) | |
6867 (while (looking-at "\\s-*,?\\s-*\\([a-zA-Z0-9_$]+\\)\\s-*=\\s-*\\([^;,]*\\),?\\s-*") | |
6868 (verilog-set-define (match-string-no-properties 1) (match-string-no-properties 2) origbuf enumname) | |
6869 (goto-char (match-end 0)) | |
6870 (forward-comment 999)))) | |
6871 ))) | |
6872 | |
6873 (defun verilog-read-includes () | |
6874 "Read `includes for the current file. | |
6875 This will find all of the `includes which are at the beginning of lines, | |
6876 ignoring any ifdefs or multiline comments around them. | |
6877 `verilog-read-defines' is then performed on the current and each included | |
6878 file. | |
6879 | |
6880 It is often useful put at the *END* of your file something like: | |
6881 | |
6882 // Local Variables: | |
6883 // eval:(verilog-read-defines) | |
6884 // eval:(verilog-read-includes) | |
6885 // End: | |
6886 | |
6887 Note includes are only read when the file is first visited, you must use | |
6888 \\[find-alternate-file] RET to have these take effect after editing them! | |
6889 | |
6890 It is good to get in the habit of including all needed files in each .v | |
6891 file that needs it, rather than waiting for compile time. This will aid | |
6892 this process, Verilint, and readability. To prevent defining the same | |
6893 variable over and over when many modules are compiled together, put a test | |
6894 around the inside each include file: | |
6895 | |
6896 foo.v (a include): | |
6897 `ifdef _FOO_V // include if not already included | |
6898 `else | |
6899 `define _FOO_V | |
6900 ... contents of file | |
6901 `endif // _FOO_V" | |
6902 ;;slow: (verilog-read-defines nil t)) | |
6903 (save-excursion | |
6904 (verilog-getopt-flags) | |
6905 (goto-char (point-min)) | |
6906 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t) | |
6907 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string 1)))) | |
6908 (verilog-read-defines inc nil t))))) | |
6909 | |
6910 (defun verilog-read-signals (&optional start end) | |
6911 "Return a simple list of all possible signals in the file. | |
6912 Bounded by optional region from START to END. Overly aggressive but fast. | |
6913 Some macros and such are also found and included. For dinotrace.el" | |
6914 (let (sigs-all keywd) | |
6915 (progn;save-excursion | |
6916 (goto-char (or start (point-min))) | |
6917 (setq end (or end (point-max))) | |
6918 (while (re-search-forward "[\"/a-zA-Z_.%`]" end t) | |
6919 (forward-char -1) | |
6920 (cond | |
6921 ((looking-at "//") | |
6922 (search-forward "\n")) | |
6923 ((looking-at "/\\*") | |
6924 (search-forward "*/")) | |
6925 ((looking-at "(\\*") | |
6926 (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)" | |
6927 (search-forward "*)"))) | |
6928 ((eq ?\" (following-char)) | |
6929 (re-search-forward "[^\\]\"")) ;; don't forward-char first, since we look for a non backslash first | |
6930 ((looking-at "\\s-*\\([a-zA-Z0-9$_.%`]+\\)") | |
6931 (goto-char (match-end 0)) | |
6932 (setq keywd (match-string-no-properties 1)) | |
6933 (or (member keywd verilog-keywords) | |
6934 (member keywd sigs-all) | |
6935 (setq sigs-all (cons keywd sigs-all)))) | |
6936 (t (forward-char 1))) | |
6937 ) | |
6938 ;; Return list | |
6939 sigs-all))) | |
6940 | |
6941 ;; | |
6942 ;; Argument file parsing | |
6943 ;; | |
6944 | |
6945 (defun verilog-getopt (arglist) | |
6946 "Parse -f, -v etc arguments in ARGLIST list or string." | |
6947 (unless (listp arglist) (setq arglist (list arglist))) | |
6948 (let ((space-args '()) | |
6949 arg next-param) | |
6950 ;; Split on spaces, so users can pass whole command lines | |
6951 (while arglist | |
6952 (setq arg (car arglist) | |
6953 arglist (cdr arglist)) | |
6954 (while (string-match "^\\([^ \t\n\f]+\\)[ \t\n\f]*\\(.*$\\)" arg) | |
6955 (setq space-args (append space-args | |
6956 (list (match-string-no-properties 1 arg)))) | |
6957 (setq arg (match-string 2 arg)))) | |
6958 ;; Parse arguments | |
6959 (while space-args | |
6960 (setq arg (car space-args) | |
6961 space-args (cdr space-args)) | |
6962 (cond | |
6963 ;; Need another arg | |
6964 ((equal arg "-f") | |
6965 (setq next-param arg)) | |
6966 ((equal arg "-v") | |
6967 (setq next-param arg)) | |
6968 ((equal arg "-y") | |
6969 (setq next-param arg)) | |
6970 ;; +libext+(ext1)+(ext2)... | |
6971 ((string-match "^\\+libext\\+\\(.*\\)" arg) | |
6972 (setq arg (match-string 1 arg)) | |
6973 (while (string-match "\\([^+]+\\)\\+?\\(.*\\)" arg) | |
6974 (verilog-add-list-unique `verilog-library-extensions | |
6975 (match-string 1 arg)) | |
6976 (setq arg (match-string 2 arg)))) | |
6977 ;; | |
6978 ((or (string-match "^-D\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; -Ddefine=val | |
6979 (string-match "^-D\\([^+=]*\\)\\(\\)" arg) ;; -Ddefine | |
6980 (string-match "^\\+define\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; +define+val | |
6981 (string-match "^\\+define\\([^+=]*\\)\\(\\)" arg)) ;; +define+define | |
6982 (verilog-set-define (match-string 1 arg) (match-string 2 arg))) | |
6983 ;; | |
6984 ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ;; +incdir+dir | |
6985 (string-match "^-I\\(.*\\)" arg)) ;; -Idir | |
6986 (verilog-add-list-unique `verilog-library-directories | |
6987 (match-string 1 arg))) | |
6988 ;; Ignore | |
6989 ((equal "+librescan" arg)) | |
6990 ((string-match "^-U\\(.*\\)" arg)) ;; -Udefine | |
6991 ;; Second parameters | |
6992 ((equal next-param "-f") | |
6993 (setq next-param nil) | |
6994 (verilog-getopt-file arg)) | |
6995 ((equal next-param "-v") | |
6996 (setq next-param nil) | |
6997 (verilog-add-list-unique `verilog-library-files arg)) | |
6998 ((equal next-param "-y") | |
6999 (setq next-param nil) | |
7000 (verilog-add-list-unique `verilog-library-directories arg)) | |
7001 ;; Filename | |
7002 ((string-match "^[^-+]" arg) | |
7003 (verilog-add-list-unique `verilog-library-files arg)) | |
7004 ;; Default - ignore; no warning | |
7005 ) | |
7006 ) | |
7007 ) | |
7008 ) | |
7009 ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir")) | |
7010 | |
7011 (defun verilog-getopt-file (filename) | |
7012 "Read verilog options from the specified FILENAME." | |
7013 (save-excursion | |
7014 (let ((fns (verilog-library-filenames filename (buffer-file-name))) | |
7015 (orig-buffer (current-buffer)) | |
7016 line) | |
7017 (if fns | |
7018 (set-buffer (find-file-noselect (car fns))) | |
7019 (error (concat (verilog-point-text) | |
7020 "Can't find verilog-getopt-file -f file: " filename))) | |
7021 (goto-char (point-min)) | |
7022 (while (not (eobp)) | |
7023 (setq line (buffer-substring (point) | |
7024 (save-excursion (end-of-line) (point)))) | |
7025 (forward-line 1) | |
7026 (when (string-match "//" line) | |
7027 (setq line (substring line 0 (match-beginning 0)))) | |
7028 (save-excursion | |
7029 (set-buffer orig-buffer) ; Variables are buffer-local, so need right context. | |
7030 (verilog-getopt line)))))) | |
7031 | |
7032 (defun verilog-getopt-flags () | |
7033 "Convert `verilog-library-flags' into standard library variables." | |
7034 ;; If the flags are local, then all the outputs should be local also | |
7035 (when (local-variable-p `verilog-library-flags (current-buffer)) | |
7036 (make-variable-buffer-local 'verilog-library-extensions) | |
7037 (make-variable-buffer-local 'verilog-library-directories) | |
7038 (make-variable-buffer-local 'verilog-library-files) | |
7039 (make-variable-buffer-local 'verilog-library-flags)) | |
7040 ;; Allow user to customize | |
7041 (run-hooks 'verilog-before-getopt-flags-hook) | |
7042 ;; Process arguments | |
7043 (verilog-getopt verilog-library-flags) | |
7044 ;; Allow user to customize | |
7045 (run-hooks 'verilog-getopt-flags-hook)) | |
7046 | |
7047 (defun verilog-add-list-unique (varref object) | |
7048 "Append to VARREF list the given OBJECT, | |
7049 unless it is already a member of the variable's list" | |
7050 (unless (member object (symbol-value varref)) | |
7051 (set varref (append (symbol-value varref) (list object)))) | |
7052 varref) | |
7053 ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l) | |
7054 | |
7055 | |
7056 ;; | |
7057 ;; Module name lookup | |
7058 ;; | |
7059 | |
7060 (defun verilog-module-inside-filename-p (module filename) | |
7061 "Return point if MODULE is specified inside FILENAME, else nil. | |
7062 Allows version control to check out the file if need be." | |
7063 (and (or (file-exists-p filename) | |
7064 (and | |
7065 (condition-case nil | |
7066 (fboundp 'vc-backend) | |
7067 (error nil)) | |
7068 (vc-backend filename))) | |
7069 (let (pt) | |
7070 (save-excursion | |
7071 (set-buffer (find-file-noselect filename)) | |
7072 (goto-char (point-min)) | |
7073 (while (and | |
7074 ;; It may be tempting to look for verilog-defun-re, don't, it slows things down a lot! | |
7075 (verilog-re-search-forward-quick "\\<module\\>" nil t) | |
7076 (verilog-re-search-forward-quick "[(;]" nil t)) | |
7077 (if (equal module (verilog-read-module-name)) | |
7078 (setq pt (point)))) | |
7079 pt)))) | |
7080 | |
7081 (defun verilog-is-number (symbol) | |
7082 "Return true if SYMBOL is number-like." | |
7083 (or (string-match "^[0-9 \t:]+$" symbol) | |
7084 (string-match "^[---]*[0-9]+$" symbol) | |
7085 (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol) | |
7086 )) | |
7087 | |
7088 (defun verilog-symbol-detick (symbol wing-it) | |
7089 "Return a expanded SYMBOL name without any defines. | |
7090 If the variable vh-{symbol} is defined, return that value. | |
7091 If undefined, and WING-IT, return just SYMBOL without the tick, else nil." | |
7092 (while (and symbol (string-match "^`" symbol)) | |
7093 (setq symbol (substring symbol 1)) | |
7094 (setq symbol | |
7095 (if (boundp (intern (concat "vh-" symbol))) | |
7096 ;; Emacs has a bug where boundp on a buffer-local | |
7097 ;; variable in only one buffer returns t in another. | |
7098 ;; This can confuse, so check for nil. | |
7099 (let ((val (eval (intern (concat "vh-" symbol))))) | |
7100 (if (eq val nil) | |
7101 (if wing-it symbol nil) | |
7102 val)) | |
7103 (if wing-it symbol nil)))) | |
7104 symbol) | |
7105 ;;(verilog-symbol-detick "`mod" nil) | |
7106 | |
7107 (defun verilog-symbol-detick-denumber (symbol) | |
7108 "Return SYMBOL with defines converted and any numbers dropped to nil." | |
7109 (when (string-match "^`" symbol) | |
7110 ;; This only will work if the define is a simple signal, not | |
7111 ;; something like a[b]. Sorry, it should be substituted into the parser | |
7112 (setq symbol | |
7113 (verilog-string-replace-matches | |
7114 "\[[^0-9: \t]+\]" "" nil nil | |
7115 (or (verilog-symbol-detick symbol nil) | |
7116 (if verilog-auto-sense-defines-constant | |
7117 "0" | |
7118 symbol))))) | |
7119 (if (verilog-is-number symbol) | |
7120 nil | |
7121 symbol)) | |
7122 | |
7123 (defun verilog-symbol-detick-text (text) | |
7124 "Return TEXT with any without any known defines. | |
7125 If the variable vh-{symbol} is defined, substitute that value." | |
7126 (let ((ok t) symbol val) | |
7127 (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text)) | |
7128 (setq symbol (match-string 1 text)) | |
7129 (message symbol) | |
7130 (cond ((and | |
7131 (boundp (intern (concat "vh-" symbol))) | |
7132 ;; Emacs has a bug where boundp on a buffer-local | |
7133 ;; variable in only one buffer returns t in another. | |
7134 ;; This can confuse, so check for nil. | |
7135 (setq val (eval (intern (concat "vh-" symbol))))) | |
7136 (setq text (replace-match val nil nil text))) | |
7137 (t (setq ok nil))))) | |
7138 text) | |
7139 ;;(progn (setq vh-mod "`foo" vh-foo "bar") (verilog-symbol-detick-text "bar `mod `undefed")) | |
7140 | |
7141 (defun verilog-expand-dirnames (&optional dirnames) | |
7142 "Return a list of existing directories given a list of wildcarded DIRNAMES. | |
7143 Or, just the existing dirnames themselves if there are no wildcards." | |
7144 (interactive) | |
7145 (unless dirnames (error "`verilog-library-directories' should include at least '.'")) | |
7146 (setq dirnames (reverse dirnames)) ; not nreverse | |
7147 (let ((dirlist nil) | |
7148 pattern dirfile dirfiles dirname root filename rest) | |
7149 (while dirnames | |
7150 (setq dirname (substitute-in-file-name (car dirnames)) | |
7151 dirnames (cdr dirnames)) | |
7152 (cond ((string-match (concat "^\\(\\|[/\\]*[^*?]*[/\\]\\)" ;; root | |
7153 "\\([^/\\]*[*?][^/\\]*\\)" ;; filename with *? | |
7154 "\\(.*\\)") ;; rest | |
7155 dirname) | |
7156 (setq root (match-string 1 dirname) | |
7157 filename (match-string 2 dirname) | |
7158 rest (match-string 3 dirname) | |
7159 pattern filename) | |
7160 ;; now replace those * and ? with .+ and . | |
7161 ;; use ^ and /> to get only whole file names | |
7162 ;;verilog-string-replace-matches | |
7163 (setq pattern (verilog-string-replace-matches "[*]" ".+" nil nil pattern) | |
7164 pattern (verilog-string-replace-matches "[?]" "." nil nil pattern) | |
7165 | |
7166 ;; Unfortunately allows abc/*/rtl to match abc/rtl | |
7167 ;; because abc/.. shows up in dirfiles. Solutions welcome. | |
7168 dirfiles (if (file-directory-p root) ; Ignore version control external | |
7169 (directory-files root t pattern nil))) | |
7170 (while dirfiles | |
7171 (setq dirfile (expand-file-name (concat (car dirfiles) rest)) | |
7172 dirfiles (cdr dirfiles)) | |
7173 (if (file-directory-p dirfile) | |
7174 (setq dirlist (cons dirfile dirlist)))) | |
7175 ) | |
7176 ;; Defaults | |
7177 (t | |
7178 (if (file-directory-p dirname) | |
7179 (setq dirlist (cons dirname dirlist)))) | |
7180 )) | |
7181 dirlist)) | |
7182 ;;(verilog-expand-dirnames (list "." ".." "nonexist" "../*" "/home/wsnyder/*/v")) | |
7183 | |
7184 (defun verilog-library-filenames (filename current &optional check-ext) | |
7185 "Return a search path to find the given FILENAME name. | |
7186 Uses the CURRENT filename, `verilog-library-directories' and | |
7187 `verilog-library-extensions' variables to build the path. | |
7188 With optional CHECK-EXT also check `verilog-library-extensions'." | |
7189 (let ((ckdir (verilog-expand-dirnames verilog-library-directories)) | |
7190 fn outlist) | |
7191 (while ckdir | |
7192 (let ((ckext (if check-ext verilog-library-extensions `("")))) | |
7193 (while ckext | |
7194 (setq fn (expand-file-name | |
7195 (concat filename (car ckext)) | |
7196 (expand-file-name (car ckdir) (file-name-directory current)))) | |
7197 (if (file-exists-p fn) | |
7198 (setq outlist (cons fn outlist))) | |
7199 (setq ckext (cdr ckext)))) | |
7200 (setq ckdir (cdr ckdir))) | |
7201 (nreverse outlist))) | |
7202 | |
7203 (defun verilog-module-filenames (module current) | |
7204 "Return a search path to find the given MODULE name. | |
7205 Uses the CURRENT filename, `verilog-library-extensions', | |
7206 `verilog-library-directories' and `verilog-library-files' | |
7207 variables to build the path." | |
7208 ;; Return search locations for it | |
7209 (append (list current) ; first, current buffer | |
7210 (verilog-library-filenames module current t) | |
7211 verilog-library-files)) ; finally, any libraries | |
7212 | |
7213 ;; | |
7214 ;; Module Information | |
7215 ;; | |
7216 ;; Many of these functions work on "modi" a module information structure | |
7217 ;; A modi is: [module-name-string file-name begin-point] | |
7218 | |
7219 (defvar verilog-cache-enabled t | |
7220 "If true, enable caching of signals, etc. Set to nil for debugging to make things SLOW!") | |
7221 | |
7222 (defvar verilog-modi-cache-list nil | |
7223 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)... | |
7224 For speeding up verilog-modi-get-* commands. | |
7225 Buffer-local.") | |
7226 | |
7227 (defvar verilog-modi-cache-preserve-tick nil | |
7228 "Modification tick after which the cache is still considered valid. | |
7229 Use verilog-preserve-cache's to set") | |
7230 (defvar verilog-modi-cache-preserve-buffer nil | |
7231 "Modification tick after which the cache is still considered valid. | |
7232 Use verilog-preserve-cache's to set") | |
7233 | |
7234 (defun verilog-modi-current () | |
7235 "Return the modi structure for the module currently at point." | |
7236 (let* (name pt) | |
7237 ;; read current module's name | |
7238 (save-excursion | |
7239 (verilog-re-search-backward-quick verilog-defun-re nil nil) | |
7240 (verilog-re-search-forward-quick "(" nil nil) | |
7241 (setq name (verilog-read-module-name)) | |
7242 (setq pt (point))) | |
7243 ;; return | |
7244 (vector name (or (buffer-file-name) (current-buffer)) pt))) | |
7245 | |
7246 (defvar verilog-modi-lookup-last-mod nil "Cache of last module looked up.") | |
7247 (defvar verilog-modi-lookup-last-modi nil "Cache of last modi returned.") | |
7248 (defvar verilog-modi-lookup-last-current nil "Cache of last `current-buffer' looked up.") | |
7249 (defvar verilog-modi-lookup-last-tick nil "Cache of last `buffer-modified-tick' looked up.") | |
7250 | |
7251 (defun verilog-modi-lookup (module allow-cache &optional ignore-error) | |
7252 "Find the file and point at which MODULE is defined. | |
7253 If ALLOW-CACHE is set, check and remember cache of previous lookups. | |
7254 Return modi if successful, else print message unless IGNORE-ERROR is true." | |
7255 (let* ((current (or (buffer-file-name) (current-buffer)))) | |
7256 (cond ((and verilog-modi-lookup-last-modi | |
7257 verilog-cache-enabled | |
7258 allow-cache | |
7259 (equal verilog-modi-lookup-last-mod module) | |
7260 (equal verilog-modi-lookup-last-current current) | |
7261 (equal verilog-modi-lookup-last-tick (buffer-modified-tick))) | |
7262 ;; ok as is | |
7263 ) | |
7264 (t (let* ((realmod (verilog-symbol-detick module t)) | |
7265 (orig-filenames (verilog-module-filenames realmod current)) | |
7266 (filenames orig-filenames) | |
7267 pt) | |
7268 (while (and filenames (not pt)) | |
7269 (if (not (setq pt (verilog-module-inside-filename-p realmod (car filenames)))) | |
7270 (setq filenames (cdr filenames)))) | |
7271 (cond (pt (setq verilog-modi-lookup-last-modi | |
7272 (vector realmod (car filenames) pt))) | |
7273 (t (setq verilog-modi-lookup-last-modi nil) | |
7274 (or ignore-error | |
7275 (error (concat (verilog-point-text) | |
7276 ": Can't locate " module " module definition" | |
7277 (if (not (equal module realmod)) | |
7278 (concat " (Expanded macro to " realmod ")") | |
7279 "") | |
7280 "\n Check the verilog-library-directories variable." | |
7281 "\n I looked in (if not listed, doesn't exist):\n\t" | |
7282 (mapconcat 'concat orig-filenames "\n\t"))))) | |
7283 ) | |
7284 (setq verilog-modi-lookup-last-mod module | |
7285 verilog-modi-lookup-last-current current | |
7286 verilog-modi-lookup-last-tick (buffer-modified-tick))))) | |
7287 verilog-modi-lookup-last-modi | |
7288 )) | |
7289 | |
7290 (defsubst verilog-modi-name (modi) | |
7291 (aref modi 0)) | |
7292 (defsubst verilog-modi-file-or-buffer (modi) | |
7293 (aref modi 1)) | |
7294 (defsubst verilog-modi-point (modi) | |
7295 (aref modi 2)) | |
7296 | |
7297 (defun verilog-modi-filename (modi) | |
7298 "Filename of MODI, or name of buffer if its never been saved." | |
7299 (if (bufferp (verilog-modi-file-or-buffer modi)) | |
7300 (or (buffer-file-name (verilog-modi-file-or-buffer modi)) | |
7301 (buffer-name (verilog-modi-file-or-buffer modi))) | |
7302 (verilog-modi-file-or-buffer modi))) | |
7303 | |
7304 (defun verilog-modi-goto (modi) | |
7305 "Move point/buffer to specified MODI." | |
7306 (or modi (error "Passed unfound modi to goto, check earlier")) | |
7307 (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi)) | |
7308 (verilog-modi-file-or-buffer modi) | |
7309 (find-file-noselect (verilog-modi-file-or-buffer modi)))) | |
7310 (or (equal major-mode `verilog-mode) ;; Put into verilog mode to get syntax | |
7311 (verilog-mode)) | |
7312 (goto-char (verilog-modi-point modi))) | |
7313 | |
7314 (defun verilog-goto-defun-file (module) | |
7315 "Move point to the file at which a given MODULE is defined." | |
7316 (interactive "sGoto File for Module: ") | |
7317 (let* ((modi (verilog-modi-lookup module nil))) | |
7318 (when modi | |
7319 (verilog-modi-goto modi) | |
7320 (switch-to-buffer (current-buffer))))) | |
7321 | |
7322 (defun verilog-modi-cache-results (modi function) | |
7323 "Run on MODI the given FUNCTION. Locate the module in a file. | |
7324 Cache the output of function so next call may have faster access." | |
7325 (let (func-returns fass) | |
7326 (save-excursion | |
7327 (verilog-modi-goto modi) | |
7328 (if (and (setq fass (assoc (list (verilog-modi-name modi) function) | |
7329 verilog-modi-cache-list)) | |
7330 ;; Destroy caching when incorrect; Modified or file changed | |
7331 (not (and verilog-cache-enabled | |
7332 (or (equal (buffer-modified-tick) (nth 1 fass)) | |
7333 (and verilog-modi-cache-preserve-tick | |
7334 (<= verilog-modi-cache-preserve-tick (nth 1 fass)) | |
7335 (equal verilog-modi-cache-preserve-buffer (current-buffer)))) | |
7336 (equal (visited-file-modtime) (nth 2 fass))))) | |
7337 (setq verilog-modi-cache-list nil | |
7338 fass nil)) | |
7339 (cond (fass | |
7340 ;; Found | |
7341 (setq func-returns (nth 3 fass))) | |
7342 (t | |
7343 ;; Read from file | |
7344 ;; Clear then restore any hilighting to make emacs19 happy | |
7345 (let ((fontlocked (when (and (boundp 'font-lock-mode) | |
7346 font-lock-mode) | |
7347 (font-lock-mode nil) | |
7348 t))) | |
7349 (setq func-returns (funcall function)) | |
7350 (when fontlocked (font-lock-mode t))) | |
7351 ;; Cache for next time | |
7352 (make-variable-buffer-local 'verilog-modi-cache-list) | |
7353 (setq verilog-modi-cache-list | |
7354 (cons (list (list (verilog-modi-name modi) function) | |
7355 (buffer-modified-tick) | |
7356 (visited-file-modtime) | |
7357 func-returns) | |
7358 verilog-modi-cache-list))) | |
7359 )) | |
7360 ;; | |
7361 func-returns)) | |
7362 | |
7363 (defun verilog-modi-cache-add (modi function element sig-list) | |
7364 "Add function return results to the module cache. | |
7365 Update MODI's cache for given FUNCTION so that the return ELEMENT of that | |
7366 function now contains the additional SIG-LIST parameters." | |
7367 (let (fass) | |
7368 (save-excursion | |
7369 (verilog-modi-goto modi) | |
7370 (if (setq fass (assoc (list (verilog-modi-name modi) function) | |
7371 verilog-modi-cache-list)) | |
7372 (let ((func-returns (nth 3 fass))) | |
7373 (aset func-returns element | |
7374 (append sig-list (aref func-returns element)))))))) | |
7375 | |
7376 (defmacro verilog-preserve-cache (&rest body) | |
7377 "Execute the BODY forms, allowing cache preservation within BODY. | |
7378 This means that changes to the buffer will not result in the cache being | |
7379 flushed. If the changes affect the modsig state, they must call the | |
7380 modsig-cache-add-* function, else the results of later calls may be | |
7381 incorrect. Without this, changes are assumed to be adding/removing signals | |
7382 and invalidating the cache." | |
7383 `(let ((verilog-modi-cache-preserve-tick (buffer-modified-tick)) | |
7384 (verilog-modi-cache-preserve-buffer (current-buffer))) | |
7385 (progn ,@body))) | |
7386 | |
7387 (defsubst verilog-modi-get-decls (modi) | |
7388 (verilog-modi-cache-results modi 'verilog-read-decls)) | |
7389 | |
7390 (defsubst verilog-modi-get-sub-decls (modi) | |
7391 (verilog-modi-cache-results modi 'verilog-read-sub-decls)) | |
7392 | |
7393 ;; Signal reading for given module | |
7394 ;; Note these all take modi's - as returned from the verilog-modi-current function | |
7395 (defsubst verilog-modi-get-outputs (modi) | |
7396 (aref (verilog-modi-get-decls modi) 0)) | |
7397 (defsubst verilog-modi-get-inouts (modi) | |
7398 (aref (verilog-modi-get-decls modi) 1)) | |
7399 (defsubst verilog-modi-get-inputs (modi) | |
7400 (aref (verilog-modi-get-decls modi) 2)) | |
7401 (defsubst verilog-modi-get-wires (modi) | |
7402 (aref (verilog-modi-get-decls modi) 3)) | |
7403 (defsubst verilog-modi-get-regs (modi) | |
7404 (aref (verilog-modi-get-decls modi) 4)) | |
7405 (defsubst verilog-modi-get-assigns (modi) | |
7406 (aref (verilog-modi-get-decls modi) 5)) | |
7407 (defsubst verilog-modi-get-consts (modi) | |
7408 (aref (verilog-modi-get-decls modi) 6)) | |
7409 (defsubst verilog-modi-get-gparams (modi) | |
7410 (aref (verilog-modi-get-decls modi) 7)) | |
7411 (defsubst verilog-modi-get-sub-outputs (modi) | |
7412 (aref (verilog-modi-get-sub-decls modi) 0)) | |
7413 (defsubst verilog-modi-get-sub-inouts (modi) | |
7414 (aref (verilog-modi-get-sub-decls modi) 1)) | |
7415 (defsubst verilog-modi-get-sub-inputs (modi) | |
7416 (aref (verilog-modi-get-sub-decls modi) 2)) | |
7417 | |
7418 | |
7419 (defun verilog-signals-matching-enum (in-list enum) | |
7420 "Return all signals in IN-LIST matching the given ENUM." | |
7421 (let (out-list) | |
7422 (while in-list | |
7423 (if (equal (verilog-sig-enum (car in-list)) enum) | |
7424 (setq out-list (cons (car in-list) out-list))) | |
7425 (setq in-list (cdr in-list))) | |
7426 ;; New scheme | |
7427 (let* ((enumvar (intern (concat "venum-" enum))) | |
7428 (enumlist (and (boundp enumvar) (eval enumvar)))) | |
7429 (while enumlist | |
7430 (add-to-list 'out-list (list (car enumlist))) | |
7431 (setq enumlist (cdr enumlist)))) | |
7432 (nreverse out-list))) | |
7433 | |
7434 (defun verilog-signals-not-matching-regexp (in-list regexp) | |
7435 "Return all signals in IN-LIST not matching the given REGEXP, if non-nil." | |
7436 (if (not regexp) | |
7437 in-list | |
7438 (let (out-list) | |
7439 (while in-list | |
7440 (if (not (string-match regexp (verilog-sig-name (car in-list)))) | |
7441 (setq out-list (cons (car in-list) out-list))) | |
7442 (setq in-list (cdr in-list))) | |
7443 (nreverse out-list)))) | |
7444 | |
7445 ;; Combined | |
7446 (defun verilog-modi-get-signals (modi) | |
7447 (append | |
7448 (verilog-modi-get-outputs modi) | |
7449 (verilog-modi-get-inouts modi) | |
7450 (verilog-modi-get-inputs modi) | |
7451 (verilog-modi-get-wires modi) | |
7452 (verilog-modi-get-regs modi) | |
7453 (verilog-modi-get-assigns modi) | |
7454 (verilog-modi-get-consts modi) | |
7455 (verilog-modi-get-gparams modi))) | |
7456 | |
7457 (defun verilog-modi-get-ports (modi) | |
7458 (append | |
7459 (verilog-modi-get-outputs modi) | |
7460 (verilog-modi-get-inouts modi) | |
7461 (verilog-modi-get-inputs modi))) | |
7462 | |
7463 (defsubst verilog-modi-cache-add-outputs (modi sig-list) | |
7464 (verilog-modi-cache-add modi 'verilog-read-decls 0 sig-list)) | |
7465 (defsubst verilog-modi-cache-add-inouts (modi sig-list) | |
7466 (verilog-modi-cache-add modi 'verilog-read-decls 1 sig-list)) | |
7467 (defsubst verilog-modi-cache-add-inputs (modi sig-list) | |
7468 (verilog-modi-cache-add modi 'verilog-read-decls 2 sig-list)) | |
7469 (defsubst verilog-modi-cache-add-wires (modi sig-list) | |
7470 (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list)) | |
7471 (defsubst verilog-modi-cache-add-regs (modi sig-list) | |
7472 (verilog-modi-cache-add modi 'verilog-read-decls 4 sig-list)) | |
7473 | |
7474 (defun verilog-signals-from-signame (signame-list) | |
7475 "Return signals in standard form from SIGNAME-LIST, a simple list of signal names." | |
7476 (mapcar (function (lambda (name) (list name nil nil))) | |
7477 signame-list)) | |
7478 | |
7479 ;; | |
7480 ;; Auto creation utilities | |
7481 ;; | |
7482 | |
7483 (defun verilog-auto-search-do (search-for func) | |
7484 "Search for the given auto text SEARCH-FOR, and perform FUNC where it occurs." | |
7485 (goto-char (point-min)) | |
7486 (while (search-forward search-for nil t) | |
7487 (if (not (save-excursion | |
7488 (goto-char (match-beginning 0)) | |
7489 (verilog-inside-comment-p))) | |
7490 (funcall func)))) | |
7491 | |
7492 (defun verilog-auto-re-search-do (search-for func) | |
7493 "Search for the given auto text SEARCH-FOR, and perform FUNC where it occurs." | |
7494 (goto-char (point-min)) | |
7495 (while (re-search-forward search-for nil t) | |
7496 (if (not (save-excursion | |
7497 (goto-char (match-beginning 0)) | |
7498 (verilog-inside-comment-p))) | |
7499 (funcall func)))) | |
7500 | |
7501 (defun verilog-insert-one-definition (sig type indent-pt) | |
7502 "Print out a definition for SIGNAL of the given TYPE, | |
7503 with appropriate INDENT-PT indentation." | |
7504 (indent-to indent-pt) | |
7505 (insert type) | |
7506 (when (verilog-sig-signed sig) | |
7507 (insert " " (verilog-sig-signed sig))) | |
7508 (when (verilog-sig-multidim sig) | |
7509 (insert " " (verilog-sig-multidim-string sig))) | |
7510 (when (verilog-sig-bits sig) | |
7511 (insert " " (verilog-sig-bits sig))) | |
7512 (indent-to (max 24 (+ indent-pt 16))) | |
7513 (unless (= (char-syntax (preceding-char)) ?\ ) | |
7514 (insert " ")) ; Need space between "]name" if indent-to did nothing | |
7515 (insert (verilog-sig-name sig))) | |
7516 | |
7517 (defun verilog-insert-definition (sigs direction indent-pt v2k &optional dont-sort) | |
7518 "Print out a definition for a list of SIGS of the given DIRECTION, | |
7519 with appropriate INDENT-PT indentation. If V2K, use Verilog 2001 I/O | |
7520 format. Sort unless DONT-SORT. DIRECTION is normally wire/reg/output." | |
7521 (or dont-sort | |
7522 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare))) | |
7523 (while sigs | |
7524 (let ((sig (car sigs))) | |
7525 (verilog-insert-one-definition | |
7526 sig | |
7527 ;; Want "type x" or "output type x", not "wire type x" | |
7528 (cond ((verilog-sig-type sig) | |
7529 (concat | |
7530 (if (not (equal direction "wire")) | |
7531 (concat direction " ")) | |
7532 (verilog-sig-type sig))) | |
7533 (t direction)) | |
7534 indent-pt) | |
7535 (insert (if v2k "," ";")) | |
7536 (if (or (not (verilog-sig-comment sig)) | |
7537 (equal "" (verilog-sig-comment sig))) | |
7538 (insert "\n") | |
7539 (indent-to (max 48 (+ indent-pt 40))) | |
7540 (insert (concat "// " (verilog-sig-comment sig) "\n"))) | |
7541 (setq sigs (cdr sigs))))) | |
7542 | |
7543 (eval-when-compile | |
7544 (if (not (boundp 'indent-pt)) | |
7545 (defvar indent-pt nil "Local used by insert-indent"))) | |
7546 | |
7547 (defun verilog-insert-indent (&rest stuff) | |
7548 "Indent to position stored in local `indent-pt' variable, then insert STUFF. | |
7549 Presumes that any newlines end a list element." | |
7550 (let ((need-indent t)) | |
7551 (while stuff | |
7552 (if need-indent (indent-to indent-pt)) | |
7553 (setq need-indent nil) | |
7554 (insert (car stuff)) | |
7555 (setq need-indent (string-match "\n$" (car stuff)) | |
7556 stuff (cdr stuff))))) | |
7557 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n")) | |
7558 | |
7559 (defun verilog-repair-open-comma () | |
7560 "If backwards-from-point is other than a open parenthesis insert comma." | |
7561 (save-excursion | |
7562 (verilog-backward-syntactic-ws) | |
7563 (when (save-excursion | |
7564 (backward-char 1) | |
7565 (and (not (looking-at "[(,]")) | |
7566 (progn | |
7567 (verilog-re-search-backward "[(`]" nil t) | |
7568 (looking-at "(")))) | |
7569 (insert ",")))) | |
7570 | |
7571 (defun verilog-repair-close-comma () | |
7572 "If point is at a comma followed by a close parenthesis, fix it. | |
7573 This repairs those mis-inserted by a AUTOARG." | |
7574 ;; It would be much nicer if Verilog allowed extra commas like Perl does! | |
7575 (save-excursion | |
7576 (verilog-forward-close-paren) | |
7577 (backward-char 1) | |
7578 (verilog-backward-syntactic-ws) | |
7579 (backward-char 1) | |
7580 (when (looking-at ",") | |
7581 (delete-char 1)))) | |
7582 | |
7583 (defun verilog-get-list (start end) | |
7584 "Return the elements of a comma separated list between START and END." | |
7585 (interactive) | |
7586 (let ((my-list (list)) | |
7587 my-string) | |
7588 (save-excursion | |
7589 (while (< (point) end) | |
7590 (when (re-search-forward "\\([^,{]+\\)" end t) | |
7591 (setq my-string (verilog-string-remove-spaces (match-string 1))) | |
7592 (setq my-list (nconc my-list (list my-string) )) | |
7593 (goto-char (match-end 0)))) | |
7594 my-list))) | |
7595 | |
7596 (defun verilog-make-width-expression (range-exp) | |
7597 "Return an expression calculating the length of a range [x:y] in RANGE-EXP." | |
7598 ;; strip off the [] | |
7599 (cond ((not range-exp) | |
7600 "1") | |
7601 (t | |
7602 (if (string-match "^\\[\\(.*\\)\\]$" range-exp) | |
7603 (setq range-exp (match-string 1 range-exp))) | |
7604 (cond ((not range-exp) | |
7605 "1") | |
7606 ((string-match "^\\s *\\([0-9]+\\)\\s *:\\s *\\([0-9]+\\)\\s *$" range-exp) | |
7607 (int-to-string (1+ (abs (- (string-to-int (match-string 1 range-exp)) | |
7608 (string-to-int (match-string 2 range-exp))))))) | |
7609 ((string-match "^\\(.*\\)\\s *:\\s *\\(.*\\)\\s *$" range-exp) | |
7610 (concat "(1+(" (match-string 1 range-exp) | |
7611 ")" | |
7612 (if (equal "0" (match-string 2 range-exp)) ;; Don't bother with -(0) | |
7613 "" | |
7614 (concat "-(" (match-string 2 range-exp) ")")) | |
7615 ")")) | |
7616 (t nil))))) | |
7617 ;;(verilog-make-width-expression "`A:`B") | |
7618 | |
7619 (defun verilog-typedef-name-p (variable-name) | |
7620 "Return true if the VARIABLE-NAME is a type definition." | |
7621 (when verilog-typedef-regexp | |
7622 (string-match verilog-typedef-regexp variable-name))) | |
7623 | |
7624 ;; | |
7625 ;; Auto deletion | |
7626 ;; | |
7627 | |
7628 (defun verilog-delete-autos-lined () | |
7629 "Delete autos that occupy multiple lines, between begin and end comments." | |
7630 (let ((pt (point))) | |
7631 (forward-line 1) | |
7632 (when (and | |
7633 (looking-at "\\s-*// Beginning") | |
7634 (search-forward "// End of automatic" nil t)) | |
7635 ;; End exists | |
7636 (end-of-line) | |
7637 (delete-region pt (point)) | |
7638 (forward-line 1)) | |
7639 )) | |
7640 | |
7641 (defun verilog-forward-close-paren () | |
7642 "Find the close parenthesis that match the current point, | |
7643 ignore other close parenthesis with matching open parens" | |
7644 (let ((parens 1)) | |
7645 (while (> parens 0) | |
7646 (unless (verilog-re-search-forward-quick "[()]" nil t) | |
7647 (error "%s: Mismatching ()" (verilog-point-text))) | |
7648 (cond ((= (preceding-char) ?\( ) | |
7649 (setq parens (1+ parens))) | |
7650 ((= (preceding-char) ?\) ) | |
7651 (setq parens (1- parens))))))) | |
7652 | |
7653 (defun verilog-backward-open-paren () | |
7654 "Find the open parenthesis that match the current point, | |
7655 ignore other open parenthesis with matching close parens" | |
7656 (let ((parens 1)) | |
7657 (while (> parens 0) | |
7658 (unless (verilog-re-search-backward-quick "[()]" nil t) | |
7659 (error "%s: Mismatching ()" (verilog-point-text))) | |
7660 (cond ((= (following-char) ?\) ) | |
7661 (setq parens (1+ parens))) | |
7662 ((= (following-char) ?\( ) | |
7663 (setq parens (1- parens))))))) | |
7664 | |
7665 (defun verilog-backward-open-bracket () | |
7666 "Find the open bracket that match the current point, | |
7667 ignore other open bracket with matching close bracket" | |
7668 (let ((parens 1)) | |
7669 (while (> parens 0) | |
7670 (unless (verilog-re-search-backward-quick "[][]" nil t) | |
7671 (error "%s: Mismatching []" (verilog-point-text))) | |
7672 (cond ((= (following-char) ?\] ) | |
7673 (setq parens (1+ parens))) | |
7674 ((= (following-char) ?\[ ) | |
7675 (setq parens (1- parens))))))) | |
7676 | |
7677 (defun verilog-delete-to-paren () | |
7678 "Delete the automatic inst/sense/arg created by autos. | |
7679 Deletion stops at the matching end parenthesis." | |
7680 (delete-region (point) | |
7681 (save-excursion | |
7682 (verilog-backward-open-paren) | |
7683 (forward-sexp 1) ;; Moves to paren that closes argdecl's | |
7684 (backward-char 1) | |
7685 (point)))) | |
7686 | |
7687 (defun verilog-auto-star-safe () | |
7688 "Return if a .* AUTOINST is safe to delete or expand. | |
7689 It was created by the AUTOS themselves, or by the user." | |
7690 (and verilog-auto-star-expand | |
7691 (looking-at "[ \t\n\f,]*\\([)]\\|// \\(Outputs\\|Inouts\\|Inputs\\)\\)"))) | |
7692 | |
7693 (defun verilog-delete-auto-star-all () | |
7694 "Delete a .* AUTOINST, if it is safe." | |
7695 (when (verilog-auto-star-safe) | |
7696 (verilog-delete-to-paren))) | |
7697 | |
7698 (defun verilog-delete-auto-star-implicit () | |
7699 "Delete all .* implicit connections created by `verilog-auto-star'. | |
7700 This function will be called automatically at save unless | |
7701 `verilog-auto-star-save' is set, any non-templated expanded pins will be | |
7702 removed." | |
7703 (interactive) | |
7704 (let (paren-pt indent have-close-paren) | |
7705 (save-excursion | |
7706 (goto-char (point-min)) | |
7707 ;; We need to match these even outside of comments. | |
7708 ;; For reasonable performance, we don't check if inside comments, sorry. | |
7709 (while (re-search-forward "// Implicit \\.\\*" nil t) | |
7710 (setq paren-pt (point)) | |
7711 (beginning-of-line) | |
7712 (setq have-close-paren | |
7713 (save-excursion | |
7714 (when (search-forward ");" paren-pt t) | |
7715 (setq indent (current-indentation)) | |
7716 t))) | |
7717 (delete-region (point) (+ 1 paren-pt)) ; Nuke line incl CR | |
7718 (when have-close-paren | |
7719 ;; Delete extra commentary | |
7720 (save-excursion | |
7721 (while (progn | |
7722 (forward-line -1) | |
7723 (looking-at "\\s *//\\s *\\(Outputs\\|Inouts\\|Inputs\\)\n")) | |
7724 (delete-region (match-beginning 0) (match-end 0)))) | |
7725 ;; If it is simple, we can put the ); on the same line as the last text | |
7726 (let ((rtn-pt (point))) | |
7727 (save-excursion | |
7728 (while (progn (backward-char 1) | |
7729 (looking-at "[ \t\n\f]"))) | |
7730 (when (looking-at ",") | |
7731 (delete-region (+ 1 (point)) rtn-pt)))) | |
7732 (when (bolp) | |
7733 (indent-to indent)) | |
7734 (insert ");\n") | |
7735 ;; Still need to kill final comma - always is one as we put one after the .* | |
7736 (re-search-backward ",") | |
7737 (delete-char 1)))))) | |
7738 | |
7739 (defun verilog-delete-auto () | |
7740 "Delete the automatic outputs, regs, and wires created by \\[verilog-auto]. | |
7741 Use \\[verilog-auto] to re-insert the updated AUTOs. | |
7742 | |
7743 The hooks `verilog-before-delete-auto-hook' and `verilog-delete-auto-hook' are | |
7744 called before and after this function, respectively." | |
7745 (interactive) | |
7746 (save-excursion | |
7747 (if (buffer-file-name) | |
7748 (find-file-noselect (buffer-file-name))) ;; To check we have latest version | |
7749 ;; Allow user to customize | |
7750 (run-hooks 'verilog-before-delete-auto-hook) | |
7751 | |
7752 ;; Remove those that have multi-line insertions | |
7753 (verilog-auto-re-search-do "/\\*AUTO\\(OUTPUTEVERY\\|CONCATCOMMENT\\|WIRE\\|REG\\|DEFINEVALUE\\|REGINPUT\\|INPUT\\|OUTPUT\\|INOUT\\|RESET\\|TIEOFF\\|UNUSED\\)\\*/" | |
7754 'verilog-delete-autos-lined) | |
7755 ;; Remove those that have multi-line insertions with parameters | |
7756 (verilog-auto-re-search-do "/\\*AUTO\\(INOUTMODULE\\|ASCIIENUM\\)([^)]*)\\*/" | |
7757 'verilog-delete-autos-lined) | |
7758 ;; Remove those that are in parenthesis | |
7759 (verilog-auto-re-search-do "/\\*\\(AS\\|AUTO\\(ARG\\|CONCATWIDTH\\|INST\\|INSTPARAM\\|SENSE\\)\\)\\*/" | |
7760 'verilog-delete-to-paren) | |
7761 ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments | |
7762 (verilog-auto-re-search-do "\\.\\*" | |
7763 'verilog-delete-auto-star-all) | |
7764 ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed | |
7765 (goto-char (point-min)) | |
7766 (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)[ \tLT0-9]*$" nil t) | |
7767 (replace-match "")) | |
7768 | |
7769 ;; Final customize | |
7770 (run-hooks 'verilog-delete-auto-hook))) | |
7771 | |
7772 ;; | |
7773 ;; Auto inject | |
7774 ;; | |
7775 | |
7776 (defun verilog-inject-auto () | |
7777 "Examine legacy non-AUTO code and insert AUTOs in appropriate places. | |
7778 | |
7779 Any always @ blocks with sensitivity lists that match computed lists will | |
7780 be replaced with /*AS*/ comments. | |
7781 | |
7782 Any cells will get /*AUTOINST*/ added to the end of the pin list. Pins with | |
7783 have identical names will be deleted. | |
7784 | |
7785 Argument lists will not be deleted, /*AUTOARG*/ will only be inserted to | |
7786 support adding new ports. You may wish to delete older ports yourself. | |
7787 | |
7788 For example: | |
7789 | |
7790 module ex_inject (i, o); | |
7791 input i; | |
7792 input j; | |
7793 output o; | |
7794 always @ (i or j) | |
7795 o = i | j; | |
7796 cell cell (.foobar(baz), | |
7797 .j(j)); | |
7798 endmodule | |
7799 | |
7800 Typing \\[verilog-inject-auto] will make this into: | |
7801 | |
7802 module ex_inject (i, o/*AUTOARG*/ | |
7803 // Inputs | |
7804 j); | |
7805 input i; | |
7806 output o; | |
7807 always @ (/*AS*/i or j) | |
7808 o = i | j; | |
7809 cell cell (.foobar(baz), | |
7810 /*AUTOINST*/ | |
7811 // Outputs | |
7812 .j(j)); | |
7813 endmodule" | |
7814 (interactive) | |
7815 (verilog-auto t)) | |
7816 | |
7817 (defun verilog-inject-arg () | |
7818 "Inject AUTOARG into new code. See `verilog-inject-auto'." | |
7819 ;; Presume one module per file. | |
7820 (save-excursion | |
7821 (goto-char (point-min)) | |
7822 (while (verilog-re-search-forward-quick "\\<module\\>" nil t) | |
7823 (let ((endmodp (save-excursion | |
7824 (verilog-re-search-forward-quick "\\<endmodule\\>" nil t) | |
7825 (point)))) | |
7826 ;; See if there's already a comment .. inside a comment so not verilog-re-search | |
7827 (when (not (re-search-forward "/\\*AUTOARG\\*/" endmodp t)) | |
7828 (verilog-re-search-forward-quick ";" nil t) | |
7829 (backward-char 1) | |
7830 (verilog-backward-syntactic-ws) | |
7831 (backward-char 1) ; Moves to paren that closes argdecl's | |
7832 (when (looking-at ")") | |
7833 (insert "/*AUTOARG*/"))))))) | |
7834 | |
7835 (defun verilog-inject-sense () | |
7836 "Inject AUTOSENSE into new code. See `verilog-inject-auto'." | |
7837 (save-excursion | |
7838 (goto-char (point-min)) | |
7839 (while (verilog-re-search-forward-quick "\\<always\\s *@\\s *(" nil t) | |
7840 (let ((start-pt (point)) | |
7841 (modi (verilog-modi-current)) | |
7842 pre-sigs | |
7843 got-sigs) | |
7844 (backward-char 1) | |
7845 (forward-sexp 1) | |
7846 (backward-char 1) ;; End ) | |
7847 (when (not (verilog-re-search-backward "/\\*\\(AUTOSENSE\\|AS\\)\\*/" start-pt t)) | |
7848 (setq pre-sigs (verilog-signals-from-signame | |
7849 (verilog-read-signals start-pt (point))) | |
7850 got-sigs (verilog-auto-sense-sigs modi nil)) | |
7851 (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal? | |
7852 (verilog-signals-not-in got-sigs pre-sigs))) | |
7853 (delete-region start-pt (point)) | |
7854 (insert "/*AS*/"))))))) | |
7855 | |
7856 (defun verilog-inject-inst () | |
7857 "Inject AUTOINST into new code. See `verilog-inject-auto'." | |
7858 (save-excursion | |
7859 (goto-char (point-min)) | |
7860 ;; It's hard to distinguish modules; we'll instead search for pins. | |
7861 (while (verilog-re-search-forward-quick "\\.\\s *[a-zA-Z0-9`_\$]+\\s *(\\s *[a-zA-Z0-9`_\$]+\\s *)" nil t) | |
7862 (verilog-backward-open-paren) ;; Inst start | |
7863 (cond | |
7864 ((= (preceding-char) ?\#) ;; #(...) parameter section, not pin. Skip. | |
7865 (forward-char 1) | |
7866 (verilog-forward-close-paren)) ;; Parameters done | |
7867 (t | |
7868 (forward-char 1) | |
7869 (let ((indent-pt (+ (current-column))) | |
7870 (end-pt (save-excursion (verilog-forward-close-paren) (point)))) | |
7871 (cond ((verilog-re-search-forward "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-pt t) | |
7872 (goto-char end-pt)) ;; Already there, continue search with next instance | |
7873 (t | |
7874 ;; Delete identical interconnect | |
7875 (let ((case-fold-search nil)) ;; So we don't convert upper-to-lower, etc | |
7876 (while (verilog-re-search-forward "\\.\\s *\\([a-zA-Z0-9`_\$]+\\)*\\s *(\\s *\\1\\s *)\\s *" end-pt t) | |
7877 (delete-region (match-beginning 0) (match-end 0)) | |
7878 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))) ;; Keep it correct | |
7879 (while (or (looking-at "[ \t\n\f,]+") | |
7880 (looking-at "//[^\n]*")) | |
7881 (delete-region (match-beginning 0) (match-end 0)) | |
7882 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0))))))) | |
7883 (verilog-forward-close-paren) | |
7884 (backward-char 1) | |
7885 ;; Not verilog-re-search, as we don't want to strip comments | |
7886 (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t) | |
7887 (delete-region (match-beginning 0) (match-end 0))) | |
7888 (insert "\n") | |
7889 (indent-to indent-pt) | |
7890 (insert "/*AUTOINST*/"))))))))) | |
7891 | |
7892 ;; | |
7893 ;; Auto save | |
7894 ;; | |
7895 | |
7896 (defun verilog-auto-save-check () | |
7897 "On saving see if we need auto update." | |
7898 (cond ((not verilog-auto-save-policy)) ; disabled | |
7899 ((not (save-excursion | |
7900 (save-match-data | |
7901 (let ((case-fold-search nil)) | |
7902 (goto-char (point-min)) | |
7903 (re-search-forward "AUTO" nil t)))))) | |
7904 ((eq verilog-auto-save-policy 'force) | |
7905 (verilog-auto)) | |
7906 ((not (buffer-modified-p))) | |
7907 ((eq verilog-auto-update-tick (buffer-modified-tick))) ; up-to-date | |
7908 ((eq verilog-auto-save-policy 'detect) | |
7909 (verilog-auto)) | |
7910 (t | |
7911 (when (yes-or-no-p "AUTO statements not recomputed, do it now? ") | |
7912 (verilog-auto)) | |
7913 ;; Don't ask again if didn't update | |
7914 (set (make-local-variable 'verilog-auto-update-tick) (buffer-modified-tick)) | |
7915 )) | |
7916 (when (not verilog-auto-star-save) | |
7917 (verilog-delete-auto-star-implicit)) | |
7918 nil) ;; Always return nil -- we don't write the file ourselves | |
7919 | |
7920 (defun verilog-auto-read-locals () | |
7921 "Return file local variable segment at bottom of file." | |
7922 (save-excursion | |
7923 (goto-char (point-max)) | |
7924 (if (re-search-backward "Local Variables:" nil t) | |
7925 (buffer-substring-no-properties (point) (point-max)) | |
7926 ""))) | |
7927 | |
7928 (defun verilog-auto-reeval-locals (&optional force) | |
7929 "Read file local variable segment at bottom of file if it has changed. | |
7930 If FORCE, always reread it." | |
7931 (make-variable-buffer-local 'verilog-auto-last-file-locals) | |
7932 (let ((curlocal (verilog-auto-read-locals))) | |
7933 (when (or force (not (equal verilog-auto-last-file-locals curlocal))) | |
7934 (setq verilog-auto-last-file-locals curlocal) | |
7935 ;; Note this may cause this function to be recursively invoked. | |
7936 ;; The above when statement will prevent it from recursing forever. | |
7937 (hack-local-variables) | |
7938 t))) | |
7939 | |
7940 ;; | |
7941 ;; Auto creation | |
7942 ;; | |
7943 | |
7944 (defun verilog-auto-arg-ports (sigs message indent-pt) | |
7945 "Print a list of ports for a AUTOINST. | |
7946 Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT." | |
7947 (when sigs | |
7948 (insert "\n") | |
7949 (indent-to indent-pt) | |
7950 (insert message) | |
7951 (insert "\n") | |
7952 (let ((space "")) | |
7953 (indent-to indent-pt) | |
7954 (while sigs | |
7955 (cond ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column) | |
7956 (insert "\n") | |
7957 (indent-to indent-pt)) | |
7958 (t (insert space))) | |
7959 (insert (verilog-sig-name (car sigs)) ",") | |
7960 (setq sigs (cdr sigs) | |
7961 space " "))))) | |
7962 | |
7963 (defun verilog-auto-arg () | |
7964 "Expand AUTOARG statements. | |
7965 Replace the argument declarations at the beginning of the | |
7966 module with ones automatically derived from input and output | |
7967 statements. This can be dangerous if the module is instantiated | |
7968 using position-based connections, so use only name-based when | |
7969 instantiating the resulting module. Long lines are split based | |
7970 on the `fill-column', see \\[set-fill-column]. | |
7971 | |
7972 Limitations: | |
7973 Concatenation and outputting partial busses is not supported. | |
7974 | |
7975 Typedefs must match `verilog-typedef-regexp', which is disabled by default. | |
7976 | |
7977 For example: | |
7978 | |
7979 module ex_arg (/*AUTOARG*/); | |
7980 input i; | |
7981 output o; | |
7982 endmodule | |
7983 | |
7984 Typing \\[verilog-auto] will make this into: | |
7985 | |
7986 module ex_arg (/*AUTOARG*/ | |
7987 // Outputs | |
7988 o, | |
7989 // Inputs | |
7990 i | |
7991 ); | |
7992 input i; | |
7993 output o; | |
7994 endmodule | |
7995 | |
7996 Any ports declared between the ( and /*AUTOARG*/ are presumed to be | |
7997 predeclared and are not redeclared by AUTOARG. AUTOARG will make a | |
7998 conservative guess on adding a comma for the first signal, if you have any | |
7999 ifdefs or complicated expressions before the AUTOARG you will need to | |
8000 choose the comma yourself. | |
8001 | |
8002 Avoid declaring ports manually, as it makes code harder to maintain." | |
8003 (save-excursion | |
8004 (let ((modi (verilog-modi-current)) | |
8005 (skip-pins (aref (verilog-read-arg-pins) 0))) | |
8006 (verilog-repair-open-comma) | |
8007 (verilog-auto-arg-ports (verilog-signals-not-in | |
8008 (verilog-modi-get-outputs modi) | |
8009 skip-pins) | |
8010 "// Outputs" | |
8011 verilog-indent-level-declaration) | |
8012 (verilog-auto-arg-ports (verilog-signals-not-in | |
8013 (verilog-modi-get-inouts modi) | |
8014 skip-pins) | |
8015 "// Inouts" | |
8016 verilog-indent-level-declaration) | |
8017 (verilog-auto-arg-ports (verilog-signals-not-in | |
8018 (verilog-modi-get-inputs modi) | |
8019 skip-pins) | |
8020 "// Inputs" | |
8021 verilog-indent-level-declaration) | |
8022 (verilog-repair-close-comma) | |
8023 (unless (eq (char-before) ?/ ) | |
8024 (insert "\n")) | |
8025 (indent-to verilog-indent-level-declaration) | |
8026 ))) | |
8027 | |
8028 (defun verilog-auto-inst-port-map (port-st) | |
8029 nil) | |
8030 | |
8031 (defvar vector-skip-list nil) ; Prevent compile warning | |
8032 (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning | |
8033 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning | |
8034 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning | |
8035 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning | |
8036 (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning | |
8037 | |
8038 (defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star) | |
8039 "Print out a instantiation connection for this PORT-ST. | |
8040 Insert to INDENT-PT, use template TPL-LIST. | |
8041 @ are instantiation numbers, replaced with TPL-NUM. | |
8042 @\"(expression @)\" are evaluated, with @ as a variable." | |
8043 (let* ((port (verilog-sig-name port-st)) | |
8044 (tpl-ass (or (assoc port (car tpl-list)) | |
8045 (verilog-auto-inst-port-map port-st))) | |
8046 ;; vl-* are documented for user use | |
8047 (vl-name (verilog-sig-name port-st)) | |
8048 (vl-width (verilog-sig-width port-st)) | |
8049 (vl-bits (if (or verilog-auto-inst-vector | |
8050 (not (assoc port vector-skip-list)) | |
8051 (not (equal (verilog-sig-bits port-st) | |
8052 (verilog-sig-bits (assoc port vector-skip-list))))) | |
8053 (or (verilog-sig-bits port-st) "") | |
8054 "")) | |
8055 ;; Default if not found | |
8056 (tpl-net (if (verilog-sig-multidim port-st) | |
8057 (concat port "/*" (verilog-sig-multidim-string port-st) | |
8058 vl-bits "*/") | |
8059 (concat port vl-bits))) | |
8060 (case-fold-search nil)) | |
8061 ;; Find template | |
8062 (cond (tpl-ass ; Template of exact port name | |
8063 (setq tpl-net (nth 1 tpl-ass))) | |
8064 ((nth 1 tpl-list) ; Wildcards in template, search them | |
8065 (let ((wildcards (nth 1 tpl-list))) | |
8066 (while wildcards | |
8067 (when (string-match (nth 0 (car wildcards)) port) | |
8068 (setq tpl-ass (car wildcards) ; so allow @ parsing | |
8069 tpl-net (replace-match (nth 1 (car wildcards)) | |
8070 t nil port))) | |
8071 (setq wildcards (cdr wildcards)))))) | |
8072 ;; Parse Templated variable | |
8073 (when tpl-ass | |
8074 ;; Evaluate @"(lispcode)" | |
8075 (when (string-match "@\".*[^\\]\"" tpl-net) | |
8076 (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net) | |
8077 (setq tpl-net | |
8078 (concat | |
8079 (substring tpl-net 0 (match-beginning 0)) | |
8080 (save-match-data | |
8081 (let* ((expr (match-string 1 tpl-net)) | |
8082 (value | |
8083 (progn | |
8084 (setq expr (verilog-string-replace-matches "\\\\\"" "\"" nil nil expr)) | |
8085 (setq expr (verilog-string-replace-matches "@" tpl-num nil nil expr)) | |
8086 (prin1 (eval (car (read-from-string expr))) | |
8087 (lambda (ch) ()))))) | |
8088 (if (numberp value) (setq value (number-to-string value))) | |
8089 value | |
8090 )) | |
8091 (substring tpl-net (match-end 0)))))) | |
8092 ;; Replace @ and [] magic variables in final output | |
8093 (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net)) | |
8094 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net)) | |
8095 ) | |
8096 (indent-to indent-pt) | |
8097 (insert "." port) | |
8098 (indent-to verilog-auto-inst-column) | |
8099 (insert "(" tpl-net "),") | |
8100 (cond (tpl-ass | |
8101 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16) | |
8102 verilog-auto-inst-column)) | |
8103 (insert " // Templated") | |
8104 (when verilog-auto-inst-template-numbers | |
8105 (insert " T" (int-to-string (nth 2 tpl-ass)) | |
8106 " L" (int-to-string (nth 3 tpl-ass))))) | |
8107 (for-star | |
8108 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16) | |
8109 verilog-auto-inst-column)) | |
8110 (insert " // Implicit .\*"))) ;For some reason the . or * must be escaped... | |
8111 (insert "\n"))) | |
8112 ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3") | |
8113 ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]") | |
8114 ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));") | |
8115 | |
8116 (defun verilog-auto-inst-first () | |
8117 "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]." | |
8118 ;; Do we need a trailing comma? | |
8119 ;; There maybe a ifdef or something similar before us. What a mess. Thus | |
8120 ;; to avoid trouble we only insert on preceeding ) or *. | |
8121 ;; Insert first port on new line | |
8122 (insert "\n") ;; Must insert before search, so point will move forward if insert comma | |
8123 (save-excursion | |
8124 (verilog-re-search-backward "[^ \t\n\f]" nil nil) | |
8125 (when (looking-at ")\\|\\*") ;; Generally don't insert, unless we are fairly sure | |
8126 (forward-char 1) | |
8127 (insert ",")))) | |
8128 | |
8129 (defun verilog-auto-star () | |
8130 "Expand SystemVerilog .* pins, as part of \\[verilog-auto]. | |
8131 | |
8132 If `verilog-auto-star-expand' is set, .* pins are treated if they were | |
8133 AUTOINST statements, otherwise they are ignored. For safety, Verilog-Mode | |
8134 will also ignore any .* that are not last in your pin list (this prevents | |
8135 it from deleting pins following the .* when it expands the AUTOINST.) | |
8136 | |
8137 On writing your file, unless `verilog-auto-star-save' is set, any | |
8138 non-templated expanded pins will be removed. You may do this at any time | |
8139 with \\[verilog-delete-auto-star-implicit]. | |
8140 | |
8141 If you are converting a module to use .* for the first time, you may wish | |
8142 to use \\[verilog-inject-auto] and then replace the created AUTOINST with .*. | |
8143 | |
8144 See `verilog-auto-inst' for examples, templates, and more information." | |
8145 (when (verilog-auto-star-safe) | |
8146 (verilog-auto-inst))) | |
8147 | |
8148 (defun verilog-auto-inst () | |
8149 "Expand AUTOINST statements, as part of \\[verilog-auto]. | |
8150 Replace the pin connections to an instantiation with ones | |
8151 automatically derived from the module header of the instantiated netlist. | |
8152 | |
8153 If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports, | |
8154 and delete them before saving unless `verilog-auto-star-save' is set. | |
8155 See `verilog-auto-star' for more information. | |
8156 | |
8157 Limitations: | |
8158 Module names must be resolvable to filenames by adding a | |
8159 `verilog-library-extensions', and being found in the same directory, or | |
8160 by changing the variable `verilog-library-flags' or | |
8161 `verilog-library-directories'. Macros `modname are translated through the | |
8162 vh-{name} Emacs variable, if that is not found, it just ignores the `. | |
8163 | |
8164 In templates you must have one signal per line, ending in a ), or ));, | |
8165 and have proper () nesting, including a final ); to end the template. | |
8166 | |
8167 Typedefs must match `verilog-typedef-regexp', which is disabled by default. | |
8168 | |
8169 SystemVerilog multidimmensional input/output has only experimental support. | |
8170 | |
8171 For example, first take the submodule inst.v: | |
8172 | |
8173 module inst (o,i) | |
8174 output [31:0] o; | |
8175 input i; | |
8176 wire [31:0] o = {32{i}}; | |
8177 endmodule | |
8178 | |
8179 This is then used in a upper level module: | |
8180 | |
8181 module ex_inst (o,i) | |
8182 output o; | |
8183 input i; | |
8184 inst inst (/*AUTOINST*/); | |
8185 endmodule | |
8186 | |
8187 Typing \\[verilog-auto] will make this into: | |
8188 | |
8189 module ex_inst (o,i) | |
8190 output o; | |
8191 input i; | |
8192 inst inst (/*AUTOINST*/ | |
8193 // Outputs | |
8194 .ov (ov[31:0]), | |
8195 // Inputs | |
8196 .i (i)); | |
8197 endmodule | |
8198 | |
8199 Where the list of inputs and outputs came from the inst module. | |
8200 | |
8201 Exceptions: | |
8202 | |
8203 Unless you are instantiating a module multiple times, or the module is | |
8204 something trivial like a adder, DO NOT CHANGE SIGNAL NAMES ACROSS HIERARCHY. | |
8205 It just makes for unmaintainable code. To sanitize signal names, try | |
8206 vrename from http://www.veripool.com | |
8207 | |
8208 When you need to violate this suggestion there are two ways to list | |
8209 exceptions, placing them before the AUTOINST, or using templates. | |
8210 | |
8211 Any ports defined before the /*AUTOINST*/ are not included in the list of | |
8212 automatics. This is similar to making a template as described below, but | |
8213 is restricted to simple connections just like you normally make. Also note | |
8214 that any signals before the AUTOINST will only be picked up by AUTOWIRE if | |
8215 you have the appropriate // Input or // Output comment, and exactly the | |
8216 same line formatting as AUTOINST itself uses. | |
8217 | |
8218 inst inst (// Inputs | |
8219 .i (my_i_dont_mess_with_it), | |
8220 /*AUTOINST*/ | |
8221 // Outputs | |
8222 .ov (ov[31:0])); | |
8223 | |
8224 | |
8225 Templates: | |
8226 | |
8227 For multiple instantiations based upon a single template, create a | |
8228 commented out template: | |
8229 | |
8230 /* instantiating_module_name AUTO_TEMPLATE ( | |
8231 .sig3 (sigz[]), | |
8232 ); | |
8233 */ | |
8234 | |
8235 Templates go ABOVE the instantiation(s). When a instantiation is | |
8236 expanded `verilog-mode' simply searches up for the closest template. | |
8237 Thus you can have multiple templates for the same module, just alternate | |
8238 between the template for a instantiation and the instantiation itself. | |
8239 | |
8240 The module name must be the same as the name of the module in the | |
8241 instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact | |
8242 words and capitalized. Only signals that must be different for each | |
8243 instantiation need to be listed. | |
8244 | |
8245 Inside a template, a [] in a connection name (with nothing else inside | |
8246 the brackets) will be replaced by the same bus subscript as it is being | |
8247 connected to, or the [] will be removed if it is a single bit signal. | |
8248 Generally it is a good idea to do this for all connections in a template, | |
8249 as then they will work for any width signal, and with AUTOWIRE. See | |
8250 PTL_BUS becoming PTL_BUSNEW below. | |
8251 | |
8252 If you have a complicated template, set `verilog-auto-inst-template-numbers' | |
8253 to see which regexps are matching. Don't leave that mode set after | |
8254 debugging is completed though, it will result in lots of extra differences | |
8255 and merge conflicts. | |
8256 | |
8257 For example: | |
8258 | |
8259 /* psm_mas AUTO_TEMPLATE ( | |
8260 .ptl_bus (ptl_busnew[]), | |
8261 ); | |
8262 */ | |
8263 psm_mas ms2m (/*AUTOINST*/); | |
8264 | |
8265 Typing \\[verilog-auto] will make this into: | |
8266 | |
8267 psm_mas ms2m (/*AUTOINST*/ | |
8268 // Outputs | |
8269 .NotInTemplate (NotInTemplate), | |
8270 .ptl_bus (ptl_busnew[3:0]), // Templated | |
8271 .... | |
8272 | |
8273 @ Templates: | |
8274 | |
8275 It is common to instantiate a cell multiple times, so templates make it | |
8276 trivial to substitute part of the cell name into the connection name. | |
8277 | |
8278 /* cell_type AUTO_TEMPLATE <optional \"REGEXP\"> ( | |
8279 .sig1 (sigx[@]), | |
8280 .sig2 (sigy[@\"(% (+ 1 @) 4)\"]), | |
8281 ); | |
8282 */ | |
8283 | |
8284 If no regular expression is provided immediately after the AUTO_TEMPLATE | |
8285 keyword, then the @ character in any connection names will be replaced | |
8286 with the instantiation number; the first digits found in the cell's | |
8287 instantiation name. | |
8288 | |
8289 If a regular expression is provided, the @ character will be replaced | |
8290 with the first \(\) grouping that matches against the cell name. Using a | |
8291 regexp of \"\\([0-9]+\\)\" provides identical values for @ as when no | |
8292 regexp is provided. If you use multiple layers of parenthesis, | |
8293 \"test\\([^0-9]+\\)_\\([0-9]+\\)\" would replace @ with non-number | |
8294 characters after test and before _, whereas | |
8295 \"\\(test\\([a-z]+\\)_\\([0-9]+\\)\\)\" would replace @ with the entire | |
8296 match. | |
8297 | |
8298 For example: | |
8299 | |
8300 /* psm_mas AUTO_TEMPLATE ( | |
8301 .ptl_mapvalidx (ptl_mapvalid[@]), | |
8302 .ptl_mapvalidp1x (ptl_mapvalid[@\"(% (+ 1 @) 4)\"]), | |
8303 ); | |
8304 */ | |
8305 psm_mas ms2m (/*AUTOINST*/); | |
8306 | |
8307 Typing \\[verilog-auto] will make this into: | |
8308 | |
8309 psm_mas ms2m (/*AUTOINST*/ | |
8310 // Outputs | |
8311 .ptl_mapvalidx (ptl_mapvalid[2]), | |
8312 .ptl_mapvalidp1x (ptl_mapvalid[3])); | |
8313 | |
8314 Note the @ character was replaced with the 2 from \"ms2m\". | |
8315 | |
8316 Alternatively, using a regular expression for @: | |
8317 | |
8318 /* psm_mas AUTO_TEMPLATE \"_\\([a-z]+\\)\" ( | |
8319 .ptl_mapvalidx (@_ptl_mapvalid), | |
8320 .ptl_mapvalidp1x (ptl_mapvalid_@), | |
8321 ); | |
8322 */ | |
8323 psm_mas ms2_FOO (/*AUTOINST*/); | |
8324 psm_mas ms2_BAR (/*AUTOINST*/); | |
8325 | |
8326 Typing \\[verilog-auto] will make this into: | |
8327 | |
8328 psm_mas ms2_FOO (/*AUTOINST*/ | |
8329 // Outputs | |
8330 .ptl_mapvalidx (FOO_ptl_mapvalid), | |
8331 .ptl_mapvalidp1x (ptl_mapvalid_FOO)); | |
8332 psm_mas ms2_BAR (/*AUTOINST*/ | |
8333 // Outputs | |
8334 .ptl_mapvalidx (BAR_ptl_mapvalid), | |
8335 .ptl_mapvalidp1x (ptl_mapvalid_BAR)); | |
8336 | |
8337 | |
8338 Regexp Templates: | |
8339 | |
8340 A template entry of the form | |
8341 | |
8342 .pci_req\\([0-9]+\\)_l (pci_req_jtag_[\\1]), | |
8343 | |
8344 will apply a Emacs style regular expression search for any port beginning | |
8345 in pci_req followed by numbers and ending in _l and connecting that to | |
8346 the pci_req_jtag_[] net, with the bus subscript coming from what matches | |
8347 inside the first set of \\( \\). Thus pci_req2_l becomes pci_req_jtag_[2]. | |
8348 | |
8349 Since \\([0-9]+\\) is so common and ugly to read, a @ in the port name | |
8350 does the same thing. (Note a @ in the connection/replacement text is | |
8351 completely different -- still use \\1 there!) Thus this is the same as | |
8352 the above template: | |
8353 | |
8354 .pci_req@_l (pci_req_jtag_[\\1]), | |
8355 | |
8356 Here's another example to remove the _l, useful when naming conventions | |
8357 specify _ alone to mean active low. Note the use of [] to keep the bus | |
8358 subscript: | |
8359 | |
8360 .\\(.*\\)_l (\\1_[]), | |
8361 | |
8362 Lisp Templates: | |
8363 | |
8364 First any regular expression template is expanded. | |
8365 | |
8366 If the syntax @\"( ... )\" is found in a connection, the expression in | |
8367 quotes will be evaluated as a Lisp expression, with @ replaced by the | |
8368 instantiation number. The MAPVALIDP1X example above would put @+1 modulo | |
8369 4 into the brackets. Quote all double-quotes inside the expression with | |
8370 a leading backslash (\\\"). There are special variables defined that are | |
8371 useful in these Lisp functions: | |
8372 | |
8373 vl-name Name portion of the input/output port | |
8374 vl-bits Bus bits portion of the input/output port ('[2:0]') | |
8375 vl-width Width of the input/output port ('3' for [2:0]) | |
8376 May be a (...) expression if bits isn't a constant. | |
8377 vl-dir Direction of the pin input/output/inout. | |
8378 vl-cell-type Module name/type of the cell ('psm_mas') | |
8379 vl-cell-name Instance name of the cell ('ms2m') | |
8380 | |
8381 Normal Lisp variables may be used in expressions. See | |
8382 `verilog-read-defines' which can set vh-{definename} variables for use | |
8383 here. Also, any comments of the form: | |
8384 | |
8385 /*AUTO_LISP(setq foo 1)*/ | |
8386 | |
8387 will evaluate any Lisp expression inside the parenthesis between the | |
8388 beginning of the buffer and the point of the AUTOINST. This allows | |
8389 functions to be defined or variables to be changed between instantiations. | |
8390 | |
8391 Note that when using lisp expressions errors may occur when @ is not a | |
8392 number, you may need to use the standard Emacs Lisp functions | |
8393 `number-to-string' and `string-to-number'. | |
8394 | |
8395 After the evaluation is completed, @ substitution and [] substitution | |
8396 occur." | |
8397 (save-excursion | |
8398 ;; Find beginning | |
8399 (let* ((pt (point)) | |
8400 (for-star (save-excursion (backward-char 2) (looking-at "\\.\\*"))) | |
8401 (indent-pt (save-excursion (verilog-backward-open-paren) | |
8402 (1+ (current-column)))) | |
8403 (verilog-auto-inst-column (max verilog-auto-inst-column | |
8404 (+ 16 (* 8 (/ (+ indent-pt 7) 8))))) | |
8405 (modi (verilog-modi-current)) | |
8406 (vector-skip-list (unless verilog-auto-inst-vector | |
8407 (verilog-modi-get-signals modi))) | |
8408 submod submodi inst skip-pins tpl-list tpl-num did-first) | |
8409 ;; Find module name that is instantiated | |
8410 (setq submod (verilog-read-inst-module) | |
8411 inst (verilog-read-inst-name) | |
8412 vl-cell-type submod | |
8413 vl-cell-name inst | |
8414 skip-pins (aref (verilog-read-inst-pins) 0)) | |
8415 | |
8416 ;; Parse any AUTO_LISP() before here | |
8417 (verilog-read-auto-lisp (point-min) pt) | |
8418 | |
8419 ;; Lookup position, etc of submodule | |
8420 ;; Note this may raise an error | |
8421 (when (setq submodi (verilog-modi-lookup submod t)) | |
8422 ;; If there's a number in the instantiation, it may be a argument to the | |
8423 ;; automatic variable instantiation program. | |
8424 (let* ((tpl-info (verilog-read-auto-template submod)) | |
8425 (tpl-regexp (aref tpl-info 0))) | |
8426 (setq tpl-num (if (string-match tpl-regexp inst) | |
8427 (match-string 1 inst) | |
8428 "") | |
8429 tpl-list (aref tpl-info 1))) | |
8430 ;; Find submodule's signals and dump | |
8431 (let ((sig-list (verilog-signals-not-in | |
8432 (verilog-modi-get-outputs submodi) | |
8433 skip-pins)) | |
8434 (vl-dir "output")) | |
8435 (when sig-list | |
8436 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) | |
8437 (indent-to indent-pt) | |
8438 (insert "// Outputs\n") ;; Note these are searched for in verilog-read-sub-decls | |
8439 (mapcar (function (lambda (port) | |
8440 (verilog-auto-inst-port port indent-pt tpl-list tpl-num for-star))) | |
8441 sig-list))) | |
8442 (let ((sig-list (verilog-signals-not-in | |
8443 (verilog-modi-get-inouts submodi) | |
8444 skip-pins)) | |
8445 (vl-dir "inout")) | |
8446 (when sig-list | |
8447 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) | |
8448 (indent-to indent-pt) | |
8449 (insert "// Inouts\n") | |
8450 (mapcar (function (lambda (port) | |
8451 (verilog-auto-inst-port port indent-pt tpl-list tpl-num for-star))) | |
8452 sig-list))) | |
8453 (let ((sig-list (verilog-signals-not-in | |
8454 (verilog-modi-get-inputs submodi) | |
8455 skip-pins)) | |
8456 (vl-dir "input")) | |
8457 (when sig-list | |
8458 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) | |
8459 (indent-to indent-pt) | |
8460 (insert "// Inputs\n") | |
8461 (mapcar (function (lambda (port) | |
8462 (verilog-auto-inst-port port indent-pt tpl-list tpl-num for-star))) | |
8463 sig-list))) | |
8464 ;; Kill extra semi | |
8465 (save-excursion | |
8466 (cond (did-first | |
8467 (re-search-backward "," pt t) | |
8468 (delete-char 1) | |
8469 (insert ");") | |
8470 (search-forward "\n") ;; Added by inst-port | |
8471 (delete-backward-char 1) | |
8472 (if (search-forward ")" nil t) ;; From user, moved up a line | |
8473 (delete-backward-char 1)) | |
8474 (if (search-forward ";" nil t) ;; Don't error if user had syntax error and forgot it | |
8475 (delete-backward-char 1)) | |
8476 ))) | |
8477 )))) | |
8478 | |
8479 (defun verilog-auto-inst-param () | |
8480 "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto]. | |
8481 Replace the parameter connections to an instantiation with ones | |
8482 automatically derived from the module header of the instantiated netlist. | |
8483 | |
8484 See \\[verilog-auto-inst] for limitations, and templates to customize the | |
8485 output. | |
8486 | |
8487 For example, first take the submodule inst.v: | |
8488 | |
8489 module inst (o,i) | |
8490 parameter PAR; | |
8491 endmodule | |
8492 | |
8493 This is then used in a upper level module: | |
8494 | |
8495 module ex_inst (o,i) | |
8496 parameter PAR; | |
8497 inst #(/*AUTOINSTPARAM*/) | |
8498 inst (/*AUTOINST*/); | |
8499 endmodule | |
8500 | |
8501 Typing \\[verilog-auto] will make this into: | |
8502 | |
8503 module ex_inst (o,i) | |
8504 output o; | |
8505 input i; | |
8506 inst (/*AUTOINSTPARAM*/ | |
8507 // Parameters | |
8508 .PAR (PAR)); | |
8509 inst (/*AUTOINST*/); | |
8510 endmodule | |
8511 | |
8512 Where the list of parameter connections come from the inst module. | |
8513 | |
8514 Templates: | |
8515 | |
8516 You can customize the parameter connections using AUTO_TEMPLATEs, | |
8517 just as you would with \\[verilog-auto-inst]." | |
8518 (save-excursion | |
8519 ;; Find beginning | |
8520 (let* ((pt (point)) | |
8521 (indent-pt (save-excursion (verilog-backward-open-paren) | |
8522 (1+ (current-column)))) | |
8523 (verilog-auto-inst-column (max verilog-auto-inst-column | |
8524 (+ 16 (* 8 (/ (+ indent-pt 7) 8))))) | |
8525 (modi (verilog-modi-current)) | |
8526 (vector-skip-list (unless verilog-auto-inst-vector | |
8527 (verilog-modi-get-signals modi))) | |
8528 submod submodi inst skip-pins tpl-list tpl-num did-first) | |
8529 ;; Find module name that is instantiated | |
8530 (setq submod (save-excursion | |
8531 ;; Get to the point where AUTOINST normally is to read the module | |
8532 (verilog-re-search-forward-quick "[(;]" nil nil) | |
8533 (verilog-read-inst-module)) | |
8534 inst (save-excursion | |
8535 ;; Get to the point where AUTOINST normally is to read the module | |
8536 (verilog-re-search-forward-quick "[(;]" nil nil) | |
8537 (verilog-read-inst-name)) | |
8538 vl-cell-type submod | |
8539 vl-cell-name inst | |
8540 skip-pins (aref (verilog-read-inst-pins) 0)) | |
8541 | |
8542 ;; Parse any AUTO_LISP() before here | |
8543 (verilog-read-auto-lisp (point-min) pt) | |
8544 | |
8545 ;; Lookup position, etc of submodule | |
8546 ;; Note this may raise an error | |
8547 (when (setq submodi (verilog-modi-lookup submod t)) | |
8548 ;; If there's a number in the instantiation, it may be a argument to the | |
8549 ;; automatic variable instantiation program. | |
8550 (let* ((tpl-info (verilog-read-auto-template submod)) | |
8551 (tpl-regexp (aref tpl-info 0))) | |
8552 (setq tpl-num (if (string-match tpl-regexp inst) | |
8553 (match-string 1 inst) | |
8554 "") | |
8555 tpl-list (aref tpl-info 1))) | |
8556 ;; Find submodule's signals and dump | |
8557 (let ((sig-list (verilog-signals-not-in | |
8558 (verilog-modi-get-gparams submodi) | |
8559 skip-pins)) | |
8560 (vl-dir "parameter")) | |
8561 (when sig-list | |
8562 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) | |
8563 (indent-to indent-pt) | |
8564 (insert "// Parameters\n") ;; Note these are searched for in verilog-read-sub-decls | |
8565 (mapcar (function (lambda (port) | |
8566 (verilog-auto-inst-port port indent-pt tpl-list tpl-num nil))) | |
8567 sig-list))) | |
8568 ;; Kill extra semi | |
8569 (save-excursion | |
8570 (cond (did-first | |
8571 (re-search-backward "," pt t) | |
8572 (delete-char 1) | |
8573 (insert ")") | |
8574 (search-forward "\n") ;; Added by inst-port | |
8575 (delete-backward-char 1) | |
8576 (if (search-forward ")" nil t) ;; From user, moved up a line | |
8577 (delete-backward-char 1)) | |
8578 ))) | |
8579 )))) | |
8580 | |
8581 (defun verilog-auto-reg () | |
8582 "Expand AUTOREG statements, as part of \\[verilog-auto]. | |
8583 Make reg statements for any output that isn't already declared, | |
8584 and isn't a wire output from a block. | |
8585 | |
8586 Limitations: | |
8587 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'). | |
8588 | |
8589 This does NOT work on memories, declare those yourself. | |
8590 | |
8591 An example: | |
8592 | |
8593 module ex_reg (o,i) | |
8594 output o; | |
8595 input i; | |
8596 /*AUTOREG*/ | |
8597 always o = i; | |
8598 endmodule | |
8599 | |
8600 Typing \\[verilog-auto] will make this into: | |
8601 | |
8602 module ex_reg (o,i) | |
8603 output o; | |
8604 input i; | |
8605 /*AUTOREG*/ | |
8606 // Beginning of automatic regs (for this module's undeclared outputs) | |
8607 reg o; | |
8608 // End of automatics | |
8609 always o = i; | |
8610 endmodule" | |
8611 (save-excursion | |
8612 ;; Point must be at insertion point. | |
8613 (let* ((indent-pt (current-indentation)) | |
8614 (modi (verilog-modi-current)) | |
8615 (sig-list (verilog-signals-not-in | |
8616 (verilog-modi-get-outputs modi) | |
8617 (append (verilog-modi-get-wires modi) | |
8618 (verilog-modi-get-regs modi) | |
8619 (verilog-modi-get-assigns modi) | |
8620 (verilog-modi-get-consts modi) | |
8621 (verilog-modi-get-gparams modi) | |
8622 (verilog-modi-get-sub-outputs modi) | |
8623 (verilog-modi-get-sub-inouts modi) | |
8624 )))) | |
8625 (forward-line 1) | |
8626 (when sig-list | |
8627 (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n") | |
8628 (verilog-insert-definition sig-list "reg" indent-pt nil) | |
8629 (verilog-modi-cache-add-regs modi sig-list) | |
8630 (verilog-insert-indent "// End of automatics\n")) | |
8631 ))) | |
8632 | |
8633 (defun verilog-auto-reg-input () | |
8634 "Expand AUTOREGINPUT statements, as part of \\[verilog-auto]. | |
8635 Make reg statements instantiation inputs that aren't already declared. | |
8636 This is useful for making a top level shell for testing the module that is | |
8637 to be instantiated. | |
8638 | |
8639 Limitations: | |
8640 This ONLY detects inputs of AUTOINSTants (see `verilog-read-sub-decls'). | |
8641 | |
8642 This does NOT work on memories, declare those yourself. | |
8643 | |
8644 An example (see `verilog-auto-inst' for what else is going on here): | |
8645 | |
8646 module ex_reg_input (o,i) | |
8647 output o; | |
8648 input i; | |
8649 /*AUTOREGINPUT*/ | |
8650 inst inst (/*AUTOINST*/); | |
8651 endmodule | |
8652 | |
8653 Typing \\[verilog-auto] will make this into: | |
8654 | |
8655 module ex_reg_input (o,i) | |
8656 output o; | |
8657 input i; | |
8658 /*AUTOREGINPUT*/ | |
8659 // Beginning of automatic reg inputs (for undeclared ... | |
8660 reg [31:0] iv; // From inst of inst.v | |
8661 // End of automatics | |
8662 inst inst (/*AUTOINST*/ | |
8663 // Outputs | |
8664 .o (o[31:0]), | |
8665 // Inputs | |
8666 .iv (iv)); | |
8667 endmodule" | |
8668 (save-excursion | |
8669 ;; Point must be at insertion point. | |
8670 (let* ((indent-pt (current-indentation)) | |
8671 (modi (verilog-modi-current)) | |
8672 (sig-list (verilog-signals-combine-bus | |
8673 (verilog-signals-not-in | |
8674 (append (verilog-modi-get-sub-inputs modi) | |
8675 (verilog-modi-get-sub-inouts modi)) | |
8676 (verilog-modi-get-signals modi) | |
8677 )))) | |
8678 (forward-line 1) | |
8679 (when sig-list | |
8680 (verilog-insert-indent "// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)\n") | |
8681 (verilog-insert-definition sig-list "reg" indent-pt nil) | |
8682 (verilog-modi-cache-add-regs modi sig-list) | |
8683 (verilog-insert-indent "// End of automatics\n")) | |
8684 ))) | |
8685 | |
8686 (defun verilog-auto-wire () | |
8687 "Expand AUTOWIRE statements, as part of \\[verilog-auto]. | |
8688 Make wire statements for instantiations outputs that aren't | |
8689 already declared. | |
8690 | |
8691 Limitations: | |
8692 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'), | |
8693 and all busses must have widths, such as those from AUTOINST, or using [] | |
8694 in AUTO_TEMPLATEs. | |
8695 | |
8696 This does NOT work on memories or SystemVerilog .name connections, | |
8697 declare those yourself. | |
8698 | |
8699 Verilog-mode will add \"Couldn't Merge\" comments to signals it cannot | |
8700 determine how to bus together. This occurs when you have ports with | |
8701 non-numeric or non-sequential bus subscripts. If Verilog-Mode | |
8702 mis-guessed, you'll have to declare them yourself. | |
8703 | |
8704 An example (see `verilog-auto-inst' for what else is going on here): | |
8705 | |
8706 module ex_wire (o,i) | |
8707 output o; | |
8708 input i; | |
8709 /*AUTOWIRE*/ | |
8710 inst inst (/*AUTOINST*/); | |
8711 endmodule | |
8712 | |
8713 Typing \\[verilog-auto] will make this into: | |
8714 | |
8715 module ex_wire (o,i) | |
8716 output o; | |
8717 input i; | |
8718 /*AUTOWIRE*/ | |
8719 // Beginning of automatic wires | |
8720 wire [31:0] ov; // From inst of inst.v | |
8721 // End of automatics | |
8722 inst inst (/*AUTOINST*/ | |
8723 // Outputs | |
8724 .ov (ov[31:0]), | |
8725 // Inputs | |
8726 .i (i)); | |
8727 wire o = | ov; | |
8728 endmodule" | |
8729 (save-excursion | |
8730 ;; Point must be at insertion point. | |
8731 (let* ((indent-pt (current-indentation)) | |
8732 (modi (verilog-modi-current)) | |
8733 (sig-list (verilog-signals-combine-bus | |
8734 (verilog-signals-not-in | |
8735 (append (verilog-modi-get-sub-outputs modi) | |
8736 (verilog-modi-get-sub-inouts modi)) | |
8737 (verilog-modi-get-signals modi) | |
8738 )))) | |
8739 (forward-line 1) | |
8740 (when sig-list | |
8741 (verilog-insert-indent "// Beginning of automatic wires (for undeclared instantiated-module outputs)\n") | |
8742 (verilog-insert-definition sig-list "wire" indent-pt nil) | |
8743 (verilog-modi-cache-add-wires modi sig-list) | |
8744 (verilog-insert-indent "// End of automatics\n") | |
8745 (when nil ;; Too slow on huge modules, plus makes everyone's module change | |
8746 (beginning-of-line) | |
8747 (setq pnt (point)) | |
8748 (verilog-pretty-declarations) | |
8749 (goto-char pnt) | |
8750 (verilog-pretty-expr "//"))) | |
8751 ))) | |
8752 | |
8753 (defun verilog-auto-output () | |
8754 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto]. | |
8755 Make output statements for any output signal from an /*AUTOINST*/ that | |
8756 isn't a input to another AUTOINST. This is useful for modules which | |
8757 only instantiate other modules. | |
8758 | |
8759 Limitations: | |
8760 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'). | |
8761 | |
8762 If placed inside the parenthesis of a module declaration, it creates | |
8763 Verilog 2001 style, else uses Verilog 1995 style. | |
8764 | |
8765 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's | |
8766 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE). | |
8767 | |
8768 Typedefs must match `verilog-typedef-regexp', which is disabled by default. | |
8769 | |
8770 Signals matching `verilog-auto-output-ignore-regexp' are not included. | |
8771 | |
8772 An example (see `verilog-auto-inst' for what else is going on here): | |
8773 | |
8774 module ex_output (ov,i) | |
8775 input i; | |
8776 /*AUTOOUTPUT*/ | |
8777 inst inst (/*AUTOINST*/); | |
8778 endmodule | |
8779 | |
8780 Typing \\[verilog-auto] will make this into: | |
8781 | |
8782 module ex_output (ov,i) | |
8783 input i; | |
8784 /*AUTOOUTPUT*/ | |
8785 // Beginning of automatic outputs (from unused autoinst outputs) | |
8786 output [31:0] ov; // From inst of inst.v | |
8787 // End of automatics | |
8788 inst inst (/*AUTOINST*/ | |
8789 // Outputs | |
8790 .ov (ov[31:0]), | |
8791 // Inputs | |
8792 .i (i)); | |
8793 endmodule" | |
8794 (save-excursion | |
8795 ;; Point must be at insertion point. | |
8796 (let* ((indent-pt (current-indentation)) | |
8797 (v2k (verilog-in-paren)) | |
8798 (modi (verilog-modi-current)) | |
8799 (sig-list (verilog-signals-not-in | |
8800 (verilog-modi-get-sub-outputs modi) | |
8801 (append (verilog-modi-get-outputs modi) | |
8802 (verilog-modi-get-inouts modi) | |
8803 (verilog-modi-get-sub-inputs modi) | |
8804 (verilog-modi-get-sub-inouts modi) | |
8805 )))) | |
8806 (setq sig-list (verilog-signals-not-matching-regexp | |
8807 sig-list verilog-auto-output-ignore-regexp)) | |
8808 (forward-line 1) | |
8809 (when v2k (verilog-repair-open-comma)) | |
8810 (when sig-list | |
8811 (verilog-insert-indent "// Beginning of automatic outputs (from unused autoinst outputs)\n") | |
8812 (verilog-insert-definition sig-list "output" indent-pt v2k) | |
8813 (verilog-modi-cache-add-outputs modi sig-list) | |
8814 (verilog-insert-indent "// End of automatics\n")) | |
8815 (when v2k (verilog-repair-close-comma)) | |
8816 ))) | |
8817 | |
8818 (defun verilog-auto-output-every () | |
8819 "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto]. | |
8820 Make output statements for any signals that aren't primary inputs or | |
8821 outputs already. This makes every signal in the design a output. This is | |
8822 useful to get Synopsys to preserve every signal in the design, since it | |
8823 won't optimize away the outputs. | |
8824 | |
8825 An example: | |
8826 | |
8827 module ex_output_every (o,i,tempa,tempb) | |
8828 output o; | |
8829 input i; | |
8830 /*AUTOOUTPUTEVERY*/ | |
8831 wire tempa = i; | |
8832 wire tempb = tempa; | |
8833 wire o = tempb; | |
8834 endmodule | |
8835 | |
8836 Typing \\[verilog-auto] will make this into: | |
8837 | |
8838 module ex_output_every (o,i,tempa,tempb) | |
8839 output o; | |
8840 input i; | |
8841 /*AUTOOUTPUTEVERY*/ | |
8842 // Beginning of automatic outputs (every signal) | |
8843 output tempb; | |
8844 output tempa; | |
8845 // End of automatics | |
8846 wire tempa = i; | |
8847 wire tempb = tempa; | |
8848 wire o = tempb; | |
8849 endmodule" | |
8850 (save-excursion | |
8851 ;;Point must be at insertion point | |
8852 (let* ((indent-pt (current-indentation)) | |
8853 (v2k (verilog-in-paren)) | |
8854 (modi (verilog-modi-current)) | |
8855 (sig-list (verilog-signals-combine-bus | |
8856 (verilog-signals-not-in | |
8857 (verilog-modi-get-signals modi) | |
8858 (verilog-modi-get-ports modi) | |
8859 )))) | |
8860 (forward-line 1) | |
8861 (when v2k (verilog-repair-open-comma)) | |
8862 (when sig-list | |
8863 (verilog-insert-indent "// Beginning of automatic outputs (every signal)\n") | |
8864 (verilog-insert-definition sig-list "output" indent-pt v2k) | |
8865 (verilog-modi-cache-add-outputs modi sig-list) | |
8866 (verilog-insert-indent "// End of automatics\n")) | |
8867 (when v2k (verilog-repair-close-comma)) | |
8868 ))) | |
8869 | |
8870 (defun verilog-auto-input () | |
8871 "Expand AUTOINPUT statements, as part of \\[verilog-auto]. | |
8872 Make input statements for any input signal into an /*AUTOINST*/ that | |
8873 isn't declared elsewhere inside the module. This is useful for modules which | |
8874 only instantiate other modules. | |
8875 | |
8876 Limitations: | |
8877 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'). | |
8878 | |
8879 If placed inside the parenthesis of a module declaration, it creates | |
8880 Verilog 2001 style, else uses Verilog 1995 style. | |
8881 | |
8882 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's | |
8883 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE). | |
8884 | |
8885 Typedefs must match `verilog-typedef-regexp', which is disabled by default. | |
8886 | |
8887 Signals matching `verilog-auto-input-ignore-regexp' are not included. | |
8888 | |
8889 An example (see `verilog-auto-inst' for what else is going on here): | |
8890 | |
8891 module ex_input (ov,i) | |
8892 output [31:0] ov; | |
8893 /*AUTOINPUT*/ | |
8894 inst inst (/*AUTOINST*/); | |
8895 endmodule | |
8896 | |
8897 Typing \\[verilog-auto] will make this into: | |
8898 | |
8899 module ex_input (ov,i) | |
8900 output [31:0] ov; | |
8901 /*AUTOINPUT*/ | |
8902 // Beginning of automatic inputs (from unused autoinst inputs) | |
8903 input i; // From inst of inst.v | |
8904 // End of automatics | |
8905 inst inst (/*AUTOINST*/ | |
8906 // Outputs | |
8907 .ov (ov[31:0]), | |
8908 // Inputs | |
8909 .i (i)); | |
8910 endmodule" | |
8911 (save-excursion | |
8912 (let* ((indent-pt (current-indentation)) | |
8913 (v2k (verilog-in-paren)) | |
8914 (modi (verilog-modi-current)) | |
8915 (sig-list (verilog-signals-not-in | |
8916 (verilog-modi-get-sub-inputs modi) | |
8917 (append (verilog-modi-get-inputs modi) | |
8918 (verilog-modi-get-inouts modi) | |
8919 (verilog-modi-get-wires modi) | |
8920 (verilog-modi-get-regs modi) | |
8921 (verilog-modi-get-consts modi) | |
8922 (verilog-modi-get-gparams modi) | |
8923 (verilog-modi-get-sub-outputs modi) | |
8924 (verilog-modi-get-sub-inouts modi) | |
8925 )))) | |
8926 (setq sig-list (verilog-signals-not-matching-regexp | |
8927 sig-list verilog-auto-input-ignore-regexp)) | |
8928 (forward-line 1) | |
8929 (when v2k (verilog-repair-open-comma)) | |
8930 (when sig-list | |
8931 (verilog-insert-indent "// Beginning of automatic inputs (from unused autoinst inputs)\n") | |
8932 (verilog-insert-definition sig-list "input" indent-pt v2k) | |
8933 (verilog-modi-cache-add-inputs modi sig-list) | |
8934 (verilog-insert-indent "// End of automatics\n")) | |
8935 (when v2k (verilog-repair-close-comma)) | |
8936 ))) | |
8937 | |
8938 (defun verilog-auto-inout () | |
8939 "Expand AUTOINOUT statements, as part of \\[verilog-auto]. | |
8940 Make inout statements for any inout signal in an /*AUTOINST*/ that | |
8941 isn't declared elsewhere inside the module. | |
8942 | |
8943 Limitations: | |
8944 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'). | |
8945 | |
8946 If placed inside the parenthesis of a module declaration, it creates | |
8947 Verilog 2001 style, else uses Verilog 1995 style. | |
8948 | |
8949 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's | |
8950 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE). | |
8951 | |
8952 Typedefs must match `verilog-typedef-regexp', which is disabled by default. | |
8953 | |
8954 Signals matching `verilog-auto-inout-ignore-regexp' are not included. | |
8955 | |
8956 An example (see `verilog-auto-inst' for what else is going on here): | |
8957 | |
8958 module ex_inout (ov,i) | |
8959 input i; | |
8960 /*AUTOINOUT*/ | |
8961 inst inst (/*AUTOINST*/); | |
8962 endmodule | |
8963 | |
8964 Typing \\[verilog-auto] will make this into: | |
8965 | |
8966 module ex_inout (ov,i) | |
8967 input i; | |
8968 /*AUTOINOUT*/ | |
8969 // Beginning of automatic inouts (from unused autoinst inouts) | |
8970 inout [31:0] ov; // From inst of inst.v | |
8971 // End of automatics | |
8972 inst inst (/*AUTOINST*/ | |
8973 // Inouts | |
8974 .ov (ov[31:0]), | |
8975 // Inputs | |
8976 .i (i)); | |
8977 endmodule" | |
8978 (save-excursion | |
8979 ;; Point must be at insertion point. | |
8980 (let* ((indent-pt (current-indentation)) | |
8981 (v2k (verilog-in-paren)) | |
8982 (modi (verilog-modi-current)) | |
8983 (sig-list (verilog-signals-not-in | |
8984 (verilog-modi-get-sub-inouts modi) | |
8985 (append (verilog-modi-get-outputs modi) | |
8986 (verilog-modi-get-inouts modi) | |
8987 (verilog-modi-get-inputs modi) | |
8988 (verilog-modi-get-sub-inputs modi) | |
8989 (verilog-modi-get-sub-outputs modi) | |
8990 )))) | |
8991 (setq sig-list (verilog-signals-not-matching-regexp | |
8992 sig-list verilog-auto-inout-ignore-regexp)) | |
8993 (forward-line 1) | |
8994 (when v2k (verilog-repair-open-comma)) | |
8995 (when sig-list | |
8996 (verilog-insert-indent "// Beginning of automatic inouts (from unused autoinst inouts)\n") | |
8997 (verilog-insert-definition sig-list "inout" indent-pt v2k) | |
8998 (verilog-modi-cache-add-inouts modi sig-list) | |
8999 (verilog-insert-indent "// End of automatics\n")) | |
9000 (when v2k (verilog-repair-close-comma)) | |
9001 ))) | |
9002 | |
9003 (defun verilog-auto-inout-module () | |
9004 "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto]. | |
9005 Take input/output/inout statements from the specified module and insert | |
9006 into the current module. This is useful for making null templates and | |
9007 shell modules which need to have identical I/O with another module. Any | |
9008 I/O which are already defined in this module will not be redefined. | |
9009 | |
9010 Limitations: | |
9011 If placed inside the parenthesis of a module declaration, it creates | |
9012 Verilog 2001 style, else uses Verilog 1995 style. | |
9013 | |
9014 Concatenation and outputting partial busses is not supported. | |
9015 | |
9016 Module names must be resolvable to filenames. See `verilog-auto-inst'. | |
9017 | |
9018 Signals are not inserted in the same order as in the original module, | |
9019 though they will appear to be in the same order to a AUTOINST | |
9020 instantiating either module. | |
9021 | |
9022 An example: | |
9023 | |
9024 module ex_shell (/*AUTOARG*/) | |
9025 /*AUTOINOUTMODULE(\"ex_main\")*/ | |
9026 endmodule | |
9027 | |
9028 module ex_main (i,o,io) | |
9029 input i; | |
9030 output o; | |
9031 inout io; | |
9032 endmodule | |
9033 | |
9034 Typing \\[verilog-auto] will make this into: | |
9035 | |
9036 module ex_shell (/*AUTOARG*/i,o,io) | |
9037 /*AUTOINOUTMODULE(\"ex_main\")*/ | |
9038 // Beginning of automatic in/out/inouts (from specific module) | |
9039 input i; | |
9040 output o; | |
9041 inout io; | |
9042 // End of automatics | |
9043 endmodule" | |
9044 (save-excursion | |
9045 (let* ((submod (car (verilog-read-auto-params 1))) submodi) | |
9046 ;; Lookup position, etc of co-module | |
9047 ;; Note this may raise an error | |
9048 (when (setq submodi (verilog-modi-lookup submod t)) | |
9049 (let* ((indent-pt (current-indentation)) | |
9050 (v2k (verilog-in-paren)) | |
9051 (modi (verilog-modi-current)) | |
9052 (sig-list-i (verilog-signals-not-in | |
9053 (verilog-modi-get-inputs submodi) | |
9054 (append (verilog-modi-get-inputs modi)))) | |
9055 (sig-list-o (verilog-signals-not-in | |
9056 (verilog-modi-get-outputs submodi) | |
9057 (append (verilog-modi-get-outputs modi)))) | |
9058 (sig-list-io (verilog-signals-not-in | |
9059 (verilog-modi-get-inouts submodi) | |
9060 (append (verilog-modi-get-inouts modi))))) | |
9061 (forward-line 1) | |
9062 (when v2k (verilog-repair-open-comma)) | |
9063 (when (or sig-list-i sig-list-o sig-list-io) | |
9064 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n") | |
9065 ;; Don't sort them so a upper AUTOINST will match the main module | |
9066 (verilog-insert-definition sig-list-o "output" indent-pt v2k t) | |
9067 (verilog-insert-definition sig-list-io "inout" indent-pt v2k t) | |
9068 (verilog-insert-definition sig-list-i "input" indent-pt v2k t) | |
9069 (verilog-modi-cache-add-inputs modi sig-list-i) | |
9070 (verilog-modi-cache-add-outputs modi sig-list-o) | |
9071 (verilog-modi-cache-add-inouts modi sig-list-io) | |
9072 (verilog-insert-indent "// End of automatics\n")) | |
9073 (when v2k (verilog-repair-close-comma)) | |
9074 ))))) | |
9075 | |
9076 (defun verilog-auto-sense-sigs (modi presense-sigs) | |
9077 "Return list of signals for current AUTOSENSE block." | |
9078 (let* ((sigss (verilog-read-always-signals)) | |
9079 (sig-list (verilog-signals-not-params | |
9080 (verilog-signals-not-in (verilog-alw-get-inputs sigss) | |
9081 (append (and (not verilog-auto-sense-include-inputs) | |
9082 (verilog-alw-get-outputs sigss)) | |
9083 (verilog-modi-get-consts modi) | |
9084 (verilog-modi-get-gparams modi) | |
9085 presense-sigs))))) | |
9086 sig-list)) | |
9087 | |
9088 (defun verilog-auto-sense () | |
9089 "Expand AUTOSENSE statements, as part of \\[verilog-auto]. | |
9090 Replace the always (/*AUTOSENSE*/) sensitivity list (/*AS*/ for short) | |
9091 with one automatically derived from all inputs declared in the always | |
9092 statement. Signals that are generated within the same always block are NOT | |
9093 placed into the sensitivity list (see `verilog-auto-sense-include-inputs'). | |
9094 Long lines are split based on the `fill-column', see \\[set-fill-column]. | |
9095 | |
9096 Limitations: | |
9097 Verilog does not allow memories (multidimensional arrays) in sensitivity | |
9098 lists. AUTOSENSE will thus exclude them, and add a /*memory or*/ comment. | |
9099 | |
9100 Constant signals: | |
9101 AUTOSENSE cannot always determine if a `define is a constant or a signal | |
9102 (it could be in a include file for example). If a `define or other signal | |
9103 is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT | |
9104 declaration anywhere in the module (parenthesis are required): | |
9105 | |
9106 /* AUTO_CONSTANT ( `this_is_really_constant_dont_autosense_it ) */ | |
9107 | |
9108 Better yet, use a parameter, which will be understood to be constant | |
9109 automatically. | |
9110 | |
9111 OOps! | |
9112 If AUTOSENSE makes a mistake, please report it. (First try putting | |
9113 a begin/end after your always!) As a workaround, if a signal that | |
9114 shouldn't be in the sensitivity list was, use the AUTO_CONSTANT above. | |
9115 If a signal should be in the sensitivity list wasn't, placing it before | |
9116 the /*AUTOSENSE*/ comment will prevent it from being deleted when the | |
9117 autos are updated (or added if it occurs there already). | |
9118 | |
9119 An example: | |
9120 | |
9121 always @ (/*AUTOSENSE*/) begin | |
9122 /* AUTO_CONSTANT (`constant) */ | |
9123 outin = ina | inb | `constant; | |
9124 out = outin; | |
9125 end | |
9126 | |
9127 Typing \\[verilog-auto] will make this into: | |
9128 | |
9129 always @ (/*AUTOSENSE*/ina or inb) begin | |
9130 /* AUTO_CONSTANT (`constant) */ | |
9131 outin = ina | inb | `constant; | |
9132 out = outin; | |
9133 end" | |
9134 (save-excursion | |
9135 ;; Find beginning | |
9136 (let* ((start-pt (save-excursion | |
9137 (verilog-re-search-backward "(" nil t) | |
9138 (point))) | |
9139 (indent-pt (save-excursion | |
9140 (or (and (goto-char start-pt) (1+ (current-column))) | |
9141 (current-indentation)))) | |
9142 (modi (verilog-modi-current)) | |
9143 (sig-memories (verilog-signals-memory | |
9144 (append | |
9145 (verilog-modi-get-regs modi) | |
9146 (verilog-modi-get-wires modi)))) | |
9147 sig-list not-first presense-sigs) | |
9148 ;; Read signals in always, eliminate outputs from sense list | |
9149 (setq presense-sigs (verilog-signals-from-signame | |
9150 (save-excursion | |
9151 (verilog-read-signals start-pt (point))))) | |
9152 (setq sig-list (verilog-auto-sense-sigs modi presense-sigs)) | |
9153 (when sig-memories | |
9154 (let ((tlen (length sig-list))) | |
9155 (setq sig-list (verilog-signals-not-in sig-list sig-memories)) | |
9156 (if (not (eq tlen (length sig-list))) (insert " /*memory or*/ ")))) | |
9157 (if (and presense-sigs ;; Add a "or" if not "(.... or /*AUTOSENSE*/" | |
9158 (save-excursion (goto-char (point)) | |
9159 (verilog-re-search-backward "[a-zA-Z0-9$_.%`]+" start-pt t) | |
9160 (verilog-re-search-backward "\\s-" start-pt t) | |
9161 (while (looking-at "\\s-`endif") | |
9162 (verilog-re-search-backward "[a-zA-Z0-9$_.%`]+" start-pt t) | |
9163 (verilog-re-search-backward "\\s-" start-pt t)) | |
9164 (not (looking-at "\\s-or\\b")))) | |
9165 (setq not-first t)) | |
9166 (setq sig-list (sort sig-list `verilog-signals-sort-compare)) | |
9167 (while sig-list | |
9168 (cond ((> (+ 4 (current-column) (length (verilog-sig-name (car sig-list)))) fill-column) ;+4 for width of or | |
9169 (insert "\n") | |
9170 (indent-to indent-pt) | |
9171 (if not-first (insert "or "))) | |
9172 (not-first (insert " or "))) | |
9173 (insert (verilog-sig-name (car sig-list))) | |
9174 (setq sig-list (cdr sig-list) | |
9175 not-first t)) | |
9176 ))) | |
9177 | |
9178 (defun verilog-auto-reset () | |
9179 "Expand AUTORESET statements, as part of \\[verilog-auto]. | |
9180 Replace the /*AUTORESET*/ comment with code to initialize all | |
9181 registers set elsewhere in the always block. | |
9182 | |
9183 Limitations: | |
9184 AUTORESET will not clear memories. | |
9185 | |
9186 AUTORESET uses <= if there are any <= in the block, else it uses =. | |
9187 | |
9188 /*AUTORESET*/ presumes that any signals mentioned between the previous | |
9189 begin/case/if statement and the AUTORESET comment are being reset manually | |
9190 and should not be automatically reset. This includes omitting any signals | |
9191 used on the right hand side of assignments. | |
9192 | |
9193 By default, AUTORESET will include the width of the signal in the autos, | |
9194 this is a recent change. To control this behavior, see | |
9195 `verilog-auto-reset-widths'. | |
9196 | |
9197 AUTORESET ties signals to deasserted, which is presumed to be zero. | |
9198 Signals that match `verilog-active-low-regexp' will be deasserted by tieing | |
9199 them to a one. | |
9200 | |
9201 An example: | |
9202 | |
9203 always @(posedge clk or negedge reset_l) begin | |
9204 if (!reset_l) begin | |
9205 c <= 1; | |
9206 /*AUTORESET*/ | |
9207 end | |
9208 else begin | |
9209 a <= in_a; | |
9210 b <= in_b; | |
9211 c <= in_c; | |
9212 end | |
9213 end | |
9214 | |
9215 Typing \\[verilog-auto] will make this into: | |
9216 | |
9217 always @(posedge core_clk or negedge reset_l) begin | |
9218 if (!reset_l) begin | |
9219 c <= 1; | |
9220 /*AUTORESET*/ | |
9221 // Beginning of autoreset for uninitialized flops | |
9222 a <= 0; | |
9223 b <= 0; | |
9224 // End of automatics | |
9225 end | |
9226 else begin | |
9227 a <= in_a; | |
9228 b <= in_b; | |
9229 c <= in_c; | |
9230 end | |
9231 end" | |
9232 | |
9233 (interactive) | |
9234 (save-excursion | |
9235 ;; Find beginning | |
9236 (let* ((indent-pt (current-indentation)) | |
9237 (modi (verilog-modi-current)) | |
9238 (all-list (verilog-modi-get-signals modi)) | |
9239 sigss sig-list prereset-sigs assignment-str) | |
9240 ;; Read signals in always, eliminate outputs from reset list | |
9241 (setq prereset-sigs (verilog-signals-from-signame | |
9242 (save-excursion | |
9243 (verilog-read-signals | |
9244 (save-excursion | |
9245 (verilog-re-search-backward "\\(@\\|\\<begin\\>\\|\\<if\\>\\|\\<case\\>\\)" nil t) | |
9246 (point)) | |
9247 (point))))) | |
9248 (save-excursion | |
9249 (verilog-re-search-backward "@" nil t) | |
9250 (setq sigss (verilog-read-always-signals))) | |
9251 (setq assignment-str (if (verilog-alw-get-uses-delayed sigss) | |
9252 (concat " <= " verilog-assignment-delay) | |
9253 " = ")) | |
9254 (setq sig-list (verilog-signals-not-in (verilog-alw-get-outputs sigss) | |
9255 prereset-sigs)) | |
9256 (setq sig-list (sort sig-list `verilog-signals-sort-compare)) | |
9257 (when sig-list | |
9258 (insert "\n"); | |
9259 (indent-to indent-pt) | |
9260 (insert "// Beginning of autoreset for uninitialized flops\n"); | |
9261 (indent-to indent-pt) | |
9262 (while sig-list | |
9263 (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ;; As sig-list has no widths | |
9264 (car sig-list)))) | |
9265 (insert (verilog-sig-name sig) | |
9266 assignment-str | |
9267 (verilog-sig-tieoff sig (not verilog-auto-reset-widths)) | |
9268 ";\n") | |
9269 (indent-to indent-pt) | |
9270 (setq sig-list (cdr sig-list)))) | |
9271 (insert "// End of automatics")) | |
9272 ))) | |
9273 | |
9274 (defun verilog-auto-tieoff () | |
9275 "Expand AUTOTIEOFF statements, as part of \\[verilog-auto]. | |
9276 Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output | |
9277 signals to deasserted. | |
9278 | |
9279 /*AUTOTIEOFF*/ is used to make stub modules; modules that have the same | |
9280 input/output list as another module, but no internals. Specifically, it | |
9281 finds all outputs in the module, and if that input is not otherwise declared | |
9282 as a register or wire, creates a tieoff. | |
9283 | |
9284 AUTORESET ties signals to deasserted, which is presumed to be zero. | |
9285 Signals that match `verilog-active-low-regexp' will be deasserted by tieing | |
9286 them to a one. | |
9287 | |
9288 An example of making a stub for another module: | |
9289 | |
9290 module FooStub (/*AUTOINST*/); | |
9291 /*AUTOINOUTMODULE(\"Foo\")*/ | |
9292 /*AUTOTIEOFF*/ | |
9293 // verilator lint_off UNUSED | |
9294 wire _unused_ok = &{1'b0, | |
9295 /*AUTOUNUSED*/ | |
9296 1'b0}; | |
9297 // verilator lint_on UNUSED | |
9298 endmodule | |
9299 | |
9300 Typing \\[verilog-auto] will make this into: | |
9301 | |
9302 module FooStub (/*AUTOINST*/...); | |
9303 /*AUTOINOUTMODULE(\"Foo\")*/ | |
9304 // Beginning of autotieoff | |
9305 output [2:0] foo; | |
9306 // End of automatics | |
9307 | |
9308 /*AUTOTIEOFF*/ | |
9309 // Beginning of autotieoff | |
9310 wire [2:0] foo = 3'b0; | |
9311 // End of automatics | |
9312 ... | |
9313 endmodule" | |
9314 (interactive) | |
9315 (save-excursion | |
9316 ;; Find beginning | |
9317 (let* ((indent-pt (current-indentation)) | |
9318 (modi (verilog-modi-current)) | |
9319 (sig-list (verilog-signals-not-in | |
9320 (verilog-modi-get-outputs modi) | |
9321 (append (verilog-modi-get-wires modi) | |
9322 (verilog-modi-get-regs modi) | |
9323 (verilog-modi-get-assigns modi) | |
9324 (verilog-modi-get-consts modi) | |
9325 (verilog-modi-get-gparams modi) | |
9326 (verilog-modi-get-sub-outputs modi) | |
9327 (verilog-modi-get-sub-inouts modi) | |
9328 )))) | |
9329 (when sig-list | |
9330 (forward-line 1) | |
9331 (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n") | |
9332 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)) | |
9333 (verilog-modi-cache-add-wires modi sig-list) ; Before we trash list | |
9334 (while sig-list | |
9335 (let ((sig (car sig-list))) | |
9336 (verilog-insert-one-definition sig "wire" indent-pt) | |
9337 (indent-to (max 48 (+ indent-pt 40))) | |
9338 (insert "= " (verilog-sig-tieoff sig) | |
9339 ";\n") | |
9340 (setq sig-list (cdr sig-list)))) | |
9341 (verilog-insert-indent "// End of automatics\n") | |
9342 )))) | |
9343 | |
9344 (defun verilog-auto-unused () | |
9345 "Expand AUTOUNUSED statements, as part of \\[verilog-auto]. | |
9346 Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused | |
9347 input and inout signals. | |
9348 | |
9349 /*AUTOUNUSED*/ is used to make stub modules; modules that have the same | |
9350 input/output list as another module, but no internals. Specifically, it | |
9351 finds all inputs and inouts in the module, and if that input is not otherwise | |
9352 used, adds it to a comma separated list. | |
9353 | |
9354 The comma separated list is intended to be used to create a _unused_ok | |
9355 signal. Using the exact name \"_unused_ok\" for name of the temporary | |
9356 signal is recommended as it will insure maximum forward compatibility, it | |
9357 also makes lint warnings easy to understand; ignore any unused warnings | |
9358 with \"unused\" in the signal name. | |
9359 | |
9360 To reduce simulation time, the _unused_ok signal should be forced to a | |
9361 constant to prevent wiggling. The easiest thing to do is use a | |
9362 reduction-and with 1'b0 as shown. | |
9363 | |
9364 This way all unused signals are in one place, making it convenient to add | |
9365 your tool's specific pragmas around the assignment to disable any unused | |
9366 warnings. | |
9367 | |
9368 You can add signals you do not want included in AUTOUNUSED with | |
9369 `verilog-auto-unused-ignore-regexp'. | |
9370 | |
9371 An example of making a stub for another module: | |
9372 | |
9373 module FooStub (/*AUTOINST*/); | |
9374 /*AUTOINOUTMODULE(\"Foo\")*/ | |
9375 /*AUTOTIEOFF*/ | |
9376 // verilator lint_off UNUSED | |
9377 wire _unused_ok = &{1'b0, | |
9378 /*AUTOUNUSED*/ | |
9379 1'b0}; | |
9380 // verilator lint_on UNUSED | |
9381 endmodule | |
9382 | |
9383 Typing \\[verilog-auto] will make this into: | |
9384 | |
9385 ... | |
9386 // verilator lint_off UNUSED | |
9387 wire _unused_ok = &{1'b0, | |
9388 /*AUTOUNUSED*/ | |
9389 // Beginning of automatics | |
9390 unused_input_a, | |
9391 unused_input_b, | |
9392 unused_input_c, | |
9393 // End of automatics | |
9394 1'b0}; | |
9395 // verilator lint_on UNUSED | |
9396 endmodule" | |
9397 (interactive) | |
9398 (save-excursion | |
9399 ;; Find beginning | |
9400 (let* ((indent-pt (progn (search-backward "/*") (current-column))) | |
9401 (modi (verilog-modi-current)) | |
9402 (sig-list (verilog-signals-not-in | |
9403 (append (verilog-modi-get-inputs modi) | |
9404 (verilog-modi-get-inouts modi)) | |
9405 (append (verilog-modi-get-sub-inputs modi) | |
9406 (verilog-modi-get-sub-inouts modi) | |
9407 )))) | |
9408 (setq sig-list (verilog-signals-not-matching-regexp | |
9409 sig-list verilog-auto-unused-ignore-regexp)) | |
9410 (when sig-list | |
9411 (forward-line 1) | |
9412 (verilog-insert-indent "// Beginning of automatic unused inputs\n") | |
9413 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)) | |
9414 (while sig-list | |
9415 (let ((sig (car sig-list))) | |
9416 (indent-to indent-pt) | |
9417 (insert (verilog-sig-name sig) ",\n") | |
9418 (setq sig-list (cdr sig-list)))) | |
9419 (verilog-insert-indent "// End of automatics\n") | |
9420 )))) | |
9421 | |
9422 (defun verilog-enum-ascii (signm elim-regexp) | |
9423 "Convert a enum name SIGNM to a ascii string for insertion. | |
9424 Remove user provided prefix ELIM-REGEXP." | |
9425 (or elim-regexp (setq elim-regexp "_ DONT MATCH IT_")) | |
9426 (let ((case-fold-search t)) | |
9427 ;; All upper becomes all lower for readability | |
9428 (downcase (verilog-string-replace-matches elim-regexp "" nil nil signm)))) | |
9429 | |
9430 (defun verilog-auto-ascii-enum () | |
9431 "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto]. | |
9432 Create a register to contain the ASCII decode of a enumerated signal type. | |
9433 This will allow trace viewers to show the ASCII name of states. | |
9434 | |
9435 First, parameters are built into a enumeration using the synopsys enum | |
9436 comment. The comment must be between the keyword and the symbol. | |
79546 | 9437 \(Annoying, but that's what Synopsys's dc_shell FSM reader requires.) |
79545 | 9438 |
9439 Next, registers which that enum applies to are also tagged with the same | |
9440 enum. Synopsys also suggests labeling state vectors, but `verilog-mode' | |
9441 doesn't care. | |
9442 | |
9443 Finally, a AUTOASCIIENUM command is used. | |
9444 | |
9445 The first parameter is the name of the signal to be decoded. | |
9446 | |
9447 The second parameter is the name to store the ASCII code into. For the | |
9448 signal foo, I suggest the name _foo__ascii, where the leading _ indicates | |
9449 a signal that is just for simulation, and the magic characters _ascii | |
9450 tell viewers like Dinotrace to display in ASCII format. | |
9451 | |
9452 The final optional parameter is a string which will be removed from the | |
9453 state names. | |
9454 | |
9455 An example: | |
9456 | |
9457 //== State enumeration | |
9458 parameter [2:0] // synopsys enum state_info | |
9459 SM_IDLE = 3'b000, | |
9460 SM_SEND = 3'b001, | |
9461 SM_WAIT1 = 3'b010; | |
9462 //== State variables | |
9463 reg [2:0] /* synopsys enum state_info */ | |
9464 state_r; /* synopsys state_vector state_r */ | |
9465 reg [2:0] /* synopsys enum state_info */ | |
9466 state_e1; | |
9467 | |
9468 //== ASCII state decoding | |
9469 | |
9470 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/ | |
9471 | |
9472 Typing \\[verilog-auto] will make this into: | |
9473 | |
9474 ... same front matter ... | |
9475 | |
9476 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/ | |
9477 // Beginning of automatic ASCII enum decoding | |
9478 reg [39:0] state_ascii_r; // Decode of state_r | |
9479 always @(state_r) begin | |
9480 case ({state_r}) | |
9481 SM_IDLE: state_ascii_r = \"idle \"; | |
9482 SM_SEND: state_ascii_r = \"send \"; | |
9483 SM_WAIT1: state_ascii_r = \"wait1\"; | |
9484 default: state_ascii_r = \"%Erro\"; | |
9485 endcase | |
9486 end | |
9487 // End of automatics" | |
9488 (save-excursion | |
9489 (let* ((params (verilog-read-auto-params 2 3)) | |
9490 (undecode-name (nth 0 params)) | |
9491 (ascii-name (nth 1 params)) | |
9492 (elim-regexp (nth 2 params)) | |
9493 ;; | |
9494 (indent-pt (current-indentation)) | |
9495 (modi (verilog-modi-current)) | |
9496 ;; | |
9497 (sig-list-consts (append (verilog-modi-get-consts modi) | |
9498 (verilog-modi-get-gparams modi))) | |
9499 (sig-list-all (append (verilog-modi-get-regs modi) | |
9500 (verilog-modi-get-outputs modi) | |
9501 (verilog-modi-get-inouts modi) | |
9502 (verilog-modi-get-inputs modi) | |
9503 (verilog-modi-get-wires modi))) | |
9504 ;; | |
9505 (undecode-sig (or (assoc undecode-name sig-list-all) | |
9506 (error "%s: Signal %s not found in design" (verilog-point-text) undecode-name))) | |
9507 (undecode-enum (or (verilog-sig-enum undecode-sig) | |
9508 (error "%s: Signal %s does not have a enum tag" (verilog-point-text) undecode-name))) | |
9509 ;; | |
9510 (enum-sigs (or (verilog-signals-matching-enum sig-list-consts undecode-enum) | |
9511 (error "%s: No state definitions for %s" (verilog-point-text) undecode-enum))) | |
9512 ;; | |
9513 (enum-chars 0) | |
9514 (ascii-chars 0)) | |
9515 ;; | |
9516 ;; Find number of ascii chars needed | |
9517 (let ((tmp-sigs enum-sigs)) | |
9518 (while tmp-sigs | |
9519 (setq enum-chars (max enum-chars (length (verilog-sig-name (car tmp-sigs)))) | |
9520 ascii-chars (max ascii-chars (length (verilog-enum-ascii | |
9521 (verilog-sig-name (car tmp-sigs)) | |
9522 elim-regexp))) | |
9523 tmp-sigs (cdr tmp-sigs)))) | |
9524 ;; | |
9525 (forward-line 1) | |
9526 (verilog-insert-indent "// Beginning of automatic ASCII enum decoding\n") | |
9527 (let ((decode-sig-list (list (list ascii-name (format "[%d:0]" (- (* ascii-chars 8) 1)) | |
9528 (concat "Decode of " undecode-name) nil nil)))) | |
9529 (verilog-insert-definition decode-sig-list "reg" indent-pt nil) | |
9530 (verilog-modi-cache-add-regs modi decode-sig-list)) | |
9531 ;; | |
9532 (verilog-insert-indent "always @(" undecode-name ") begin\n") | |
9533 (setq indent-pt (+ indent-pt verilog-indent-level)) | |
9534 (indent-to indent-pt) | |
9535 (insert "case ({" undecode-name "})\n") | |
9536 (setq indent-pt (+ indent-pt verilog-case-indent)) | |
9537 ;; | |
9538 (let ((tmp-sigs enum-sigs) | |
9539 (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n" (1+ (max 8 enum-chars)) | |
9540 ascii-name ascii-chars)) | |
9541 (errname (substring "%Error" 0 (min 6 ascii-chars)))) | |
9542 (while tmp-sigs | |
9543 (verilog-insert-indent | |
9544 (format chrfmt (concat (verilog-sig-name (car tmp-sigs)) ":") | |
9545 (verilog-enum-ascii (verilog-sig-name (car tmp-sigs)) | |
9546 elim-regexp))) | |
9547 (setq tmp-sigs (cdr tmp-sigs))) | |
9548 (verilog-insert-indent (format chrfmt "default:" errname))) | |
9549 ;; | |
9550 (setq indent-pt (- indent-pt verilog-case-indent)) | |
9551 (verilog-insert-indent "endcase\n") | |
9552 (setq indent-pt (- indent-pt verilog-indent-level)) | |
9553 (verilog-insert-indent "end\n" | |
9554 "// End of automatics\n") | |
9555 ))) | |
9556 | |
9557 (defun verilog-auto-templated-rel () | |
9558 "Replace Templated relative line numbers with absolute line numbers. | |
9559 Internal use only. This hacks around the line numbers in AUTOINST Templates | |
9560 being different from the final output's line numbering." | |
9561 (let ((templateno 0) (template-line (list 0))) | |
9562 ;; Find line number each template is on | |
9563 (goto-char (point-min)) | |
9564 (while (search-forward "AUTO_TEMPLATE" nil t) | |
9565 (setq templateno (1+ templateno)) | |
9566 (setq template-line (cons (count-lines (point-min) (point)) template-line))) | |
9567 (setq template-line (nreverse template-line)) | |
9568 ;; Replace T# L# with absolute line number | |
9569 (goto-char (point-min)) | |
9570 (while (re-search-forward " Templated T\\([0-9]+\\) L\\([0-9]+\\)" nil t) | |
9571 (replace-match (concat " Templated " | |
9572 (int-to-string (+ (nth (string-to-int (match-string 1)) | |
9573 template-line) | |
9574 (string-to-int (match-string 2))))) | |
9575 t t)))) | |
9576 | |
9577 | |
9578 ;; | |
9579 ;; Auto top level | |
9580 ;; | |
9581 | |
9582 (defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing a arg | |
9583 "Expand AUTO statements. | |
9584 Look for any /*AUTO...*/ commands in the code, as used in | |
9585 instantiations or argument headers. Update the list of signals | |
9586 following the /*AUTO...*/ command. | |
9587 | |
9588 Use \\[verilog-delete-auto] to remove the AUTOs. | |
9589 | |
9590 Use \\[verilog-inject-auto] to insert AUTOs for the first time. | |
9591 | |
9592 Use \\[verilog-faq] for a pointer to frequently asked questions. | |
9593 | |
9594 The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are | |
9595 called before and after this function, respectively. | |
9596 | |
9597 For example: | |
9598 module (/*AUTOARG*/) | |
9599 /*AUTOINPUT*/ | |
9600 /*AUTOOUTPUT*/ | |
9601 /*AUTOWIRE*/ | |
9602 /*AUTOREG*/ | |
9603 somesub sub #(/*AUTOINSTPARAM*/) (/*AUTOINST*/); | |
9604 | |
9605 You can also update the AUTOs from the shell using: | |
9606 emacs --batch <filenames.v> -f verilog-batch-auto | |
9607 Or fix indentation with: | |
9608 emacs --batch <filenames.v> -f verilog-batch-indent | |
9609 Likewise, you can delete or inject AUTOs with: | |
9610 emacs --batch <filenames.v> -f verilog-batch-delete-auto | |
9611 emacs --batch <filenames.v> -f verilog-batch-inject-auto | |
9612 | |
9613 Using \\[describe-function], see also: | |
9614 `verilog-auto-arg' for AUTOARG module instantiations | |
9615 `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding | |
9616 `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere | |
9617 `verilog-auto-inout' for AUTOINOUT making hierarchy inouts | |
9618 `verilog-auto-input' for AUTOINPUT making hierarchy inputs | |
9619 `verilog-auto-inst' for AUTOINST instantiation pins | |
9620 `verilog-auto-star' for AUTOINST .* SystemVerilog pins | |
9621 `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params | |
9622 `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs | |
9623 `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs | |
9624 `verilog-auto-reg' for AUTOREG registers | |
9625 `verilog-auto-reg-input' for AUTOREGINPUT instantiation registers | |
9626 `verilog-auto-reset' for AUTORESET flop resets | |
9627 `verilog-auto-sense' for AUTOSENSE always sensitivity lists | |
9628 `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs | |
9629 `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts | |
9630 `verilog-auto-wire' for AUTOWIRE instantiation wires | |
9631 | |
9632 `verilog-read-defines' for reading `define values | |
9633 `verilog-read-includes' for reading `includes | |
9634 | |
9635 If you have bugs with these autos, try contacting the AUTOAUTHOR | |
9636 Wilson Snyder (wsnyder@wsnyder.org), and/or see http://www.veripool.com." | |
9637 (interactive) | |
9638 (unless noninteractive (message "Updating AUTOs...")) | |
9639 (if (featurep 'dinotrace) | |
9640 (dinotrace-unannotate-all)) | |
9641 (let ((oldbuf (if (not (buffer-modified-p)) | |
9642 (buffer-string))) | |
9643 ;; Before version 20, match-string with font-lock returns a | |
9644 ;; vector that is not equal to the string. IE if on "input" | |
9645 ;; nil==(equal "input" (progn (looking-at "input") (match-string 0))) | |
9646 (fontlocked (when (and (boundp 'font-lock-mode) | |
9647 font-lock-mode) | |
9648 (font-lock-mode nil) | |
9649 t))) | |
9650 (unwind-protect | |
9651 (save-excursion | |
9652 ;; If we're not in verilog-mode, change syntax table so parsing works right | |
9653 (unless (eq major-mode `verilog-mode) (verilog-mode)) | |
9654 ;; Allow user to customize | |
9655 (run-hooks 'verilog-before-auto-hook) | |
9656 ;; Try to save the user from needing to revert-file to reread file local-variables | |
9657 (verilog-auto-reeval-locals) | |
9658 (verilog-read-auto-lisp (point-min) (point-max)) | |
9659 (verilog-getopt-flags) | |
9660 ;; These two may seem obvious to do always, but on large includes it can be way too slow | |
9661 (when verilog-auto-read-includes | |
9662 (verilog-read-includes) | |
9663 (verilog-read-defines nil nil t)) | |
9664 ;; This particular ordering is important | |
9665 ;; INST: Lower modules correct, no internal dependencies, FIRST | |
9666 (verilog-preserve-cache | |
9667 ;; Clear existing autos else we'll be screwed by existing ones | |
9668 (verilog-delete-auto) | |
9669 ;; Injection if appropriate | |
9670 (when inject | |
9671 (verilog-inject-inst) | |
9672 (verilog-inject-sense) | |
9673 (verilog-inject-arg)) | |
9674 ;; | |
9675 (verilog-auto-search-do "/*AUTOINSTPARAM*/" 'verilog-auto-inst-param) | |
9676 (verilog-auto-search-do "/*AUTOINST*/" 'verilog-auto-inst) | |
9677 (verilog-auto-search-do ".*" 'verilog-auto-star) | |
9678 ;; Doesn't matter when done, but combine it with a common changer | |
9679 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense) | |
9680 (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset) | |
9681 ;; Must be done before autoin/out as creates a reg | |
9682 (verilog-auto-re-search-do "/\\*AUTOASCIIENUM([^)]*)\\*/" 'verilog-auto-ascii-enum) | |
9683 ;; | |
9684 ;; first in/outs from other files | |
9685 (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE([^)]*)\\*/" 'verilog-auto-inout-module) | |
9686 ;; next in/outs which need previous sucked inputs first | |
9687 (verilog-auto-search-do "/*AUTOOUTPUT*/" 'verilog-auto-output) | |
9688 (verilog-auto-search-do "/*AUTOINPUT*/" 'verilog-auto-input) | |
9689 (verilog-auto-search-do "/*AUTOINOUT*/" 'verilog-auto-inout) | |
9690 ;; Then tie off those in/outs | |
9691 (verilog-auto-search-do "/*AUTOTIEOFF*/" 'verilog-auto-tieoff) | |
9692 ;; Wires/regs must be after inputs/outputs | |
9693 (verilog-auto-search-do "/*AUTOWIRE*/" 'verilog-auto-wire) | |
9694 (verilog-auto-search-do "/*AUTOREG*/" 'verilog-auto-reg) | |
9695 (verilog-auto-search-do "/*AUTOREGINPUT*/" 'verilog-auto-reg-input) | |
9696 ;; outputevery needs AUTOOUTPUTs done first | |
9697 (verilog-auto-search-do "/*AUTOOUTPUTEVERY*/" 'verilog-auto-output-every) | |
9698 ;; After we've created all new variables | |
9699 (verilog-auto-search-do "/*AUTOUNUSED*/" 'verilog-auto-unused) | |
9700 ;; Must be after all inputs outputs are generated | |
9701 (verilog-auto-search-do "/*AUTOARG*/" 'verilog-auto-arg) | |
9702 ;; Fix line numbers (comments only) | |
9703 (verilog-auto-templated-rel) | |
9704 ) | |
9705 ;; | |
9706 (run-hooks 'verilog-auto-hook) | |
9707 ;; | |
9708 (set (make-local-variable 'verilog-auto-update-tick) (buffer-modified-tick)) | |
9709 ;; | |
9710 ;; If end result is same as when started, clear modified flag | |
9711 (cond ((and oldbuf (equal oldbuf (buffer-string))) | |
9712 (set-buffer-modified-p nil) | |
9713 (unless noninteractive (message "Updating AUTOs...done (no changes)"))) | |
9714 (t (unless noninteractive (message "Updating AUTOs...done"))))) | |
9715 ;; Unwind forms | |
9716 (progn | |
9717 ;; Restore font-lock | |
9718 (when fontlocked (font-lock-mode t))) | |
9719 ))) | |
9720 | |
9721 | |
9722 ;; | |
9723 ;; Skeleton based code insertion | |
9724 ;; | |
79546 | 9725 (defvar verilog-template-map |
9726 (let ((map (make-sparse-keymap))) | |
9727 (define-key map "a" 'verilog-sk-always) | |
9728 (define-key map "b" 'verilog-sk-begin) | |
9729 (define-key map "c" 'verilog-sk-case) | |
9730 (define-key map "f" 'verilog-sk-for) | |
9731 (define-key map "g" 'verilog-sk-generate) | |
9732 (define-key map "h" 'verilog-sk-header) | |
9733 (define-key map "i" 'verilog-sk-initial) | |
9734 (define-key map "j" 'verilog-sk-fork) | |
9735 (define-key map "m" 'verilog-sk-module) | |
9736 (define-key map "p" 'verilog-sk-primitive) | |
9737 (define-key map "r" 'verilog-sk-repeat) | |
9738 (define-key map "s" 'verilog-sk-specify) | |
9739 (define-key map "t" 'verilog-sk-task) | |
9740 (define-key map "w" 'verilog-sk-while) | |
9741 (define-key map "x" 'verilog-sk-casex) | |
9742 (define-key map "z" 'verilog-sk-casez) | |
9743 (define-key map "?" 'verilog-sk-if) | |
9744 (define-key map ":" 'verilog-sk-else-if) | |
9745 (define-key map "/" 'verilog-sk-comment) | |
9746 (define-key map "A" 'verilog-sk-assign) | |
9747 (define-key map "F" 'verilog-sk-function) | |
9748 (define-key map "I" 'verilog-sk-input) | |
9749 (define-key map "O" 'verilog-sk-output) | |
9750 (define-key map "S" 'verilog-sk-state-machine) | |
9751 (define-key map "=" 'verilog-sk-inout) | |
9752 (define-key map "W" 'verilog-sk-wire) | |
9753 (define-key map "R" 'verilog-sk-reg) | |
79550
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
9754 (define-key map "D" 'verilog-sk-define-signal) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
9755 map) |
79545 | 9756 "Keymap used in Verilog mode for smart template operations.") |
9757 | |
9758 | |
9759 ;; | |
9760 ;; Place the templates into Verilog Mode. They may be inserted under any key. | |
9761 ;; C-c C-t will be the default. If you use templates a lot, you | |
9762 ;; may want to consider moving the binding to another key in your .emacs | |
9763 ;; file. | |
9764 ;; | |
9765 ;(define-key verilog-mode-map "\C-ct" verilog-template-map) | |
9766 (define-key verilog-mode-map "\C-c\C-t" verilog-template-map) | |
9767 | |
9768 ;;; ---- statement skeletons ------------------------------------------ | |
9769 | |
9770 (define-skeleton verilog-sk-prompt-condition | |
9771 "Prompt for the loop condition." | |
9772 "[condition]: " str ) | |
9773 | |
9774 (define-skeleton verilog-sk-prompt-init | |
9775 "Prompt for the loop init statement." | |
9776 "[initial statement]: " str ) | |
9777 | |
9778 (define-skeleton verilog-sk-prompt-inc | |
9779 "Prompt for the loop increment statement." | |
9780 "[increment statement]: " str ) | |
9781 | |
9782 (define-skeleton verilog-sk-prompt-name | |
9783 "Prompt for the name of something." | |
9784 "[name]: " str) | |
9785 | |
9786 (define-skeleton verilog-sk-prompt-clock | |
9787 "Prompt for the name of something." | |
9788 "name and edge of clock(s): " str) | |
9789 | |
9790 (defvar verilog-sk-reset nil) | |
9791 (defun verilog-sk-prompt-reset () | |
9792 "Prompt for the name of a state machine reset." | |
9793 (setq verilog-sk-reset (read-input "name of reset: " "rst"))) | |
9794 | |
9795 | |
9796 (define-skeleton verilog-sk-prompt-state-selector | |
9797 "Prompt for the name of a state machine selector." | |
9798 "name of selector (eg {a,b,c,d}): " str ) | |
9799 | |
9800 (define-skeleton verilog-sk-prompt-output | |
9801 "Prompt for the name of something." | |
9802 "output: " str) | |
9803 | |
9804 (define-skeleton verilog-sk-prompt-msb | |
9805 "Prompt for least significant bit specification." | |
9806 "msb:" str & ?: & (verilog-sk-prompt-lsb) | -1 ) | |
9807 | |
9808 (define-skeleton verilog-sk-prompt-lsb | |
9809 "Prompt for least significant bit specification." | |
9810 "lsb:" str ) | |
9811 | |
9812 (defvar verilog-sk-p nil) | |
9813 (define-skeleton verilog-sk-prompt-width | |
9814 "Prompt for a width specification." | |
9815 () | |
9816 (progn | |
9817 (setq verilog-sk-p (point)) | |
9818 (verilog-sk-prompt-msb) | |
9819 (if (> (point) verilog-sk-p) "] " " "))) | |
9820 | |
9821 (defun verilog-sk-header () | |
9822 "Insert a descriptive header at the top of the file." | |
9823 (interactive "*") | |
9824 (save-excursion | |
9825 (goto-char (point-min)) | |
9826 (verilog-sk-header-tmpl))) | |
9827 | |
9828 (define-skeleton verilog-sk-header-tmpl | |
9829 "Insert a comment block containing the module title, author, etc." | |
9830 "[Description]: " | |
9831 "// -*- Mode: Verilog -*-" | |
9832 "\n// Filename : " (buffer-name) | |
9833 "\n// Description : " str | |
9834 "\n// Author : " (user-full-name) | |
9835 "\n// Created On : " (current-time-string) | |
9836 "\n// Last Modified By: ." | |
9837 "\n// Last Modified On: ." | |
9838 "\n// Update Count : 0" | |
9839 "\n// Status : Unknown, Use with caution!" | |
9840 "\n") | |
9841 | |
9842 (define-skeleton verilog-sk-module | |
9843 "Insert a module definition." | |
9844 () | |
9845 > "module " (verilog-sk-prompt-name) " (/*AUTOARG*/ ) ;" \n | |
9846 > _ \n | |
9847 > (- verilog-indent-level-behavioral) "endmodule" (progn (electric-verilog-terminate-line) nil)) | |
9848 | |
9849 (define-skeleton verilog-sk-primitive | |
9850 "Insert a task definition." | |
9851 () | |
9852 > "primitive " (verilog-sk-prompt-name) " ( " (verilog-sk-prompt-output) ("input:" ", " str ) " );"\n | |
9853 > _ \n | |
9854 > (- verilog-indent-level-behavioral) "endprimitive" (progn (electric-verilog-terminate-line) nil)) | |
9855 | |
9856 (define-skeleton verilog-sk-task | |
9857 "Insert a task definition." | |
9858 () | |
9859 > "task " (verilog-sk-prompt-name) & ?; \n | |
9860 > _ \n | |
9861 > "begin" \n | |
9862 > \n | |
9863 > (- verilog-indent-level-behavioral) "end" \n | |
9864 > (- verilog-indent-level-behavioral) "endtask" (progn (electric-verilog-terminate-line) nil)) | |
9865 | |
9866 (define-skeleton verilog-sk-function | |
9867 "Insert a function definition." | |
9868 () | |
9869 > "function [" (verilog-sk-prompt-width) | -1 (verilog-sk-prompt-name) ?; \n | |
9870 > _ \n | |
9871 > "begin" \n | |
9872 > \n | |
9873 > (- verilog-indent-level-behavioral) "end" \n | |
9874 > (- verilog-indent-level-behavioral) "endfunction" (progn (electric-verilog-terminate-line) nil)) | |
9875 | |
9876 (define-skeleton verilog-sk-always | |
9877 "Insert always block. Uses the minibuffer to prompt | |
9878 for sensitivity list." | |
9879 () | |
9880 > "always @ ( /*AUTOSENSE*/ ) begin\n" | |
9881 > _ \n | |
9882 > (- verilog-indent-level-behavioral) "end" \n > | |
9883 ) | |
9884 | |
9885 (define-skeleton verilog-sk-initial | |
9886 "Insert an initial block." | |
9887 () | |
9888 > "initial begin\n" | |
9889 > _ \n | |
9890 > (- verilog-indent-level-behavioral) "end" \n > ) | |
9891 | |
9892 (define-skeleton verilog-sk-specify | |
9893 "Insert specify block. " | |
9894 () | |
9895 > "specify\n" | |
9896 > _ \n | |
9897 > (- verilog-indent-level-behavioral) "endspecify" \n > ) | |
9898 | |
9899 (define-skeleton verilog-sk-generate | |
9900 "Insert generate block. " | |
9901 () | |
9902 > "generate\n" | |
9903 > _ \n | |
9904 > (- verilog-indent-level-behavioral) "endgenerate" \n > ) | |
9905 | |
9906 (define-skeleton verilog-sk-begin | |
9907 "Insert begin end block. Uses the minibuffer to prompt for name" | |
9908 () | |
9909 > "begin" (verilog-sk-prompt-name) \n | |
9910 > _ \n | |
9911 > (- verilog-indent-level-behavioral) "end" | |
9912 ) | |
9913 | |
9914 (define-skeleton verilog-sk-fork | |
9915 "Insert an fork join block." | |
9916 () | |
9917 > "fork\n" | |
9918 > "begin" \n | |
9919 > _ \n | |
9920 > (- verilog-indent-level-behavioral) "end" \n | |
9921 > "begin" \n | |
9922 > \n | |
9923 > (- verilog-indent-level-behavioral) "end" \n | |
9924 > (- verilog-indent-level-behavioral) "join" \n | |
9925 > ) | |
9926 | |
9927 | |
9928 (define-skeleton verilog-sk-case | |
9929 "Build skeleton case statement, prompting for the selector expression, | |
9930 and the case items." | |
9931 "[selector expression]: " | |
9932 > "case (" str ") " \n | |
9933 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n ) | |
9934 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)) | |
9935 | |
9936 (define-skeleton verilog-sk-casex | |
9937 "Build skeleton casex statement, prompting for the selector expression, | |
9938 and the case items." | |
9939 "[selector expression]: " | |
9940 > "casex (" str ") " \n | |
9941 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n ) | |
9942 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)) | |
9943 | |
9944 (define-skeleton verilog-sk-casez | |
9945 "Build skeleton casez statement, prompting for the selector expression, | |
9946 and the case items." | |
9947 "[selector expression]: " | |
9948 > "casez (" str ") " \n | |
9949 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n ) | |
9950 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)) | |
9951 | |
9952 (define-skeleton verilog-sk-if | |
9953 "Insert a skeleton if statement." | |
9954 > "if (" (verilog-sk-prompt-condition) & ")" " begin" \n | |
9955 > _ \n | |
9956 > (- verilog-indent-level-behavioral) "end " \n ) | |
9957 | |
9958 (define-skeleton verilog-sk-else-if | |
9959 "Insert a skeleton else if statement." | |
9960 > (verilog-indent-line) "else if (" | |
9961 (progn (setq verilog-sk-p (point)) nil) (verilog-sk-prompt-condition) (if (> (point) verilog-sk-p) ") " -1 ) & " begin" \n | |
9962 > _ \n | |
9963 > "end" (progn (electric-verilog-terminate-line) nil)) | |
9964 | |
9965 (define-skeleton verilog-sk-datadef | |
9966 "Common routine to get data definition" | |
9967 () | |
9968 (verilog-sk-prompt-width) | -1 ("name (RET to end):" str ", ") -2 ";" \n) | |
9969 | |
9970 (define-skeleton verilog-sk-input | |
9971 "Insert an input definition." | |
9972 () | |
9973 > "input [" (verilog-sk-datadef)) | |
9974 | |
9975 (define-skeleton verilog-sk-output | |
9976 "Insert an output definition." | |
9977 () | |
9978 > "output [" (verilog-sk-datadef)) | |
9979 | |
9980 (define-skeleton verilog-sk-inout | |
9981 "Insert an inout definition." | |
9982 () | |
9983 > "inout [" (verilog-sk-datadef)) | |
9984 | |
9985 (defvar verilog-sk-signal nil) | |
9986 (define-skeleton verilog-sk-def-reg | |
9987 "Insert a reg definition." | |
9988 () | |
9989 > "reg [" (verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations) ) | |
9990 | |
9991 (defun verilog-sk-define-signal () | |
9992 "Insert a definition of signal under point at top of module." | |
9993 (interactive "*") | |
9994 (let* ( | |
9995 (sig-re "[a-zA-Z0-9_]*") | |
9996 (v1 (buffer-substring | |
9997 (save-excursion | |
9998 (skip-chars-backward sig-re) | |
9999 (point)) | |
10000 (save-excursion | |
10001 (skip-chars-forward sig-re) | |
10002 (point)))) | |
10003 ) | |
10004 (if (not (member v1 verilog-keywords)) | |
10005 (save-excursion | |
10006 (setq verilog-sk-signal v1) | |
10007 (verilog-beg-of-defun) | |
10008 (verilog-end-of-statement) | |
10009 (verilog-forward-syntactic-ws) | |
10010 (verilog-sk-def-reg) | |
10011 (message "signal at point is %s" v1)) | |
10012 (message "object at point (%s) is a keyword" v1)) | |
10013 ) | |
10014 ) | |
10015 | |
10016 | |
10017 (define-skeleton verilog-sk-wire | |
10018 "Insert a wire definition." | |
10019 () | |
10020 > "wire [" (verilog-sk-datadef)) | |
10021 | |
10022 (define-skeleton verilog-sk-reg | |
10023 "Insert a reg definition." | |
10024 () | |
10025 > "reg [" (verilog-sk-datadef)) | |
10026 | |
10027 (define-skeleton verilog-sk-assign | |
10028 "Insert a skeleton assign statement." | |
10029 () | |
10030 > "assign " (verilog-sk-prompt-name) " = " _ ";" \n) | |
10031 | |
10032 (define-skeleton verilog-sk-while | |
10033 "Insert a skeleton while loop statement." | |
10034 () | |
10035 > "while (" (verilog-sk-prompt-condition) ") begin" \n | |
10036 > _ \n | |
10037 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil)) | |
10038 | |
10039 (define-skeleton verilog-sk-repeat | |
10040 "Insert a skeleton repeat loop statement." | |
10041 () | |
10042 > "repeat (" (verilog-sk-prompt-condition) ") begin" \n | |
10043 > _ \n | |
10044 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil)) | |
10045 | |
10046 (define-skeleton verilog-sk-for | |
10047 "Insert a skeleton while loop statement." | |
10048 () | |
10049 > "for (" | |
10050 (verilog-sk-prompt-init) "; " | |
10051 (verilog-sk-prompt-condition) "; " | |
10052 (verilog-sk-prompt-inc) | |
10053 ") begin" \n | |
10054 > _ \n | |
10055 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil)) | |
10056 | |
10057 (define-skeleton verilog-sk-comment | |
10058 "Inserts three comment lines, making a display comment." | |
10059 () | |
10060 > "/*\n" | |
10061 > "* " _ \n | |
10062 > "*/") | |
10063 | |
10064 (define-skeleton verilog-sk-state-machine | |
10065 "Insert a state machine definition." | |
10066 "Name of state variable: " | |
10067 '(setq input "state") | |
10068 > "// State registers for " str | -23 \n | |
10069 '(setq verilog-sk-state str) | |
10070 > "reg [" (verilog-sk-prompt-width) | -1 verilog-sk-state ", next_" verilog-sk-state ?; \n | |
10071 '(setq input nil) | |
10072 > \n | |
10073 > "// State FF for " verilog-sk-state \n | |
10074 > "always @ ( " (read-string "clock:" "posedge clk") " or " (verilog-sk-prompt-reset) " ) begin" \n | |
10075 > "if ( " verilog-sk-reset " ) " verilog-sk-state " = 0; else" \n | |
10076 > verilog-sk-state " = next_" verilog-sk-state ?; \n | |
10077 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil) | |
10078 > \n | |
10079 > "// Next State Logic for " verilog-sk-state \n | |
10080 > "always @ ( /*AUTOSENSE*/ ) begin\n" | |
10081 > "case (" (verilog-sk-prompt-state-selector) ") " \n | |
10082 > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n ) | |
10083 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil) | |
10084 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil)) | |
10085 | |
10086 ;; Eliminate compile warning | |
10087 (eval-when-compile | |
10088 (if (not (boundp 'mode-popup-menu)) | |
10089 (defvar mode-popup-menu nil "Compatibility with XEmacs."))) | |
10090 | |
10091 ;; ---- add menu 'Statements' in Verilog mode (MH) | |
10092 (defun verilog-add-statement-menu () | |
10093 "Add the menu 'Statements' to the menu bar in Verilog mode." | |
10094 (if (featurep 'xemacs) | |
10095 (progn | |
10096 (easy-menu-add verilog-stmt-menu) | |
10097 (easy-menu-add verilog-menu) | |
10098 (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu))))) | |
10099 | |
10100 (add-hook 'verilog-mode-hook 'verilog-add-statement-menu) | |
10101 | |
10102 | |
10103 | |
10104 ;; | |
10105 ;; Include file loading with mouse/return event | |
10106 ;; | |
10107 ;; idea & first impl.: M. Rouat (eldo-mode.el) | |
10108 ;; second (emacs/xemacs) impl.: G. Van der Plas (spice-mode.el) | |
10109 | |
10110 (if (featurep 'xemacs) | |
10111 (require 'overlay) | |
10112 (require 'lucid)) ;; what else can we do ?? | |
10113 | |
10114 (defconst verilog-include-file-regexp | |
10115 "^`include\\s-+\"\\([^\n\"]*\\)\"" | |
10116 "Regexp that matches the include file.") | |
10117 | |
79546 | 10118 (defvar verilog-mode-mouse-map |
79545 | 10119 (let ((map (make-sparse-keymap))) ; as described in info pages, make a map |
10120 (set-keymap-parent map verilog-mode-map) | |
10121 ;; mouse button bindings | |
10122 (define-key map "\r" 'verilog-load-file-at-point) | |
10123 (if (featurep 'xemacs) | |
10124 (define-key map 'button2 'verilog-load-file-at-mouse);ffap-at-mouse ? | |
10125 (define-key map [mouse-2] 'verilog-load-file-at-mouse)) | |
10126 (if (featurep 'xemacs) | |
10127 (define-key map 'Sh-button2 'mouse-yank) ; you wanna paste don't you ? | |
79550
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
10128 (define-key map [S-mouse-2] 'mouse-yank-at-click)) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
10129 map) |
79546 | 10130 "Map containing mouse bindings for `verilog-mode'.") |
10131 | |
79545 | 10132 |
10133 (defun verilog-colorize-include-files (beg end old-len) | |
10134 "This function colorizes included files when the mouse passes over them. | |
10135 Clicking on the middle-mouse button loads them in a buffer (as in dired)." | |
10136 (save-excursion | |
10137 (save-match-data | |
10138 (let (end-point) | |
10139 (goto-char end) | |
10140 (setq end-point (verilog-get-end-of-line)) | |
10141 (goto-char beg) | |
10142 (beginning-of-line) ; scan entire line ! | |
10143 ;; delete overlays existing on this line | |
10144 (let ((overlays (overlays-in (point) end-point))) | |
10145 (while overlays | |
10146 (if (and | |
10147 (overlay-get (car overlays) 'detachable) | |
10148 (overlay-get (car overlays) 'verilog-include-file)) | |
10149 (delete-overlay (car overlays))) | |
10150 (setq overlays (cdr overlays)))) ; let | |
10151 ;; make new ones, could reuse deleted one ? | |
10152 (while (search-forward-regexp verilog-include-file-regexp end-point t) | |
79550
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
10153 (let (ov) |
79545 | 10154 (goto-char (match-beginning 1)) |
79550
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
10155 (setq ov (make-overlay (match-beginning 1) (match-end 1))) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
10156 (overlay-put ov 'start-closed 't) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
10157 (overlay-put ov 'end-closed 't) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
10158 (overlay-put ov 'evaporate 't) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
10159 (overlay-put ov 'verilog-include-file 't) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
10160 (overlay-put ov 'mouse-face 'highlight) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
10161 (overlay-put ov 'local-map verilog-mode-mouse-map))))))) |
79545 | 10162 |
10163 | |
10164 (defun verilog-colorize-include-files-buffer () | |
10165 "Colorize a include file." | |
10166 (interactive) | |
10167 ;; delete overlays | |
10168 (let ((overlays (overlays-in (point-min) (point-max)))) | |
10169 (while overlays | |
10170 (if (and | |
10171 (overlay-get (car overlays) 'detachable) | |
10172 (overlay-get (car overlays) 'verilog-include-file)) | |
10173 (delete-overlay (car overlays))) | |
10174 (setq overlays (cdr overlays)))) ; let | |
10175 ;; remake overlays | |
10176 (verilog-colorize-include-files (point-min) (point-max) nil)) | |
10177 | |
10178 ;; ffap-at-mouse isn't useful for verilog mode. It uses library paths. | |
10179 ;; so define this function to do more or less the same as ffap-at-mouse | |
10180 ;; but first resolve filename... | |
10181 (defun verilog-load-file-at-mouse (event) | |
10182 "Load file under button 2 click's EVENT. | |
10183 Files are checked based on `verilog-library-directories'." | |
10184 (interactive "@e") | |
10185 (save-excursion ;; implement a verilog specific ffap-at-mouse | |
10186 (mouse-set-point event) | |
10187 (beginning-of-line) | |
10188 (if (looking-at verilog-include-file-regexp) | |
10189 (if (and (car (verilog-library-filenames | |
10190 (match-string 1) (buffer-file-name))) | |
10191 (file-readable-p (car (verilog-library-filenames | |
10192 (match-string 1) (buffer-file-name))))) | |
10193 (find-file (car (verilog-library-filenames | |
10194 (match-string 1) (buffer-file-name)))) | |
10195 (progn | |
10196 (message | |
10197 "File '%s' isn't readable, use shift-mouse2 to paste in this field" | |
10198 (match-string 1)))) | |
10199 ))) | |
10200 | |
10201 ;; ffap isn't useable for verilog mode. It uses library paths. | |
10202 ;; so define this function to do more or less the same as ffap | |
10203 ;; but first resolve filename... | |
10204 (defun verilog-load-file-at-point () | |
10205 "Load file under point. | |
10206 Files are checked based on `verilog-library-directories'." | |
10207 (interactive) | |
10208 (save-excursion ;; implement a verilog specific ffap | |
10209 (beginning-of-line) | |
10210 (if (looking-at verilog-include-file-regexp) | |
10211 (if (and | |
10212 (car (verilog-library-filenames | |
10213 (match-string 1) (buffer-file-name))) | |
10214 (file-readable-p (car (verilog-library-filenames | |
10215 (match-string 1) (buffer-file-name))))) | |
10216 (find-file (car (verilog-library-filenames | |
10217 (match-string 1) (buffer-file-name)))))) | |
10218 )) | |
10219 | |
10220 | |
10221 ;; | |
10222 ;; Bug reporting | |
10223 ;; | |
10224 | |
10225 (defun verilog-faq () | |
10226 "Tell the user their current version, and where to get the FAQ etc." | |
10227 (interactive) | |
10228 (with-output-to-temp-buffer "*verilog-mode help*" | |
10229 (princ (format "You are using verilog-mode %s\n" verilog-mode-version)) | |
10230 (princ "\n") | |
10231 (princ "For new releases, see http://www.verilog.com\n") | |
10232 (princ "\n") | |
10233 (princ "For frequently asked questions, see http://www.veripool.com/verilog-mode-faq.html\n") | |
10234 (princ "\n") | |
10235 (princ "To submit a bug, use M-x verilog-submit-bug-report\n") | |
10236 (princ "\n"))) | |
10237 | |
10238 (defun verilog-submit-bug-report () | |
10239 "Submit via mail a bug report on verilog-mode.el." | |
10240 (interactive) | |
10241 (let ((reporter-prompt-for-summary-p t)) | |
10242 (reporter-submit-bug-report | |
10243 "mac@verilog.com" | |
10244 (concat "verilog-mode v" verilog-mode-version) | |
10245 '( | |
10246 verilog-align-ifelse | |
10247 verilog-auto-endcomments | |
10248 verilog-auto-hook | |
10249 verilog-auto-indent-on-newline | |
10250 verilog-auto-inst-vector | |
10251 verilog-auto-inst-template-numbers | |
10252 verilog-auto-lineup | |
10253 verilog-auto-newline | |
10254 verilog-auto-save-policy | |
10255 verilog-auto-sense-defines-constant | |
10256 verilog-auto-sense-include-inputs | |
10257 verilog-before-auto-hook | |
10258 verilog-case-indent | |
10259 verilog-cexp-indent | |
10260 verilog-compiler | |
10261 verilog-coverage | |
10262 verilog-highlight-translate-off | |
10263 verilog-indent-begin-after-if | |
10264 verilog-indent-declaration-macros | |
10265 verilog-indent-level | |
10266 verilog-indent-level-behavioral | |
10267 verilog-indent-level-declaration | |
10268 verilog-indent-level-directive | |
10269 verilog-indent-level-module | |
10270 verilog-indent-lists | |
10271 verilog-library-flags | |
10272 verilog-library-directories | |
10273 verilog-library-extensions | |
10274 verilog-library-files | |
10275 verilog-linter | |
10276 verilog-minimum-comment-distance | |
10277 verilog-mode-hook | |
10278 verilog-simulator | |
10279 verilog-tab-always-indent | |
10280 verilog-tab-to-comment | |
10281 ) | |
10282 nil nil | |
10283 (concat "Hi Mac, | |
10284 | |
10285 I want to report a bug. I've read the `Bugs' section of `Info' on | |
10286 Emacs, so I know how to make a clear and unambiguous report. To get | |
10287 to that Info section, I typed | |
10288 | |
10289 M-x info RET m " invocation-name " RET m bugs RET | |
10290 | |
10291 Before I go further, I want to say that Verilog mode has changed my life. | |
10292 I save so much time, my files are colored nicely, my co workers respect | |
10293 my coding ability... until now. I'd really appreciate anything you | |
10294 could do to help me out with this minor deficiency in the product. | |
10295 | |
10296 If you have bugs with the AUTO functions, please CC the AUTOAUTHOR Wilson | |
10297 Snyder (wsnyder@wsnyder.org) and/or see http://www.veripool.com. | |
10298 You may also want to look at the Verilog-Mode FAQ, see | |
10299 http://www.veripool.com/verilog-mode-faq.html. | |
10300 | |
10301 To reproduce the bug, start a fresh Emacs via " invocation-name " | |
10302 -no-init-file -no-site-file'. In a new buffer, in verilog mode, type | |
10303 the code included below. | |
10304 | |
10305 Given those lines, I expected [[Fill in here]] to happen; | |
10306 but instead, [[Fill in here]] happens!. | |
10307 | |
10308 == The code: ==")))) | |
10309 | |
79546 | 10310 (provide 'verilog-mode) |
10311 | |
79545 | 10312 ;; Local Variables: |
10313 ;; checkdoc-permit-comma-termination-flag:t | |
10314 ;; checkdoc-force-docstrings-flag:nil | |
10315 ;; End: | |
10316 | |
79552 | 10317 ;; arch-tag: 87923725-57b3-41b5-9494-be21118c6a6f |
79545 | 10318 ;;; verilog-mode.el ends here |