Mercurial > emacs
annotate lisp/progmodes/verilog-mode.el @ 92023:97d327ff77e5
*** empty log message ***
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Thu, 21 Feb 2008 07:46:44 +0000 |
parents | 125866467ba5 |
children | 2e44cd9cc88a |
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, | |
79717 | 4 ;; 2005, 2006, 2007, 2008 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 | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
14 ;; This code supports Emacs 21.1 and later |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
15 ;; And XEmacs 21.1 and later |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
16 ;; Please do not make changes that break Emacs 21. Thanks! |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
17 ;; |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
18 ;; |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
19 |
79551 | 20 ;; This file is part of GNU Emacs. |
21 | |
22 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
79545 | 23 ;; it under the terms of the GNU General Public License as published by |
79551 | 24 ;; the Free Software Foundation; either version 3, or (at your option) |
25 ;; any later version. | |
26 | |
27 ;; GNU Emacs is distributed in the hope that it will be useful, | |
79545 | 28 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
29 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
30 ;; GNU General Public License for more details. | |
31 | |
32 ;; You should have received a copy of the GNU General Public License | |
79551 | 33 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
34 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
35 ;; Boston, MA 02110-1301, USA. | |
79545 | 36 |
37 ;;; Commentary: | |
38 | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
39 ;; This mode borrows heavily from the Pascal-mode and the cc-mode of Emacs |
79545 | 40 |
41 ;; USAGE | |
42 ;; ===== | |
43 | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
44 ;; A major mode for editing Verilog HDL source code. When you have |
79545 | 45 ;; entered Verilog mode, you may get more info by pressing C-h m. You |
46 ;; may also get online help describing various functions by: C-h f | |
47 ;; <Name of function you want described> | |
48 | |
49 ;; KNOWN BUGS / BUG REPORTS | |
50 ;; ======================= | |
51 | |
52 ;; Verilog is a rapidly evolving language, and hence this mode is | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
53 ;; under continuous development. Hence this is beta code, and likely |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
54 ;; has bugs. Please report any and all bugs to me at mac@verilog.com. |
79545 | 55 ;; Please use verilog-submit-bug-report to submit a report; type C-c |
56 ;; C-b to invoke this and as a result I will have a much easier time | |
57 ;; of reproducing the bug you find, and hence fixing it. | |
58 | |
59 ;; INSTALLING THE MODE | |
60 ;; =================== | |
61 | |
62 ;; An older version of this mode may be already installed as a part of | |
63 ;; your environment, and one method of updating would be to update | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
64 ;; your Emacs environment. Sometimes this is difficult for local |
79545 | 65 ;; political/control reasons, and hence you can always install a |
66 ;; private copy (or even a shared copy) which overrides the system | |
67 ;; default. | |
68 | |
69 ;; You can get step by step help in installing this file by going to | |
70 ;; <http://www.verilog.com/emacs_install.html> | |
71 | |
72 ;; The short list of installation instructions are: To set up | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
73 ;; automatic Verilog mode, put this file in your load path, and put |
79545 | 74 ;; the following in code (please un comment it first!) in your |
75 ;; .emacs, or in your site's site-load.el | |
76 | |
77 ; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t ) | |
78 ; (setq auto-mode-alist (cons '("\\.v\\'" . verilog-mode) auto-mode-alist)) | |
79 ; (setq auto-mode-alist (cons '("\\.dv\\'" . verilog-mode) auto-mode-alist)) | |
80 | |
81 ;; If you want to customize Verilog mode to fit your needs better, | |
82 ;; you may add these lines (the values of the variables presented | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
83 ;; here are the defaults). Note also that if you use an Emacs that |
79545 | 84 ;; supports custom, it's probably better to use the custom menu to |
85 ;; edit these. | |
86 ;; | |
87 ;; Be sure to examine at the help for verilog-auto, and the other | |
88 ;; verilog-auto-* functions for some major coding time savers. | |
89 ;; | |
90 ; ;; User customization for Verilog mode | |
91 ; (setq verilog-indent-level 3 | |
92 ; verilog-indent-level-module 3 | |
93 ; verilog-indent-level-declaration 3 | |
94 ; verilog-indent-level-behavioral 3 | |
95 ; verilog-indent-level-directive 1 | |
96 ; verilog-case-indent 2 | |
97 ; verilog-auto-newline t | |
98 ; verilog-auto-indent-on-newline t | |
99 ; verilog-tab-always-indent t | |
100 ; verilog-auto-endcomments t | |
101 ; verilog-minimum-comment-distance 40 | |
102 ; verilog-indent-begin-after-if t | |
103 ; verilog-auto-lineup '(all) | |
104 ; verilog-highlight-p1800-keywords nil | |
105 ; verilog-linter "my_lint_shell_command" | |
106 ; ) | |
107 | |
108 ;; | |
109 | |
110 ;;; History: | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
111 ;; |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
112 ;; See commit history at http://www.veripool.com/verilog-mode.html |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
113 ;; (This section is required to appease checkdoc.) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
114 |
79545 | 115 ;;; Code: |
116 | |
117 ;; This variable will always hold the version number of the mode | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
118 (defconst verilog-mode-version "383" |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
119 "Version of this Verilog mode.") |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
120 (defconst verilog-mode-release-date "2008-01-07-GNU" |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
121 "Release date of this Verilog mode.") |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
122 (defconst verilog-mode-release-emacs t |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
123 "If non-nil, this version of Verilog mode was released with Emacs itself.") |
79545 | 124 |
125 (defun verilog-version () | |
126 "Inform caller of the version of this file." | |
127 (interactive) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
128 (message "Using verilog-mode version %s" verilog-mode-version)) |
79545 | 129 |
130 ;; Insure we have certain packages, and deal with it if we don't | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
131 ;; Be sure to note which Emacs flavor and version added each feature. |
79546 | 132 (eval-when-compile |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
133 ;; The below were disabled when GNU Emacs 22 was released; |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
134 ;; perhaps some still need to be there to support Emacs 21. |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
135 (when (featurep 'xemacs) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
136 (condition-case nil |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
137 (require 'easymenu) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
138 (error nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
139 (condition-case nil |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
140 (require 'regexp-opt) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
141 (error nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
142 ;; Bug in 19.28 through 19.30 skeleton.el, not provided. |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
143 (condition-case nil |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
144 (load "skeleton") |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
145 (error nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
146 (condition-case nil |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
147 (if (fboundp 'when) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
148 nil ;; fab |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
149 (defmacro when (cond &rest body) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
150 (list 'if cond (cons 'progn body)))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
151 (error nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
152 (condition-case nil |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
153 (if (fboundp 'unless) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
154 nil ;; fab |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
155 (defmacro unless (cond &rest body) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
156 (cons 'if (cons cond (cons nil body))))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
157 (error nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
158 (condition-case nil |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
159 (if (fboundp 'store-match-data) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
160 nil ;; fab |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
161 (defmacro store-match-data (&rest args) nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
162 (error nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
163 (condition-case nil |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
164 (if (boundp 'current-menubar) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
165 nil ;; great |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
166 (progn |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
167 (defmacro add-submenu (&rest args) nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
168 ) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
169 (error nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
170 (condition-case nil |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
171 (if (fboundp 'char-before) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
172 nil ;; great |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
173 (defmacro char-before (&rest body) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
174 (char-after (1- (point))))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
175 (error nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
176 (condition-case nil |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
177 (require 'custom) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
178 (error nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
179 (condition-case nil |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
180 (if (fboundp 'match-string-no-properties) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
181 nil ;; great |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
182 (defsubst match-string-no-properties (num &optional string) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
183 "Return string of text matched by last search, without text properties. |
79545 | 184 NUM specifies which parenthesized expression in the last regexp. |
185 Value is nil if NUMth pair didn't match, or there were less than NUM pairs. | |
186 Zero means the entire text matched by the whole regexp or whole string. | |
187 STRING should be given if the last search was by `string-match' on STRING." | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
188 (if (match-beginning num) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
189 (if string |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
190 (let ((result |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
191 (substring string |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
192 (match-beginning num) (match-end num)))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
193 (set-text-properties 0 (length result) nil result) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
194 result) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
195 (buffer-substring-no-properties (match-beginning num) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
196 (match-end num) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
197 (current-buffer))))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
198 ) |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
199 (error nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
200 (if (and (featurep 'custom) (fboundp 'custom-declare-variable)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
201 nil ;; We've got what we needed |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
202 ;; We have the old custom-library, hack around it! |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
203 (defmacro defgroup (&rest args) nil) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
204 (defmacro customize (&rest args) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
205 (message |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
206 "Sorry, Customize is not available with this version of Emacs")) |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
207 (defmacro defcustom (var value doc &rest args) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
208 `(defvar ,var ,value ,doc)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
209 ) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
210 (if (fboundp 'defface) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
211 nil ; great! |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
212 (defmacro defface (var values doc &rest args) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
213 `(make-face ,var)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
214 ) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
215 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
216 (if (and (featurep 'custom) (fboundp 'customize-group)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
217 nil ;; We've got what we needed |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
218 ;; We have an intermediate custom-library, hack around it! |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
219 (defmacro customize-group (var &rest args) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
220 `(customize ,var)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
221 ))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
222 |
79545 | 223 ;; Provide a regular expression optimization routine, using regexp-opt |
224 ;; if provided by the user's elisp libraries | |
225 (eval-and-compile | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
226 ;; The below were disabled when GNU Emacs 22 was released; |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
227 ;; perhaps some still need to be there to support Emacs 21. |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
228 (if (featurep 'xemacs) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
229 (if (fboundp 'regexp-opt) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
230 ;; regexp-opt is defined, does it take 3 or 2 arguments? |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
231 (if (fboundp 'function-max-args) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
232 (let ((args (function-max-args `regexp-opt))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
233 (cond |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
234 ((eq args 3) ;; It takes 3 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
235 (condition-case nil ; Hide this defun from emacses |
79545 | 236 ;with just a two input regexp |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
237 (defun verilog-regexp-opt (a b) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
238 "Deal with differing number of required arguments for `regexp-opt'. |
79545 | 239 Call 'regexp-opt' on A and B." |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
240 (regexp-opt a b 't)) |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
241 (error nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
242 ) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
243 ((eq args 2) ;; It takes 2 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
244 (defun verilog-regexp-opt (a b) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
245 "Call 'regexp-opt' on A and B." |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
246 (regexp-opt a b)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
247 ) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
248 (t nil))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
249 ;; We can't tell; assume it takes 2 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
250 (defun verilog-regexp-opt (a b) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
251 "Call 'regexp-opt' on A and B." |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
252 (regexp-opt a b)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
253 ) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
254 ;; There is no regexp-opt, provide our own |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
255 (defun verilog-regexp-opt (strings &optional paren shy) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
256 (let ((open (if paren "\\(" "")) (close (if paren "\\)" ""))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
257 (concat open (mapconcat 'regexp-quote strings "\\|") close))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
258 ) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
259 ;; Emacs. |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
260 (defalias 'verilog-regexp-opt 'regexp-opt))) |
79545 | 261 |
79555
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
262 (eval-when-compile |
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
263 (defun verilog-regexp-words (a) |
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
264 "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
|
265 (concat "\\<" (verilog-regexp-opt a t) "\\>"))) |
79545 | 266 |
267 (defun verilog-customize () | |
268 "Link to customize screen for Verilog." | |
269 (interactive) | |
270 (customize-group 'verilog-mode)) | |
271 | |
272 (defun verilog-font-customize () | |
273 "Link to customize fonts used for Verilog." | |
274 (interactive) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
275 (if (fboundp 'customize-apropos) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
276 (customize-apropos "font-lock-*" 'faces))) |
79545 | 277 |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
278 (defun verilog-booleanp (value) |
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
279 "Return t if VALUE is boolean. |
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
280 This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs. |
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
281 This function may be removed when Emacs 21 is no longer supported." |
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
282 (or (equal value t) (equal value nil))) |
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
283 |
79545 | 284 (defgroup verilog-mode nil |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
285 "Facilitates easy editing of Verilog source text." |
79545 | 286 :group 'languages) |
287 | |
288 ; (defgroup verilog-mode-fonts nil | |
289 ; "Facilitates easy customization fonts used in Verilog source text" | |
290 ; :link '(customize-apropos "font-lock-*" 'faces) | |
291 ; :group 'verilog-mode) | |
292 | |
293 (defgroup verilog-mode-indent nil | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
294 "Customize indentation and highlighting of Verilog source text." |
79545 | 295 :group 'verilog-mode) |
296 | |
297 (defgroup verilog-mode-actions nil | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
298 "Customize actions on Verilog source text." |
79545 | 299 :group 'verilog-mode) |
300 | |
301 (defgroup verilog-mode-auto nil | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
302 "Customize AUTO actions when expanding Verilog source text." |
79545 | 303 :group 'verilog-mode) |
304 | |
305 (defcustom verilog-linter | |
306 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'" | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
307 "*Unix program and arguments to call to run a lint checker on Verilog source. |
79545 | 308 Depending on the `verilog-set-compile-command', this may be invoked when |
309 you type \\[compile]. When the compile completes, \\[next-error] will take | |
310 you to the next lint error." | |
311 :type 'string | |
312 :group 'verilog-mode-actions) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
313 ;; We don't mark it safe, as it's used as a shell command |
79545 | 314 |
315 (defcustom verilog-coverage | |
316 "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'" | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
317 "*Program and arguments to use to annotate for coverage Verilog source. |
79545 | 318 Depending on the `verilog-set-compile-command', this may be invoked when |
319 you type \\[compile]. When the compile completes, \\[next-error] will take | |
320 you to the next lint error." | |
321 :type 'string | |
322 :group 'verilog-mode-actions) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
323 ;; We don't mark it safe, as it's used as a shell command |
79545 | 324 |
325 (defcustom verilog-simulator | |
326 "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'" | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
327 "*Program and arguments to use to interpret Verilog source. |
79545 | 328 Depending on the `verilog-set-compile-command', this may be invoked when |
329 you type \\[compile]. When the compile completes, \\[next-error] will take | |
330 you to the next lint error." | |
331 :type 'string | |
332 :group 'verilog-mode-actions) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
333 ;; We don't mark it safe, as it's used as a shell command |
79545 | 334 |
335 (defcustom verilog-compiler | |
336 "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'" | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
337 "*Program and arguments to use to compile Verilog source. |
79545 | 338 Depending on the `verilog-set-compile-command', this may be invoked when |
339 you type \\[compile]. When the compile completes, \\[next-error] will take | |
340 you to the next lint error." | |
341 :type 'string | |
342 :group 'verilog-mode-actions) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
343 ;; We don't mark it safe, as it's used as a shell command |
79545 | 344 |
345 (defvar verilog-tool 'verilog-linter | |
346 "Which tool to use for building compiler-command. | |
347 Either nil, `verilog-linter, `verilog-coverage, `verilog-simulator, or | |
348 `verilog-compiler. Alternatively use the \"Choose Compilation Action\" | |
349 menu. See `verilog-set-compile-command' for more information.") | |
350 | |
351 (defcustom verilog-highlight-translate-off nil | |
352 "*Non-nil means background-highlight code excluded from translation. | |
353 That is, all code between \"// synopsys translate_off\" and | |
354 \"// synopsys translate_on\" is highlighted using a different background color | |
355 \(face `verilog-font-lock-translate-off-face'). | |
356 | |
357 Note: This will slow down on-the-fly fontification (and thus editing). | |
358 | |
359 Note: Activate the new setting in a Verilog buffer by re-fontifying it (menu | |
360 entry \"Fontify Buffer\"). XEmacs: turn off and on font locking." | |
361 :type 'boolean | |
362 :group 'verilog-mode-indent) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
363 ;; Note we don't use :safe, as that would break on Emacsen before 22.0. |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
364 (put 'verilog-highlight-translate-off 'safe-local-variable 'verilog-booleanp) |
79545 | 365 |
366 (defcustom verilog-indent-level 3 | |
367 "*Indentation of Verilog statements with respect to containing block." | |
368 :group 'verilog-mode-indent | |
369 :type 'integer) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
370 (put 'verilog-indent-level 'safe-local-variable 'integerp) |
79545 | 371 |
372 (defcustom verilog-indent-level-module 3 | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
373 "*Indentation of Module level Verilog statements (eg always, initial). |
79545 | 374 Set to 0 to get initial and always statements lined up on the left side of |
375 your screen." | |
376 :group 'verilog-mode-indent | |
377 :type 'integer) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
378 (put 'verilog-indent-level-module 'safe-local-variable 'integerp) |
79545 | 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) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
385 (put 'verilog-indent-level-declaration 'safe-local-variable 'integerp) |
79545 | 386 |
387 (defcustom verilog-indent-declaration-macros nil | |
388 "*How to treat macro expansions in a declaration. | |
389 If nil, indent as: | |
390 input [31:0] a; | |
391 input `CP; | |
392 output c; | |
393 If non nil, treat as: | |
394 input [31:0] a; | |
395 input `CP ; | |
396 output c;" | |
397 :group 'verilog-mode-indent | |
398 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
399 (put 'verilog-indent-declaration-macros 'safe-local-variable 'verilog-booleanp) |
79545 | 400 |
401 (defcustom verilog-indent-lists t | |
402 "*How to treat indenting items in a list. | |
403 If t (the default), indent as: | |
404 always @( posedge a or | |
405 reset ) begin | |
406 | |
407 If nil, treat as: | |
408 always @( posedge a or | |
409 reset ) begin" | |
410 :group 'verilog-mode-indent | |
411 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
412 (put 'verilog-indent-lists 'safe-local-variable 'verilog-booleanp) |
79545 | 413 |
414 (defcustom verilog-indent-level-behavioral 3 | |
415 "*Absolute indentation of first begin in a task or function block. | |
416 Set to 0 to get such code to start at the left side of the screen." | |
417 :group 'verilog-mode-indent | |
418 :type 'integer) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
419 (put 'verilog-indent-level-behavioral 'safe-local-variable 'integerp) |
79545 | 420 |
421 (defcustom verilog-indent-level-directive 1 | |
422 "*Indentation to add to each level of `ifdef declarations. | |
423 Set to 0 to have all directives start at the left side of the screen." | |
424 :group 'verilog-mode-indent | |
425 :type 'integer) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
426 (put 'verilog-indent-level-directive 'safe-local-variable 'integerp) |
79545 | 427 |
428 (defcustom verilog-cexp-indent 2 | |
429 "*Indentation of Verilog statements split across lines." | |
430 :group 'verilog-mode-indent | |
431 :type 'integer) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
432 (put 'verilog-cexp-indent 'safe-local-variable 'integerp) |
79545 | 433 |
434 (defcustom verilog-case-indent 2 | |
435 "*Indentation for case statements." | |
436 :group 'verilog-mode-indent | |
437 :type 'integer) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
438 (put 'verilog-case-indent 'safe-local-variable 'integerp) |
79545 | 439 |
440 (defcustom verilog-auto-newline t | |
441 "*True means automatically newline after semicolons." | |
442 :group 'verilog-mode-indent | |
443 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
444 (put 'verilog-auto-newline 'safe-local-variable 'verilog-booleanp) |
79545 | 445 |
446 (defcustom verilog-auto-indent-on-newline t | |
447 "*True means automatically indent line after newline." | |
448 :group 'verilog-mode-indent | |
449 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
450 (put 'verilog-auto-indent-on-newline 'safe-local-variable 'verilog-booleanp) |
79545 | 451 |
452 (defcustom verilog-tab-always-indent t | |
453 "*True means TAB should always re-indent the current line. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
454 A nil value means TAB will only reindent when at the beginning of the line." |
79545 | 455 :group 'verilog-mode-indent |
456 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
457 (put 'verilog-tab-always-indent 'safe-local-variable 'verilog-booleanp) |
79545 | 458 |
459 (defcustom verilog-tab-to-comment nil | |
460 "*True means TAB moves to the right hand column in preparation for a comment." | |
461 :group 'verilog-mode-actions | |
462 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
463 (put 'verilog-tab-to-comment 'safe-local-variable 'verilog-booleanp) |
79545 | 464 |
465 (defcustom verilog-indent-begin-after-if t | |
466 "*If true, indent begin statements following if, else, while, for and repeat. | |
467 Otherwise, line them up." | |
468 :group 'verilog-mode-indent | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
469 :type 'boolean) |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
470 (put 'verilog-indent-begin-after-if 'safe-local-variable 'verilog-booleanp) |
79545 | 471 |
472 | |
473 (defcustom verilog-align-ifelse nil | |
474 "*If true, align `else' under matching `if'. | |
475 Otherwise else is lined up with first character on line holding matching if." | |
476 :group 'verilog-mode-indent | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
477 :type 'boolean) |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
478 (put 'verilog-align-ifelse 'safe-local-variable 'verilog-booleanp) |
79545 | 479 |
480 (defcustom verilog-minimum-comment-distance 10 | |
481 "*Minimum distance (in lines) between begin and end required before a comment. | |
482 Setting this variable to zero results in every end acquiring a comment; the | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
483 default avoids too many redundant comments in tight quarters." |
79545 | 484 :group 'verilog-mode-indent |
485 :type 'integer) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
486 (put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp) |
79545 | 487 |
488 (defcustom verilog-auto-lineup '(declaration) | |
489 "*Algorithm for lining up statements on multiple lines. | |
490 | |
491 If this list contains the symbol 'all', then all line ups described below | |
492 are done. | |
493 | |
494 If this list contains the symbol 'declaration', then declarations are lined up | |
495 with any preceding declarations, taking into account widths and the like, so | |
496 for example the code: | |
497 reg [31:0] a; | |
498 reg b; | |
499 would become | |
500 reg [31:0] a; | |
501 reg b; | |
502 | |
503 If this list contains the symbol 'assignment', then assignments are lined up | |
504 with any preceding assignments, so for example the code | |
505 a_long_variable = b + c; | |
506 d = e + f; | |
507 would become | |
508 a_long_variable = b + c; | |
509 d = e + f;" | |
510 | |
511 ;; The following is not implemented: | |
512 ;If this list contains the symbol 'case', then case items are lined up | |
513 ;with any preceding case items, so for example the code | |
514 ; case (a) begin | |
515 ; a_long_state : a = 3; | |
516 ; b: a = 4; | |
517 ; endcase | |
518 ;would become | |
519 ; case (a) begin | |
520 ; a_long_state : a = 3; | |
521 ; b : a = 4; | |
522 ; endcase | |
523 ; | |
524 | |
525 :group 'verilog-mode-indent | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
526 :type 'list) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
527 (put 'verilog-auto-lineup 'safe-local-variable 'listp) |
79545 | 528 |
529 (defcustom verilog-highlight-p1800-keywords nil | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
530 "*True means highlight words newly reserved by IEEE-1800. |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
531 These will appear in `verilog-font-lock-p1800-face' in order to gently |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
532 suggest changing where these words are used as variables to something else. |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
533 A nil value means highlight these words as appropriate for the SystemVerilog |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
534 IEEE-1800 standard. Note that changing this will require restarting Emacs |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
535 to see the effect as font color choices are cached by Emacs." |
79545 | 536 :group 'verilog-mode-indent |
537 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
538 (put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp) |
79545 | 539 |
540 (defcustom verilog-auto-endcomments t | |
541 "*True means insert a comment /* ... */ after 'end's. | |
542 The name of the function or case will be set between the braces." | |
543 :group 'verilog-mode-actions | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
544 :type 'boolean) |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
545 (put 'verilog-auto-endcomments 'safe-local-variable 'verilog-booleanp) |
79545 | 546 |
547 (defcustom verilog-auto-read-includes nil | |
548 "*True means to automatically read includes before AUTOs. | |
549 This will do a `verilog-read-defines' and `verilog-read-includes' before | |
550 each AUTO expansion. This makes it easier to embed defines and includes, | |
551 but can result in very slow reading times if there are many or large | |
552 include files." | |
553 :group 'verilog-mode-actions | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
554 :type 'boolean) |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
555 (put 'verilog-auto-read-includes 'safe-local-variable 'verilog-booleanp) |
79545 | 556 |
557 (defcustom verilog-auto-save-policy nil | |
558 "*Non-nil indicates action to take when saving a Verilog buffer with AUTOs. | |
559 A value of `force' will always do a \\[verilog-auto] automatically if | |
560 needed on every save. A value of `detect' will do \\[verilog-auto] | |
561 automatically when it thinks necessary. A value of `ask' will query the | |
562 user when it thinks updating is needed. | |
563 | |
564 You should not rely on the 'ask or 'detect policies, they are safeguards | |
565 only. They do not detect when AUTOINSTs need to be updated because a | |
566 sub-module's port list has changed." | |
567 :group 'verilog-mode-actions | |
568 :type '(choice (const nil) (const ask) (const detect) (const force))) | |
569 | |
570 (defcustom verilog-auto-star-expand t | |
571 "*Non-nil indicates to expand a SystemVerilog .* instance ports. | |
572 They will be expanded in the same way as if there was a AUTOINST in the | |
573 instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'." | |
574 :group 'verilog-mode-actions | |
575 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
576 (put 'verilog-auto-star-expand 'safe-local-variable 'verilog-booleanp) |
79545 | 577 |
578 (defcustom verilog-auto-star-save nil | |
579 "*Non-nil indicates to save to disk SystemVerilog .* instance expansions. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
580 A nil value indicates direct connections will be removed before saving. |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
581 Only meaningful to those created due to `verilog-auto-star-expand' being set. |
79545 | 582 |
583 Instead of setting this, you may want to use /*AUTOINST*/, which will | |
584 always be saved." | |
585 :group 'verilog-mode-actions | |
586 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
587 (put 'verilog-auto-star-save 'safe-local-variable 'verilog-booleanp) |
79545 | 588 |
589 (defvar verilog-auto-update-tick nil | |
590 "Modification tick at which autos were last performed.") | |
591 | |
592 (defvar verilog-auto-last-file-locals nil | |
593 "Text from file-local-variables during last evaluation.") | |
594 | |
595 (defvar verilog-error-regexp-add-didit nil) | |
596 (defvar verilog-error-regexp nil) | |
597 (setq verilog-error-regexp-add-didit nil | |
598 verilog-error-regexp | |
599 '( | |
600 ; SureLint | |
601 ;; ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2) | |
602 ; Most SureFire tools | |
603 ("\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\), \\(line \\|\\)\\([0-9]+\\):" 2 4 ) | |
604 ("\ | |
605 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\ | |
606 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5) | |
607 ; xsim | |
608 ; Error! in file /homes/mac/Axis/Xsim/test.v at line 13 [OBJ_NOT_DECLARED] | |
609 ("\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3) | |
610 ; vcs | |
611 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3) | |
612 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2) | |
613 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3) | |
614 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2) | |
615 ; Verilator | |
616 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4) | |
617 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4) | |
618 ; vxl | |
619 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3) | |
620 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 1 2) ; vxl | |
621 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 1 2) | |
622 ; nc-verilog | |
623 (".*\\*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 1 2) | |
624 ; Leda | |
625 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 1 2) | |
626 ) | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
627 ; "*List of regexps for Verilog compilers, like verilint. See compilation-error-regexp-alist for the formatting." |
79545 | 628 ) |
629 | |
630 (defvar verilog-error-font-lock-keywords | |
631 '( | |
632 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t) | |
633 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t) | |
634 | |
635 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t) | |
636 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t) | |
637 | |
638 ("\ | |
639 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\ | |
640 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t) | |
641 ("\ | |
642 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\ | |
643 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t) | |
644 | |
645 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t) | |
646 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t) | |
647 | |
648 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t) | |
649 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t) | |
650 | |
651 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t) | |
652 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t) | |
653 | |
654 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t) | |
655 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t) | |
656 | |
657 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t) | |
658 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t) | |
659 ; vxl | |
660 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t) | |
661 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t) | |
662 | |
663 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 1 bold t) | |
664 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 2 bold t) | |
665 | |
666 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 1 bold t) | |
667 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 2 bold t) | |
668 ; nc-verilog | |
669 (".*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 1 bold t) | |
670 (".*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t) | |
671 ; Leda | |
672 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 1 bold t) | |
673 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 2 bold t) | |
674 ) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
675 "*Keywords to also highlight in Verilog *compilation* buffers.") |
79545 | 676 |
677 (defcustom verilog-library-flags '("") | |
678 "*List of standard Verilog arguments to use for /*AUTOINST*/. | |
679 These arguments are used to find files for `verilog-auto', and match | |
680 the flags accepted by a standard Verilog-XL simulator. | |
681 | |
682 -f filename Reads more `verilog-library-flags' from the filename. | |
683 +incdir+dir Adds the directory to `verilog-library-directories'. | |
684 -Idir Adds the directory to `verilog-library-directories'. | |
685 -y dir Adds the directory to `verilog-library-directories'. | |
686 +libext+.v Adds the extensions to `verilog-library-extensions'. | |
687 -v filename Adds the filename to `verilog-library-files'. | |
688 | |
689 filename Adds the filename to `verilog-library-files'. | |
690 This is not recommended, -v is a better choice. | |
691 | |
692 You might want these defined in each file; put at the *END* of your file | |
693 something like: | |
694 | |
695 // Local Variables: | |
696 // verilog-library-flags:(\"-y dir -y otherdir\") | |
697 // End: | |
698 | |
699 Verilog-mode attempts to detect changes to this local variable, but they | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
700 are only insured to be correct when the file is first visited. Thus if you |
79545 | 701 have problems, use \\[find-alternate-file] RET to have these take effect. |
702 | |
703 See also the variables mentioned above." | |
704 :group 'verilog-mode-auto | |
705 :type '(repeat string)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
706 (put 'verilog-library-flags 'safe-local-variable 'listp) |
79545 | 707 |
708 (defcustom verilog-library-directories '(".") | |
709 "*List of directories when looking for files for /*AUTOINST*/. | |
710 The directory may be relative to the current file, or absolute. | |
711 Environment variables are also expanded in the directory names. | |
712 Having at least the current directory is a good idea. | |
713 | |
714 You might want these defined in each file; put at the *END* of your file | |
715 something like: | |
716 | |
717 // Local Variables: | |
718 // verilog-library-directories:(\".\" \"subdir\" \"subdir2\") | |
719 // End: | |
720 | |
721 Verilog-mode attempts to detect changes to this local variable, but they | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
722 are only insured to be correct when the file is first visited. Thus if you |
79545 | 723 have problems, use \\[find-alternate-file] RET to have these take effect. |
724 | |
725 See also `verilog-library-flags', `verilog-library-files' | |
726 and `verilog-library-extensions'." | |
727 :group 'verilog-mode-auto | |
728 :type '(repeat file)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
729 (put 'verilog-library-directories 'safe-local-variable 'listp) |
79545 | 730 |
731 (defcustom verilog-library-files '() | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
732 "*List of files to search for modules. |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
733 AUTOINST will use this when it needs to resolve a module name. |
79545 | 734 This is a complete path, usually to a technology file with many standard |
735 cells defined in it. | |
736 | |
737 You might want these defined in each file; put at the *END* of your file | |
738 something like: | |
739 | |
740 // Local Variables: | |
741 // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\") | |
742 // End: | |
743 | |
744 Verilog-mode attempts to detect changes to this local variable, but they | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
745 are only insured to be correct when the file is first visited. Thus if you |
79545 | 746 have problems, use \\[find-alternate-file] RET to have these take effect. |
747 | |
748 See also `verilog-library-flags', `verilog-library-directories'." | |
749 :group 'verilog-mode-auto | |
750 :type '(repeat directory)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
751 (put 'verilog-library-files 'safe-local-variable 'listp) |
79545 | 752 |
753 (defcustom verilog-library-extensions '(".v") | |
754 "*List of extensions to use when looking for files for /*AUTOINST*/. | |
755 See also `verilog-library-flags', `verilog-library-directories'." | |
756 :type '(repeat string) | |
757 :group 'verilog-mode-auto) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
758 (put 'verilog-library-extensions 'safe-local-variable 'listp) |
79545 | 759 |
760 (defcustom verilog-active-low-regexp nil | |
761 "*If set, treat signals matching this regexp as active low. | |
762 This is used for AUTORESET and AUTOTIEOFF. For proper behavior, | |
763 you will probably also need `verilog-auto-reset-widths' set." | |
764 :group 'verilog-mode-auto | |
765 :type 'string) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
766 (put 'verilog-active-low-regexp 'safe-local-variable 'stringp) |
79545 | 767 |
768 (defcustom verilog-auto-sense-include-inputs nil | |
769 "*If true, AUTOSENSE should include all inputs. | |
770 If nil, only inputs that are NOT output signals in the same block are | |
771 included." | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
772 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
773 :type 'boolean) |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
774 (put 'verilog-auto-sense-include-inputs 'safe-local-variable 'verilog-booleanp) |
79545 | 775 |
776 (defcustom verilog-auto-sense-defines-constant nil | |
777 "*If true, AUTOSENSE should assume all defines represent constants. | |
778 When true, the defines will not be included in sensitivity lists. To | |
779 maintain compatibility with other sites, this should be set at the bottom | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
780 of each Verilog file that requires it, rather than being set globally." |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
781 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
782 :type 'boolean) |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
783 (put 'verilog-auto-sense-defines-constant 'safe-local-variable 'verilog-booleanp) |
79545 | 784 |
785 (defcustom verilog-auto-reset-widths t | |
786 "*If true, AUTORESET should determine the width of signals. | |
787 This is then used to set the width of the zero (32'h0 for example). This | |
788 is required by some lint tools that aren't smart enough to ignore widths of | |
789 the constant zero. This may result in ugly code when parameters determine | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
790 the MSB or LSB of a signal inside an AUTORESET." |
79545 | 791 :type 'boolean |
792 :group 'verilog-mode-auto) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
793 (put 'verilog-auto-reset-widths 'safe-local-variable 'verilog-booleanp) |
79545 | 794 |
795 (defcustom verilog-assignment-delay "" | |
796 "*Text used for delays in delayed assignments. Add a trailing space if set." | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
797 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
798 :type 'string) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
799 (put 'verilog-assignment-delay 'safe-local-variable 'stringp) |
79545 | 800 |
801 (defcustom verilog-auto-inst-vector t | |
802 "*If true, when creating default ports with AUTOINST, use bus subscripts. | |
803 If nil, skip the subscript when it matches the entire bus as declared in | |
804 the module (AUTOWIRE signals always are subscripted, you must manually | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
805 declare the wire to have the subscripts removed.) Setting this to nil may |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
806 speed up some simulators, but is less general and harder to read, so avoid." |
79545 | 807 :group 'verilog-mode-auto |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
808 :type 'boolean) |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
809 (put 'verilog-auto-inst-vector 'safe-local-variable 'verilog-booleanp) |
79545 | 810 |
811 (defcustom verilog-auto-inst-template-numbers nil | |
812 "*If true, when creating templated ports with AUTOINST, add a comment. | |
813 The comment will add the line number of the template that was used for that | |
814 port declaration. Setting this aids in debugging, but nil is suggested for | |
815 regular use to prevent large numbers of merge conflicts." | |
816 :group 'verilog-mode-auto | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
817 :type 'boolean) |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
818 (put 'verilog-auto-inst-template-numbers 'safe-local-variable 'verilog-booleanp) |
79545 | 819 |
820 (defvar verilog-auto-inst-column 40 | |
821 "Column number for first part of auto-inst.") | |
822 | |
823 (defcustom verilog-auto-input-ignore-regexp nil | |
824 "*If set, when creating AUTOINPUT list, ignore signals matching this regexp. | |
825 See the \\[verilog-faq] for examples on using this." | |
826 :group 'verilog-mode-auto | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
827 :type 'string) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
828 (put 'verilog-auto-input-ignore-regexp 'safe-local-variable 'stringp) |
79545 | 829 |
830 (defcustom verilog-auto-inout-ignore-regexp nil | |
831 "*If set, when creating AUTOINOUT list, ignore signals matching this regexp. | |
832 See the \\[verilog-faq] for examples on using this." | |
833 :group 'verilog-mode-auto | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
834 :type 'string) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
835 (put 'verilog-auto-inout-ignore-regexp 'safe-local-variable 'stringp) |
79545 | 836 |
837 (defcustom verilog-auto-output-ignore-regexp nil | |
838 "*If set, when creating AUTOOUTPUT list, ignore signals matching this regexp. | |
839 See the \\[verilog-faq] for examples on using this." | |
840 :group 'verilog-mode-auto | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
841 :type 'string) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
842 (put 'verilog-auto-output-ignore-regexp 'safe-local-variable 'stringp) |
79545 | 843 |
844 (defcustom verilog-auto-unused-ignore-regexp nil | |
845 "*If set, when creating AUTOUNUSED list, ignore signals matching this regexp. | |
846 See the \\[verilog-faq] for examples on using this." | |
847 :group 'verilog-mode-auto | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
848 :type 'string) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
849 (put 'verilog-auto-unused-ignore-regexp 'safe-local-variable 'stringp) |
79545 | 850 |
851 (defcustom verilog-typedef-regexp nil | |
852 "*If non-nil, regular expression that matches Verilog-2001 typedef names. | |
853 For example, \"_t$\" matches typedefs named with _t, as in the C language." | |
854 :group 'verilog-mode-auto | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
855 :type 'string) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
856 (put 'verilog-typedef-regexp 'safe-local-variable 'stringp) |
79545 | 857 |
858 (defcustom verilog-mode-hook 'verilog-set-compile-command | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
859 "*Hook run after Verilog mode is loaded." |
79545 | 860 :type 'hook |
861 :group 'verilog-mode) | |
862 | |
863 (defcustom verilog-auto-hook nil | |
864 "*Hook run after `verilog-mode' updates AUTOs." | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
865 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
866 :type 'hook) |
79545 | 867 |
868 (defcustom verilog-before-auto-hook nil | |
869 "*Hook run before `verilog-mode' updates AUTOs." | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
870 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
871 :type 'hook) |
79545 | 872 |
873 (defcustom verilog-delete-auto-hook nil | |
874 "*Hook run after `verilog-mode' deletes AUTOs." | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
875 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
876 :type 'hook) |
79545 | 877 |
878 (defcustom verilog-before-delete-auto-hook nil | |
879 "*Hook run before `verilog-mode' deletes AUTOs." | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
880 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
881 :type 'hook) |
79545 | 882 |
883 (defcustom verilog-getopt-flags-hook nil | |
884 "*Hook run after `verilog-getopt-flags' determines the Verilog option lists." | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
885 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
886 :type 'hook) |
79545 | 887 |
888 (defcustom verilog-before-getopt-flags-hook nil | |
889 "*Hook run before `verilog-getopt-flags' determines the Verilog option lists." | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
890 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
891 :type 'hook) |
79545 | 892 |
893 (defvar verilog-imenu-generic-expression | |
894 '((nil "^\\s-*\\(\\(m\\(odule\\|acromodule\\)\\)\\|primitive\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 4) | |
895 ("*Vars*" "^\\s-*\\(reg\\|wire\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3)) | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
896 "Imenu expression for Verilog mode. See `imenu-generic-expression'.") |
79545 | 897 |
898 ;; | |
899 ;; provide a verilog-header function. | |
900 ;; Customization variables: | |
901 ;; | |
902 (defvar verilog-date-scientific-format nil | |
903 "*If non-nil, dates are written in scientific format (e.g. 1997/09/17). | |
904 If nil, in European format (e.g. 17.09.1997). The brain-dead American | |
905 format (e.g. 09/17/1997) is not supported.") | |
906 | |
907 (defvar verilog-company nil | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
908 "*Default name of Company for Verilog header. |
79545 | 909 If set will become buffer local.") |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
910 (make-variable-buffer-local 'verilog-company) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
911 |
79545 | 912 (defvar verilog-project nil |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
913 "*Default name of Project for Verilog header. |
79545 | 914 If set will become buffer local.") |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
915 (make-variable-buffer-local 'verilog-project) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
916 |
79549
d9595ed9b084
* progmodes/verilog-mode.el (verilog-mode-map): Fix typo.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79547
diff
changeset
|
917 (defvar verilog-mode-map |
79546 | 918 (let ((map (make-sparse-keymap))) |
919 (define-key map ";" 'electric-verilog-semi) | |
920 (define-key map [(control 59)] 'electric-verilog-semi-with-comment) | |
921 (define-key map ":" 'electric-verilog-colon) | |
922 ;;(define-key map "=" 'electric-verilog-equal) | |
923 (define-key map "\`" 'electric-verilog-tick) | |
924 (define-key map "\t" 'electric-verilog-tab) | |
925 (define-key map "\r" 'electric-verilog-terminate-line) | |
926 ;; backspace/delete key bindings | |
927 (define-key map [backspace] 'backward-delete-char-untabify) | |
928 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable | |
929 (define-key map [delete] 'delete-char) | |
930 (define-key map [(meta delete)] 'kill-word)) | |
931 (define-key map "\M-\C-b" 'electric-verilog-backward-sexp) | |
932 (define-key map "\M-\C-f" 'electric-verilog-forward-sexp) | |
933 (define-key map "\M-\r" `electric-verilog-terminate-and-indent) | |
934 (define-key map "\M-\t" 'verilog-complete-word) | |
935 (define-key map "\M-?" 'verilog-show-completions) | |
936 (define-key map "\C-c\`" 'verilog-lint-off) | |
937 (define-key map "\C-c\*" 'verilog-delete-auto-star-implicit) | |
938 (define-key map "\C-c\C-r" 'verilog-label-be) | |
939 (define-key map "\C-c\C-i" 'verilog-pretty-declarations) | |
940 (define-key map "\C-c=" 'verilog-pretty-expr) | |
941 (define-key map "\C-c\C-b" 'verilog-submit-bug-report) | |
942 (define-key map "\M-*" 'verilog-star-comment) | |
943 (define-key map "\C-c\C-c" 'verilog-comment-region) | |
944 (define-key map "\C-c\C-u" 'verilog-uncomment-region) | |
79810
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
945 (when (featurep 'xemacs) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
946 (define-key map [(meta control h)] 'verilog-mark-defun) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
947 (define-key map "\M-\C-a" 'verilog-beg-of-defun) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
948 (define-key map "\M-\C-e" 'verilog-end-of-defun)) |
79546 | 949 (define-key map "\C-c\C-d" 'verilog-goto-defun) |
950 (define-key map "\C-c\C-k" 'verilog-delete-auto) | |
951 (define-key map "\C-c\C-a" 'verilog-auto) | |
952 (define-key map "\C-c\C-s" 'verilog-auto-save-compile) | |
953 (define-key map "\C-c\C-z" 'verilog-inject-auto) | |
954 (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
|
955 (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
|
956 map) |
79545 | 957 "Keymap used in Verilog mode.") |
958 | |
959 ;; menus | |
960 (defvar verilog-xemacs-menu | |
79810
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
961 `("Verilog" |
79545 | 962 ("Choose Compilation Action" |
963 ["None" | |
964 (progn | |
965 (setq verilog-tool nil) | |
966 (verilog-set-compile-command)) | |
967 :style radio | |
968 :selected (equal verilog-tool nil)] | |
969 ["Lint" | |
970 (progn | |
971 (setq verilog-tool 'verilog-linter) | |
972 (verilog-set-compile-command)) | |
973 :style radio | |
974 :selected (equal verilog-tool `verilog-linter)] | |
975 ["Coverage" | |
976 (progn | |
977 (setq verilog-tool 'verilog-coverage) | |
978 (verilog-set-compile-command)) | |
979 :style radio | |
980 :selected (equal verilog-tool `verilog-coverage)] | |
981 ["Simulator" | |
982 (progn | |
983 (setq verilog-tool 'verilog-simulator) | |
984 (verilog-set-compile-command)) | |
985 :style radio | |
986 :selected (equal verilog-tool `verilog-simulator)] | |
987 ["Compiler" | |
988 (progn | |
989 (setq verilog-tool 'verilog-compiler) | |
990 (verilog-set-compile-command)) | |
991 :style radio | |
992 :selected (equal verilog-tool `verilog-compiler)] | |
993 ) | |
994 ("Move" | |
79810
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
995 ,(if (featurep 'xemacs) |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
996 (progn |
79810
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
997 ["Beginning of function" verilog-beg-of-defun t] |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
998 ["End of function" verilog-end-of-defun t] |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
999 ["Mark function" verilog-mark-defun t]) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1000 ["Beginning of function" beginning-of-defun t] |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1001 ["End of function" end-of-defun t] |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1002 ["Mark function" mark-defun t]) |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
1003 |
79545 | 1004 ["Goto function/module" verilog-goto-defun t] |
1005 ["Move to beginning of block" electric-verilog-backward-sexp t] | |
1006 ["Move to end of block" electric-verilog-forward-sexp t] | |
1007 ) | |
1008 ("Comments" | |
1009 ["Comment Region" verilog-comment-region t] | |
1010 ["UnComment Region" verilog-uncomment-region t] | |
1011 ["Multi-line comment insert" verilog-star-comment t] | |
1012 ["Lint error to comment" verilog-lint-off t] | |
1013 ) | |
1014 "----" | |
1015 ["Compile" compile t] | |
1016 ["AUTO, Save, Compile" verilog-auto-save-compile t] | |
1017 ["Next Compile Error" next-error t] | |
1018 ["Ignore Lint Warning at point" verilog-lint-off t] | |
1019 "----" | |
1020 ["Line up declarations around point" verilog-pretty-declarations t] | |
1021 ["Line up equations around point" verilog-pretty-expr t] | |
1022 ["Redo/insert comments on every end" verilog-label-be t] | |
1023 ["Expand [x:y] vector line" verilog-expand-vector t] | |
1024 ["Insert begin-end block" verilog-insert-block t] | |
1025 ["Complete word" verilog-complete-word t] | |
1026 "----" | |
1027 ["Recompute AUTOs" verilog-auto t] | |
1028 ["Kill AUTOs" verilog-delete-auto t] | |
1029 ["Inject AUTOs" verilog-inject-auto t] | |
1030 ("AUTO Help..." | |
1031 ["AUTO General" (describe-function 'verilog-auto) t] | |
1032 ["AUTO Library Flags" (describe-variable 'verilog-library-flags) t] | |
1033 ["AUTO Library Path" (describe-variable 'verilog-library-directories) t] | |
1034 ["AUTO Library Files" (describe-variable 'verilog-library-files) t] | |
1035 ["AUTO Library Extensions" (describe-variable 'verilog-library-extensions) t] | |
1036 ["AUTO `define Reading" (describe-function 'verilog-read-defines) t] | |
1037 ["AUTO `include Reading" (describe-function 'verilog-read-includes) t] | |
1038 ["AUTOARG" (describe-function 'verilog-auto-arg) t] | |
1039 ["AUTOASCIIENUM" (describe-function 'verilog-auto-ascii-enum) t] | |
1040 ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module) t] | |
1041 ["AUTOINOUT" (describe-function 'verilog-auto-inout) t] | |
1042 ["AUTOINPUT" (describe-function 'verilog-auto-input) t] | |
1043 ["AUTOINST" (describe-function 'verilog-auto-inst) t] | |
1044 ["AUTOINST (.*)" (describe-function 'verilog-auto-star) t] | |
1045 ["AUTOINSTPARAM" (describe-function 'verilog-auto-inst-param) t] | |
1046 ["AUTOOUTPUT" (describe-function 'verilog-auto-output) t] | |
1047 ["AUTOOUTPUTEVERY" (describe-function 'verilog-auto-output-every) t] | |
1048 ["AUTOREG" (describe-function 'verilog-auto-reg) t] | |
1049 ["AUTOREGINPUT" (describe-function 'verilog-auto-reg-input) t] | |
1050 ["AUTORESET" (describe-function 'verilog-auto-reset) t] | |
1051 ["AUTOSENSE" (describe-function 'verilog-auto-sense) t] | |
1052 ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff) t] | |
1053 ["AUTOUNUSED" (describe-function 'verilog-auto-unused) t] | |
1054 ["AUTOWIRE" (describe-function 'verilog-auto-wire) t] | |
1055 ) | |
1056 "----" | |
1057 ["Submit bug report" verilog-submit-bug-report t] | |
1058 ["Version and FAQ" verilog-faq t] | |
1059 ["Customize Verilog Mode..." verilog-customize t] | |
1060 ["Customize Verilog Fonts & Colors" verilog-font-customize t] | |
1061 ) | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
1062 "Emacs menu for Verilog mode." |
79545 | 1063 ) |
1064 (defvar verilog-statement-menu | |
1065 '("Statements" | |
1066 ["Header" verilog-sk-header t] | |
1067 ["Comment" verilog-sk-comment t] | |
1068 "----" | |
1069 ["Module" verilog-sk-module t] | |
1070 ["Primitive" verilog-sk-primitive t] | |
1071 "----" | |
1072 ["Input" verilog-sk-input t] | |
1073 ["Output" verilog-sk-output t] | |
1074 ["Inout" verilog-sk-inout t] | |
1075 ["Wire" verilog-sk-wire t] | |
1076 ["Reg" verilog-sk-reg t] | |
1077 ["Define thing under point as a register" verilog-sk-define-signal t] | |
1078 "----" | |
1079 ["Initial" verilog-sk-initial t] | |
1080 ["Always" verilog-sk-always t] | |
1081 ["Function" verilog-sk-function t] | |
1082 ["Task" verilog-sk-task t] | |
1083 ["Specify" verilog-sk-specify t] | |
1084 ["Generate" verilog-sk-generate t] | |
1085 "----" | |
1086 ["Begin" verilog-sk-begin t] | |
1087 ["If" verilog-sk-if t] | |
1088 ["(if) else" verilog-sk-else-if t] | |
1089 ["For" verilog-sk-for t] | |
1090 ["While" verilog-sk-while t] | |
1091 ["Fork" verilog-sk-fork t] | |
1092 ["Repeat" verilog-sk-repeat t] | |
1093 ["Case" verilog-sk-case t] | |
1094 ["Casex" verilog-sk-casex t] | |
1095 ["Casez" verilog-sk-casez t] | |
1096 ) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1097 "Menu for statement templates in Verilog.") |
79545 | 1098 |
1099 (easy-menu-define verilog-menu verilog-mode-map "Menu for Verilog mode" | |
1100 verilog-xemacs-menu) | |
1101 (easy-menu-define verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog." | |
1102 verilog-statement-menu) | |
1103 | |
1104 (defvar verilog-mode-abbrev-table nil | |
1105 "Abbrev table in use in Verilog-mode buffers.") | |
1106 | |
1107 (define-abbrev-table 'verilog-mode-abbrev-table ()) | |
1108 | |
79547
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1109 ;; |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1110 ;; Macros |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1111 ;; |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1112 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1113 (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
|
1114 "Replace occurrences of FROM-STRING with TO-STRING. |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1115 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
|
1116 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
|
1117 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
|
1118 ;; Hopefully soon to a emacs built-in |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1119 (let ((start 0)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1120 (while (string-match from-string string start) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1121 (setq string (replace-match to-string fixedcase literal string) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1122 start (min (length string) (match-end 0)))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1123 string)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1124 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1125 (defsubst verilog-string-remove-spaces (string) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1126 "Remove spaces surrounding STRING." |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1127 (save-match-data |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1128 (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
|
1129 (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
|
1130 string)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1131 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1132 (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1133 ; checkdoc-params: (REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1134 "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
|
1135 (store-match-data '(nil nil)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1136 (while (and |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1137 (re-search-forward REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1138 (and (verilog-skip-forward-comment-or-string) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1139 (progn |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1140 (store-match-data '(nil nil)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1141 (if BOUND |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1142 (< (point) BOUND) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1143 t))))) |
79547
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1144 (match-end 0)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1145 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1146 (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1147 ; checkdoc-params: (REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1148 "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
|
1149 (store-match-data '(nil nil)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1150 (while (and |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1151 (re-search-backward REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1152 (and (verilog-skip-backward-comment-or-string) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1153 (progn |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1154 (store-match-data '(nil nil)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1155 (if BOUND |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1156 (> (point) BOUND) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1157 t))))) |
79547
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1158 (match-end 0)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1159 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1160 (defsubst verilog-re-search-forward-quick (regexp bound noerror) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1161 "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
|
1162 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
|
1163 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
|
1164 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
|
1165 (let (pt) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1166 (while (and (not pt) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1167 (re-search-forward regexp bound noerror)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1168 (if (not (verilog-inside-comment-p)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1169 (setq pt (match-end 0)))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1170 pt)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1171 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1172 (defsubst verilog-re-search-backward-quick (regexp bound noerror) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1173 ; checkdoc-params: (REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1174 "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
|
1175 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
|
1176 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
|
1177 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
|
1178 (let (pt) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1179 (while (and (not pt) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1180 (re-search-backward regexp bound noerror)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1181 (if (not (verilog-inside-comment-p)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1182 (setq pt (match-end 0)))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1183 pt)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1184 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1185 (defsubst verilog-get-beg-of-line (&optional arg) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1186 (save-excursion |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1187 (beginning-of-line arg) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1188 (point))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1189 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1190 (defsubst verilog-get-end-of-line (&optional arg) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1191 (save-excursion |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1192 (end-of-line arg) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1193 (point))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1194 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1195 (defsubst verilog-within-string () |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1196 (save-excursion |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1197 (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
|
1198 |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1199 (defvar compile-command) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1200 |
79545 | 1201 ;; compilation program |
1202 (defun verilog-set-compile-command () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
1203 "Function to compute shell command to compile Verilog. |
79545 | 1204 |
1205 This reads `verilog-tool' and sets `compile-command'. This specifies the | |
1206 program that executes when you type \\[compile] or | |
1207 \\[verilog-auto-save-compile]. | |
1208 | |
1209 By default `verilog-tool' uses a Makefile if one exists in the current | |
1210 directory. If not, it is set to the `verilog-linter', `verilog-coverage', | |
1211 `verilog-simulator', or `verilog-compiler' variables, as selected with the | |
1212 Verilog -> \"Choose Compilation Action\" menu. | |
1213 | |
1214 You should set `verilog-tool' or the other variables to the path and | |
1215 arguments for your Verilog simulator. For example: | |
1216 \"vcs -p123 -O\" | |
1217 or a string like: | |
1218 \"(cd /tmp; surecov %s)\". | |
1219 | |
1220 In the former case, the path to the current buffer is concat'ed to the | |
1221 value of `verilog-tool'; in the later, the path to the current buffer is | |
1222 substituted for the %s. | |
1223 | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
1224 Where __FILE__ appears in the string, the `buffer-file-name' of the |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
1225 current buffer, without the directory portion, will be substituted." |
79545 | 1226 (interactive) |
1227 (cond | |
1228 ((or (file-exists-p "makefile") ;If there is a makefile, use it | |
1229 (file-exists-p "Makefile")) | |
1230 (make-local-variable 'compile-command) | |
1231 (setq compile-command "make ")) | |
1232 (t | |
1233 (make-local-variable 'compile-command) | |
1234 (setq compile-command | |
1235 (if verilog-tool | |
1236 (if (string-match "%s" (eval verilog-tool)) | |
1237 (format (eval verilog-tool) (or buffer-file-name "")) | |
1238 (concat (eval verilog-tool) " " (or buffer-file-name ""))) | |
1239 "")))) | |
1240 (verilog-modify-compile-command)) | |
1241 | |
1242 (defun verilog-modify-compile-command () | |
1243 "Replace meta-information in `compile-command'. | |
1244 Where __FILE__ appears in the string, the current buffer's file-name, | |
1245 without the directory portion, will be substituted." | |
1246 (when (and | |
1247 (stringp compile-command) | |
1248 (string-match "\\b__FILE__\\b" compile-command)) | |
1249 (make-local-variable 'compile-command) | |
1250 (setq compile-command | |
1251 (verilog-string-replace-matches | |
1252 "\\b__FILE__\\b" (file-name-nondirectory (buffer-file-name)) | |
1253 t t compile-command)))) | |
1254 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1255 ;; Following code only gets called from compilation-mode-hook. |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1256 (defvar compilation-error-regexp-alist) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1257 |
79545 | 1258 (defun verilog-error-regexp-add () |
1259 "Add the messages to the `compilation-error-regexp-alist'. | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1260 Called by `compilation-mode-hook'. This allows \\[next-error] to |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1261 find the errors." |
79545 | 1262 (if (not verilog-error-regexp-add-didit) |
1263 (progn | |
1264 (setq verilog-error-regexp-add-didit t) | |
1265 (setq-default compilation-error-regexp-alist | |
1266 (append verilog-error-regexp | |
1267 (default-value 'compilation-error-regexp-alist))) | |
1268 ;; Could be buffer local at this point; maybe also in let; change all three | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1269 (setq compilation-error-regexp-alist |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1270 (default-value 'compilation-error-regexp-alist)) |
79545 | 1271 (set (make-local-variable 'compilation-error-regexp-alist) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1272 (default-value 'compilation-error-regexp-alist))))) |
79545 | 1273 |
1274 (add-hook 'compilation-mode-hook 'verilog-error-regexp-add) | |
1275 | |
1276 (defconst verilog-directive-re | |
1277 ;; "`case" "`default" "`define" "`define" "`else" "`endfor" "`endif" | |
1278 ;; "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef" | |
1279 ;; "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale" | |
1280 ;; "`time_scale" "`undef" "`while" | |
1281 "\\<`\\(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\\)\\>") | |
1282 | |
1283 (defconst verilog-directive-begin | |
1284 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>") | |
1285 | |
1286 (defconst verilog-directive-middle | |
1287 "\\<`\\(else\\|default\\|case\\)\\>") | |
1288 | |
1289 (defconst verilog-directive-end | |
1290 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>") | |
1291 | |
1292 (defconst verilog-directive-re-1 | |
1293 (concat "[ \t]*" verilog-directive-re)) | |
1294 | |
1295 ;; | |
1296 ;; Regular expressions used to calculate indent, etc. | |
1297 ;; | |
1298 (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>") | |
1299 (defconst verilog-case-re "\\(\\<case[xz]?\\>\\|\\<randcase\\>\\)") | |
1300 ;; Want to match | |
1301 ;; aa : | |
1302 ;; aa,bb : | |
1303 ;; a[34:32] : | |
1304 ;; a, | |
1305 ;; b : | |
1306 | |
1307 (defconst verilog-no-indent-begin-re | |
1308 "\\<\\(if\\|else\\|while\\|for\\|repeat\\|always\\|always_comb\\|always_ff\\|always_latch\\)\\>") | |
1309 | |
1310 (defconst verilog-ends-re | |
1311 ;; Parenthesis indicate type of keyword found | |
1312 (concat | |
1313 "\\(\\<else\\>\\)\\|" ; 1 | |
1314 "\\(\\<if\\>\\)\\|" ; 2 | |
1315 "\\(\\<end\\>\\)\\|" ; 3 | |
1316 "\\(\\<endcase\\>\\)\\|" ; 4 | |
1317 "\\(\\<endfunction\\>\\)\\|" ; 5 | |
1318 "\\(\\<endtask\\>\\)\\|" ; 6 | |
1319 "\\(\\<endspecify\\>\\)\\|" ; 7 | |
1320 "\\(\\<endtable\\>\\)\\|" ; 8 | |
1321 "\\(\\<endgenerate\\>\\)\\|" ; 9 | |
1322 "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10 | |
1323 "\\(\\<endclass\\>\\)\\|" ; 11 | |
1324 "\\(\\<endgroup\\>\\)" ; 12 | |
1325 )) | |
1326 | |
1327 (defconst verilog-auto-end-comment-lines-re | |
1328 ;; Matches to names in this list cause auto-end-commentation | |
1329 (concat "\\(" | |
1330 verilog-directive-re "\\)\\|\\(" | |
1331 (eval-when-compile | |
1332 (verilog-regexp-words | |
1333 `( "begin" | |
1334 "else" | |
1335 "end" | |
1336 "endcase" | |
1337 "endclass" | |
1338 "endclocking" | |
1339 "endgroup" | |
1340 "endfunction" | |
1341 "endmodule" | |
1342 "endprogram" | |
1343 "endprimitive" | |
1344 "endinterface" | |
1345 "endpackage" | |
1346 "endsequence" | |
1347 "endspecify" | |
1348 "endtable" | |
1349 "endtask" | |
1350 "join" | |
1351 "join_any" | |
1352 "join_none" | |
1353 "module" | |
1354 "macromodule" | |
1355 "primitive" | |
1356 "interface" | |
1357 "package"))) | |
1358 "\\)")) | |
1359 | |
1360 ;;; NOTE: verilog-leap-to-head expects that verilog-end-block-re and | |
1361 ;;; verilog-end-block-ordered-re matches exactly the same strings. | |
1362 (defconst verilog-end-block-ordered-re | |
1363 ;; Parenthesis indicate type of keyword found | |
1364 (concat "\\(\\<endcase\\>\\)\\|" ; 1 | |
1365 "\\(\\<end\\>\\)\\|" ; 2 | |
1366 "\\(\\<end" ; 3, but not used | |
1367 "\\(" ; 4, but not used | |
1368 "\\(function\\)\\|" ; 5 | |
1369 "\\(task\\)\\|" ; 6 | |
1370 "\\(module\\)\\|" ; 7 | |
1371 "\\(primitive\\)\\|" ; 8 | |
1372 "\\(interface\\)\\|" ; 9 | |
1373 "\\(package\\)\\|" ; 10 | |
1374 "\\(class\\)\\|" ; 11 | |
1375 "\\(group\\)\\|" ; 12 | |
1376 "\\(program\\)\\|" ; 13 | |
1377 "\\(sequence\\)\\|" ; 14 | |
1378 "\\(clocking\\)\\|" ; 15 | |
1379 "\\)\\>\\)")) | |
1380 (defconst verilog-end-block-re | |
1381 (eval-when-compile | |
1382 (verilog-regexp-words | |
1383 | |
1384 `("end" ;; closes begin | |
1385 "endcase" ;; closes any of case, casex casez or randcase | |
1386 "join" "join_any" "join_none" ;; closes fork | |
1387 "endclass" | |
1388 "endtable" | |
1389 "endspecify" | |
1390 "endfunction" | |
1391 "endgenerate" | |
1392 "endtask" | |
1393 "endgroup" | |
1394 "endproperty" | |
1395 "endinterface" | |
1396 "endpackage" | |
1397 "endprogram" | |
1398 "endsequence" | |
1399 "endclocking" | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1400 )))) |
79545 | 1401 |
1402 | |
1403 (defconst verilog-endcomment-reason-re | |
1404 ;; Parenthesis indicate type of keyword found | |
1405 (concat | |
1406 "\\(\\<fork\\>\\)\\|" | |
1407 "\\(\\<begin\\>\\)\\|" | |
1408 "\\(\\<if\\>\\)\\|" | |
1409 "\\(\\<clocking\\>\\)\\|" | |
1410 "\\(\\<else\\>\\)\\|" | |
1411 "\\(\\<end\\>.*\\<else\\>\\)\\|" | |
1412 "\\(\\<task\\>\\)\\|" | |
1413 "\\(\\<function\\>\\)\\|" | |
1414 "\\(\\<initial\\>\\)\\|" | |
1415 "\\(\\<interface\\>\\)\\|" | |
1416 "\\(\\<package\\>\\)\\|" | |
1417 "\\(\\<final\\>\\)\\|" | |
1418 "\\(\\<always\\>\\(\[ \t\]*@\\)?\\)\\|" | |
1419 "\\(\\<always_comb\\>\\(\[ \t\]*@\\)?\\)\\|" | |
1420 "\\(\\<always_ff\\>\\(\[ \t\]*@\\)?\\)\\|" | |
1421 "\\(\\<always_latch\\>\\(\[ \t\]*@\\)?\\)\\|" | |
1422 "\\(@\\)\\|" | |
1423 "\\(\\<while\\>\\)\\|" | |
1424 "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|" | |
1425 "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|" | |
1426 "#")) | |
1427 | |
1428 (defconst verilog-named-block-re "begin[ \t]*:") | |
1429 | |
1430 ;; These words begin a block which can occur inside a module which should be indented, | |
1431 ;; and closed with the respective word from the end-block list | |
1432 | |
1433 (defconst verilog-beg-block-re | |
1434 (eval-when-compile | |
1435 (verilog-regexp-words | |
1436 `("begin" | |
1437 "case" "casex" "casez" "randcase" | |
1438 "clocking" | |
1439 "generate" | |
1440 "fork" | |
1441 "function" | |
1442 "property" | |
1443 "specify" | |
1444 "table" | |
1445 "task" | |
1446 )))) | |
1447 ;; These are the same words, in a specific order in the regular | |
1448 ;; expression so that matching will work nicely for | |
1449 ;; verilog-forward-sexp and verilog-calc-indent | |
1450 | |
1451 (defconst verilog-beg-block-re-ordered | |
1452 ( concat "\\<" | |
1453 "\\(begin\\)" ;1 | |
1454 "\\|\\(randcase\\|\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)" ; 2 | |
1455 ;; "\\|\\(randcase\\|case[xz]?\\)" ; 2 | |
1456 "\\|\\(fork\\)" ;3 | |
1457 "\\|\\(class\\)" ;4 | |
1458 "\\|\\(table\\)" ;5 | |
1459 "\\|\\(specify\\)" ;6 | |
1460 "\\|\\(function\\)" ;7 | |
1461 "\\|\\(task\\)" ;8 | |
1462 "\\|\\(generate\\)" ;9 | |
1463 "\\|\\(covergroup\\)" ;10 | |
1464 "\\|\\(property\\)" ;11 | |
1465 "\\|\\(\\(rand\\)?sequence\\)" ;12 | |
1466 "\\|\\(clocking\\)" ;13 | |
1467 "\\>")) | |
1468 | |
1469 (defconst verilog-end-block-ordered-rry | |
1470 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" | |
1471 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)" | |
1472 "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" | |
1473 "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" | |
1474 "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" | |
1475 "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" | |
1476 "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" | |
1477 "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" | |
1478 "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" | |
1479 "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" | |
1480 "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" | |
1481 "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" | |
1482 "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" | |
1483 ] ) | |
1484 | |
1485 (defconst verilog-nameable-item-re | |
1486 (eval-when-compile | |
1487 (verilog-regexp-words | |
1488 `("begin" | |
1489 "fork" | |
1490 "join" "join_any" "join_none" | |
1491 "end" | |
1492 "endcase" | |
1493 "endconfig" | |
1494 "endclass" | |
1495 "endclocking" | |
1496 "endfunction" | |
1497 "endgenerate" | |
1498 "endmodule" | |
1499 "endprimative" | |
1500 "endinterface" | |
1501 "endpackage" | |
1502 "endspecify" | |
1503 "endtable" | |
1504 "endtask" ) | |
1505 ))) | |
1506 | |
1507 (defconst verilog-declaration-opener | |
1508 (eval-when-compile | |
1509 (verilog-regexp-words | |
1510 `("module" "begin" "task" "function")))) | |
1511 | |
1512 (defconst verilog-declaration-prefix-re | |
1513 (eval-when-compile | |
1514 (verilog-regexp-words | |
1515 `( | |
1516 ;; port direction | |
79546 | 1517 "inout" "input" "output" "ref" |
79545 | 1518 ;; changeableness |
1519 "const" "static" "protected" "local" | |
1520 ;; parameters | |
79546 | 1521 "localparam" "parameter" "var" |
79545 | 1522 ;; type creation |
1523 "typedef" | |
1524 )))) | |
1525 (defconst verilog-declaration-core-re | |
1526 (eval-when-compile | |
1527 (verilog-regexp-words | |
1528 `( | |
1529 ;; integer_atom_type | |
1530 "byte" "shortint" "int" "longint" "integer" "time" | |
1531 ;; integer_vector_type | |
1532 "bit" "logic" "reg" | |
1533 ;; non_integer_type | |
1534 "shortreal" "real" "realtime" | |
1535 ;; net_type | |
1536 "supply0" "supply1" "tri" "triand" "trior" "trireg" "tri0" "tri1" "uwire" "wire" "wand" "wor" | |
1537 ;; misc | |
1538 "string" "event" "chandle" "virtual" "enum" "genvar" | |
1539 "struct" "union" | |
1540 ;; builtin classes | |
79546 | 1541 "mailbox" "semaphore" |
79545 | 1542 )))) |
79546 | 1543 (defconst verilog-declaration-re |
79545 | 1544 (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re)) |
1545 (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+") | |
1546 (defconst verilog-optional-signed-re "\\s-*\\(signed\\)?") | |
1547 (defconst verilog-optional-signed-range-re | |
1548 (concat | |
1549 "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?")) | |
1550 (defconst verilog-macroexp-re "`\\sw+") | |
1551 | |
1552 (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)") | |
1553 (defconst verilog-declaration-re-2-no-macro | |
1554 (concat "\\s-*" verilog-declaration-re | |
1555 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)" | |
1556 "\\)?")) | |
1557 (defconst verilog-declaration-re-2-macro | |
1558 (concat "\\s-*" verilog-declaration-re | |
1559 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)" | |
1560 "\\|\\(" verilog-macroexp-re "\\)" | |
1561 "\\)?")) | |
1562 (defconst verilog-declaration-re-1-macro | |
1563 (concat "^" verilog-declaration-re-2-macro)) | |
1564 | |
1565 (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro)) | |
1566 | |
1567 (defconst verilog-defun-re | |
1568 (eval-when-compile (verilog-regexp-words `("macromodule" "module" "class" "program" "interface" "package" "primitive" "config")))) | |
1569 (defconst verilog-end-defun-re | |
1570 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig")))) | |
1571 (defconst verilog-zero-indent-re | |
1572 (concat verilog-defun-re "\\|" verilog-end-defun-re)) | |
1573 | |
1574 (defconst verilog-behavioral-block-beg-re | |
1575 (concat "\\(\\<initial\\>\\|\\<final\\>\\|\\<always\\>\\|\\<always_comb\\>\\|\\<always_ff\\>\\|" | |
1576 "\\<always_latch\\>\\|\\<function\\>\\|\\<task\\>\\)")) | |
1577 | |
1578 (defconst verilog-indent-re | |
1579 (eval-when-compile | |
1580 (verilog-regexp-words | |
1581 `( | |
1582 "{" | |
1583 "always" "always_latch" "always_ff" "always_comb" | |
1584 "begin" "end" | |
1585 ; "unique" "priority" | |
1586 "case" "casex" "casez" "randcase" "endcase" | |
1587 "class" "endclass" | |
1588 "clocking" "endclocking" | |
1589 "config" "endconfig" | |
1590 "covergroup" "endgroup" | |
1591 "fork" "join" "join_any" "join_none" | |
1592 "function" "endfunction" | |
1593 "final" | |
1594 "generate" "endgenerate" | |
1595 "initial" | |
1596 "interface" "endinterface" | |
1597 "module" "macromodule" "endmodule" | |
1598 "package" "endpackage" | |
1599 "primitive" "endprimative" | |
1600 "program" "endprogram" | |
1601 "property" "endproperty" | |
1602 "sequence" "randsequence" "endsequence" | |
1603 "specify" "endspecify" | |
1604 "table" "endtable" | |
1605 "task" "endtask" | |
1606 "`case" | |
1607 "`default" | |
1608 "`define" "`undef" | |
1609 "`if" "`ifdef" "`ifndef" "`else" "`endif" | |
1610 "`while" "`endwhile" | |
1611 "`for" "`endfor" | |
1612 "`format" | |
1613 "`include" | |
1614 "`let" | |
1615 "`protect" "`endprotect" | |
1616 "`switch" "`endswitch" | |
1617 "`timescale" | |
1618 "`time_scale" | |
1619 )))) | |
1620 | |
1621 (defconst verilog-defun-level-re | |
1622 (eval-when-compile | |
1623 (verilog-regexp-words | |
1624 `( | |
1625 "module" "macromodule" "primitive" "class" "program" "initial" "final" "always" "always_comb" | |
1626 "always_ff" "always_latch" "endtask" "endfunction" "interface" "package" | |
1627 "config")))) | |
1628 | |
1629 (defconst verilog-defun-level-not-generate-re | |
1630 (eval-when-compile | |
1631 (verilog-regexp-words | |
1632 `( | |
1633 "module" "macromodule" "primitive" "class" "program" "interface" "package" "config")))) | |
1634 | |
1635 (defconst verilog-cpp-level-re | |
1636 (eval-when-compile | |
1637 (verilog-regexp-words | |
1638 `( | |
1639 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass" | |
1640 )))) | |
1641 (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?") | |
1642 (defconst verilog-extended-complete-re | |
1643 (concat "\\(\\<extern\\s-+\\|\\<virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)" | |
1644 "\\|\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)" | |
1645 "\\|" verilog-extended-case-re )) | |
1646 (defconst verilog-basic-complete-re | |
1647 (eval-when-compile | |
1648 (verilog-regexp-words | |
1649 `( | |
1650 "always" "assign" "always_latch" "always_ff" "always_comb" "constraint" | |
1651 "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while" | |
1652 "if" "for" "forever" "foreach" "else" "parameter" "do" | |
1653 )))) | |
1654 (defconst verilog-complete-reg | |
1655 (concat | |
1656 verilog-extended-complete-re | |
1657 "\\|" | |
1658 verilog-basic-complete-re)) | |
1659 | |
1660 (defconst verilog-end-statement-re | |
1661 (concat "\\(" verilog-beg-block-re "\\)\\|\\(" | |
1662 verilog-end-block-re "\\)")) | |
1663 | |
1664 (defconst verilog-endcase-re | |
1665 (concat verilog-case-re "\\|" | |
1666 "\\(endcase\\)\\|" | |
1667 verilog-defun-re | |
1668 )) | |
1669 | |
1670 (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----" | |
1671 "String used to mark beginning of excluded text.") | |
1672 (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */" | |
1673 "String used to mark end of excluded text.") | |
1674 (defconst verilog-preprocessor-re | |
1675 (eval-when-compile | |
1676 (verilog-regexp-words | |
1677 `( | |
1678 "`define" "`include" "`ifdef" "`ifndef" "`if" "`endif" "`else" | |
1679 )))) | |
1680 | |
1681 (defconst verilog-keywords | |
1682 '( "`case" "`default" "`define" "`else" "`endfor" "`endif" | |
1683 "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef" | |
1684 "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale" | |
1685 "`time_scale" "`undef" "`while" | |
1686 | |
1687 "after" "alias" "always" "always_comb" "always_ff" "always_latch" "and" | |
1688 "assert" "assign" "assume" "automatic" "before" "begin" "bind" | |
1689 "bins" "binsof" "bit" "break" "buf" "bufif0" "bufif1" "byte" | |
1690 "case" "casex" "casez" "cell" "chandle" "class" "clocking" "cmos" | |
1691 "config" "const" "constraint" "context" "continue" "cover" | |
1692 "covergroup" "coverpoint" "cross" "deassign" "default" "defparam" | |
1693 "design" "disable" "dist" "do" "edge" "else" "end" "endcase" | |
1694 "endclass" "endclocking" "endconfig" "endfunction" "endgenerate" | |
1695 "endgroup" "endinterface" "endmodule" "endpackage" "endprimitive" | |
1696 "endprogram" "endproperty" "endspecify" "endsequence" "endtable" | |
1697 "endtask" "enum" "event" "expect" "export" "extends" "extern" | |
1698 "final" "first_match" "for" "force" "foreach" "forever" "fork" | |
1699 "forkjoin" "function" "generate" "genvar" "highz0" "highz1" "if" | |
1700 "iff" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir" | |
1701 "include" "initial" "inout" "input" "inside" "instance" "int" | |
1702 "integer" "interface" "intersect" "join" "join_any" "join_none" | |
1703 "large" "liblist" "library" "local" "localparam" "logic" | |
1704 "longint" "macromodule" "mailbox" "matches" "medium" "modport" "module" | |
1705 "nand" "negedge" "new" "nmos" "nor" "noshowcancelled" "not" | |
1706 "notif0" "notif1" "null" "or" "output" "package" "packed" | |
1707 "parameter" "pmos" "posedge" "primitive" "priority" "program" | |
1708 "property" "protected" "pull0" "pull1" "pulldown" "pullup" | |
1709 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc" | |
1710 "randcase" "randsequence" "rcmos" "real" "realtime" "ref" "reg" | |
1711 "release" "repeat" "return" "rnmos" "rpmos" "rtran" "rtranif0" | |
1712 "rtranif1" "scalared" "semaphore" "sequence" "shortint" "shortreal" | |
1713 "showcancelled" "signed" "small" "solve" "specify" "specparam" | |
1714 "static" "string" "strong0" "strong1" "struct" "super" "supply0" | |
1715 "supply1" "table" "tagged" "task" "this" "throughout" "time" | |
1716 "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri" | |
1717 "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union" | |
1718 "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void" | |
1719 "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard" | |
1720 "wire" "with" "within" "wor" "xnor" "xor" | |
1721 ) | |
1722 "List of Verilog keywords.") | |
1723 | |
1724 (defconst verilog-comment-start-regexp "//\\|/\\*" | |
1725 "Dual comment value for `comment-start-regexp'.") | |
1726 | |
79810
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1727 (defvar verilog-mode-syntax-table |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1728 (let ((table (make-syntax-table))) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1729 ;; Populate the syntax TABLE. |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1730 (modify-syntax-entry ?\\ "\\" table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1731 (modify-syntax-entry ?+ "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1732 (modify-syntax-entry ?- "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1733 (modify-syntax-entry ?= "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1734 (modify-syntax-entry ?% "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1735 (modify-syntax-entry ?< "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1736 (modify-syntax-entry ?> "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1737 (modify-syntax-entry ?& "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1738 (modify-syntax-entry ?| "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1739 (modify-syntax-entry ?` "w" table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1740 (modify-syntax-entry ?_ "w" table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1741 (modify-syntax-entry ?\' "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1742 |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1743 ;; Set up TABLE to handle block and line style comments. |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1744 (if (featurep 'xemacs) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1745 (progn |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1746 ;; XEmacs (formerly Lucid) has the best implementation |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1747 (modify-syntax-entry ?/ ". 1456" table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1748 (modify-syntax-entry ?* ". 23" table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1749 (modify-syntax-entry ?\n "> b" table)) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1750 ;; Emacs 19 does things differently, but we can work with it |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1751 (modify-syntax-entry ?/ ". 124b" table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1752 (modify-syntax-entry ?* ". 23" table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1753 (modify-syntax-entry ?\n "> b" table)) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1754 table) |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
1755 "Syntax table used in Verilog mode buffers.") |
79545 | 1756 |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1757 (defvar verilog-font-lock-keywords nil |
79545 | 1758 "Default highlighting for Verilog mode.") |
1759 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1760 (defvar verilog-font-lock-keywords-1 nil |
79545 | 1761 "Subdued level highlighting for Verilog mode.") |
1762 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1763 (defvar verilog-font-lock-keywords-2 nil |
79545 | 1764 "Medium level highlighting for Verilog mode. |
1765 See also `verilog-font-lock-extra-types'.") | |
1766 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1767 (defvar verilog-font-lock-keywords-3 nil |
79545 | 1768 "Gaudy level highlighting for Verilog mode. |
1769 See also `verilog-font-lock-extra-types'.") | |
1770 (defvar verilog-font-lock-translate-off-face | |
1771 'verilog-font-lock-translate-off-face | |
1772 "Font to use for translated off regions.") | |
1773 (defface verilog-font-lock-translate-off-face | |
1774 '((((class color) | |
1775 (background light)) | |
1776 (:background "gray90" :italic t )) | |
1777 (((class color) | |
1778 (background dark)) | |
1779 (:background "gray10" :italic t )) | |
1780 (((class grayscale) (background light)) | |
1781 (:foreground "DimGray" :italic t)) | |
1782 (((class grayscale) (background dark)) | |
1783 (:foreground "LightGray" :italic t)) | |
1784 (t (:italis t))) | |
1785 "Font lock mode face used to background highlight translate-off regions." | |
1786 :group 'font-lock-highlighting-faces) | |
1787 | |
1788 (defvar verilog-font-lock-p1800-face | |
1789 'verilog-font-lock-p1800-face | |
1790 "Font to use for p1800 keywords.") | |
1791 (defface verilog-font-lock-p1800-face | |
1792 '((((class color) | |
1793 (background light)) | |
1794 (:foreground "DarkOrange3" :bold t )) | |
1795 (((class color) | |
1796 (background dark)) | |
1797 (:foreground "orange1" :bold t )) | |
1798 (t (:italic t))) | |
1799 "Font lock mode face used to highlight P1800 keywords." | |
1800 :group 'font-lock-highlighting-faces) | |
1801 | |
1802 (defvar verilog-font-lock-ams-face | |
1803 'verilog-font-lock-ams-face | |
1804 "Font to use for Analog/Mixed Signal keywords.") | |
1805 (defface verilog-font-lock-ams-face | |
1806 '((((class color) | |
1807 (background light)) | |
1808 (:foreground "Purple" :bold t )) | |
1809 (((class color) | |
1810 (background dark)) | |
1811 (:foreground "orange1" :bold t )) | |
1812 (t (:italic t))) | |
1813 "Font lock mode face used to highlight AMS keywords." | |
1814 :group 'font-lock-highlighting-faces) | |
1815 | |
1816 (let* ((verilog-type-font-keywords | |
1817 (eval-when-compile | |
1818 (verilog-regexp-opt | |
1819 '( | |
1820 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam" | |
1821 "event" "genvar" "inout" "input" "integer" "localparam" | |
1822 "logic" "mailbox" "nand" "nmos" "not" "notif0" "notif1" "or" | |
1823 "output" "parameter" "pmos" "pull0" "pull1" "pullup" | |
1824 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" | |
1825 "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply" | |
1826 "supply0" "supply1" "time" "tran" "tranif0" "tranif1" | |
1827 "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef" | |
1828 "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor" | |
1829 ) nil ))) | |
1830 | |
1831 (verilog-pragma-keywords | |
1832 (eval-when-compile | |
1833 (verilog-regexp-opt | |
1834 '("surefire" "synopsys" "rtl_synthesis" "verilint" ) nil | |
1835 ))) | |
1836 | |
1837 (verilog-p1800-keywords | |
1838 (eval-when-compile | |
1839 (verilog-regexp-opt | |
1840 '("alias" "assert" "assume" "automatic" "before" "bind" | |
1841 "bins" "binsof" "break" "byte" "cell" "chandle" "class" | |
1842 "clocking" "config" "const" "constraint" "context" "continue" | |
1843 "cover" "covergroup" "coverpoint" "cross" "deassign" "design" | |
1844 "dist" "do" "edge" "endclass" "endclocking" "endconfig" | |
1845 "endgroup" "endprogram" "endproperty" "endsequence" "enum" | |
1846 "expect" "export" "extends" "extern" "first_match" "foreach" | |
1847 "forkjoin" "genvar" "highz0" "highz1" "ifnone" "ignore_bins" | |
1848 "illegal_bins" "import" "incdir" "include" "inside" "instance" | |
1849 "int" "intersect" "large" "liblist" "library" "local" "longint" | |
1850 "matches" "medium" "modport" "new" "noshowcancelled" "null" | |
1851 "packed" "program" "property" "protected" "pull0" "pull1" | |
1852 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc" | |
1853 "randcase" "randsequence" "ref" "release" "return" "scalared" | |
1854 "sequence" "shortint" "shortreal" "showcancelled" "small" "solve" | |
1855 "specparam" "static" "string" "strong0" "strong1" "struct" | |
1856 "super" "tagged" "this" "throughout" "timeprecision" "timeunit" | |
1857 "type" "union" "unsigned" "use" "var" "virtual" "void" | |
1858 "wait_order" "weak0" "weak1" "wildcard" "with" "within" | |
1859 ) nil ))) | |
1860 | |
1861 (verilog-ams-keywords | |
1862 (eval-when-compile | |
1863 (verilog-regexp-opt | |
1864 '("above" "abs" "absdelay" "acos" "acosh" "ac_stim" | |
1865 "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh" | |
1866 "branch" "ceil" "connectmodule" "connectrules" "cos" "cosh" "ddt" | |
1867 "ddx" "discipline" "driver_update" "enddiscipline" "endconnectrules" | |
1868 "endnature" "endparamset" "exclude" "exp" "final_step" "flicker_noise" | |
1869 "floor" "flow" "from" "ground" "hypot" "idt" "idtmod" "inf" | |
1870 "initial_step" "laplace_nd" "laplace_np" "laplace_zd" "laplace_zp" | |
1871 "last_crossing" "limexp" "ln" "log" "max" "min" "nature" | |
1872 "net_resolution" "noise_table" "paramset" "potential" "pow" "sin" | |
1873 "sinh" "slew" "sqrt" "tan" "tanh" "timer" "transition" "white_noise" | |
1874 "wreal" "zi_nd" "zi_np" "zi_zd" ) nil ))) | |
1875 | |
1876 (verilog-font-keywords | |
1877 (eval-when-compile | |
1878 (verilog-regexp-opt | |
1879 '( | |
1880 "assign" "begin" "case" "casex" "casez" "randcase" "deassign" | |
1881 "default" "disable" "else" "end" "endcase" "endfunction" | |
1882 "endgenerate" "endinterface" "endmodule" "endprimitive" | |
1883 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break" | |
1884 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial" | |
1885 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge" | |
1886 "package" "endpackage" "always" "always_comb" "always_ff" | |
1887 "always_latch" "posedge" "primitive" "priority" "release" | |
1888 "repeat" "specify" "table" "task" "unique" "wait" "while" | |
1889 "class" "program" "endclass" "endprogram" | |
1890 ) nil )))) | |
1891 | |
1892 (setq verilog-font-lock-keywords | |
1893 (list | |
1894 ;; Fontify all builtin keywords | |
1895 (concat "\\<\\(" verilog-font-keywords "\\|" | |
1896 ;; And user/system tasks and functions | |
1897 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*" | |
1898 "\\)\\>") | |
1899 ;; Fontify all types | |
1900 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>") | |
1901 'font-lock-type-face) | |
1902 ;; Fontify IEEE-P1800 keywords appropriately | |
1903 (if verilog-highlight-p1800-keywords | |
1904 (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>") | |
1905 'verilog-font-lock-p1800-face) | |
1906 (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>") | |
1907 'font-lock-type-face)) | |
1908 ;; Fontify Verilog-AMS keywords | |
1909 (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1910 'verilog-font-lock-ams-face))) |
79545 | 1911 |
1912 (setq verilog-font-lock-keywords-1 | |
1913 (append verilog-font-lock-keywords | |
1914 (list | |
1915 ;; Fontify module definitions | |
1916 (list | |
1917 "\\<\\(\\(macro\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)" | |
1918 '(1 font-lock-keyword-face) | |
1919 '(3 font-lock-function-name-face 'prepend)) | |
1920 ;; Fontify function definitions | |
1921 (list | |
1922 (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" ) | |
1923 '(1 font-lock-keyword-face) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1924 '(3 font-lock-reference-face prepend)) |
79545 | 1925 '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)" |
1926 (1 font-lock-keyword-face) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1927 (2 font-lock-reference-face append)) |
79545 | 1928 '("\\<function\\>\\s-+\\(\\sw+\\)" |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1929 1 'font-lock-reference-face append)))) |
79545 | 1930 |
1931 (setq verilog-font-lock-keywords-2 | |
1932 (append verilog-font-lock-keywords-1 | |
1933 (list | |
1934 ;; Fontify pragmas | |
1935 (concat "\\(//\\s-*" verilog-pragma-keywords "\\s-.*\\)") | |
1936 ;; Fontify escaped names | |
1937 '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face) | |
1938 ;; Fontify macro definitions/ uses | |
1939 '("`\\s-*[A-Za-z][A-Za-z0-9_]*" 0 (if (boundp 'font-lock-preprocessor-face) | |
1940 'font-lock-preprocessor-face | |
1941 'font-lock-type-face)) | |
1942 ;; Fontify delays/numbers | |
1943 '("\\(@\\)\\|\\(#\\s-*\\(\\(\[0-9_.\]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)" | |
1944 0 font-lock-type-face append) | |
1945 ;; Fontify instantiation names | |
1946 '("\\([A-Za-z][A-Za-z0-9_]+\\)\\s-*(" 1 font-lock-function-name-face) | |
1947 ))) | |
1948 | |
1949 (setq verilog-font-lock-keywords-3 | |
1950 (append verilog-font-lock-keywords-2 | |
1951 (when verilog-highlight-translate-off | |
1952 (list | |
1953 ;; Fontify things in translate off regions | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1954 '(verilog-match-translate-off |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1955 (0 'verilog-font-lock-translate-off-face prepend)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1956 ))))) |
79545 | 1957 |
1958 | |
1959 (defun verilog-inside-comment-p () | |
1960 "Check if point inside a nested comment." | |
1961 (save-excursion | |
1962 (let ((st-point (point)) hitbeg) | |
1963 (or (search-backward "//" (verilog-get-beg-of-line) t) | |
1964 (if (progn | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1965 ;; This is for tricky case //*, we keep searching if /* |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1966 ;; is proceeded by // on same line. |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1967 (while |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1968 (and (setq hitbeg (search-backward "/*" nil t)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1969 (progn |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1970 (forward-char 1) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1971 (search-backward "//" (verilog-get-beg-of-line) t)))) |
79545 | 1972 hitbeg) |
1973 (not (search-forward "*/" st-point t))))))) | |
1974 | |
1975 (defun verilog-declaration-end () | |
1976 (search-forward ";")) | |
1977 | |
1978 (defun verilog-point-text (&optional pointnum) | |
1979 "Return text describing where POINTNUM or current point is (for errors). | |
1980 Use filename, if current buffer being edited shorten to just buffer name." | |
1981 (concat (or (and (equal (window-buffer (selected-window)) (current-buffer)) | |
1982 (buffer-name)) | |
1983 buffer-file-name | |
1984 (buffer-name)) | |
1985 ":" (int-to-string (count-lines (point-min) (or pointnum (point)))))) | |
1986 | |
1987 (defun electric-verilog-backward-sexp () | |
1988 "Move backward over a sexp." | |
1989 (interactive) | |
1990 ;; before that see if we are in a comment | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1991 (verilog-backward-sexp)) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1992 |
79545 | 1993 (defun electric-verilog-forward-sexp () |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
1994 "Move forward over a sexp." |
79545 | 1995 (interactive) |
1996 ;; before that see if we are in a comment | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1997 (verilog-forward-sexp)) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1998 |
79545 | 1999 ;;;used by hs-minor-mode |
2000 (defun verilog-forward-sexp-function (arg) | |
2001 (if (< arg 0) | |
2002 (verilog-backward-sexp) | |
2003 (verilog-forward-sexp))) | |
2004 | |
2005 | |
2006 (defun verilog-backward-sexp () | |
2007 (let ((reg) | |
2008 (elsec 1) | |
2009 (found nil) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2010 (st (point))) |
79545 | 2011 (if (not (looking-at "\\<")) |
2012 (forward-word -1)) | |
2013 (cond | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2014 ((verilog-skip-backward-comment-or-string)) |
79545 | 2015 ((looking-at "\\<else\\>") |
2016 (setq reg (concat | |
2017 verilog-end-block-re | |
2018 "\\|\\(\\<else\\>\\)" | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2019 "\\|\\(\\<if\\>\\)")) |
79545 | 2020 (while (and (not found) |
2021 (verilog-re-search-backward reg nil 'move)) | |
2022 (cond | |
2023 ((match-end 1) ; matched verilog-end-block-re | |
2024 ; try to leap back to matching outward block by striding across | |
2025 ; indent level changing tokens then immediately | |
2026 ; previous line governs indentation. | |
2027 (verilog-leap-to-head)) | |
2028 ((match-end 2) ; else, we're in deep | |
2029 (setq elsec (1+ elsec))) | |
2030 ((match-end 3) ; found it | |
2031 (setq elsec (1- elsec)) | |
2032 (if (= 0 elsec) | |
2033 ;; Now previous line describes syntax | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2034 (setq found 't)))))) |
79545 | 2035 ((looking-at verilog-end-block-re) |
2036 (verilog-leap-to-head)) | |
2037 ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)\\|\\(\\<endclass\\>\\)\\|\\(\\<endprogram\\>\\)\\|\\(\\<endinterface\\>\\)\\|\\(\\<endpackage\\>\\)") | |
2038 (cond | |
2039 ((match-end 1) | |
2040 (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move)) | |
2041 ((match-end 2) | |
2042 (verilog-re-search-backward "\\<primitive\\>" nil 'move)) | |
2043 ((match-end 3) | |
2044 (verilog-re-search-backward "\\<class\\>" nil 'move)) | |
2045 ((match-end 4) | |
2046 (verilog-re-search-backward "\\<program\\>" nil 'move)) | |
2047 ((match-end 5) | |
2048 (verilog-re-search-backward "\\<interface\\>" nil 'move)) | |
2049 ((match-end 6) | |
2050 (verilog-re-search-backward "\\<package\\>" nil 'move)) | |
2051 (t | |
2052 (goto-char st) | |
2053 (backward-sexp 1)))) | |
2054 (t | |
2055 (goto-char st) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2056 (backward-sexp))))) |
79545 | 2057 |
2058 (defun verilog-forward-sexp () | |
2059 (let ((reg) | |
2060 (md 2) | |
2061 (st (point))) | |
2062 (if (not (looking-at "\\<")) | |
2063 (forward-word -1)) | |
2064 (cond | |
2065 ((verilog-skip-forward-comment-or-string) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2066 (verilog-forward-syntactic-ws)) |
79545 | 2067 ((looking-at verilog-beg-block-re-ordered);; begin|case|fork|class|table|specify|function|task|generate|covergroup|property|sequence|clocking |
2068 (cond | |
2069 ((match-end 1) ; end | |
2070 ;; Search forward for matching begin | |
2071 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" )) | |
2072 ((match-end 2) ; endcase | |
2073 ;; Search forward for matching case | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2074 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )) |
79545 | 2075 ((match-end 3) ; join |
2076 ;; Search forward for matching fork | |
2077 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )) | |
2078 ((match-end 4) ; endclass | |
2079 ;; Search forward for matching class | |
2080 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" )) | |
2081 ((match-end 5) ; endtable | |
2082 ;; Search forward for matching table | |
2083 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )) | |
2084 ((match-end 6) ; endspecify | |
2085 ;; Search forward for matching specify | |
2086 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )) | |
2087 ((match-end 7) ; endfunction | |
2088 ;; Search forward for matching function | |
2089 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )) | |
2090 ((match-end 8) ; endtask | |
2091 ;; Search forward for matching task | |
2092 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" )) | |
2093 ((match-end 9) ; endgenerate | |
2094 ;; Search forward for matching generate | |
2095 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" )) | |
2096 ((match-end 10) ; endgroup | |
2097 ;; Search forward for matching covergroup | |
2098 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )) | |
2099 ((match-end 11) ; endproperty | |
2100 ;; Search forward for matching property | |
2101 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" )) | |
2102 ((match-end 12) ; endsequence | |
2103 ;; Search forward for matching sequence | |
2104 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2105 (setq md 3)) ; 3 to get to endsequence in the reg above |
79545 | 2106 ((match-end 13) ; endclocking |
2107 ;; Search forward for matching clocking | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2108 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" ))) |
79545 | 2109 (if (forward-word 1) |
2110 (catch 'skip | |
2111 (let ((nest 1)) | |
2112 (while (verilog-re-search-forward reg nil 'move) | |
2113 (cond | |
2114 ((match-end md) ; the closer in reg, so we are climbing out | |
2115 (setq nest (1- nest)) | |
2116 (if (= 0 nest) ; we are out! | |
2117 (throw 'skip 1))) | |
2118 ((match-end 1) ; the opener in reg, so we are deeper now | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2119 (setq nest (1+ nest))))))))) |
79545 | 2120 ((looking-at (concat |
2121 "\\(\\<\\(macro\\)?module\\>\\)\\|" | |
2122 "\\(\\<primitive\\>\\)\\|" | |
2123 "\\(\\<class\\>\\)\\|" | |
2124 "\\(\\<program\\>\\)\\|" | |
2125 "\\(\\<interface\\>\\)\\|" | |
2126 "\\(\\<package\\>\\)")) | |
2127 (cond | |
2128 ((match-end 1) | |
2129 (verilog-re-search-forward "\\<endmodule\\>" nil 'move)) | |
2130 ((match-end 2) | |
2131 (verilog-re-search-forward "\\<endprimitive\\>" nil 'move)) | |
2132 ((match-end 3) | |
2133 (verilog-re-search-forward "\\<endclass\\>" nil 'move)) | |
2134 ((match-end 4) | |
2135 (verilog-re-search-forward "\\<endprogram\\>" nil 'move)) | |
2136 ((match-end 5) | |
2137 (verilog-re-search-forward "\\<endinterface\\>" nil 'move)) | |
2138 ((match-end 6) | |
2139 (verilog-re-search-forward "\\<endpackage\\>" nil 'move)) | |
2140 (t | |
2141 (goto-char st) | |
2142 (if (= (following-char) ?\) ) | |
2143 (forward-char 1) | |
2144 (forward-sexp 1))))) | |
2145 (t | |
2146 (goto-char st) | |
2147 (if (= (following-char) ?\) ) | |
2148 (forward-char 1) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2149 (forward-sexp 1)))))) |
79545 | 2150 |
2151 (defun verilog-declaration-beg () | |
2152 (verilog-re-search-backward verilog-declaration-re (bobp) t)) | |
2153 | |
2154 (defun verilog-font-lock-init () | |
2155 "Initialize fontification." | |
2156 ;; highlight keywords and standardized types, attributes, enumeration | |
2157 ;; values, and subprograms | |
2158 (setq verilog-font-lock-keywords-3 | |
2159 (append verilog-font-lock-keywords-2 | |
2160 (when verilog-highlight-translate-off | |
2161 (list | |
2162 ;; Fontify things in translate off regions | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2163 '(verilog-match-translate-off |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2164 (0 'verilog-font-lock-translate-off-face prepend)))))) |
79545 | 2165 (put 'verilog-mode 'font-lock-defaults |
2166 '((verilog-font-lock-keywords | |
2167 verilog-font-lock-keywords-1 | |
2168 verilog-font-lock-keywords-2 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2169 verilog-font-lock-keywords-3) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2170 nil ; nil means highlight strings & comments as well as keywords |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2171 nil ; nil means keywords must match case |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2172 nil ; syntax table handled elsewhere |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2173 ;; Function to move to beginning of reasonable region to highlight |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2174 verilog-beg-of-defun))) |
79545 | 2175 |
2176 ;; initialize fontification for Verilog Mode | |
2177 (verilog-font-lock-init) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2178 |
79545 | 2179 ;; |
2180 ;; | |
2181 ;; Mode | |
2182 ;; | |
2183 (defvar verilog-which-tool 1) | |
79546 | 2184 ;;;###autoload |
79545 | 2185 (defun verilog-mode () |
2186 "Major mode for editing Verilog code. | |
2187 \\<verilog-mode-map> | |
2188 See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how | |
2189 AUTOs can improve coding efficiency. | |
2190 | |
2191 Use \\[verilog-faq] for a pointer to frequently asked questions. | |
2192 | |
2193 NEWLINE, TAB indents for Verilog code. | |
2194 Delete converts tabs to spaces as it moves back. | |
2195 | |
2196 Supports highlighting. | |
2197 | |
2198 Turning on Verilog mode calls the value of the variable `verilog-mode-hook' | |
2199 with no args, if that value is non-nil. | |
2200 | |
2201 Variables controlling indentation/edit style: | |
2202 | |
2203 variable `verilog-indent-level' (default 3) | |
2204 Indentation of Verilog statements with respect to containing block. | |
2205 `verilog-indent-level-module' (default 3) | |
2206 Absolute indentation of Module level Verilog statements. | |
2207 Set to 0 to get initial and always statements lined up | |
2208 on the left side of your screen. | |
2209 `verilog-indent-level-declaration' (default 3) | |
2210 Indentation of declarations with respect to containing block. | |
2211 Set to 0 to get them list right under containing block. | |
2212 `verilog-indent-level-behavioral' (default 3) | |
2213 Indentation of first begin in a task or function block | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
2214 Set to 0 to get such code to lined up underneath the task or |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
2215 function keyword. |
79545 | 2216 `verilog-indent-level-directive' (default 1) |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
2217 Indentation of `ifdef/`endif blocks. |
79545 | 2218 `verilog-cexp-indent' (default 1) |
2219 Indentation of Verilog statements broken across lines i.e.: | |
2220 if (a) | |
2221 begin | |
2222 `verilog-case-indent' (default 2) | |
2223 Indentation for case statements. | |
2224 `verilog-auto-newline' (default nil) | |
2225 Non-nil means automatically newline after semicolons and the punctuation | |
2226 mark after an end. | |
2227 `verilog-auto-indent-on-newline' (default t) | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
2228 Non-nil means automatically indent line after newline. |
79545 | 2229 `verilog-tab-always-indent' (default t) |
2230 Non-nil means TAB in Verilog mode should always reindent the current line, | |
2231 regardless of where in the line point is when the TAB command is used. | |
2232 `verilog-indent-begin-after-if' (default t) | |
2233 Non-nil means to indent begin statements following a preceding | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
2234 if, else, while, for and repeat statements, if any. Otherwise, |
79545 | 2235 the begin is lined up with the preceding token. If t, you get: |
2236 if (a) | |
2237 begin // amount of indent based on `verilog-cexp-indent' | |
2238 otherwise you get: | |
2239 if (a) | |
2240 begin | |
2241 `verilog-auto-endcomments' (default t) | |
2242 Non-nil means a comment /* ... */ is set after the ends which ends | |
2243 cases, tasks, functions and modules. | |
2244 The type and name of the object will be set between the braces. | |
2245 `verilog-minimum-comment-distance' (default 10) | |
2246 Minimum distance (in lines) between begin and end required before a comment | |
2247 will be inserted. Setting this variable to zero results in every | |
2248 end acquiring a comment; the default avoids too many redundant | |
2249 comments in tight quarters. | |
2250 `verilog-auto-lineup' (default `(all)) | |
2251 List of contexts where auto lineup of code should be done. | |
2252 | |
2253 Variables controlling other actions: | |
2254 | |
2255 `verilog-linter' (default surelint) | |
2256 Unix program to call to run the lint checker. This is the default | |
2257 command for \\[compile-command] and \\[verilog-auto-save-compile]. | |
2258 | |
2259 See \\[customize] for the complete list of variables. | |
2260 | |
2261 AUTO expansion functions are, in part: | |
2262 | |
2263 \\[verilog-auto] Expand AUTO statements. | |
2264 \\[verilog-delete-auto] Remove the AUTOs. | |
2265 \\[verilog-inject-auto] Insert AUTOs for the first time. | |
2266 | |
2267 Some other functions are: | |
2268 | |
2269 \\[verilog-complete-word] Complete word with appropriate possibilities. | |
2270 \\[verilog-mark-defun] Mark function. | |
2271 \\[verilog-beg-of-defun] Move to beginning of current function. | |
2272 \\[verilog-end-of-defun] Move to end of current function. | |
2273 \\[verilog-label-be] Label matching begin ... end, fork ... join, etc statements. | |
2274 | |
2275 \\[verilog-comment-region] Put marked area in a comment. | |
2276 \\[verilog-uncomment-region] Uncomment an area commented with \\[verilog-comment-region]. | |
2277 \\[verilog-insert-block] Insert begin ... end;. | |
2278 \\[verilog-star-comment] Insert /* ... */. | |
2279 | |
2280 \\[verilog-sk-always] Insert a always @(AS) begin .. end block. | |
2281 \\[verilog-sk-begin] Insert a begin .. end block. | |
2282 \\[verilog-sk-case] Insert a case block, prompting for details. | |
2283 \\[verilog-sk-for] Insert a for (...) begin .. end block, prompting for details. | |
2284 \\[verilog-sk-generate] Insert a generate .. endgenerate block. | |
2285 \\[verilog-sk-header] Insert a nice header block at the top of file. | |
2286 \\[verilog-sk-initial] Insert an initial begin .. end block. | |
2287 \\[verilog-sk-fork] Insert a fork begin .. end .. join block. | |
2288 \\[verilog-sk-module] Insert a module .. (/*AUTOARG*/);.. endmodule block. | |
2289 \\[verilog-sk-primitive] Insert a primitive .. (.. );.. endprimitive block. | |
2290 \\[verilog-sk-repeat] Insert a repeat (..) begin .. end block. | |
2291 \\[verilog-sk-specify] Insert a specify .. endspecify block. | |
2292 \\[verilog-sk-task] Insert a task .. begin .. end endtask block. | |
2293 \\[verilog-sk-while] Insert a while (...) begin .. end block, prompting for details. | |
2294 \\[verilog-sk-casex] Insert a casex (...) item: begin.. end endcase block, prompting for details. | |
2295 \\[verilog-sk-casez] Insert a casez (...) item: begin.. end endcase block, prompting for details. | |
2296 \\[verilog-sk-if] Insert an if (..) begin .. end block. | |
2297 \\[verilog-sk-else-if] Insert an else if (..) begin .. end block. | |
2298 \\[verilog-sk-comment] Insert a comment block. | |
2299 \\[verilog-sk-assign] Insert an assign .. = ..; statement. | |
2300 \\[verilog-sk-function] Insert a function .. begin .. end endfunction block. | |
2301 \\[verilog-sk-input] Insert an input declaration, prompting for details. | |
2302 \\[verilog-sk-output] Insert an output declaration, prompting for details. | |
2303 \\[verilog-sk-state-machine] Insert a state machine definition, prompting for details. | |
2304 \\[verilog-sk-inout] Insert an inout declaration, prompting for details. | |
2305 \\[verilog-sk-wire] Insert a wire declaration, prompting for details. | |
2306 \\[verilog-sk-reg] Insert a register declaration, prompting for details. | |
2307 \\[verilog-sk-define-signal] Define signal under point as a register at the top of the module. | |
2308 | |
2309 All key bindings can be seen in a Verilog-buffer with \\[describe-bindings]. | |
2310 Key bindings specific to `verilog-mode-map' are: | |
2311 | |
2312 \\{verilog-mode-map}" | |
2313 (interactive) | |
2314 (kill-all-local-variables) | |
2315 (use-local-map verilog-mode-map) | |
2316 (setq major-mode 'verilog-mode) | |
2317 (setq mode-name "Verilog") | |
2318 (setq local-abbrev-table verilog-mode-abbrev-table) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2319 (set (make-local-variable 'beginning-of-defun-function) |
79546 | 2320 'verilog-beg-of-defun) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2321 (set (make-local-variable 'end-of-defun-function) |
79546 | 2322 'verilog-end-of-defun) |
79545 | 2323 (set-syntax-table verilog-mode-syntax-table) |
2324 (make-local-variable 'indent-line-function) | |
2325 (setq indent-line-function 'verilog-indent-line-relative) | |
2326 (setq comment-indent-function 'verilog-comment-indent) | |
2327 (make-local-variable 'parse-sexp-ignore-comments) | |
2328 (setq parse-sexp-ignore-comments nil) | |
2329 (make-local-variable 'comment-start) | |
2330 (make-local-variable 'comment-end) | |
2331 (make-local-variable 'comment-multi-line) | |
2332 (make-local-variable 'comment-start-skip) | |
2333 (setq comment-start "// " | |
2334 comment-end "" | |
2335 comment-start-skip "/\\*+ *\\|// *" | |
2336 comment-multi-line nil) | |
2337 ;; Set up for compilation | |
2338 (setq verilog-which-tool 1) | |
2339 (setq verilog-tool 'verilog-linter) | |
2340 (verilog-set-compile-command) | |
2341 (when (boundp 'hack-local-variables-hook) ;; Also modify any file-local-variables | |
2342 (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t)) | |
2343 | |
2344 ;; Setting up menus | |
79546 | 2345 (when (featurep 'xemacs) |
2346 (when (and current-menubar | |
2347 (not (assoc "Verilog" current-menubar))) | |
2348 ;; (set-buffer-menubar (copy-sequence current-menubar)) | |
2349 (add-submenu nil verilog-xemacs-menu) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2350 (add-submenu nil verilog-stmt-menu))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2351 |
79545 | 2352 ;; Stuff for GNU emacs |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2353 (set (make-local-variable 'font-lock-defaults) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2354 '((verilog-font-lock-keywords verilog-font-lock-keywords-1 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2355 verilog-font-lock-keywords-2 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2356 verilog-font-lock-keywords-3) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2357 nil nil nil verilog-beg-of-defun)) |
79545 | 2358 ;;------------------------------------------------------------ |
2359 ;; now hook in 'verilog-colorize-include-files (eldo-mode.el&spice-mode.el) | |
2360 ;; all buffer local: | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2361 (when (featurep 'xemacs) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2362 (make-local-hook 'font-lock-mode-hook) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2363 (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in emacs 20 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2364 (make-local-hook 'after-change-functions)) |
79545 | 2365 (add-hook 'font-lock-mode-hook 'verilog-colorize-include-files-buffer t t) |
2366 (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-colorize-include-files-buffer t t) ; not in emacs 20 | |
2367 (add-hook 'after-change-functions 'verilog-colorize-include-files t t) | |
2368 | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
2369 ;; Tell imenu how to handle Verilog. |
79545 | 2370 (make-local-variable 'imenu-generic-expression) |
2371 (setq imenu-generic-expression verilog-imenu-generic-expression) | |
2372 ;; hideshow support | |
2373 (unless (assq 'verilog-mode hs-special-modes-alist) | |
2374 (setq hs-special-modes-alist | |
2375 (cons '(verilog-mode-mode "\\<begin\\>" "\\<end\\>" nil | |
2376 verilog-forward-sexp-function) | |
2377 hs-special-modes-alist))) | |
2378 | |
2379 ;; Stuff for autos | |
2380 (add-hook 'write-contents-hooks 'verilog-auto-save-check) ; already local | |
2381 ;; (verilog-auto-reeval-locals t) ; Save locals in case user changes them | |
2382 ;; (verilog-getopt-flags) | |
2383 (run-hooks 'verilog-mode-hook)) | |
2384 | |
2385 | |
2386 ;; | |
2387 ;; Electric functions | |
2388 ;; | |
2389 (defun electric-verilog-terminate-line (&optional arg) | |
2390 "Terminate line and indent next line. | |
2391 With optional ARG, remove existing end of line comments." | |
2392 (interactive) | |
2393 ;; before that see if we are in a comment | |
2394 (let ((state | |
2395 (save-excursion | |
2396 (parse-partial-sexp (point-min) (point))))) | |
2397 (cond | |
2398 ((nth 7 state) ; Inside // comment | |
2399 (if (eolp) | |
2400 (progn | |
2401 (delete-horizontal-space) | |
2402 (newline)) | |
2403 (progn | |
2404 (newline) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2405 (insert "// ") |
79545 | 2406 (beginning-of-line))) |
2407 (verilog-indent-line)) | |
2408 ((nth 4 state) ; Inside any comment (hence /**/) | |
2409 (newline) | |
2410 (verilog-more-comment)) | |
2411 ((eolp) | |
2412 ;; First, check if current line should be indented | |
2413 (if (save-excursion | |
2414 (delete-horizontal-space) | |
2415 (beginning-of-line) | |
2416 (skip-chars-forward " \t") | |
2417 (if (looking-at verilog-auto-end-comment-lines-re) | |
2418 (let ((indent-str (verilog-indent-line))) | |
2419 ;; Maybe we should set some endcomments | |
2420 (if verilog-auto-endcomments | |
2421 (verilog-set-auto-endcomments indent-str arg)) | |
2422 (end-of-line) | |
2423 (delete-horizontal-space) | |
2424 (if arg | |
2425 () | |
2426 (newline)) | |
2427 nil) | |
2428 (progn | |
2429 (end-of-line) | |
2430 (delete-horizontal-space) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2431 't))) |
79545 | 2432 ;; see if we should line up assignments |
2433 (progn | |
2434 (if (or (memq 'all verilog-auto-lineup) | |
2435 (memq 'assignments verilog-auto-lineup)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2436 (verilog-pretty-expr)) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2437 (newline)) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2438 (forward-line 1)) |
79545 | 2439 ;; Indent next line |
2440 (if verilog-auto-indent-on-newline | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2441 (verilog-indent-line))) |
79545 | 2442 (t |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2443 (newline))))) |
79545 | 2444 |
2445 (defun electric-verilog-terminate-and-indent () | |
2446 "Insert a newline and indent for the next statement." | |
2447 (interactive) | |
2448 (electric-verilog-terminate-line 1)) | |
2449 | |
2450 (defun electric-verilog-semi () | |
2451 "Insert `;' character and reindent the line." | |
2452 (interactive) | |
2453 (insert last-command-char) | |
2454 | |
2455 (if (or (verilog-in-comment-or-string-p) | |
2456 (verilog-in-escaped-name-p)) | |
2457 () | |
2458 (save-excursion | |
2459 (beginning-of-line) | |
2460 (verilog-forward-ws&directives) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2461 (verilog-indent-line)) |
79545 | 2462 (if (and verilog-auto-newline |
2463 (not (verilog-parenthesis-depth))) | |
2464 (electric-verilog-terminate-line)))) | |
2465 | |
2466 (defun electric-verilog-semi-with-comment () | |
2467 "Insert `;' character, reindent the line and indent for comment." | |
2468 (interactive) | |
2469 (insert "\;") | |
2470 (save-excursion | |
2471 (beginning-of-line) | |
2472 (verilog-indent-line)) | |
2473 (indent-for-comment)) | |
2474 | |
2475 (defun electric-verilog-colon () | |
2476 "Insert `:' and do all indentations except line indent on this line." | |
2477 (interactive) | |
2478 (insert last-command-char) | |
2479 ;; Do nothing if within string. | |
2480 (if (or | |
2481 (verilog-within-string) | |
2482 (not (verilog-in-case-region-p))) | |
2483 () | |
2484 (save-excursion | |
2485 (let ((p (point)) | |
2486 (lim (progn (verilog-beg-of-statement) (point)))) | |
2487 (goto-char p) | |
2488 (verilog-backward-case-item lim) | |
2489 (verilog-indent-line))) | |
2490 ;; (let ((verilog-tab-always-indent nil)) | |
2491 ;; (verilog-indent-line)) | |
2492 )) | |
2493 | |
2494 ;;(defun electric-verilog-equal () | |
2495 ;; "Insert `=', and do indentation if within block." | |
2496 ;; (interactive) | |
2497 ;; (insert last-command-char) | |
2498 ;; Could auto line up expressions, but not yet | |
2499 ;; (if (eq (car (verilog-calculate-indent)) 'block) | |
2500 ;; (let ((verilog-tab-always-indent nil)) | |
2501 ;; (verilog-indent-command))) | |
2502 ;; ) | |
2503 | |
2504 (defun electric-verilog-tick () | |
2505 "Insert back-tick, and indent to column 0 if this is a CPP directive." | |
2506 (interactive) | |
2507 (insert last-command-char) | |
2508 (save-excursion | |
2509 (if (progn | |
2510 (beginning-of-line) | |
2511 (looking-at verilog-directive-re-1)) | |
2512 (verilog-indent-line)))) | |
2513 | |
2514 (defun electric-verilog-tab () | |
2515 "Function called when TAB is pressed in Verilog mode." | |
2516 (interactive) | |
2517 ;; If verilog-tab-always-indent, indent the beginning of the line. | |
2518 (if (or verilog-tab-always-indent | |
2519 (save-excursion | |
2520 (skip-chars-backward " \t") | |
2521 (bolp))) | |
2522 (let* ((oldpnt (point)) | |
2523 (boi-point | |
2524 (save-excursion | |
2525 (beginning-of-line) | |
2526 (skip-chars-forward " \t") | |
2527 (verilog-indent-line) | |
2528 (back-to-indentation) | |
2529 (point)))) | |
2530 (if (< (point) boi-point) | |
2531 (back-to-indentation) | |
2532 (cond ((not verilog-tab-to-comment)) | |
2533 ((not (eolp)) | |
2534 (end-of-line)) | |
2535 (t | |
2536 (indent-for-comment) | |
2537 (when (and (eolp) (= oldpnt (point))) | |
2538 ; kill existing comment | |
2539 (beginning-of-line) | |
2540 (re-search-forward comment-start-skip oldpnt 'move) | |
2541 (goto-char (match-beginning 0)) | |
2542 (skip-chars-backward " \t") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2543 (kill-region (point) oldpnt)))))) |
79545 | 2544 (progn (insert "\t")))) |
2545 | |
2546 | |
2547 | |
2548 ;; | |
2549 ;; Interactive functions | |
2550 ;; | |
2551 | |
2552 (defun verilog-indent-buffer () | |
2553 "Indent-region the entire buffer as Verilog code. | |
2554 To call this from the command line, see \\[verilog-batch-indent]." | |
2555 (interactive) | |
2556 (verilog-mode) | |
2557 (indent-region (point-min) (point-max) nil)) | |
2558 | |
2559 (defun verilog-insert-block () | |
2560 "Insert Verilog begin ... end; block in the code with right indentation." | |
2561 (interactive) | |
2562 (verilog-indent-line) | |
2563 (insert "begin") | |
2564 (electric-verilog-terminate-line) | |
2565 (save-excursion | |
2566 (electric-verilog-terminate-line) | |
2567 (insert "end") | |
2568 (beginning-of-line) | |
2569 (verilog-indent-line))) | |
2570 | |
2571 (defun verilog-star-comment () | |
2572 "Insert Verilog star comment at point." | |
2573 (interactive) | |
2574 (verilog-indent-line) | |
2575 (insert "/*") | |
2576 (save-excursion | |
2577 (newline) | |
2578 (insert " */")) | |
2579 (newline) | |
2580 (insert " * ")) | |
2581 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2582 (defun verilog-insert-1 (fmt max) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2583 "Use format string FMT to insert integers 0 to MAX - 1. |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2584 Inserts one integer per line, at the current column. Stops early |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2585 if it reaches the end of the buffer." |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2586 (let ((col (current-column)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2587 (n 0)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2588 (save-excursion |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2589 (while (< n max) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2590 (insert (format fmt n)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2591 (forward-line 1) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2592 ;; Note that this function does not bother to check for lines |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2593 ;; shorter than col. |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2594 (if (eobp) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2595 (setq n max) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2596 (setq n (1+ n)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2597 (move-to-column col)))))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2598 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2599 (defun verilog-insert-indices (max) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2600 "Insert a set of indices into a rectangle. |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2601 The upper left corner is defined by point. Indices begin with 0 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2602 and extend to the MAX - 1. If no prefix arg is given, the user |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2603 is prompted for a value. The indices are surrounded by square |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2604 brackets \[]. For example, the following code with the point |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2605 located after the first 'a' gives: |
79545 | 2606 |
2607 a = b a[ 0] = b | |
2608 a = b a[ 1] = b | |
2609 a = b a[ 2] = b | |
2610 a = b a[ 3] = b | |
2611 a = b ==> insert-indices ==> a[ 4] = b | |
2612 a = b a[ 5] = b | |
2613 a = b a[ 6] = b | |
2614 a = b a[ 7] = b | |
2615 a = b a[ 8] = b" | |
2616 | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2617 (interactive "NMAX: ") |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2618 (verilog-insert-1 "[%3d]" max)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2619 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2620 (defun verilog-generate-numbers (max) |
79545 | 2621 "Insert a set of generated numbers into a rectangle. |
2622 The upper left corner is defined by point. The numbers are padded to three | |
2623 digits, starting with 000 and extending to (MAX - 1). If no prefix argument | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2624 is supplied, then the user is prompted for the MAX number. Consider the |
79545 | 2625 following code fragment: |
2626 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2627 buf buf buf buf000 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2628 buf buf buf buf001 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2629 buf buf buf buf002 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2630 buf buf buf buf003 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2631 buf buf ==> generate-numbers ==> buf buf004 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2632 buf buf buf buf005 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2633 buf buf buf buf006 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2634 buf buf buf buf007 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2635 buf buf buf buf008" |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2636 |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2637 (interactive "NMAX: ") |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2638 (verilog-insert-1 "%3.3d" max)) |
79545 | 2639 |
2640 (defun verilog-mark-defun () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
2641 "Mark the current Verilog function (or procedure). |
79545 | 2642 This puts the mark at the end, and point at the beginning." |
2643 (interactive) | |
79810
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
2644 (when (featurep 'xemacs) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
2645 (push-mark (point)) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
2646 (verilog-end-of-defun) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
2647 (push-mark (point)) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
2648 (verilog-beg-of-defun) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
2649 (if (fboundp 'zmacs-activate-region) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
2650 (zmacs-activate-region)))) |
79545 | 2651 |
2652 (defun verilog-comment-region (start end) | |
2653 ; checkdoc-params: (start end) | |
2654 "Put the region into a Verilog comment. | |
2655 The comments that are in this area are \"deformed\": | |
2656 `*)' becomes `!(*' and `}' becomes `!{'. | |
2657 These deformed comments are returned to normal if you use | |
2658 \\[verilog-uncomment-region] to undo the commenting. | |
2659 | |
2660 The commented area starts with `verilog-exclude-str-start', and ends with | |
2661 `verilog-exclude-str-end'. But if you change these variables, | |
2662 \\[verilog-uncomment-region] won't recognize the comments." | |
2663 (interactive "r") | |
2664 (save-excursion | |
2665 ;; Insert start and endcomments | |
2666 (goto-char end) | |
2667 (if (and (save-excursion (skip-chars-forward " \t") (eolp)) | |
2668 (not (save-excursion (skip-chars-backward " \t") (bolp)))) | |
2669 (forward-line 1) | |
2670 (beginning-of-line)) | |
2671 (insert verilog-exclude-str-end) | |
2672 (setq end (point)) | |
2673 (newline) | |
2674 (goto-char start) | |
2675 (beginning-of-line) | |
2676 (insert verilog-exclude-str-start) | |
2677 (newline) | |
2678 ;; Replace end-comments within commented area | |
2679 (goto-char end) | |
2680 (save-excursion | |
2681 (while (re-search-backward "\\*/" start t) | |
2682 (replace-match "*-/" t t))) | |
2683 (save-excursion | |
2684 (let ((s+1 (1+ start))) | |
2685 (while (re-search-backward "/\\*" s+1 t) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2686 (replace-match "/-*" t t)))))) |
79545 | 2687 |
2688 (defun verilog-uncomment-region () | |
2689 "Uncomment a commented area; change deformed comments back to normal. | |
2690 This command does nothing if the pointer is not in a commented | |
2691 area. See also `verilog-comment-region'." | |
2692 (interactive) | |
2693 (save-excursion | |
2694 (let ((start (point)) | |
2695 (end (point))) | |
2696 ;; Find the boundaries of the comment | |
2697 (save-excursion | |
2698 (setq start (progn (search-backward verilog-exclude-str-start nil t) | |
2699 (point))) | |
2700 (setq end (progn (search-forward verilog-exclude-str-end nil t) | |
2701 (point)))) | |
2702 ;; Check if we're really inside a comment | |
2703 (if (or (equal start (point)) (<= end (point))) | |
2704 (message "Not standing within commented area.") | |
2705 (progn | |
2706 ;; Remove endcomment | |
2707 (goto-char end) | |
2708 (beginning-of-line) | |
2709 (let ((pos (point))) | |
2710 (end-of-line) | |
2711 (delete-region pos (1+ (point)))) | |
2712 ;; Change comments back to normal | |
2713 (save-excursion | |
2714 (while (re-search-backward "\\*-/" start t) | |
2715 (replace-match "*/" t t))) | |
2716 (save-excursion | |
2717 (while (re-search-backward "/-\\*" start t) | |
2718 (replace-match "/*" t t))) | |
2719 ;; Remove start comment | |
2720 (goto-char start) | |
2721 (beginning-of-line) | |
2722 (let ((pos (point))) | |
2723 (end-of-line) | |
2724 (delete-region pos (1+ (point))))))))) | |
2725 | |
2726 (defun verilog-beg-of-defun () | |
2727 "Move backward to the beginning of the current function or procedure." | |
2728 (interactive) | |
2729 (verilog-re-search-backward verilog-defun-re nil 'move)) | |
2730 | |
2731 (defun verilog-end-of-defun () | |
2732 "Move forward to the end of the current function or procedure." | |
2733 (interactive) | |
2734 (verilog-re-search-forward verilog-end-defun-re nil 'move)) | |
2735 | |
2736 (defun verilog-get-beg-of-defun (&optional warn) | |
2737 (save-excursion | |
2738 (cond ((verilog-re-search-forward-quick verilog-defun-re nil t) | |
2739 (point)) | |
2740 (t | |
2741 (error "%s: Can't find module beginning" (verilog-point-text)) | |
2742 (point-max))))) | |
2743 (defun verilog-get-end-of-defun (&optional warn) | |
2744 (save-excursion | |
2745 (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t) | |
2746 (point)) | |
2747 (t | |
2748 (error "%s: Can't find endmodule" (verilog-point-text)) | |
2749 (point-max))))) | |
2750 | |
2751 (defun verilog-label-be (&optional arg) | |
2752 "Label matching begin ... end, fork ... join and case ... endcase statements. | |
2753 With ARG, first kill any existing labels." | |
2754 (interactive) | |
2755 (let ((cnt 0) | |
2756 (oldpos (point)) | |
2757 (b (progn | |
2758 (verilog-beg-of-defun) | |
2759 (point-marker))) | |
2760 (e (progn | |
2761 (verilog-end-of-defun) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2762 (point-marker)))) |
79545 | 2763 (goto-char (marker-position b)) |
2764 (if (> (- e b) 200) | |
2765 (message "Relabeling module...")) | |
2766 (while (and | |
2767 (> (marker-position e) (point)) | |
2768 (verilog-re-search-forward | |
2769 (concat | |
2770 "\\<end\\(\\(function\\)\\|\\(task\\)\\|\\(module\\)\\|\\(primitive\\)\\|\\(interface\\)\\|\\(package\\)\\|\\(case\\)\\)?\\>" | |
2771 "\\|\\(`endif\\)\\|\\(`else\\)") | |
2772 nil 'move)) | |
2773 (goto-char (match-beginning 0)) | |
2774 (let ((indent-str (verilog-indent-line))) | |
2775 (verilog-set-auto-endcomments indent-str 't) | |
2776 (end-of-line) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2777 (delete-horizontal-space)) |
79545 | 2778 (setq cnt (1+ cnt)) |
2779 (if (= 9 (% cnt 10)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2780 (message "%d..." cnt))) |
79545 | 2781 (goto-char oldpos) |
2782 (if (or | |
2783 (> (- e b) 200) | |
2784 (> cnt 20)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2785 (message "%d lines auto commented" cnt)))) |
79545 | 2786 |
2787 (defun verilog-beg-of-statement () | |
2788 "Move backward to beginning of statement." | |
2789 (interactive) | |
2790 ;; Move back token by token until we see the end | |
2791 ;; of some ealier line. | |
2792 (while | |
2793 ;; If the current point does not begin a new | |
2794 ;; statement, as in the character ahead of us is a ';', or SOF | |
2795 ;; or the string after us unambiguosly starts a statement, | |
2796 ;; or the token before us unambiguously ends a statement, | |
2797 ;; then move back a token and test again. | |
2798 (not (or | |
2799 (bolp) | |
2800 (= (preceding-char) ?\;) | |
2801 (not (or | |
2802 (looking-at "\\<") | |
2803 (forward-word -1))) | |
2804 (and | |
2805 (looking-at verilog-extended-complete-re) | |
2806 (not (save-excursion | |
2807 (verilog-backward-token) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2808 (looking-at verilog-extended-complete-re)))) |
79545 | 2809 (looking-at verilog-basic-complete-re) |
2810 (save-excursion | |
2811 (verilog-backward-token) | |
2812 (or | |
2813 (looking-at verilog-end-block-re) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2814 (looking-at verilog-preprocessor-re))))) |
79545 | 2815 (verilog-backward-syntactic-ws) |
2816 (verilog-backward-token)) | |
2817 ;; Now point is where the previous line ended. | |
2818 (verilog-forward-syntactic-ws)) | |
2819 | |
2820 (defun verilog-beg-of-statement-1 () | |
2821 "Move backward to beginning of statement." | |
2822 (interactive) | |
2823 (let ((pt (point))) | |
2824 | |
2825 (while (and (not (looking-at verilog-complete-reg)) | |
2826 (setq pt (point)) | |
2827 (verilog-backward-token) | |
2828 (not (looking-at verilog-complete-reg)) | |
2829 (verilog-backward-syntactic-ws) | |
2830 (setq pt (point)) | |
2831 (not (bolp)) | |
2832 (not (= (preceding-char) ?\;)))) | |
2833 (goto-char pt) | |
2834 (verilog-forward-ws&directives))) | |
2835 | |
2836 (defun verilog-end-of-statement () | |
2837 "Move forward to end of current statement." | |
2838 (interactive) | |
2839 (let ((nest 0) pos) | |
2840 (or (looking-at verilog-beg-block-re) | |
2841 ;; Skip to end of statement | |
2842 (setq pos (catch 'found | |
2843 (while t | |
2844 (forward-sexp 1) | |
2845 (verilog-skip-forward-comment-or-string) | |
2846 (cond ((looking-at "[ \t]*;") | |
2847 (skip-chars-forward "^;") | |
2848 (forward-char 1) | |
2849 (throw 'found (point))) | |
2850 ((save-excursion | |
2851 (forward-sexp -1) | |
2852 (looking-at verilog-beg-block-re)) | |
2853 (goto-char (match-beginning 0)) | |
2854 (throw 'found nil)) | |
2855 ((looking-at "[ \t]*)") | |
79546 | 2856 (throw 'found (point))) |
79545 | 2857 ((eobp) |
2858 (throw 'found (point)))))))) | |
2859 (if (not pos) | |
2860 ;; Skip a whole block | |
2861 (catch 'found | |
2862 (while t | |
2863 (verilog-re-search-forward verilog-end-statement-re nil 'move) | |
2864 (setq nest (if (match-end 1) | |
2865 (1+ nest) | |
2866 (1- nest))) | |
2867 (cond ((eobp) | |
2868 (throw 'found (point))) | |
2869 ((= 0 nest) | |
2870 (throw 'found (verilog-end-of-statement)))))) | |
2871 pos))) | |
2872 | |
2873 (defun verilog-in-case-region-p () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
2874 "Return true if in a case region. |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
2875 More specifically, point @ in the line foo : @ begin" |
79545 | 2876 (interactive) |
2877 (save-excursion | |
2878 (if (and | |
2879 (progn (verilog-forward-syntactic-ws) | |
2880 (looking-at "\\<begin\\>")) | |
2881 (progn (verilog-backward-syntactic-ws) | |
2882 (= (preceding-char) ?\:))) | |
2883 (catch 'found | |
2884 (let ((nest 1)) | |
2885 (while t | |
2886 (verilog-re-search-backward | |
2887 (concat "\\(\\<module\\>\\)\\|\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|" | |
2888 "\\(\\<endcase\\>\\)\\>") | |
2889 nil 'move) | |
2890 (cond | |
2891 ((match-end 3) | |
2892 (setq nest (1+ nest))) | |
2893 ((match-end 2) | |
2894 (if (= nest 1) | |
2895 (throw 'found 1)) | |
2896 (setq nest (1- nest))) | |
2897 (t | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2898 (throw 'found (= nest 0))))))) |
79545 | 2899 nil))) |
2900 (defun verilog-in-struct-region-p () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
2901 "Return true if in a struct region. |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
2902 More specifically, in a list after a struct|union keyword." |
79545 | 2903 (interactive) |
2904 (save-excursion | |
2905 (let* ((state (parse-partial-sexp (point-min) (point))) | |
2906 (depth (nth 0 state))) | |
2907 (if depth | |
2908 (progn (backward-up-list depth) | |
2909 (verilog-beg-of-statement) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2910 (looking-at "\\<typedef\\>?\\s-*\\<struct\\|union\\>")))))) |
79545 | 2911 |
2912 (defun verilog-in-generate-region-p () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
2913 "Return true if in a generate region. |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
2914 More specifically, after a generate and before an endgenerate." |
79545 | 2915 (interactive) |
2916 (let ((lim (save-excursion (verilog-beg-of-defun) (point))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2917 (nest 1)) |
79545 | 2918 (save-excursion |
2919 (while (and | |
2920 (/= nest 0) | |
2921 (verilog-re-search-backward "\\<\\(generate\\)\\|\\(endgenerate\\)\\>" lim 'move) | |
2922 (cond | |
2923 ((match-end 1) ; generate | |
2924 (setq nest (1- nest))) | |
2925 ((match-end 2) ; endgenerate | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2926 (setq nest (1+ nest))))))) |
79545 | 2927 (= nest 0) )) ; return nest |
2928 | |
2929 (defun verilog-in-fork-region-p () | |
2930 "Return true if between a fork and join." | |
2931 (interactive) | |
2932 (let ((lim (save-excursion (verilog-beg-of-defun) (point))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2933 (nest 1)) |
79545 | 2934 (save-excursion |
2935 (while (and | |
2936 (/= nest 0) | |
2937 (verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\(_any\\|_none\\)?\\)\\>" lim 'move) | |
2938 (cond | |
2939 ((match-end 1) ; fork | |
2940 (setq nest (1- nest))) | |
2941 ((match-end 2) ; join | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2942 (setq nest (1+ nest))))))) |
79545 | 2943 (= nest 0) )) ; return nest |
2944 | |
2945 (defun verilog-backward-case-item (lim) | |
2946 "Skip backward to nearest enclosing case item. | |
2947 Limit search to point LIM." | |
2948 (interactive) | |
2949 (let ((str 'nil) | |
2950 (lim1 | |
2951 (progn | |
2952 (save-excursion | |
2953 (verilog-re-search-backward verilog-endcomment-reason-re | |
2954 lim 'move) | |
2955 (point))))) | |
2956 ;; Try to find the real : | |
2957 (if (save-excursion (search-backward ":" lim1 t)) | |
2958 (let ((colon 0) | |
2959 b e ) | |
2960 (while | |
2961 (and | |
2962 (< colon 1) | |
2963 (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)" | |
2964 lim1 'move)) | |
2965 (cond | |
2966 ((match-end 1) ;; [ | |
2967 (setq colon (1+ colon)) | |
2968 (if (>= colon 0) | |
2969 (error "%s: unbalanced [" (verilog-point-text)))) | |
2970 ((match-end 2) ;; ] | |
2971 (setq colon (1- colon))) | |
2972 | |
2973 ((match-end 3) ;; : | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2974 (setq colon (1+ colon))))) |
79545 | 2975 ;; Skip back to beginning of case item |
2976 (skip-chars-backward "\t ") | |
2977 (verilog-skip-backward-comment-or-string) | |
2978 (setq e (point)) | |
2979 (setq b | |
2980 (progn | |
2981 (if | |
2982 (verilog-re-search-backward | |
2983 "\\<\\(case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move) | |
2984 (progn | |
2985 (cond | |
2986 ((match-end 1) | |
2987 (goto-char (match-end 1)) | |
2988 (verilog-forward-ws&directives) | |
2989 (if (looking-at "(") | |
2990 (progn | |
2991 (forward-sexp) | |
2992 (verilog-forward-ws&directives))) | |
2993 (point)) | |
2994 (t | |
2995 (goto-char (match-end 0)) | |
2996 (verilog-forward-ws&directives) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2997 (point)))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2998 (error "Malformed case item")))) |
79545 | 2999 (setq str (buffer-substring b e)) |
3000 (if | |
3001 (setq e | |
3002 (string-match | |
3003 "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str)) | |
3004 (setq str (concat (substring str 0 e) "..."))) | |
3005 str) | |
3006 'nil))) | |
3007 | |
3008 | |
3009 ;; | |
3010 ;; Other functions | |
3011 ;; | |
3012 | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3013 (defun verilog-kill-existing-comment () |
79545 | 3014 "Kill auto comment on this line." |
3015 (save-excursion | |
3016 (let* ( | |
3017 (e (progn | |
3018 (end-of-line) | |
3019 (point))) | |
3020 (b (progn | |
3021 (beginning-of-line) | |
3022 (search-forward "//" e t)))) | |
3023 (if b | |
3024 (delete-region (- b 2) e))))) | |
3025 | |
3026 (defconst verilog-directive-nest-re | |
3027 (concat "\\(`else\\>\\)\\|" | |
3028 "\\(`endif\\>\\)\\|" | |
3029 "\\(`if\\>\\)\\|" | |
3030 "\\(`ifdef\\>\\)\\|" | |
3031 "\\(`ifndef\\>\\)")) | |
3032 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment) | |
3033 "Add ending comment with given INDENT-STR. | |
3034 With KILL-EXISTING-COMMENT, remove what was there before. | |
3035 Insert `// case: 7 ' or `// NAME ' on this line if appropriate. | |
3036 Insert `// case expr ' if this line ends a case block. | |
3037 Insert `// ifdef FOO ' if this line ends code conditional on FOO. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
3038 Insert `// NAME ' if this line ends a function, task, module, |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
3039 primitive or interface named NAME." |
79545 | 3040 (save-excursion |
3041 (cond | |
3042 (; Comment close preprocessor directives | |
3043 (and | |
3044 (looking-at "\\(`endif\\)\\|\\(`else\\)") | |
3045 (or kill-existing-comment | |
3046 (not (save-excursion | |
3047 (end-of-line) | |
3048 (search-backward "//" (verilog-get-beg-of-line) t))))) | |
3049 (let ((nest 1) b e | |
3050 m | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3051 (else (if (match-end 2) "!" " "))) |
79545 | 3052 (end-of-line) |
3053 (if kill-existing-comment | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3054 (verilog-kill-existing-comment)) |
79545 | 3055 (delete-horizontal-space) |
3056 (save-excursion | |
3057 (backward-sexp 1) | |
3058 (while (and (/= nest 0) | |
3059 (verilog-re-search-backward verilog-directive-nest-re nil 'move)) | |
3060 (cond | |
3061 ((match-end 1) ; `else | |
3062 (if (= nest 1) | |
3063 (setq else "!"))) | |
3064 ((match-end 2) ; `endif | |
3065 (setq nest (1+ nest))) | |
3066 ((match-end 3) ; `if | |
3067 (setq nest (1- nest))) | |
3068 ((match-end 4) ; `ifdef | |
3069 (setq nest (1- nest))) | |
3070 ((match-end 5) ; `ifndef | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3071 (setq nest (1- nest))))) |
79545 | 3072 (if (match-end 0) |
3073 (setq | |
3074 m (buffer-substring | |
3075 (match-beginning 0) | |
3076 (match-end 0)) | |
3077 b (progn | |
3078 (skip-chars-forward "^ \t") | |
3079 (verilog-forward-syntactic-ws) | |
3080 (point)) | |
3081 e (progn | |
3082 (skip-chars-forward "a-zA-Z0-9_") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3083 (point))))) |
79545 | 3084 (if b |
3085 (if (> (count-lines (point) b) verilog-minimum-comment-distance) | |
3086 (insert (concat " // " else m " " (buffer-substring b e)))) | |
3087 (progn | |
3088 (insert " // unmatched `else or `endif") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3089 (ding 't))))) |
79545 | 3090 |
3091 (; Comment close case/class/function/task/module and named block | |
3092 (and (looking-at "\\<end") | |
3093 (or kill-existing-comment | |
3094 (not (save-excursion | |
3095 (end-of-line) | |
3096 (search-backward "//" (verilog-get-beg-of-line) t))))) | |
3097 (let ((type (car indent-str))) | |
3098 (unless (eq type 'declaration) | |
3099 (unless (looking-at (concat "\\(" verilog-end-block-ordered-re "\\)[ \t]*:")) ;; ignore named ends | |
3100 (if (looking-at verilog-end-block-ordered-re) | |
3101 (cond | |
3102 (;- This is a case block; search back for the start of this case | |
3103 (match-end 1) ;; of verilog-end-block-ordered-re | |
3104 | |
3105 (let ((err 't) | |
3106 (str "UNMATCHED!!")) | |
3107 (save-excursion | |
3108 (verilog-leap-to-head) | |
3109 (cond | |
3110 ((looking-at "\\<randcase\\>") | |
3111 (setq str "randcase") | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3112 (setq err nil)) |
79545 | 3113 ((match-end 0) |
3114 (goto-char (match-end 1)) | |
3115 (if nil | |
3116 (let (s f) | |
3117 (setq s (match-beginning 1)) | |
3118 (setq f (progn (end-of-line) | |
3119 (point))) | |
3120 (setq str (buffer-substring s f))) | |
3121 (setq err nil)) | |
3122 (setq str (concat (buffer-substring (match-beginning 1) (match-end 1)) | |
3123 " " | |
3124 (verilog-get-expr)))))) | |
3125 (end-of-line) | |
3126 (if kill-existing-comment | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3127 (verilog-kill-existing-comment)) |
79545 | 3128 (delete-horizontal-space) |
3129 (insert (concat " // " str )) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3130 (if err (ding 't)))) |
79545 | 3131 |
3132 (;- This is a begin..end block | |
3133 (match-end 2) ;; of verilog-end-block-ordered-re | |
3134 (let ((str " // UNMATCHED !!") | |
3135 (err 't) | |
3136 (here (point)) | |
3137 there | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3138 cntx) |
79545 | 3139 (save-excursion |
3140 (verilog-leap-to-head) | |
3141 (setq there (point)) | |
3142 (if (not (match-end 0)) | |
3143 (progn | |
3144 (goto-char here) | |
3145 (end-of-line) | |
3146 (if kill-existing-comment | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3147 (verilog-kill-existing-comment)) |
79545 | 3148 (delete-horizontal-space) |
3149 (insert str) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3150 (ding 't)) |
79545 | 3151 (let ((lim |
3152 (save-excursion (verilog-beg-of-defun) (point))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3153 (here (point))) |
79545 | 3154 (cond |
3155 (;-- handle named block differently | |
3156 (looking-at verilog-named-block-re) | |
3157 (search-forward ":") | |
3158 (setq there (point)) | |
3159 (setq str (verilog-get-expr)) | |
3160 (setq err nil) | |
3161 (setq str (concat " // block: " str ))) | |
3162 | |
3163 ((verilog-in-case-region-p) ;-- handle case item differently | |
3164 (goto-char here) | |
3165 (setq str (verilog-backward-case-item lim)) | |
3166 (setq there (point)) | |
3167 (setq err nil) | |
3168 (setq str (concat " // case: " str ))) | |
3169 | |
3170 (;- try to find "reason" for this begin | |
3171 (cond | |
3172 (; | |
3173 (eq here (progn | |
3174 (verilog-backward-token) | |
3175 (verilog-beg-of-statement-1) | |
3176 (point))) | |
3177 (setq err nil) | |
3178 (setq str "")) | |
3179 ((looking-at verilog-endcomment-reason-re) | |
3180 (setq there (match-end 0)) | |
3181 (setq cntx (concat | |
3182 (buffer-substring (match-beginning 0) (match-end 0)) " ")) | |
3183 (cond | |
3184 (;- begin | |
3185 (match-end 2) | |
3186 (setq err nil) | |
3187 (save-excursion | |
3188 (if (and (verilog-continued-line) | |
3189 (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>")) | |
3190 (progn | |
3191 (goto-char (match-end 0)) | |
3192 (setq there (point)) | |
3193 (setq str | |
3194 (concat " // " | |
3195 (buffer-substring (match-beginning 0) (match-end 0)) " " | |
3196 (verilog-get-expr)))) | |
3197 (setq str "")))) | |
3198 | |
3199 (;- else | |
3200 (match-end 4) | |
3201 (let ((nest 0) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3202 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)")) |
79545 | 3203 (catch 'skip |
3204 (while (verilog-re-search-backward reg nil 'move) | |
3205 (cond | |
3206 ((match-end 1) ; begin | |
3207 (setq nest (1- nest))) | |
3208 ((match-end 2) ; end | |
3209 (setq nest (1+ nest))) | |
3210 ((match-end 3) | |
3211 (if (= 0 nest) | |
3212 (progn | |
3213 (goto-char (match-end 0)) | |
3214 (setq there (point)) | |
3215 (setq err nil) | |
3216 (setq str (verilog-get-expr)) | |
3217 (setq str (concat " // else: !if" str )) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3218 (throw 'skip 1))))))))) |
79545 | 3219 |
3220 (;- end else | |
3221 (match-end 5) | |
3222 (goto-char there) | |
3223 (let ((nest 0) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3224 (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)")) |
79545 | 3225 (catch 'skip |
3226 (while (verilog-re-search-backward reg nil 'move) | |
3227 (cond | |
3228 ((match-end 1) ; begin | |
3229 (setq nest (1- nest))) | |
3230 ((match-end 2) ; end | |
3231 (setq nest (1+ nest))) | |
3232 ((match-end 3) | |
3233 (if (= 0 nest) | |
3234 (progn | |
3235 (goto-char (match-end 0)) | |
3236 (setq there (point)) | |
3237 (setq err nil) | |
3238 (setq str (verilog-get-expr)) | |
3239 (setq str (concat " // else: !if" str )) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3240 (throw 'skip 1))))))))) |
79545 | 3241 |
3242 (;- task/function/initial et cetera | |
3243 t | |
3244 (match-end 0) | |
3245 (goto-char (match-end 0)) | |
3246 (setq there (point)) | |
3247 (setq err nil) | |
3248 (setq str (verilog-get-expr)) | |
3249 (setq str (concat " // " cntx str ))) | |
3250 | |
3251 (;-- otherwise... | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3252 (setq str " // auto-endcomment confused ")))) |
79545 | 3253 |
3254 ((and | |
3255 (verilog-in-case-region-p) ;-- handle case item differently | |
3256 (progn | |
3257 (setq there (point)) | |
3258 (goto-char here) | |
3259 (setq str (verilog-backward-case-item lim)))) | |
3260 (setq err nil) | |
3261 (setq str (concat " // case: " str ))) | |
3262 | |
3263 ((verilog-in-fork-region-p) | |
3264 (setq err nil) | |
3265 (setq str " // fork branch" )) | |
3266 | |
3267 ((looking-at "\\<end\\>") | |
3268 ;; HERE | |
3269 (forward-word 1) | |
3270 (verilog-forward-syntactic-ws) | |
3271 (setq err nil) | |
3272 (setq str (verilog-get-expr)) | |
3273 (setq str (concat " // " cntx str ))) | |
3274 | |
3275 )))) | |
3276 (goto-char here) | |
3277 (end-of-line) | |
3278 (if kill-existing-comment | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3279 (verilog-kill-existing-comment)) |
79545 | 3280 (delete-horizontal-space) |
3281 (if (or err | |
3282 (> (count-lines here there) verilog-minimum-comment-distance)) | |
3283 (insert str)) | |
3284 (if err (ding 't)) | |
3285 )))) | |
3286 (;- this is endclass, which can be nested | |
3287 (match-end 11) ;; of verilog-end-block-ordered-re | |
3288 ;;(goto-char there) | |
3289 (let ((nest 0) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3290 (reg "\\<\\(class\\)\\|\\(endclass\\)\\|\\(package\\|primitive\\|\\(macro\\)?module\\)\\>") |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3291 string) |
79545 | 3292 (save-excursion |
3293 (catch 'skip | |
3294 (while (verilog-re-search-backward reg nil 'move) | |
3295 (cond | |
3296 ((match-end 3) ; endclass | |
3297 (ding 't) | |
3298 (setq string "unmatched endclass") | |
3299 (throw 'skip 1)) | |
3300 | |
3301 ((match-end 2) ; endclass | |
3302 (setq nest (1+ nest))) | |
3303 | |
3304 ((match-end 1) ; class | |
3305 (setq nest (1- nest)) | |
3306 (if (< nest 0) | |
3307 (progn | |
3308 (goto-char (match-end 0)) | |
3309 (let (b e) | |
3310 (setq b (progn | |
3311 (skip-chars-forward "^ \t") | |
3312 (verilog-forward-ws&directives) | |
3313 (point)) | |
3314 e (progn | |
3315 (skip-chars-forward "a-zA-Z0-9_") | |
3316 (point))) | |
3317 (setq string (buffer-substring b e))) | |
3318 (throw 'skip 1)))) | |
3319 )))) | |
3320 (end-of-line) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3321 (insert (concat " // " string )))) |
79545 | 3322 |
3323 (;- this is end{function,generate,task,module,primitive,table,generate} | |
3324 ;- which can not be nested. | |
3325 t | |
3326 (let (string reg (width nil)) | |
3327 (end-of-line) | |
3328 (if kill-existing-comment | |
3329 (save-match-data | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3330 (verilog-kill-existing-comment))) |
79545 | 3331 (delete-horizontal-space) |
3332 (backward-sexp) | |
3333 (cond | |
3334 ((match-end 5) ;; of verilog-end-block-ordered-re | |
3335 (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3336 (setq width "\\(\\s-*\\(\\[[^]]*\\]\\)\\|\\(real\\(time\\)?\\)\\|\\(integer\\)\\|\\(time\\)\\)?")) |
79545 | 3337 ((match-end 6) ;; of verilog-end-block-ordered-re |
3338 (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)")) | |
3339 ((match-end 7) ;; of verilog-end-block-ordered-re | |
3340 (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>")) | |
3341 ((match-end 8) ;; of verilog-end-block-ordered-re | |
3342 (setq reg "\\(\\<primitive\\>\\)\\|\\(\\<\\(endprimitive\\|package\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3343 ((match-end 9) ;; of verilog-end-block-ordered-re | |
3344 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<\\(endinterface\\|package\\|primitive\\|\\(macro\\)?module\\)\\>\\)")) | |
3345 ((match-end 10) ;; of verilog-end-block-ordered-re | |
3346 (setq reg "\\(\\<package\\>\\)\\|\\(\\<\\(endpackage\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3347 ((match-end 11) ;; of verilog-end-block-ordered-re | |
3348 (setq reg "\\(\\<class\\>\\)\\|\\(\\<\\(endclass\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3349 ((match-end 12) ;; of verilog-end-block-ordered-re | |
3350 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<\\(endcovergroup\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3351 ((match-end 13) ;; of verilog-end-block-ordered-re | |
3352 (setq reg "\\(\\<program\\>\\)\\|\\(\\<\\(endprogram\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3353 ((match-end 14) ;; of verilog-end-block-ordered-re | |
3354 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<\\(endsequence\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3355 ((match-end 15) ;; of verilog-end-block-ordered-re | |
3356 (setq reg "\\(\\<clocking\\>\\)\\|\\<endclocking\\>")) | |
3357 | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3358 (t (error "Problem in verilog-set-auto-endcomments"))) |
79545 | 3359 (let (b e) |
3360 (save-excursion | |
3361 (verilog-re-search-backward reg nil 'move) | |
3362 (cond | |
3363 ((match-end 1) | |
3364 (setq b (progn | |
3365 (skip-chars-forward "^ \t") | |
3366 (verilog-forward-ws&directives) | |
3367 (if (and width (looking-at width)) | |
3368 (progn | |
3369 (goto-char (match-end 0)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3370 (verilog-forward-ws&directives))) |
79545 | 3371 (point)) |
3372 e (progn | |
3373 (skip-chars-forward "a-zA-Z0-9_") | |
3374 (point))) | |
3375 (setq string (buffer-substring b e))) | |
3376 (t | |
3377 (ding 't) | |
3378 (setq string "unmatched end(function|task|module|primitive|interface|package|class|clocking)"))))) | |
3379 (end-of-line) | |
3380 (insert (concat " // " string ))) | |
3381 )))))))))) | |
3382 | |
3383 (defun verilog-get-expr() | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
3384 "Grab expression at point, e.g, case ( a | b & (c ^d))." |
79545 | 3385 (let* ((b (progn |
3386 (verilog-forward-syntactic-ws) | |
3387 (skip-chars-forward " \t") | |
3388 (point))) | |
3389 (e (let ((par 1)) | |
3390 (cond | |
3391 ((looking-at "@") | |
3392 (forward-char 1) | |
3393 (verilog-forward-syntactic-ws) | |
3394 (if (looking-at "(") | |
3395 (progn | |
3396 (forward-char 1) | |
3397 (while (and (/= par 0) | |
3398 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move)) | |
3399 (cond | |
3400 ((match-end 1) | |
3401 (setq par (1+ par))) | |
3402 ((match-end 2) | |
3403 (setq par (1- par))))))) | |
3404 (point)) | |
3405 ((looking-at "(") | |
3406 (forward-char 1) | |
3407 (while (and (/= par 0) | |
3408 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move)) | |
3409 (cond | |
3410 ((match-end 1) | |
3411 (setq par (1+ par))) | |
3412 ((match-end 2) | |
3413 (setq par (1- par))))) | |
3414 (point)) | |
3415 ((looking-at "\\[") | |
3416 (forward-char 1) | |
3417 (while (and (/= par 0) | |
3418 (verilog-re-search-forward "\\(\\[\\)\\|\\(\\]\\)" nil 'move)) | |
3419 (cond | |
3420 ((match-end 1) | |
3421 (setq par (1+ par))) | |
3422 ((match-end 2) | |
3423 (setq par (1- par))))) | |
3424 (verilog-forward-syntactic-ws) | |
3425 (skip-chars-forward "^ \t\n\f") | |
3426 (point)) | |
3427 ((looking-at "/[/\\*]") | |
3428 b) | |
3429 ('t | |
3430 (skip-chars-forward "^: \t\n\f") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3431 (point))))) |
79545 | 3432 (str (buffer-substring b e))) |
3433 (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str)) | |
3434 (setq str (concat (substring str 0 e) "..."))) | |
3435 str)) | |
3436 | |
3437 (defun verilog-expand-vector () | |
3438 "Take a signal vector on the current line and expand it to multiple lines. | |
3439 Useful for creating tri's and other expanded fields." | |
3440 (interactive) | |
3441 (verilog-expand-vector-internal "[" "]")) | |
3442 | |
3443 (defun verilog-expand-vector-internal (bra ket) | |
3444 "Given BRA, the start brace and KET, the end brace, expand one line into many lines." | |
3445 (save-excursion | |
3446 (forward-line 0) | |
3447 (let ((signal-string (buffer-substring (point) | |
3448 (progn | |
3449 (end-of-line) (point))))) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3450 (if (string-match |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3451 (concat "\\(.*\\)" |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3452 (regexp-quote bra) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3453 "\\([0-9]*\\)\\(:[0-9]*\\|\\)\\(::[0-9---]*\\|\\)" |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3454 (regexp-quote ket) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3455 "\\(.*\\)$") signal-string) |
79545 | 3456 (let* ((sig-head (match-string 1 signal-string)) |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3457 (vec-start (string-to-number (match-string 2 signal-string))) |
79545 | 3458 (vec-end (if (= (match-beginning 3) (match-end 3)) |
3459 vec-start | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3460 (string-to-number |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3461 (substring signal-string (1+ (match-beginning 3)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3462 (match-end 3))))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3463 (vec-range |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3464 (if (= (match-beginning 4) (match-end 4)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3465 1 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3466 (string-to-number |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3467 (substring signal-string (+ 2 (match-beginning 4)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3468 (match-end 4))))) |
79545 | 3469 (sig-tail (match-string 5 signal-string)) |
3470 vec) | |
3471 ;; Decode vectors | |
3472 (setq vec nil) | |
3473 (if (< vec-range 0) | |
3474 (let ((tmp vec-start)) | |
3475 (setq vec-start vec-end | |
3476 vec-end tmp | |
3477 vec-range (- vec-range)))) | |
3478 (if (< vec-end vec-start) | |
3479 (while (<= vec-end vec-start) | |
3480 (setq vec (append vec (list vec-start))) | |
3481 (setq vec-start (- vec-start vec-range))) | |
3482 (while (<= vec-start vec-end) | |
3483 (setq vec (append vec (list vec-start))) | |
3484 (setq vec-start (+ vec-start vec-range)))) | |
3485 ;; | |
3486 ;; Delete current line | |
3487 (delete-region (point) (progn (forward-line 0) (point))) | |
3488 ;; | |
3489 ;; Expand vector | |
3490 (while vec | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3491 (insert (concat sig-head bra |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3492 (int-to-string (car vec)) ket sig-tail "\n")) |
79545 | 3493 (setq vec (cdr vec))) |
3494 (delete-char -1) | |
3495 ;; | |
3496 ))))) | |
3497 | |
3498 (defun verilog-strip-comments () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
3499 "Strip all comments from the Verilog code." |
79545 | 3500 (interactive) |
3501 (goto-char (point-min)) | |
3502 (while (re-search-forward "//" nil t) | |
3503 (if (verilog-within-string) | |
3504 (re-search-forward "\"" nil t) | |
3505 (if (verilog-in-star-comment-p) | |
3506 (re-search-forward "\*/" nil t) | |
3507 (let ((bpt (- (point) 2))) | |
3508 (end-of-line) | |
3509 (delete-region bpt (point)))))) | |
3510 ;; | |
3511 (goto-char (point-min)) | |
3512 (while (re-search-forward "/\\*" nil t) | |
3513 (if (verilog-within-string) | |
3514 (re-search-forward "\"" nil t) | |
3515 (let ((bpt (- (point) 2))) | |
3516 (re-search-forward "\\*/") | |
3517 (delete-region bpt (point)))))) | |
3518 | |
3519 (defun verilog-one-line () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
3520 "Convert structural Verilog instances to occupy one line." |
79545 | 3521 (interactive) |
3522 (goto-char (point-min)) | |
3523 (while (re-search-forward "\\([^;]\\)[ \t]*\n[ \t]*" nil t) | |
3524 (replace-match "\\1 " nil nil))) | |
3525 | |
3526 (defun verilog-linter-name () | |
3527 "Return name of linter, either surelint or verilint." | |
3528 (let ((compile-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil | |
3529 compile-command)) | |
3530 (lint-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil | |
3531 verilog-linter))) | |
3532 (cond ((equal compile-word1 "surelint") `surelint) | |
3533 ((equal compile-word1 "verilint") `verilint) | |
3534 ((equal lint-word1 "surelint") `surelint) | |
3535 ((equal lint-word1 "verilint") `verilint) | |
3536 (t `surelint)))) ;; back compatibility | |
3537 | |
3538 (defun verilog-lint-off () | |
3539 "Convert a Verilog linter warning line into a disable statement. | |
3540 For example: | |
3541 pci_bfm_null.v, line 46: Unused input: pci_rst_ | |
3542 becomes a comment for the appropriate tool. | |
3543 | |
3544 The first word of the `compile-command' or `verilog-linter' | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
3545 variables is used to determine which product is being used. |
79545 | 3546 |
3547 See \\[verilog-surelint-off] and \\[verilog-verilint-off]." | |
3548 (interactive) | |
3549 (let ((linter (verilog-linter-name))) | |
3550 (cond ((equal linter `surelint) | |
3551 (verilog-surelint-off)) | |
3552 ((equal linter `verilint) | |
3553 (verilog-verilint-off)) | |
3554 (t (error "Linter name not set"))))) | |
3555 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3556 (defvar compilation-last-buffer) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3557 |
79545 | 3558 (defun verilog-surelint-off () |
3559 "Convert a SureLint warning line into a disable statement. | |
3560 Run from Verilog source window; assumes there is a *compile* buffer | |
3561 with point set appropriately. | |
3562 | |
3563 For example: | |
3564 WARNING [STD-UDDONX]: xx.v, line 8: output out is never assigned. | |
3565 becomes: | |
3566 // surefire lint_line_off UDDONX" | |
3567 (interactive) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3568 (let ((buff (if (boundp 'next-error-last-buffer) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3569 next-error-last-buffer |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3570 compilation-last-buffer))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3571 (when (buffer-live-p buff) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3572 ;; FIXME with-current-buffer? |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3573 (save-excursion |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3574 (switch-to-buffer buff) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3575 (beginning-of-line) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3576 (when |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3577 (looking-at "\\(INFO\\|WARNING\\|ERROR\\) \\[[^-]+-\\([^]]+\\)\\]: \\([^,]+\\), line \\([0-9]+\\): \\(.*\\)$") |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3578 (let* ((code (match-string 2)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3579 (file (match-string 3)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3580 (line (match-string 4)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3581 (buffer (get-file-buffer file)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3582 dir filename) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3583 (unless buffer |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3584 (progn |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3585 (setq buffer |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3586 (and (file-exists-p file) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3587 (find-file-noselect file))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3588 (or buffer |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3589 (let* ((pop-up-windows t)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3590 (let ((name (expand-file-name |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3591 (read-file-name |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3592 (format "Find this error in: (default %s) " |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3593 file) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3594 dir file t)))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3595 (if (file-directory-p name) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3596 (setq name (expand-file-name filename name))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3597 (setq buffer |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3598 (and (file-exists-p name) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3599 (find-file-noselect name)))))))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3600 (switch-to-buffer buffer) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3601 (goto-line (string-to-number line)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3602 (end-of-line) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3603 (catch 'already |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3604 (cond |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3605 ((verilog-in-slash-comment-p) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3606 (re-search-backward "//") |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3607 (cond |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3608 ((looking-at "// surefire lint_off_line ") |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3609 (goto-char (match-end 0)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3610 (let ((lim (save-excursion (end-of-line) (point)))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3611 (if (re-search-forward code lim 'move) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3612 (throw 'already t) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3613 (insert (concat " " code))))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3614 (t |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3615 ))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3616 ((verilog-in-star-comment-p) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3617 (re-search-backward "/\*") |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3618 (insert (format " // surefire lint_off_line %6s" code ))) |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3619 (t |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3620 (insert (format " // surefire lint_off_line %6s" code )) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3621 ))))))))) |
79545 | 3622 |
3623 (defun verilog-verilint-off () | |
3624 "Convert a Verilint warning line into a disable statement. | |
3625 | |
3626 For example: | |
3627 (W240) pci_bfm_null.v, line 46: Unused input: pci_rst_ | |
3628 becomes: | |
3629 //Verilint 240 off // WARNING: Unused input" | |
3630 (interactive) | |
3631 (save-excursion | |
3632 (beginning-of-line) | |
3633 (when (looking-at "\\(.*\\)([WE]\\([0-9A-Z]+\\)).*,\\s +line\\s +[0-9]+:\\s +\\([^:\n]+\\):?.*$") | |
3634 (replace-match (format | |
3635 ;; %3s makes numbers 1-999 line up nicely | |
3636 "\\1//Verilint %3s off // WARNING: \\3" | |
3637 (match-string 2))) | |
3638 (beginning-of-line) | |
3639 (verilog-indent-line)))) | |
3640 | |
3641 (defun verilog-auto-save-compile () | |
3642 "Update automatics with \\[verilog-auto], save the buffer, and compile." | |
3643 (interactive) | |
3644 (verilog-auto) ; Always do it for safety | |
3645 (save-buffer) | |
3646 (compile compile-command)) | |
3647 | |
3648 | |
3649 | |
3650 ;; | |
3651 ;; Batch | |
3652 ;; | |
3653 | |
3654 (defmacro verilog-batch-error-wrapper (&rest body) | |
3655 "Execute BODY and add error prefix to any errors found. | |
3656 This lets programs calling batch mode to easily extract error messages." | |
79546 | 3657 `(condition-case err |
3658 (progn ,@body) | |
3659 (error | |
3660 (error "%%Error: %s%s" (error-message-string err) | |
3661 (if (featurep 'xemacs) "\n" ""))))) ;; xemacs forgets to add a newline | |
79545 | 3662 |
3663 (defun verilog-batch-execute-func (funref) | |
3664 "Internal processing of a batch command, running FUNREF on all command arguments." | |
3665 (verilog-batch-error-wrapper | |
3666 ;; General globals needed | |
3667 (setq make-backup-files nil) | |
3668 (setq-default make-backup-files nil) | |
3669 (setq enable-local-variables t) | |
3670 (setq enable-local-eval t) | |
3671 ;; Make sure any sub-files we read get proper mode | |
3672 (setq default-major-mode `verilog-mode) | |
3673 ;; Ditto files already read in | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3674 (mapc (lambda (buf) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3675 (when (buffer-file-name buf) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3676 (save-excursion |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3677 (set-buffer buf) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3678 (verilog-mode)))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3679 (buffer-list)) |
79545 | 3680 ;; Process the files |
3681 (mapcar '(lambda (buf) | |
3682 (when (buffer-file-name buf) | |
3683 (save-excursion | |
3684 (if (not (file-exists-p (buffer-file-name buf))) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3685 (error |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3686 (concat "File not found: " (buffer-file-name buf)))) |
79545 | 3687 (message (concat "Processing " (buffer-file-name buf))) |
3688 (set-buffer buf) | |
3689 (funcall funref) | |
3690 (save-buffer)))) | |
3691 (buffer-list)))) | |
3692 | |
3693 (defun verilog-batch-auto () | |
3694 "For use with --batch, perform automatic expansions as a stand-alone tool. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
3695 This sets up the appropriate Verilog mode environment, updates automatics |
79545 | 3696 with \\[verilog-auto] on all command-line files, and saves the buffers. |
3697 For proper results, multiple filenames need to be passed on the command | |
3698 line in bottom-up order." | |
3699 (unless noninteractive | |
3700 (error "Use verilog-batch-auto only with --batch")) ;; Otherwise we'd mess up buffer modes | |
3701 (verilog-batch-execute-func `verilog-auto)) | |
3702 | |
3703 (defun verilog-batch-delete-auto () | |
3704 "For use with --batch, perform automatic deletion as a stand-alone tool. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
3705 This sets up the appropriate Verilog mode environment, deletes automatics |
79545 | 3706 with \\[verilog-delete-auto] on all command-line files, and saves the buffers." |
3707 (unless noninteractive | |
3708 (error "Use verilog-batch-delete-auto only with --batch")) ;; Otherwise we'd mess up buffer modes | |
3709 (verilog-batch-execute-func `verilog-delete-auto)) | |
3710 | |
3711 (defun verilog-batch-inject-auto () | |
3712 "For use with --batch, perform automatic injection as a stand-alone tool. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
3713 This sets up the appropriate Verilog mode environment, injects new automatics |
79545 | 3714 with \\[verilog-inject-auto] on all command-line files, and saves the buffers. |
3715 For proper results, multiple filenames need to be passed on the command | |
3716 line in bottom-up order." | |
3717 (unless noninteractive | |
3718 (error "Use verilog-batch-inject-auto only with --batch")) ;; Otherwise we'd mess up buffer modes | |
3719 (verilog-batch-execute-func `verilog-inject-auto)) | |
3720 | |
3721 (defun verilog-batch-indent () | |
3722 "For use with --batch, reindent an a entire file as a stand-alone tool. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
3723 This sets up the appropriate Verilog mode environment, calls |
79545 | 3724 \\[verilog-indent-buffer] on all command-line files, and saves the buffers." |
3725 (unless noninteractive | |
3726 (error "Use verilog-batch-indent only with --batch")) ;; Otherwise we'd mess up buffer modes | |
3727 (verilog-batch-execute-func `verilog-indent-buffer)) | |
3728 | |
3729 | |
3730 ;; | |
3731 ;; Indentation | |
3732 ;; | |
3733 (defconst verilog-indent-alist | |
3734 '((block . (+ ind verilog-indent-level)) | |
3735 (case . (+ ind verilog-case-indent)) | |
3736 (cparenexp . (+ ind verilog-indent-level)) | |
3737 (cexp . (+ ind verilog-cexp-indent)) | |
3738 (defun . verilog-indent-level-module) | |
3739 (declaration . verilog-indent-level-declaration) | |
3740 (directive . (verilog-calculate-indent-directive)) | |
3741 (tf . verilog-indent-level) | |
3742 (behavioral . (+ verilog-indent-level-behavioral verilog-indent-level-module)) | |
3743 (statement . ind) | |
3744 (cpp . 0) | |
3745 (comment . (verilog-comment-indent)) | |
3746 (unknown . 3) | |
3747 (string . 0))) | |
3748 | |
3749 (defun verilog-continued-line-1 (lim) | |
3750 "Return true if this is a continued line. | |
3751 Set point to where line starts. Limit search to point LIM." | |
3752 (let ((continued 't)) | |
3753 (if (eq 0 (forward-line -1)) | |
3754 (progn | |
3755 (end-of-line) | |
3756 (verilog-backward-ws&directives lim) | |
3757 (if (bobp) | |
3758 (setq continued nil) | |
3759 (setq continued (verilog-backward-token)))) | |
3760 (setq continued nil)) | |
3761 continued)) | |
3762 | |
3763 (defun verilog-calculate-indent () | |
3764 "Calculate the indent of the current Verilog line. | |
3765 Examine previous lines. Once a line is found that is definitive as to the | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
3766 type of the current line, return that lines' indent level and its type. |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
3767 Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)." |
79545 | 3768 (save-excursion |
3769 (let* ((starting_position (point)) | |
3770 (par 0) | |
3771 (begin (looking-at "[ \t]*begin\\>")) | |
3772 (lim (save-excursion (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil t))) | |
3773 (type (catch 'nesting | |
3774 ;; Keep working backwards until we can figure out | |
3775 ;; what type of statement this is. | |
3776 ;; Basically we need to figure out | |
3777 ;; 1) if this is a continuation of the previous line; | |
3778 ;; 2) are we in a block scope (begin..end) | |
3779 | |
3780 ;; if we are in a comment, done. | |
3781 (if (verilog-in-star-comment-p) | |
3782 (throw 'nesting 'comment)) | |
3783 | |
3784 ;; if we have a directive, done. | |
3785 (if (save-excursion (beginning-of-line) (looking-at verilog-directive-re-1)) | |
3786 (throw 'nesting 'directive)) | |
3787 | |
3788 ;; unless we are in the newfangled coverpoint or constraint blocks | |
3789 ;; if we are in a parenthesized list, and the user likes to indent these, return. | |
3790 (if (and | |
3791 verilog-indent-lists | |
3792 (not (verilog-in-coverage)) | |
3793 (verilog-in-paren)) | |
3794 (progn (setq par 1) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3795 (throw 'nesting 'block))) |
79545 | 3796 |
3797 ;; See if we are continuing a previous line | |
3798 (while t | |
3799 ;; trap out if we crawl off the top of the buffer | |
3800 (if (bobp) (throw 'nesting 'cpp)) | |
3801 | |
3802 (if (verilog-continued-line-1 lim) | |
3803 (let ((sp (point))) | |
3804 (if (and | |
3805 (not (looking-at verilog-complete-reg)) | |
3806 (verilog-continued-line-1 lim)) | |
3807 (progn (goto-char sp) | |
3808 (throw 'nesting 'cexp)) | |
3809 | |
3810 (goto-char sp)) | |
3811 | |
3812 (if (and begin | |
3813 (not verilog-indent-begin-after-if) | |
3814 (looking-at verilog-no-indent-begin-re)) | |
3815 (progn | |
3816 (beginning-of-line) | |
3817 (skip-chars-forward " \t") | |
3818 (throw 'nesting 'statement)) | |
3819 (progn | |
3820 (throw 'nesting 'cexp)))) | |
3821 ;; not a continued line | |
3822 (goto-char starting_position)) | |
3823 | |
3824 (if (looking-at "\\<else\\>") | |
3825 ;; search back for governing if, striding across begin..end pairs | |
3826 ;; appropriately | |
3827 (let ((elsec 1)) | |
3828 (while (verilog-re-search-backward verilog-ends-re nil 'move) | |
3829 (cond | |
3830 ((match-end 1) ; else, we're in deep | |
3831 (setq elsec (1+ elsec))) | |
3832 ((match-end 2) ; if | |
3833 (setq elsec (1- elsec)) | |
3834 (if (= 0 elsec) | |
3835 (if verilog-align-ifelse | |
3836 (throw 'nesting 'statement) | |
3837 (progn ;; back up to first word on this line | |
3838 (beginning-of-line) | |
3839 (verilog-forward-syntactic-ws) | |
3840 (throw 'nesting 'statement))))) | |
3841 (t ; endblock | |
3842 ; try to leap back to matching outward block by striding across | |
3843 ; indent level changing tokens then immediately | |
3844 ; previous line governs indentation. | |
3845 (let (( reg) (nest 1)) | |
3846 ;; verilog-ends => else|if|end|join(_any|_none|)|endcase|endclass|endtable|endspecify|endfunction|endtask|endgenerate|endgroup | |
3847 (cond | |
3848 ((match-end 3) ; end | |
3849 ;; Search back for matching begin | |
3850 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" )) | |
3851 ((match-end 4) ; endcase | |
3852 ;; Search back for matching case | |
3853 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )) | |
3854 ((match-end 5) ; endfunction | |
3855 ;; Search back for matching function | |
3856 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )) | |
3857 ((match-end 6) ; endtask | |
3858 ;; Search back for matching task | |
3859 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" )) | |
3860 ((match-end 7) ; endspecify | |
3861 ;; Search back for matching specify | |
3862 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )) | |
3863 ((match-end 8) ; endtable | |
3864 ;; Search back for matching table | |
3865 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )) | |
3866 ((match-end 9) ; endgenerate | |
3867 ;; Search back for matching generate | |
3868 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" )) | |
3869 ((match-end 10) ; joins | |
3870 ;; Search back for matching fork | |
3871 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|none\\)?\\>\\)" )) | |
3872 ((match-end 11) ; class | |
3873 ;; Search back for matching class | |
3874 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" )) | |
3875 ((match-end 12) ; covergroup | |
3876 ;; Search back for matching covergroup | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3877 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))) |
79545 | 3878 (catch 'skip |
3879 (while (verilog-re-search-backward reg nil 'move) | |
3880 (cond | |
3881 ((match-end 1) ; begin | |
3882 (setq nest (1- nest)) | |
3883 (if (= 0 nest) | |
3884 (throw 'skip 1))) | |
3885 ((match-end 2) ; end | |
3886 (setq nest (1+ nest))))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3887 ))))))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3888 (throw 'nesting (verilog-calc-1))) |
79545 | 3889 );; catch nesting |
3890 );; type | |
3891 ) | |
3892 ;; Return type of block and indent level. | |
3893 (if (not type) | |
3894 (setq type 'cpp)) | |
3895 (if (> par 0) ; Unclosed Parenthesis | |
3896 (list 'cparenexp par) | |
3897 (cond | |
3898 ((eq type 'case) | |
3899 (list type (verilog-case-indent-level))) | |
3900 ((eq type 'statement) | |
3901 (list type (current-column))) | |
3902 ((eq type 'defun) | |
3903 (list type 0)) | |
3904 (t | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3905 (list type (verilog-current-indent-level)))))))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3906 |
79545 | 3907 (defun verilog-wai () |
3908 "Show matching nesting block for debugging." | |
3909 (interactive) | |
3910 (save-excursion | |
3911 (let ((nesting (verilog-calc-1))) | |
3912 (message "You are at nesting %s" nesting)))) | |
3913 | |
3914 (defun verilog-calc-1 () | |
3915 (catch 'nesting | |
3916 (while (verilog-re-search-backward (concat "\\({\\|}\\|" verilog-indent-re "\\)") nil 'move) | |
3917 (cond | |
3918 ((equal (char-after) ?\{) | |
3919 (if (verilog-at-constraint-p) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3920 (throw 'nesting 'block))) |
79545 | 3921 ((equal (char-after) ?\}) |
3922 | |
3923 (let ((there (verilog-at-close-constraint-p))) | |
3924 (if there (goto-char there)))) | |
3925 | |
3926 ((looking-at verilog-beg-block-re-ordered) | |
3927 (cond | |
3928 ((match-end 2) ; *sigh* could be "unique case" or "priority casex" | |
3929 (let ((here (point))) | |
3930 (verilog-beg-of-statement) | |
3931 (if (looking-at verilog-extended-case-re) | |
3932 (throw 'nesting 'case) | |
3933 (goto-char here))) | |
3934 (throw 'nesting 'case)) | |
3935 | |
3936 ;; need to consider typedef struct here... | |
3937 ((looking-at "\\<class\\|struct\\|function\\|task\\|property\\>") | |
3938 ; *sigh* These words have an optional prefix: | |
3939 ; extern {virtual|protected}? function a(); | |
3940 ; assert property (p_1); | |
3941 ; typedef class foo; | |
3942 ; and we don't want to confuse this with | |
3943 ; function a(); | |
3944 ; property | |
3945 ; ... | |
3946 ; endfunction | |
3947 (let ((here (point))) | |
3948 (save-excursion | |
3949 (verilog-beg-of-statement) | |
3950 (if (= (point) here) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3951 (throw 'nesting 'block))))) |
79545 | 3952 (t (throw 'nesting 'block)))) |
3953 | |
3954 ((looking-at verilog-end-block-re) | |
3955 (verilog-leap-to-head) | |
3956 (if (verilog-in-case-region-p) | |
3957 (progn | |
3958 (verilog-leap-to-case-head) | |
3959 (if (looking-at verilog-case-re) | |
3960 (throw 'nesting 'case))))) | |
3961 | |
3962 ((looking-at (if (verilog-in-generate-region-p) | |
3963 verilog-defun-level-not-generate-re | |
3964 verilog-defun-level-re)) | |
3965 (throw 'nesting 'defun)) | |
3966 | |
3967 ((looking-at verilog-cpp-level-re) | |
3968 (throw 'nesting 'cpp)) | |
3969 | |
3970 ((bobp) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3971 (throw 'nesting 'cpp)))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3972 (throw 'nesting 'cpp))) |
79545 | 3973 |
3974 (defun verilog-calculate-indent-directive () | |
3975 "Return indentation level for directive. | |
3976 For speed, the searcher looks at the last directive, not the indent | |
3977 of the appropriate enclosing block." | |
3978 (let ((base -1) ;; Indent of the line that determines our indentation | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3979 (ind 0)) ;; Relative offset caused by other directives (like `endif on same line as `else) |
79545 | 3980 ;; Start at current location, scan back for another directive |
3981 | |
3982 (save-excursion | |
3983 (beginning-of-line) | |
3984 (while (and (< base 0) | |
3985 (verilog-re-search-backward verilog-directive-re nil t)) | |
3986 (cond ((save-excursion (skip-chars-backward " \t") (bolp)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3987 (setq base (current-indentation)))) |
79545 | 3988 (cond ((and (looking-at verilog-directive-end) (< base 0)) ;; Only matters when not at BOL |
3989 (setq ind (- ind verilog-indent-level-directive))) | |
3990 ((and (looking-at verilog-directive-middle) (>= base 0)) ;; Only matters when at BOL | |
3991 (setq ind (+ ind verilog-indent-level-directive))) | |
3992 ((looking-at verilog-directive-begin) | |
3993 (setq ind (+ ind verilog-indent-level-directive))))) | |
3994 ;; Adjust indent to starting indent of critical line | |
3995 (setq ind (max 0 (+ ind base)))) | |
3996 | |
3997 (save-excursion | |
3998 (beginning-of-line) | |
3999 (skip-chars-forward " \t") | |
4000 (cond ((or (looking-at verilog-directive-middle) | |
4001 (looking-at verilog-directive-end)) | |
4002 (setq ind (max 0 (- ind verilog-indent-level-directive)))))) | |
4003 ind)) | |
4004 | |
4005 (defun verilog-leap-to-case-head () | |
4006 (let ((nest 1)) | |
4007 (while (/= 0 nest) | |
4008 (verilog-re-search-backward "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" nil 'move) | |
4009 (cond | |
4010 ((match-end 1) | |
4011 (setq nest (1- nest))) | |
4012 ((match-end 2) | |
4013 (setq nest (1+ nest))) | |
4014 ((bobp) | |
4015 (ding 't) | |
4016 (setq nest 0)))))) | |
4017 | |
4018 (defun verilog-leap-to-head () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
4019 "Move point to the head of this block. |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
4020 Jump from end to matching begin, from endcase to matching case, and so on." |
79545 | 4021 (let ((reg nil) |
4022 snest | |
4023 (nest 1)) | |
4024 (cond | |
4025 ((looking-at "\\<end\\>") | |
4026 ;; 1: Search back for matching begin | |
4027 (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|" | |
4028 "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))) | |
4029 ((looking-at "\\<endcase\\>") | |
4030 ;; 2: Search back for matching case | |
4031 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)" )) | |
4032 ((looking-at "\\<join\\(_any\\|_none\\)?\\>") | |
4033 ;; 3: Search back for matching fork | |
4034 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )) | |
4035 ((looking-at "\\<endclass\\>") | |
4036 ;; 4: Search back for matching class | |
4037 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" )) | |
4038 ((looking-at "\\<endtable\\>") | |
4039 ;; 5: Search back for matching table | |
4040 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )) | |
4041 ((looking-at "\\<endspecify\\>") | |
4042 ;; 6: Search back for matching specify | |
4043 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )) | |
4044 ((looking-at "\\<endfunction\\>") | |
4045 ;; 7: Search back for matching function | |
4046 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )) | |
4047 ((looking-at "\\<endgenerate\\>") | |
4048 ;; 8: Search back for matching generate | |
4049 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" )) | |
4050 ((looking-at "\\<endtask\\>") | |
4051 ;; 9: Search back for matching task | |
4052 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" )) | |
4053 ((looking-at "\\<endgroup\\>") | |
4054 ;; 10: Search back for matching covergroup | |
4055 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )) | |
4056 ((looking-at "\\<endproperty\\>") | |
4057 ;; 11: Search back for matching property | |
4058 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" )) | |
4059 ((looking-at "\\<endinterface\\>") | |
4060 ;; 12: Search back for matching interface | |
4061 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" )) | |
4062 ((looking-at "\\<endsequence\\>") | |
4063 ;; 12: Search back for matching sequence | |
4064 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )) | |
4065 ((looking-at "\\<endclocking\\>") | |
4066 ;; 12: Search back for matching clocking | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4067 (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" ))) |
79545 | 4068 (if reg |
4069 (catch 'skip | |
4070 (let (sreg) | |
4071 (while (verilog-re-search-backward reg nil 'move) | |
4072 (cond | |
4073 ((match-end 1) ; begin | |
4074 (setq nest (1- nest)) | |
4075 (if (= 0 nest) | |
4076 ;; Now previous line describes syntax | |
4077 (throw 'skip 1)) | |
4078 (if (and snest | |
4079 (= snest nest)) | |
4080 (setq reg sreg))) | |
4081 ((match-end 2) ; end | |
4082 (setq nest (1+ nest))) | |
4083 ((match-end 3) | |
4084 ;; endcase, jump to case | |
4085 (setq snest nest) | |
4086 (setq nest (1+ nest)) | |
4087 (setq sreg reg) | |
4088 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )) | |
4089 ((match-end 4) | |
4090 ;; join, jump to fork | |
4091 (setq snest nest) | |
4092 (setq nest (1+ nest)) | |
4093 (setq sreg reg) | |
4094 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )) | |
4095 ))))))) | |
4096 | |
4097 (defun verilog-continued-line () | |
4098 "Return true if this is a continued line. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
4099 Set point to where line starts." |
79545 | 4100 (let ((continued 't)) |
4101 (if (eq 0 (forward-line -1)) | |
4102 (progn | |
4103 (end-of-line) | |
4104 (verilog-backward-ws&directives) | |
4105 (if (bobp) | |
4106 (setq continued nil) | |
4107 (while (and continued | |
4108 (save-excursion | |
4109 (skip-chars-backward " \t") | |
4110 (not (bolp)))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4111 (setq continued (verilog-backward-token))))) |
79545 | 4112 (setq continued nil)) |
4113 continued)) | |
4114 | |
4115 (defun verilog-backward-token () | |
4116 "Step backward token, returning true if we are now at an end of line token." | |
4117 (interactive) | |
4118 (verilog-backward-syntactic-ws) | |
4119 (cond | |
4120 ((bolp) | |
4121 nil) | |
4122 (;-- Anything ending in a ; is complete | |
4123 (= (preceding-char) ?\;) | |
4124 nil) | |
4125 (; If a "}" is prefixed by a ";", then this is a complete statement | |
4126 ; i.e.: constraint foo { a = b; } | |
4127 (= (preceding-char) ?\}) | |
4128 (progn | |
4129 (backward-char) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4130 (verilog-at-close-constraint-p))) |
79545 | 4131 (;-- constraint foo { a = b } |
4132 ; is a complete statement. *sigh* | |
4133 (= (preceding-char) ?\{) | |
4134 (progn | |
4135 (backward-char) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4136 (not (verilog-at-constraint-p)))) |
79545 | 4137 (;-- Could be 'case (foo)' or 'always @(bar)' which is complete |
4138 ; also could be simply '@(foo)' | |
4139 ; or foo u1 #(a=8) | |
4140 ; (b, ... which ISN'T complete | |
4141 ;;;; Do we need this??? | |
4142 (= (preceding-char) ?\)) | |
4143 (progn | |
4144 (backward-char) | |
4145 (backward-up-list 1) | |
4146 (verilog-backward-syntactic-ws) | |
4147 (let ((back (point))) | |
4148 (forward-word -1) | |
4149 (cond | |
4150 ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>") | |
4151 (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]"))) | |
4152 (t | |
4153 (goto-char back) | |
4154 (cond | |
4155 ((= (preceding-char) ?\@) | |
4156 (backward-char) | |
4157 (save-excursion | |
4158 (verilog-backward-token) | |
4159 (not (looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|initial\\|while\\)\\>")))) | |
4160 ((= (preceding-char) ?\#) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4161 (backward-char)) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4162 (t t))))))) |
79545 | 4163 |
4164 (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete | |
4165 t | |
4166 (forward-word -1) | |
4167 (cond | |
4168 ((looking-at "\\<else\\>") | |
4169 t) | |
4170 ((looking-at verilog-indent-re) | |
4171 nil) | |
4172 (t | |
4173 (let | |
4174 ((back (point))) | |
4175 (verilog-backward-syntactic-ws) | |
4176 (cond | |
4177 ((= (preceding-char) ?\:) | |
4178 (backward-char) | |
4179 (verilog-backward-syntactic-ws) | |
4180 (backward-sexp) | |
4181 (if (looking-at verilog-nameable-item-re ) | |
4182 nil | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4183 t)) |
79545 | 4184 ((= (preceding-char) ?\#) |
4185 (backward-char) | |
4186 t) | |
4187 ((= (preceding-char) ?\`) | |
4188 (backward-char) | |
4189 t) | |
4190 | |
4191 (t | |
4192 (goto-char back) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4193 t)))))))) |
79545 | 4194 |
4195 (defun verilog-backward-syntactic-ws (&optional bound) | |
4196 "Backward skip over syntactic whitespace for Emacs 19. | |
4197 Optional BOUND limits search." | |
4198 (save-restriction | |
4199 (let* ((bound (or bound (point-min))) (here bound) ) | |
4200 (if (< bound (point)) | |
4201 (progn | |
4202 (narrow-to-region bound (point)) | |
4203 (while (/= here (point)) | |
4204 (setq here (point)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4205 (verilog-skip-backward-comments)))))) |
79545 | 4206 t) |
4207 | |
4208 (defun verilog-forward-syntactic-ws (&optional bound) | |
4209 "Forward skip over syntactic whitespace for Emacs 19. | |
4210 Optional BOUND limits search." | |
4211 (save-restriction | |
4212 (let* ((bound (or bound (point-max))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4213 (here bound)) |
79545 | 4214 (if (> bound (point)) |
4215 (progn | |
4216 (narrow-to-region (point) bound) | |
4217 (while (/= here (point)) | |
4218 (setq here (point)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4219 (forward-comment (buffer-size)))))))) |
79545 | 4220 |
4221 (defun verilog-backward-ws&directives (&optional bound) | |
4222 "Backward skip over syntactic whitespace and compiler directives for Emacs 19. | |
4223 Optional BOUND limits search." | |
4224 (save-restriction | |
4225 (let* ((bound (or bound (point-min))) | |
4226 (here bound) | |
4227 (p nil) ) | |
4228 (if (< bound (point)) | |
4229 (progn | |
4230 (let ((state | |
4231 (save-excursion | |
4232 (parse-partial-sexp (point-min) (point))))) | |
4233 (cond | |
4234 ((nth 7 state) ;; in // comment | |
4235 (verilog-re-search-backward "//" nil 'move) | |
4236 (skip-chars-backward "/")) | |
4237 ((nth 4 state) ;; in /* */ comment | |
4238 (verilog-re-search-backward "/\*" nil 'move)))) | |
4239 (narrow-to-region bound (point)) | |
4240 (while (/= here (point)) | |
4241 (setq here (point)) | |
4242 (verilog-skip-backward-comments) | |
4243 (setq p | |
4244 (save-excursion | |
4245 (beginning-of-line) | |
4246 (cond | |
4247 ((verilog-within-translate-off) | |
4248 (verilog-back-to-start-translate-off (point-min))) | |
4249 ((looking-at verilog-directive-re-1) | |
4250 (point)) | |
4251 (t | |
4252 nil)))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4253 (if p (goto-char p)))))))) |
79545 | 4254 |
4255 (defun verilog-forward-ws&directives (&optional bound) | |
4256 "Forward skip over syntactic whitespace and compiler directives for Emacs 19. | |
4257 Optional BOUND limits search." | |
4258 (save-restriction | |
4259 (let* ((bound (or bound (point-max))) | |
4260 (here bound) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4261 jump) |
79545 | 4262 (if (> bound (point)) |
4263 (progn | |
4264 (let ((state | |
4265 (save-excursion | |
4266 (parse-partial-sexp (point-min) (point))))) | |
4267 (cond | |
4268 ((nth 7 state) ;; in // comment | |
4269 (verilog-re-search-forward "//" nil 'move)) | |
4270 ((nth 4 state) ;; in /* */ comment | |
4271 (verilog-re-search-forward "/\*" nil 'move)))) | |
4272 (narrow-to-region (point) bound) | |
4273 (while (/= here (point)) | |
4274 (setq here (point) | |
4275 jump nil) | |
4276 (forward-comment (buffer-size)) | |
4277 (save-excursion | |
4278 (beginning-of-line) | |
4279 (if (looking-at verilog-directive-re-1) | |
4280 (setq jump t))) | |
4281 (if jump | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4282 (beginning-of-line 2)))))))) |
79545 | 4283 |
4284 (defun verilog-in-comment-p () | |
4285 "Return true if in a star or // comment." | |
4286 (let ((state | |
4287 (save-excursion | |
4288 (parse-partial-sexp (point-min) (point))))) | |
4289 (or (nth 4 state) (nth 7 state)))) | |
4290 | |
4291 (defun verilog-in-star-comment-p () | |
4292 "Return true if in a star comment." | |
4293 (let ((state | |
4294 (save-excursion | |
4295 (parse-partial-sexp (point-min) (point))))) | |
4296 (and | |
4297 (nth 4 state) ; t if in a comment of style a // or b /**/ | |
4298 (not | |
4299 (nth 7 state) ; t if in a comment of style b /**/ | |
4300 )))) | |
4301 | |
4302 (defun verilog-in-slash-comment-p () | |
4303 "Return true if in a slash comment." | |
4304 (let ((state | |
4305 (save-excursion | |
4306 (parse-partial-sexp (point-min) (point))))) | |
4307 (nth 7 state))) | |
4308 | |
4309 (defun verilog-in-comment-or-string-p () | |
4310 "Return true if in a string or comment." | |
4311 (let ((state | |
4312 (save-excursion | |
4313 (parse-partial-sexp (point-min) (point))))) | |
4314 (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment) | |
4315 | |
4316 (defun verilog-in-escaped-name-p () | |
4317 "Return true if in an escaped name." | |
4318 (save-excursion | |
4319 (backward-char) | |
4320 (skip-chars-backward "^ \t\n\f") | |
4321 (if (equal (char-after (point) ) ?\\ ) | |
4322 t | |
4323 nil))) | |
4324 | |
4325 (defun verilog-in-paren () | |
4326 "Return true if in a parenthetical expression." | |
4327 (let ((state | |
4328 (save-excursion | |
4329 (parse-partial-sexp (point-min) (point))))) | |
4330 (> (nth 0 state) 0 ))) | |
4331 | |
4332 (defun verilog-in-coverage () | |
4333 "Return true if in a constraint or coverpoint expression." | |
4334 (interactive) | |
4335 (save-excursion | |
4336 (if (verilog-in-paren) | |
4337 (progn | |
4338 (backward-up-list 1) | |
4339 (verilog-at-constraint-p) | |
4340 ) | |
4341 nil))) | |
4342 (defun verilog-at-close-constraint-p () | |
4343 "If at the } that closes a constraint or covergroup, return true." | |
4344 (if (and | |
4345 (equal (char-after) ?\}) | |
4346 (verilog-in-paren)) | |
4347 | |
4348 (save-excursion | |
4349 (verilog-backward-ws&directives) | |
4350 (if (equal (char-before) ?\;) | |
4351 (point) | |
4352 nil)))) | |
4353 | |
4354 (defun verilog-at-constraint-p () | |
4355 "If at the { of a constraint or coverpoint definition, return true, moving point to constraint." | |
4356 (if (save-excursion | |
4357 (and | |
4358 (equal (char-after) ?\{) | |
4359 (forward-list) | |
4360 (progn (backward-char 1) | |
4361 (verilog-backward-ws&directives) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4362 (equal (char-before) ?\;)))) |
79545 | 4363 ;; maybe |
4364 (verilog-re-search-backward "\\<constraint\\|coverpoint\\|cross\\>" nil 'move) | |
4365 ;; not | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4366 nil)) |
79545 | 4367 |
4368 (defun verilog-parenthesis-depth () | |
4369 "Return non zero if in parenthetical-expression." | |
4370 (save-excursion | |
4371 (nth 1 (parse-partial-sexp (point-min) (point))))) | |
4372 | |
4373 | |
4374 (defun verilog-skip-forward-comment-or-string () | |
4375 "Return true if in a string or comment." | |
4376 (let ((state | |
4377 (save-excursion | |
4378 (parse-partial-sexp (point-min) (point))))) | |
4379 (cond | |
4380 ((nth 3 state) ;Inside string | |
4381 (goto-char (nth 3 state)) | |
4382 t) | |
4383 ((nth 7 state) ;Inside // comment | |
4384 (forward-line 1) | |
4385 t) | |
4386 ((nth 4 state) ;Inside any comment (hence /**/) | |
4387 (search-forward "*/")) | |
4388 (t | |
4389 nil)))) | |
4390 | |
4391 (defun verilog-skip-backward-comment-or-string () | |
4392 "Return true if in a string or comment." | |
4393 (let ((state | |
4394 (save-excursion | |
4395 (parse-partial-sexp (point-min) (point))))) | |
4396 (cond | |
4397 ((nth 3 state) ;Inside string | |
4398 (search-backward "\"") | |
4399 t) | |
4400 ((nth 7 state) ;Inside // comment | |
4401 (search-backward "//") | |
4402 (skip-chars-backward "/") | |
4403 t) | |
4404 ((nth 4 state) ;Inside /* */ comment | |
4405 (search-backward "/*") | |
4406 t) | |
4407 (t | |
4408 nil)))) | |
4409 | |
4410 (defun verilog-skip-backward-comments () | |
4411 "Return true if a comment was skipped." | |
4412 (let ((more t)) | |
4413 (while more | |
4414 (setq more | |
4415 (let ((state | |
4416 (save-excursion | |
4417 (parse-partial-sexp (point-min) (point))))) | |
4418 (cond | |
4419 ((nth 7 state) ;Inside // comment | |
4420 (search-backward "//") | |
4421 (skip-chars-backward "/") | |
4422 (skip-chars-backward " \t\n\f") | |
4423 t) | |
4424 ((nth 4 state) ;Inside /* */ comment | |
4425 (search-backward "/*") | |
4426 (skip-chars-backward " \t\n\f") | |
4427 t) | |
4428 ((and (not (bobp)) | |
4429 (= (char-before) ?\/) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4430 (= (char-before (1- (point))) ?\*)) |
79545 | 4431 (goto-char (- (point) 2)) |
4432 t) | |
4433 (t | |
4434 (skip-chars-backward " \t\n\f") | |
4435 nil))))))) | |
4436 | |
4437 (defun verilog-skip-forward-comment-p () | |
4438 "If in comment, move to end and return true." | |
4439 (let (state) | |
4440 (progn | |
4441 (setq state | |
4442 (save-excursion | |
4443 (parse-partial-sexp (point-min) (point)))) | |
4444 (cond | |
4445 ((nth 3 state) | |
4446 t) | |
4447 ((nth 7 state) ;Inside // comment | |
4448 (end-of-line) | |
4449 (forward-char 1) | |
4450 t) | |
4451 ((nth 4 state) ;Inside any comment | |
4452 t) | |
4453 (t | |
4454 nil))))) | |
4455 | |
4456 (defun verilog-indent-line-relative () | |
4457 "Cheap version of indent line. | |
4458 Only look at a few lines to determine indent level." | |
4459 (interactive) | |
4460 (let ((indent-str) | |
4461 (sp (point))) | |
4462 (if (looking-at "^[ \t]*$") | |
4463 (cond ;- A blank line; No need to be too smart. | |
4464 ((bobp) | |
4465 (setq indent-str (list 'cpp 0))) | |
4466 ((verilog-continued-line) | |
4467 (let ((sp1 (point))) | |
4468 (if (verilog-continued-line) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4469 (progn |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4470 (goto-char sp) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4471 (setq indent-str |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4472 (list 'statement (verilog-current-indent-level)))) |
79545 | 4473 (goto-char sp1) |
4474 (setq indent-str (list 'block (verilog-current-indent-level))))) | |
4475 (goto-char sp)) | |
4476 ((goto-char sp) | |
4477 (setq indent-str (verilog-calculate-indent)))) | |
4478 (progn (skip-chars-forward " \t") | |
4479 (setq indent-str (verilog-calculate-indent)))) | |
4480 (verilog-do-indent indent-str))) | |
4481 | |
4482 (defun verilog-indent-line () | |
4483 "Indent for special part of code." | |
4484 (verilog-do-indent (verilog-calculate-indent))) | |
4485 | |
4486 (defun verilog-do-indent (indent-str) | |
4487 (let ((type (car indent-str)) | |
4488 (ind (car (cdr indent-str)))) | |
4489 (cond | |
4490 (; handle continued exp | |
4491 (eq type 'cexp) | |
4492 (let ((here (point))) | |
4493 (verilog-backward-syntactic-ws) | |
4494 (cond | |
4495 ((or | |
4496 (= (preceding-char) ?\,) | |
4497 (= (preceding-char) ?\]) | |
4498 (save-excursion | |
4499 (verilog-beg-of-statement-1) | |
4500 (looking-at verilog-declaration-re))) | |
4501 (let* ( fst | |
4502 (val | |
4503 (save-excursion | |
4504 (backward-char 1) | |
4505 (verilog-beg-of-statement-1) | |
4506 (setq fst (point)) | |
4507 (if (looking-at verilog-declaration-re) | |
4508 (progn ;; we have multiple words | |
4509 (goto-char (match-end 0)) | |
4510 (skip-chars-forward " \t") | |
4511 (cond | |
4512 ((and verilog-indent-declaration-macros | |
4513 (= (following-char) ?\`)) | |
4514 (progn | |
4515 (forward-char 1) | |
4516 (forward-word 1) | |
4517 (skip-chars-forward " \t"))) | |
4518 ((= (following-char) ?\[) | |
4519 (progn | |
4520 (forward-char 1) | |
4521 (backward-up-list -1) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4522 (skip-chars-forward " \t")))) |
79545 | 4523 (current-column)) |
4524 (progn | |
4525 (goto-char fst) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4526 (+ (current-column) verilog-cexp-indent)))))) |
79545 | 4527 (goto-char here) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4528 (indent-line-to val))) |
79545 | 4529 ((= (preceding-char) ?\) ) |
4530 (goto-char here) | |
4531 (let ((val (eval (cdr (assoc type verilog-indent-alist))))) | |
4532 (indent-line-to val))) | |
4533 (t | |
4534 (goto-char here) | |
4535 (let ((val)) | |
4536 (verilog-beg-of-statement-1) | |
4537 (if (and (< (point) here) | |
4538 (verilog-re-search-forward "=[ \\t]*" here 'move)) | |
4539 (setq val (current-column)) | |
4540 (setq val (eval (cdr (assoc type verilog-indent-alist))))) | |
4541 (goto-char here) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4542 (indent-line-to val)))))) |
79545 | 4543 |
4544 (; handle inside parenthetical expressions | |
4545 (eq type 'cparenexp) | |
4546 (let ((val (save-excursion | |
4547 (backward-up-list 1) | |
4548 (forward-char 1) | |
4549 (skip-chars-forward " \t") | |
4550 (current-column)))) | |
4551 (indent-line-to val) | |
4552 (if (and (not (verilog-in-struct-region-p)) | |
4553 (looking-at verilog-declaration-re)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4554 (verilog-indent-declaration ind)))) |
79545 | 4555 |
4556 (;-- Handle the ends | |
4557 (or | |
4558 (looking-at verilog-end-block-re ) | |
4559 (verilog-at-close-constraint-p)) | |
4560 (let ((val (if (eq type 'statement) | |
4561 (- ind verilog-indent-level) | |
4562 ind))) | |
4563 (indent-line-to val))) | |
4564 | |
4565 (;-- Case -- maybe line 'em up | |
4566 (and (eq type 'case) (not (looking-at "^[ \t]*$"))) | |
4567 (progn | |
4568 (cond | |
4569 ((looking-at "\\<endcase\\>") | |
4570 (indent-line-to ind)) | |
4571 (t | |
4572 (let ((val (eval (cdr (assoc type verilog-indent-alist))))) | |
4573 (indent-line-to val)))))) | |
4574 | |
4575 (;-- defun | |
4576 (and (eq type 'defun) | |
4577 (looking-at verilog-zero-indent-re)) | |
4578 (indent-line-to 0)) | |
4579 | |
4580 (;-- declaration | |
4581 (and (or | |
4582 (eq type 'defun) | |
4583 (eq type 'block)) | |
4584 (looking-at verilog-declaration-re)) | |
4585 (verilog-indent-declaration ind)) | |
4586 | |
4587 (;-- Everything else | |
4588 t | |
4589 (let ((val (eval (cdr (assoc type verilog-indent-alist))))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4590 (indent-line-to val)))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4591 |
79545 | 4592 (if (looking-at "[ \t]+$") |
4593 (skip-chars-forward " \t")) | |
4594 indent-str ; Return indent data | |
4595 )) | |
4596 | |
4597 (defun verilog-current-indent-level () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
4598 "Return the indent-level of the current statement." |
79545 | 4599 (save-excursion |
4600 (let (par-pos) | |
4601 (beginning-of-line) | |
4602 (setq par-pos (verilog-parenthesis-depth)) | |
4603 (while par-pos | |
4604 (goto-char par-pos) | |
4605 (beginning-of-line) | |
4606 (setq par-pos (verilog-parenthesis-depth))) | |
4607 (skip-chars-forward " \t") | |
4608 (current-column)))) | |
4609 | |
4610 (defun verilog-case-indent-level () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
4611 "Return the indent-level of the current statement. |
79545 | 4612 Do not count named blocks or case-statements." |
4613 (save-excursion | |
4614 (skip-chars-forward " \t") | |
4615 (cond | |
4616 ((looking-at verilog-named-block-re) | |
4617 (current-column)) | |
4618 ((and (not (looking-at verilog-case-re)) | |
4619 (looking-at "^[^:;]+[ \t]*:")) | |
4620 (verilog-re-search-forward ":" nil t) | |
4621 (skip-chars-forward " \t") | |
4622 (current-column)) | |
4623 (t | |
4624 (current-column))))) | |
4625 | |
4626 (defun verilog-indent-comment () | |
4627 "Indent current line as comment." | |
4628 (let* ((stcol | |
4629 (cond | |
4630 ((verilog-in-star-comment-p) | |
4631 (save-excursion | |
4632 (re-search-backward "/\\*" nil t) | |
4633 (1+(current-column)))) | |
4634 (comment-column | |
4635 comment-column ) | |
4636 (t | |
4637 (save-excursion | |
4638 (re-search-backward "//" nil t) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4639 (current-column)))))) |
79545 | 4640 (indent-line-to stcol) |
4641 stcol)) | |
4642 | |
4643 (defun verilog-more-comment () | |
4644 "Make more comment lines like the previous." | |
4645 (let* ((star 0) | |
4646 (stcol | |
4647 (cond | |
4648 ((verilog-in-star-comment-p) | |
4649 (save-excursion | |
4650 (setq star 1) | |
4651 (re-search-backward "/\\*" nil t) | |
4652 (1+(current-column)))) | |
4653 (comment-column | |
4654 comment-column ) | |
4655 (t | |
4656 (save-excursion | |
4657 (re-search-backward "//" nil t) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4658 (current-column)))))) |
79545 | 4659 (progn |
4660 (indent-to stcol) | |
4661 (if (and star | |
4662 (save-excursion | |
4663 (forward-line -1) | |
4664 (skip-chars-forward " \t") | |
4665 (looking-at "\*"))) | |
4666 (insert "* "))))) | |
4667 | |
4668 (defun verilog-comment-indent (&optional arg) | |
4669 "Return the column number the line should be indented to. | |
4670 ARG is ignored, for `comment-indent-function' compatibility." | |
4671 (cond | |
4672 ((verilog-in-star-comment-p) | |
4673 (save-excursion | |
4674 (re-search-backward "/\\*" nil t) | |
4675 (1+(current-column)))) | |
4676 ( comment-column | |
4677 comment-column ) | |
4678 (t | |
4679 (save-excursion | |
4680 (re-search-backward "//" nil t) | |
4681 (current-column))))) | |
4682 | |
4683 ;; | |
4684 | |
4685 (defun verilog-pretty-declarations () | |
4686 "Line up declarations around point." | |
4687 (interactive) | |
4688 (save-excursion | |
4689 (if (progn | |
4690 (verilog-beg-of-statement-1) | |
4691 (looking-at verilog-declaration-re)) | |
4692 (let* ((m1 (make-marker)) | |
4693 (e) (r) | |
4694 (here (point)) | |
4695 ;; Start of declaration range | |
4696 (start | |
4697 (progn | |
4698 (verilog-beg-of-statement-1) | |
4699 (while (looking-at verilog-declaration-re) | |
4700 (beginning-of-line) | |
4701 (setq e (point)) | |
4702 (verilog-backward-syntactic-ws) | |
4703 (backward-char) | |
4704 (verilog-beg-of-statement-1)) ;Ack, need to grok `define | |
4705 e)) | |
4706 ;; End of declaration range | |
4707 (end | |
4708 (progn | |
4709 (goto-char here) | |
4710 (verilog-end-of-statement) | |
4711 (setq e (point)) ;Might be on last line | |
4712 (verilog-forward-syntactic-ws) | |
4713 (while (looking-at verilog-declaration-re) | |
4714 (beginning-of-line) | |
4715 (verilog-end-of-statement) | |
4716 (setq e (point)) | |
4717 (verilog-forward-syntactic-ws)) | |
4718 e)) | |
4719 (edpos (set-marker (make-marker) end)) | |
4720 (ind) | |
4721 (base-ind | |
4722 (progn | |
4723 (goto-char start) | |
4724 (verilog-do-indent (verilog-calculate-indent)) | |
4725 (verilog-forward-ws&directives) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4726 (current-column)))) |
79545 | 4727 (goto-char end) |
4728 (goto-char start) | |
4729 (if (> (- end start) 100) | |
4730 (message "Lining up declarations..(please stand by)")) | |
4731 ;; Get the beginning of line indent first | |
4732 (while (progn (setq e (marker-position edpos)) | |
4733 (< (point) e)) | |
4734 (cond | |
4735 ( (save-excursion (skip-chars-backward " \t") | |
4736 (bolp)) | |
4737 (verilog-forward-ws&directives) | |
4738 (indent-line-to base-ind) | |
4739 (verilog-forward-ws&directives) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4740 (verilog-re-search-forward "[ \t\n\f]" e 'move)) |
79545 | 4741 (t |
4742 (just-one-space) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4743 (verilog-re-search-forward "[ \t\n\f]" e 'move))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4744 ;;(forward-line) |
79545 | 4745 ) |
4746 ;; Now find biggest prefix | |
4747 (setq ind (verilog-get-lineup-indent start edpos)) | |
4748 ;; Now indent each line. | |
4749 (goto-char start) | |
4750 (while (progn (setq e (marker-position edpos)) | |
4751 (setq r (- e (point))) | |
4752 (> r 0)) | |
4753 (setq e (point)) | |
4754 (message "%d" r) | |
4755 (cond | |
4756 ((or (and verilog-indent-declaration-macros | |
4757 (looking-at verilog-declaration-re-1-macro)) | |
4758 (looking-at verilog-declaration-re-1-no-macro)) | |
4759 (let ((p (match-end 0))) | |
4760 (set-marker m1 p) | |
4761 (if (verilog-re-search-forward "[[#`]" p 'move) | |
4762 (progn | |
4763 (forward-char -1) | |
4764 (just-one-space) | |
4765 (goto-char (marker-position m1)) | |
4766 (just-one-space) | |
4767 (indent-to ind)) | |
4768 (progn | |
4769 (just-one-space) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4770 (indent-to ind))))) |
79545 | 4771 ((verilog-continued-line-1 start) |
4772 (goto-char e) | |
4773 (indent-line-to ind)) | |
4774 (t ; Must be comment or white space | |
4775 (goto-char e) | |
4776 (verilog-forward-ws&directives) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4777 (forward-line -1))) |
79545 | 4778 (forward-line 1)) |
4779 (message ""))))) | |
4780 | |
4781 (defun verilog-pretty-expr (&optional myre) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4782 "Line up expressions around point, or optional regexp MYRE." |
79545 | 4783 (interactive "sRegular Expression: ((<|:)?=) ") |
4784 (save-excursion | |
4785 (if (or (eq myre nil) | |
4786 (string-equal myre "")) | |
4787 (setq myre "\\(<\\|:\\)?=")) | |
4788 ; (setq myre (concat "\\(^[^;" myre "]*\\)\\([" myre "]\\)")) | |
4789 (setq myre (concat "\\(^[^;#:?=]*\\)\\([" myre "]\\)")) | |
4790 (beginning-of-line) | |
4791 (if (and (not (looking-at (concat "^\\s-*" verilog-complete-reg))) | |
4792 (looking-at myre)) | |
4793 (let* ((here (point)) | |
4794 (e) (r) | |
4795 (start | |
4796 (progn | |
4797 (beginning-of-line) | |
4798 (setq e (point)) | |
4799 (verilog-backward-syntactic-ws) | |
4800 (beginning-of-line) | |
4801 (while (and (not (looking-at (concat "^\\s-*" verilog-complete-reg))) | |
4802 (looking-at myre) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4803 (not (bobp))) |
79545 | 4804 (setq e (point)) |
4805 (verilog-backward-syntactic-ws) | |
4806 (beginning-of-line) | |
4807 ) ;Ack, need to grok `define | |
4808 e)) | |
4809 (end | |
4810 (progn | |
4811 (goto-char here) | |
4812 (end-of-line) | |
4813 (setq e (point)) ;Might be on last line | |
4814 (verilog-forward-syntactic-ws) | |
4815 (beginning-of-line) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4816 (while (and (not (looking-at |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4817 (concat "^\\s-*" verilog-complete-reg))) |
79545 | 4818 (looking-at myre)) |
4819 (end-of-line) | |
4820 (setq e (point)) | |
4821 (verilog-forward-syntactic-ws) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4822 (beginning-of-line)) |
79545 | 4823 e)) |
4824 (edpos (set-marker (make-marker) end)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4825 (ind)) |
79545 | 4826 (goto-char start) |
4827 (verilog-do-indent (verilog-calculate-indent)) | |
4828 (if (> (- end start) 100) | |
4829 (message "Lining up expressions..(please stand by)")) | |
4830 | |
4831 ;; Set indent to minimum throughout region | |
4832 (while (< (point) (marker-position edpos)) | |
4833 (beginning-of-line) | |
4834 (verilog-just-one-space myre) | |
4835 (end-of-line) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4836 (verilog-forward-syntactic-ws)) |
79545 | 4837 |
4838 ;; Now find biggest prefix | |
4839 (setq ind (verilog-get-lineup-indent-2 myre start edpos)) | |
4840 | |
4841 ;; Now indent each line. | |
4842 (goto-char start) | |
4843 (while (progn (setq e (marker-position edpos)) | |
4844 (setq r (- e (point))) | |
4845 (> r 0)) | |
4846 (setq e (point)) | |
4847 (message "%d" r) | |
4848 (cond | |
4849 ((looking-at myre) | |
4850 (goto-char (match-end 1)) | |
4851 (if (eq (char-after) ?=) | |
4852 (indent-to (1+ ind)) ; line up the = of the <= with surrounding = | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4853 (indent-to ind))) |
79545 | 4854 ((verilog-continued-line-1 start) |
4855 (goto-char e) | |
4856 (indent-line-to ind)) | |
4857 (t ; Must be comment or white space | |
4858 (goto-char e) | |
4859 (verilog-forward-ws&directives) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4860 (forward-line -1))) |
79545 | 4861 (forward-line 1)) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4862 (message ""))))) |
79545 | 4863 |
4864 (defun verilog-just-one-space (myre) | |
4865 "Remove extra spaces around regular expression MYRE." | |
4866 (interactive) | |
4867 (if (and (not(looking-at verilog-complete-reg)) | |
4868 (looking-at myre)) | |
4869 (let ((p1 (match-end 1)) | |
4870 (p2 (match-end 2))) | |
4871 (progn | |
4872 (goto-char p2) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4873 (if (looking-at "\\s-") (just-one-space)) |
79545 | 4874 (goto-char p1) |
4875 (forward-char -1) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4876 (if (looking-at "\\s-") (just-one-space))))) |
79545 | 4877 (message "")) |
4878 | |
4879 (defun verilog-indent-declaration (baseind) | |
4880 "Indent current lines as declaration. | |
4881 Line up the variable names based on previous declaration's indentation. | |
4882 BASEIND is the base indent to offset everything." | |
4883 (interactive) | |
4884 (let ((pos (point-marker)) | |
4885 (lim (save-excursion | |
4886 ;; (verilog-re-search-backward verilog-declaration-opener nil 'move) | |
4887 (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)\\|\\(\\<task\\>\\)" nil 'move) | |
4888 (point))) | |
4889 (ind) | |
4890 (val) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4891 (m1 (make-marker))) |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4892 (setq val |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4893 (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist))))) |
79545 | 4894 (indent-line-to val) |
4895 | |
4896 ;; Use previous declaration (in this module) as template. | |
4897 (if (or (memq 'all verilog-auto-lineup) | |
4898 (memq 'declaration verilog-auto-lineup)) | |
79546 | 4899 (if (verilog-re-search-backward |
79545 | 4900 (or (and verilog-indent-declaration-macros |
4901 verilog-declaration-re-1-macro) | |
4902 verilog-declaration-re-1-no-macro) lim t) | |
4903 (progn | |
4904 (goto-char (match-end 0)) | |
4905 (skip-chars-forward " \t") | |
4906 (setq ind (current-column)) | |
4907 (goto-char pos) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4908 (setq val |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4909 (+ baseind |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4910 (eval (cdr (assoc 'declaration verilog-indent-alist))))) |
79545 | 4911 (indent-line-to val) |
4912 (if (and verilog-indent-declaration-macros | |
4913 (looking-at verilog-declaration-re-2-macro)) | |
4914 (let ((p (match-end 0))) | |
4915 (set-marker m1 p) | |
4916 (if (verilog-re-search-forward "[[#`]" p 'move) | |
4917 (progn | |
4918 (forward-char -1) | |
4919 (just-one-space) | |
4920 (goto-char (marker-position m1)) | |
4921 (just-one-space) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4922 (indent-to ind)) |
79545 | 4923 (if (/= (current-column) ind) |
4924 (progn | |
4925 (just-one-space) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4926 (indent-to ind))))) |
79545 | 4927 (if (looking-at verilog-declaration-re-2-no-macro) |
4928 (let ((p (match-end 0))) | |
4929 (set-marker m1 p) | |
4930 (if (verilog-re-search-forward "[[`#]" p 'move) | |
4931 (progn | |
4932 (forward-char -1) | |
4933 (just-one-space) | |
4934 (goto-char (marker-position m1)) | |
4935 (just-one-space) | |
4936 (indent-to ind)) | |
4937 (if (/= (current-column) ind) | |
4938 (progn | |
4939 (just-one-space) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4940 (indent-to ind)))))))))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4941 (goto-char pos))) |
79545 | 4942 |
4943 (defun verilog-get-lineup-indent (b edpos) | |
4944 "Return the indent level that will line up several lines within the region. | |
4945 Region is defined by B and EDPOS." | |
4946 (save-excursion | |
4947 (let ((ind 0) e) | |
4948 (goto-char b) | |
4949 ;; Get rightmost position | |
4950 (while (progn (setq e (marker-position edpos)) | |
4951 (< (point) e)) | |
79546 | 4952 (if (verilog-re-search-forward |
79545 | 4953 (or (and verilog-indent-declaration-macros |
4954 verilog-declaration-re-1-macro) | |
4955 verilog-declaration-re-1-no-macro) e 'move) | |
4956 (progn | |
4957 (goto-char (match-end 0)) | |
4958 (verilog-backward-syntactic-ws) | |
4959 (if (> (current-column) ind) | |
4960 (setq ind (current-column))) | |
4961 (goto-char (match-end 0))))) | |
4962 (if (> ind 0) | |
4963 (1+ ind) | |
4964 ;; No lineup-string found | |
4965 (goto-char b) | |
4966 (end-of-line) | |
4967 (skip-chars-backward " \t") | |
4968 (1+ (current-column)))))) | |
4969 | |
4970 (defun verilog-get-lineup-indent-2 (myre b edpos) | |
4971 "Return the indent level that will line up several lines within the region." | |
4972 (save-excursion | |
4973 (let ((ind 0) e) | |
4974 (goto-char b) | |
4975 ;; Get rightmost position | |
4976 (while (progn (setq e (marker-position edpos)) | |
4977 (< (point) e)) | |
4978 (if (verilog-re-search-forward myre e 'move) | |
4979 (progn | |
4980 (goto-char (match-end 0)) | |
4981 (verilog-backward-syntactic-ws) | |
4982 (if (> (current-column) ind) | |
4983 (setq ind (current-column))) | |
4984 (goto-char (match-end 0))))) | |
4985 (if (> ind 0) | |
4986 (1+ ind) | |
4987 ;; No lineup-string found | |
4988 (goto-char b) | |
4989 (end-of-line) | |
4990 (skip-chars-backward " \t") | |
4991 (1+ (current-column)))))) | |
4992 | |
4993 (defun verilog-comment-depth (type val) | |
4994 "A useful mode debugging aide. TYPE and VAL are comments for insertion." | |
4995 (save-excursion | |
4996 (let | |
4997 ((b (prog2 | |
4998 (beginning-of-line) | |
4999 (point-marker) | |
5000 (end-of-line))) | |
5001 (e (point-marker))) | |
5002 (if (re-search-backward " /\\* \[#-\]# \[a-zA-Z\]+ \[0-9\]+ ## \\*/" b t) | |
5003 (progn | |
5004 (replace-match " /* -# ## */") | |
5005 (end-of-line)) | |
5006 (progn | |
5007 (end-of-line) | |
5008 (insert " /* ## ## */")))) | |
5009 (backward-char 6) | |
5010 (insert | |
5011 (format "%s %d" type val)))) | |
5012 | |
5013 ;; | |
5014 ;; | |
5015 ;; Completion | |
5016 ;; | |
5017 (defvar verilog-str nil) | |
5018 (defvar verilog-all nil) | |
5019 (defvar verilog-pred nil) | |
5020 (defvar verilog-buffer-to-use nil) | |
5021 (defvar verilog-flag nil) | |
5022 (defvar verilog-toggle-completions nil | |
5023 "*True means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one. | |
5024 Repeated use of \\[verilog-complete-word] will show you all of them. | |
5025 Normally, when there is more than one possible completion, | |
5026 it displays a list of all possible completions.") | |
5027 | |
5028 | |
5029 (defvar verilog-type-keywords | |
5030 '( | |
5031 "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input" | |
5032 "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0" | |
5033 "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pullup" | |
5034 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0" | |
5035 "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1" | |
5036 "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor" | |
5037 ) | |
5038 "*Keywords for types used when completing a word in a declaration or parmlist. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5039 \(Eg. integer, real, reg...)") |
79545 | 5040 |
5041 (defvar verilog-cpp-keywords | |
5042 '("module" "macromodule" "primitive" "timescale" "define" "ifdef" "ifndef" "else" | |
5043 "endif") | |
5044 "*Keywords to complete when at first word of a line in declarative scope. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5045 \(Eg. initial, always, begin, assign.) |
79545 | 5046 The procedures and variables defined within the Verilog program |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5047 will be completed at runtime and should not be added to this list.") |
79545 | 5048 |
5049 (defvar verilog-defun-keywords | |
5050 (append | |
5051 '( | |
5052 "always" "always_comb" "always_ff" "always_latch" "assign" | |
5053 "begin" "end" "generate" "endgenerate" "module" "endmodule" | |
5054 "specify" "endspecify" "function" "endfunction" "initial" "final" | |
5055 "task" "endtask" "primitive" "endprimitive" | |
5056 ) | |
5057 verilog-type-keywords) | |
5058 "*Keywords to complete when at first word of a line in declarative scope. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5059 \(Eg. initial, always, begin, assign.) |
79545 | 5060 The procedures and variables defined within the Verilog program |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5061 will be completed at runtime and should not be added to this list.") |
79545 | 5062 |
5063 (defvar verilog-block-keywords | |
5064 '( | |
5065 "begin" "break" "case" "continue" "else" "end" "endfunction" | |
5066 "endgenerate" "endinterface" "endpackage" "endspecify" "endtask" | |
5067 "for" "fork" "if" "join" "join_any" "join_none" "repeat" "return" | |
5068 "while") | |
5069 "*Keywords to complete when at first word of a line in behavioral scope. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5070 \(Eg. begin, if, then, else, for, fork.) |
79545 | 5071 The procedures and variables defined within the Verilog program |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5072 will be completed at runtime and should not be added to this list.") |
79545 | 5073 |
5074 (defvar verilog-tf-keywords | |
5075 '("begin" "break" "fork" "join" "join_any" "join_none" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat") | |
5076 "*Keywords to complete when at first word of a line in a task or function. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5077 \(Eg. begin, if, then, else, for, fork.) |
79545 | 5078 The procedures and variables defined within the Verilog program |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5079 will be completed at runtime and should not be added to this list.") |
79545 | 5080 |
5081 (defvar verilog-case-keywords | |
5082 '("begin" "fork" "join" "join_any" "join_none" "case" "end" "endcase" "if" "else" "for" "repeat") | |
5083 "*Keywords to complete when at first word of a line in case scope. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5084 \(Eg. begin, if, then, else, for, fork.) |
79545 | 5085 The procedures and variables defined within the Verilog program |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5086 will be completed at runtime and should not be added to this list.") |
79545 | 5087 |
5088 (defvar verilog-separator-keywords | |
5089 '("else" "then" "begin") | |
5090 "*Keywords to complete when NOT standing at the first word of a statement. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5091 \(Eg. else, then.) |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5092 Variables and function names defined within the Verilog program |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5093 will be completed at runtime and should not be added to this list.") |
79545 | 5094 |
5095 (defun verilog-string-diff (str1 str2) | |
5096 "Return index of first letter where STR1 and STR2 differs." | |
5097 (catch 'done | |
5098 (let ((diff 0)) | |
5099 (while t | |
5100 (if (or (> (1+ diff) (length str1)) | |
5101 (> (1+ diff) (length str2))) | |
5102 (throw 'done diff)) | |
5103 (or (equal (aref str1 diff) (aref str2 diff)) | |
5104 (throw 'done diff)) | |
5105 (setq diff (1+ diff)))))) | |
5106 | |
5107 ;; Calculate all possible completions for functions if argument is `function', | |
5108 ;; completions for procedures if argument is `procedure' or both functions and | |
5109 ;; procedures otherwise. | |
5110 | |
5111 (defun verilog-func-completion (type) | |
5112 "Build regular expression for module/task/function names. | |
5113 TYPE is 'module, 'tf for task or function, or t if unknown." | |
5114 (if (string= verilog-str "") | |
5115 (setq verilog-str "[a-zA-Z_]")) | |
5116 (let ((verilog-str (concat (cond | |
5117 ((eq type 'module) "\\<\\(module\\)\\s +") | |
5118 ((eq type 'tf) "\\<\\(task\\|function\\)\\s +") | |
5119 (t "\\<\\(task\\|function\\|module\\)\\s +")) | |
5120 "\\<\\(" verilog-str "[a-zA-Z0-9_.]*\\)\\>")) | |
5121 match) | |
5122 | |
5123 (if (not (looking-at verilog-defun-re)) | |
5124 (verilog-re-search-backward verilog-defun-re nil t)) | |
5125 (forward-char 1) | |
5126 | |
5127 ;; Search through all reachable functions | |
5128 (goto-char (point-min)) | |
5129 (while (verilog-re-search-forward verilog-str (point-max) t) | |
5130 (progn (setq match (buffer-substring (match-beginning 2) | |
5131 (match-end 2))) | |
5132 (if (or (null verilog-pred) | |
5133 (funcall verilog-pred match)) | |
5134 (setq verilog-all (cons match verilog-all))))) | |
5135 (if (match-beginning 0) | |
5136 (goto-char (match-beginning 0))))) | |
5137 | |
5138 (defun verilog-get-completion-decl (end) | |
5139 "Macro for searching through current declaration (var, type or const) | |
5140 for matches of `str' and adding the occurrence tp `all' through point END." | |
5141 (let ((re (or (and verilog-indent-declaration-macros | |
5142 verilog-declaration-re-2-macro) | |
5143 verilog-declaration-re-2-no-macro)) | |
5144 decl-end match) | |
5145 ;; Traverse lines | |
5146 (while (and (< (point) end) | |
5147 (verilog-re-search-forward re end t)) | |
5148 ;; Traverse current line | |
5149 (setq decl-end (save-excursion (verilog-declaration-end))) | |
5150 (while (and (verilog-re-search-forward verilog-symbol-re decl-end t) | |
5151 (not (match-end 1))) | |
5152 (setq match (buffer-substring (match-beginning 0) (match-end 0))) | |
5153 (if (string-match (concat "\\<" verilog-str) match) | |
5154 (if (or (null verilog-pred) | |
5155 (funcall verilog-pred match)) | |
5156 (setq verilog-all (cons match verilog-all))))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5157 (forward-line 1))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5158 verilog-all) |
79545 | 5159 |
5160 (defun verilog-type-completion () | |
5161 "Calculate all possible completions for types." | |
5162 (let ((start (point)) | |
5163 goon) | |
5164 ;; Search for all reachable type declarations | |
5165 (while (or (verilog-beg-of-defun) | |
5166 (setq goon (not goon))) | |
5167 (save-excursion | |
5168 (if (and (< start (prog1 (save-excursion (verilog-end-of-defun) | |
5169 (point)) | |
5170 (forward-char 1))) | |
5171 (verilog-re-search-forward | |
5172 "\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>" | |
5173 start t) | |
5174 (not (match-end 1))) | |
5175 ;; Check current type declaration | |
5176 (verilog-get-completion-decl start)))))) | |
5177 | |
5178 (defun verilog-var-completion () | |
5179 "Calculate all possible completions for variables (or constants)." | |
5180 (let ((start (point))) | |
5181 ;; Search for all reachable var declarations | |
5182 (verilog-beg-of-defun) | |
5183 (save-excursion | |
5184 ;; Check var declarations | |
5185 (verilog-get-completion-decl start)))) | |
5186 | |
5187 (defun verilog-keyword-completion (keyword-list) | |
5188 "Give list of all possible completions of keywords in KEYWORD-LIST." | |
5189 (mapcar '(lambda (s) | |
5190 (if (string-match (concat "\\<" verilog-str) s) | |
5191 (if (or (null verilog-pred) | |
5192 (funcall verilog-pred s)) | |
5193 (setq verilog-all (cons s verilog-all))))) | |
5194 keyword-list)) | |
5195 | |
5196 | |
5197 (defun verilog-completion (verilog-str verilog-pred verilog-flag) | |
5198 "Function passed to `completing-read', `try-completion' or `all-completions'. | |
5199 Called to get completion on VERILOG-STR. If VERILOG-PRED is non-nil, it | |
5200 must be a function to be called for every match to check if this should | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5201 really be a match. If VERILOG-FLAG is t, the function returns a list of |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5202 all possible completions. If VERILOG-FLAG is nil it returns a string, |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5203 the longest possible completion, or t if VERILOG-STR is an exact match. |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5204 If VERILOG-FLAG is 'lambda, the function returns t if VERILOG-STR is an |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5205 exact match, nil otherwise." |
79545 | 5206 (save-excursion |
5207 (let ((verilog-all nil)) | |
5208 ;; Set buffer to use for searching labels. This should be set | |
5209 ;; within functions which use verilog-completions | |
5210 (set-buffer verilog-buffer-to-use) | |
5211 | |
5212 ;; Determine what should be completed | |
5213 (let ((state (car (verilog-calculate-indent)))) | |
5214 (cond ((eq state 'defun) | |
5215 (save-excursion (verilog-var-completion)) | |
5216 (verilog-func-completion 'module) | |
5217 (verilog-keyword-completion verilog-defun-keywords)) | |
5218 | |
5219 ((eq state 'behavioral) | |
5220 (save-excursion (verilog-var-completion)) | |
5221 (verilog-func-completion 'module) | |
5222 (verilog-keyword-completion verilog-defun-keywords)) | |
5223 | |
5224 ((eq state 'block) | |
5225 (save-excursion (verilog-var-completion)) | |
5226 (verilog-func-completion 'tf) | |
5227 (verilog-keyword-completion verilog-block-keywords)) | |
5228 | |
5229 ((eq state 'case) | |
5230 (save-excursion (verilog-var-completion)) | |
5231 (verilog-func-completion 'tf) | |
5232 (verilog-keyword-completion verilog-case-keywords)) | |
5233 | |
5234 ((eq state 'tf) | |
5235 (save-excursion (verilog-var-completion)) | |
5236 (verilog-func-completion 'tf) | |
5237 (verilog-keyword-completion verilog-tf-keywords)) | |
5238 | |
5239 ((eq state 'cpp) | |
5240 (save-excursion (verilog-var-completion)) | |
5241 (verilog-keyword-completion verilog-cpp-keywords)) | |
5242 | |
5243 ((eq state 'cparenexp) | |
5244 (save-excursion (verilog-var-completion))) | |
5245 | |
5246 (t;--Anywhere else | |
5247 (save-excursion (verilog-var-completion)) | |
5248 (verilog-func-completion 'both) | |
5249 (verilog-keyword-completion verilog-separator-keywords)))) | |
5250 | |
5251 ;; Now we have built a list of all matches. Give response to caller | |
5252 (verilog-completion-response)))) | |
5253 | |
5254 (defun verilog-completion-response () | |
5255 (cond ((or (equal verilog-flag 'lambda) (null verilog-flag)) | |
5256 ;; This was not called by all-completions | |
5257 (if (null verilog-all) | |
5258 ;; Return nil if there was no matching label | |
5259 nil | |
5260 ;; Get longest string common in the labels | |
5261 (let* ((elm (cdr verilog-all)) | |
5262 (match (car verilog-all)) | |
5263 (min (length match)) | |
5264 tmp) | |
5265 (if (string= match verilog-str) | |
5266 ;; Return t if first match was an exact match | |
5267 (setq match t) | |
5268 (while (not (null elm)) | |
5269 ;; Find longest common string | |
5270 (if (< (setq tmp (verilog-string-diff match (car elm))) min) | |
5271 (progn | |
5272 (setq min tmp) | |
5273 (setq match (substring match 0 min)))) | |
5274 ;; Terminate with match=t if this is an exact match | |
5275 (if (string= (car elm) verilog-str) | |
5276 (progn | |
5277 (setq match t) | |
5278 (setq elm nil)) | |
5279 (setq elm (cdr elm))))) | |
5280 ;; If this is a test just for exact match, return nil ot t | |
5281 (if (and (equal verilog-flag 'lambda) (not (equal match 't))) | |
5282 nil | |
5283 match)))) | |
5284 ;; If flag is t, this was called by all-completions. Return | |
5285 ;; list of all possible completions | |
5286 (verilog-flag | |
5287 verilog-all))) | |
5288 | |
5289 (defvar verilog-last-word-numb 0) | |
5290 (defvar verilog-last-word-shown nil) | |
5291 (defvar verilog-last-completions nil) | |
5292 | |
5293 (defun verilog-complete-word () | |
5294 "Complete word at current point. | |
5295 \(See also `verilog-toggle-completions', `verilog-type-keywords', | |
5296 and `verilog-separator-keywords'.)" | |
5297 (interactive) | |
5298 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point))) | |
5299 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))) | |
5300 (verilog-str (buffer-substring b e)) | |
5301 ;; The following variable is used in verilog-completion | |
5302 (verilog-buffer-to-use (current-buffer)) | |
5303 (allcomp (if (and verilog-toggle-completions | |
5304 (string= verilog-last-word-shown verilog-str)) | |
5305 verilog-last-completions | |
5306 (all-completions verilog-str 'verilog-completion))) | |
5307 (match (if verilog-toggle-completions | |
5308 "" (try-completion | |
5309 verilog-str (mapcar '(lambda (elm) | |
5310 (cons elm 0)) allcomp))))) | |
5311 ;; Delete old string | |
5312 (delete-region b e) | |
5313 | |
5314 ;; Toggle-completions inserts whole labels | |
5315 (if verilog-toggle-completions | |
5316 (progn | |
5317 ;; Update entry number in list | |
5318 (setq verilog-last-completions allcomp | |
5319 verilog-last-word-numb | |
5320 (if (>= verilog-last-word-numb (1- (length allcomp))) | |
5321 0 | |
5322 (1+ verilog-last-word-numb))) | |
5323 (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb)) | |
5324 ;; Display next match or same string if no match was found | |
5325 (if (not (null allcomp)) | |
5326 (insert "" verilog-last-word-shown) | |
5327 (insert "" verilog-str) | |
5328 (message "(No match)"))) | |
5329 ;; The other form of completion does not necessarily do that. | |
5330 | |
5331 ;; Insert match if found, or the original string if no match | |
5332 (if (or (null match) (equal match 't)) | |
5333 (progn (insert "" verilog-str) | |
5334 (message "(No match)")) | |
5335 (insert "" match)) | |
5336 ;; Give message about current status of completion | |
5337 (cond ((equal match 't) | |
5338 (if (not (null (cdr allcomp))) | |
5339 (message "(Complete but not unique)") | |
5340 (message "(Sole completion)"))) | |
5341 ;; Display buffer if the current completion didn't help | |
5342 ;; on completing the label. | |
5343 ((and (not (null (cdr allcomp))) (= (length verilog-str) | |
5344 (length match))) | |
5345 (with-output-to-temp-buffer "*Completions*" | |
5346 (display-completion-list allcomp)) | |
5347 ;; Wait for a key press. Then delete *Completion* window | |
5348 (momentary-string-display "" (point)) | |
5349 (delete-window (get-buffer-window (get-buffer "*Completions*"))) | |
5350 ))))) | |
5351 | |
5352 (defun verilog-show-completions () | |
5353 "Show all possible completions at current point." | |
5354 (interactive) | |
5355 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point))) | |
5356 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))) | |
5357 (verilog-str (buffer-substring b e)) | |
5358 ;; The following variable is used in verilog-completion | |
5359 (verilog-buffer-to-use (current-buffer)) | |
5360 (allcomp (if (and verilog-toggle-completions | |
5361 (string= verilog-last-word-shown verilog-str)) | |
5362 verilog-last-completions | |
5363 (all-completions verilog-str 'verilog-completion)))) | |
5364 ;; Show possible completions in a temporary buffer. | |
5365 (with-output-to-temp-buffer "*Completions*" | |
5366 (display-completion-list allcomp)) | |
5367 ;; Wait for a key press. Then delete *Completion* window | |
5368 (momentary-string-display "" (point)) | |
5369 (delete-window (get-buffer-window (get-buffer "*Completions*"))))) | |
5370 | |
5371 | |
5372 (defun verilog-get-default-symbol () | |
5373 "Return symbol around current point as a string." | |
5374 (save-excursion | |
5375 (buffer-substring (progn | |
5376 (skip-chars-backward " \t") | |
5377 (skip-chars-backward "a-zA-Z0-9_") | |
5378 (point)) | |
5379 (progn | |
5380 (skip-chars-forward "a-zA-Z0-9_") | |
5381 (point))))) | |
5382 | |
5383 (defun verilog-build-defun-re (str &optional arg) | |
5384 "Return function/task/module starting with STR as regular expression. | |
5385 With optional second ARG non-nil, STR is the complete name of the instruction." | |
5386 (if arg | |
5387 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "\\)\\>") | |
5388 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>"))) | |
5389 | |
5390 (defun verilog-comp-defun (verilog-str verilog-pred verilog-flag) | |
5391 "Function passed to `completing-read', `try-completion' or `all-completions'. | |
5392 Returns a completion on any function name based on VERILOG-STR prefix. If | |
5393 VERILOG-PRED is non-nil, it must be a function to be called for every match | |
5394 to check if this should really be a match. If VERILOG-FLAG is t, the | |
5395 function returns a list of all possible completions. If it is nil it | |
5396 returns a string, the longest possible completion, or t if VERILOG-STR is | |
5397 an exact match. If VERILOG-FLAG is 'lambda, the function returns t if | |
5398 VERILOG-STR is an exact match, nil otherwise." | |
5399 (save-excursion | |
5400 (let ((verilog-all nil) | |
5401 match) | |
5402 | |
5403 ;; Set buffer to use for searching labels. This should be set | |
5404 ;; within functions which use verilog-completions | |
5405 (set-buffer verilog-buffer-to-use) | |
5406 | |
5407 (let ((verilog-str verilog-str)) | |
5408 ;; Build regular expression for functions | |
5409 (if (string= verilog-str "") | |
5410 (setq verilog-str (verilog-build-defun-re "[a-zA-Z_]")) | |
5411 (setq verilog-str (verilog-build-defun-re verilog-str))) | |
5412 (goto-char (point-min)) | |
5413 | |
5414 ;; Build a list of all possible completions | |
5415 (while (verilog-re-search-forward verilog-str nil t) | |
5416 (setq match (buffer-substring (match-beginning 2) (match-end 2))) | |
5417 (if (or (null verilog-pred) | |
5418 (funcall verilog-pred match)) | |
5419 (setq verilog-all (cons match verilog-all))))) | |
5420 | |
5421 ;; Now we have built a list of all matches. Give response to caller | |
5422 (verilog-completion-response)))) | |
5423 | |
5424 (defun verilog-goto-defun () | |
5425 "Move to specified Verilog module/task/function. | |
5426 The default is a name found in the buffer around point. | |
5427 If search fails, other files are checked based on | |
5428 `verilog-library-flags'." | |
5429 (interactive) | |
5430 (let* ((default (verilog-get-default-symbol)) | |
5431 ;; The following variable is used in verilog-comp-function | |
5432 (verilog-buffer-to-use (current-buffer)) | |
5433 (label (if (not (string= default "")) | |
5434 ;; Do completion with default | |
5435 (completing-read (concat "Label: (default " default ") ") | |
5436 'verilog-comp-defun nil nil "") | |
5437 ;; There is no default value. Complete without it | |
5438 (completing-read "Label: " | |
5439 'verilog-comp-defun nil nil ""))) | |
5440 pt) | |
5441 ;; If there was no response on prompt, use default value | |
5442 (if (string= label "") | |
5443 (setq label default)) | |
5444 ;; Goto right place in buffer if label is not an empty string | |
5445 (or (string= label "") | |
5446 (progn | |
5447 (save-excursion | |
5448 (goto-char (point-min)) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5449 (setq pt |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5450 (re-search-forward (verilog-build-defun-re label t) nil t))) |
79545 | 5451 (when pt |
5452 (goto-char pt) | |
5453 (beginning-of-line)) | |
5454 pt) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5455 (verilog-goto-defun-file label)))) |
79545 | 5456 |
5457 ;; Eliminate compile warning | |
5458 (eval-when-compile | |
5459 (if (not (boundp 'occur-pos-list)) | |
5460 (defvar occur-pos-list nil "Backward compatibility occur positions."))) | |
5461 | |
5462 (defun verilog-showscopes () | |
5463 "List all scopes in this module." | |
5464 (interactive) | |
5465 (let ((buffer (current-buffer)) | |
5466 (linenum 1) | |
5467 (nlines 0) | |
5468 (first 1) | |
5469 (prevpos (point-min)) | |
5470 (final-context-start (make-marker)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5471 (regexp "\\(module\\s-+\\w+\\s-*(\\)\\|\\(\\w+\\s-+\\w+\\s-*(\\)")) |
79545 | 5472 (with-output-to-temp-buffer "*Occur*" |
5473 (save-excursion | |
5474 (message (format "Searching for %s ..." regexp)) | |
5475 ;; Find next match, but give up if prev match was at end of buffer. | |
5476 (while (and (not (= prevpos (point-max))) | |
5477 (verilog-re-search-forward regexp nil t)) | |
5478 (goto-char (match-beginning 0)) | |
5479 (beginning-of-line) | |
5480 (save-match-data | |
5481 (setq linenum (+ linenum (count-lines prevpos (point))))) | |
5482 (setq prevpos (point)) | |
5483 (goto-char (match-end 0)) | |
5484 (let* ((start (save-excursion | |
5485 (goto-char (match-beginning 0)) | |
5486 (forward-line (if (< nlines 0) nlines (- nlines))) | |
5487 (point))) | |
5488 (end (save-excursion | |
5489 (goto-char (match-end 0)) | |
5490 (if (> nlines 0) | |
5491 (forward-line (1+ nlines)) | |
5492 (forward-line 1)) | |
5493 (point))) | |
5494 (tag (format "%3d" linenum)) | |
5495 (empty (make-string (length tag) ?\ )) | |
5496 tem) | |
5497 (save-excursion | |
5498 (setq tem (make-marker)) | |
5499 (set-marker tem (point)) | |
5500 (set-buffer standard-output) | |
5501 (setq occur-pos-list (cons tem occur-pos-list)) | |
5502 (or first (zerop nlines) | |
5503 (insert "--------\n")) | |
5504 (setq first nil) | |
5505 (insert-buffer-substring buffer start end) | |
5506 (backward-char (- end start)) | |
5507 (setq tem (if (< nlines 0) (- nlines) nlines)) | |
5508 (while (> tem 0) | |
5509 (insert empty ?:) | |
5510 (forward-line 1) | |
5511 (setq tem (1- tem))) | |
5512 (let ((this-linenum linenum)) | |
5513 (set-marker final-context-start | |
5514 (+ (point) (- (match-end 0) (match-beginning 0)))) | |
5515 (while (< (point) final-context-start) | |
5516 (if (null tag) | |
5517 (setq tag (format "%3d" this-linenum))) | |
5518 (insert tag ?:))))))) | |
5519 (set-buffer-modified-p nil)))) | |
5520 | |
5521 | |
5522 ;; Highlight helper functions | |
5523 (defconst verilog-directive-regexp "\\(translate\\|coverage\\|lint\\)_") | |
5524 (defun verilog-within-translate-off () | |
5525 "Return point if within translate-off region, else nil." | |
5526 (and (save-excursion | |
5527 (re-search-backward | |
5528 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>") | |
5529 nil t)) | |
5530 (equal "off" (match-string 2)) | |
5531 (point))) | |
5532 | |
5533 (defun verilog-start-translate-off (limit) | |
5534 "Return point before translate-off directive if before LIMIT, else nil." | |
5535 (when (re-search-forward | |
5536 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>") | |
5537 limit t) | |
5538 (match-beginning 0))) | |
5539 | |
5540 (defun verilog-back-to-start-translate-off (limit) | |
5541 "Return point before translate-off directive if before LIMIT, else nil." | |
5542 (when (re-search-backward | |
5543 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>") | |
5544 limit t) | |
5545 (match-beginning 0))) | |
5546 | |
5547 (defun verilog-end-translate-off (limit) | |
5548 "Return point after translate-on directive if before LIMIT, else nil." | |
5549 | |
5550 (re-search-forward (concat | |
5551 "//\\s-*.*\\s-*" verilog-directive-regexp "on\\>") limit t)) | |
5552 | |
5553 (defun verilog-match-translate-off (limit) | |
5554 "Match a translate-off block, setting `match-data' and returning t, else nil. | |
5555 Bound search by LIMIT." | |
5556 (when (< (point) limit) | |
5557 (let ((start (or (verilog-within-translate-off) | |
5558 (verilog-start-translate-off limit))) | |
5559 (case-fold-search t)) | |
5560 (when start | |
5561 (let ((end (or (verilog-end-translate-off limit) limit))) | |
5562 (set-match-data (list start end)) | |
5563 (goto-char end)))))) | |
5564 | |
5565 (defun verilog-font-lock-match-item (limit) | |
5566 "Match, and move over, any declaration item after point. | |
5567 Bound search by LIMIT. Adapted from | |
5568 `font-lock-match-c-style-declaration-item-and-skip-to-next'." | |
5569 (condition-case nil | |
5570 (save-restriction | |
5571 (narrow-to-region (point-min) limit) | |
5572 ;; match item | |
5573 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)") | |
5574 (save-match-data | |
5575 (goto-char (match-end 1)) | |
5576 ;; move to next item | |
5577 (if (looking-at "\\(\\s-*,\\)") | |
5578 (goto-char (match-end 1)) | |
5579 (end-of-line) t)))) | |
5580 (error nil))) | |
5581 | |
5582 | |
5583 ;; Added by Subbu Meiyappan for Header | |
5584 | |
5585 (defun verilog-header () | |
5586 "Insert a standard Verilog file header." | |
5587 (interactive) | |
5588 (let ((start (point))) | |
5589 (insert "\ | |
5590 //----------------------------------------------------------------------------- | |
5591 // Title : <title> | |
5592 // Project : <project> | |
5593 //----------------------------------------------------------------------------- | |
5594 // File : <filename> | |
5595 // Author : <author> | |
5596 // Created : <credate> | |
5597 // Last modified : <moddate> | |
5598 //----------------------------------------------------------------------------- | |
5599 // Description : | |
5600 // <description> | |
5601 //----------------------------------------------------------------------------- | |
5602 // Copyright (c) <copydate> by <company> This model is the confidential and | |
5603 // proprietary property of <company> and the possession or use of this | |
5604 // file requires a written license from <company>. | |
5605 //------------------------------------------------------------------------------ | |
5606 // Modification history : | |
5607 // <modhist> | |
5608 //----------------------------------------------------------------------------- | |
5609 | |
5610 ") | |
5611 (goto-char start) | |
5612 (search-forward "<filename>") | |
5613 (replace-match (buffer-name) t t) | |
5614 (search-forward "<author>") (replace-match "" t t) | |
5615 (insert (user-full-name)) | |
5616 (insert " <" (user-login-name) "@" (system-name) ">") | |
5617 (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
|
5618 (verilog-insert-date) |
79545 | 5619 (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
|
5620 (verilog-insert-date) |
79545 | 5621 (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
|
5622 (verilog-insert-year) |
79545 | 5623 (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
|
5624 (verilog-insert-date) |
79545 | 5625 (insert " : created") |
5626 (goto-char start) | |
5627 (let (string) | |
5628 (setq string (read-string "title: ")) | |
5629 (search-forward "<title>") | |
5630 (replace-match string t t) | |
5631 (setq string (read-string "project: " verilog-project)) | |
5632 (setq verilog-project string) | |
5633 (search-forward "<project>") | |
5634 (replace-match string t t) | |
5635 (setq string (read-string "Company: " verilog-company)) | |
5636 (setq verilog-company string) | |
5637 (search-forward "<company>") | |
5638 (replace-match string t t) | |
5639 (search-forward "<company>") | |
5640 (replace-match string t t) | |
5641 (search-forward "<company>") | |
5642 (replace-match string t t) | |
5643 (search-backward "<description>") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5644 (replace-match "" t t)))) |
79545 | 5645 |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
5646 ;; 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
|
5647 |
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
5648 (defun verilog-insert-date () |
79545 | 5649 "Insert date from the system." |
5650 (interactive) | |
5651 (let ((timpos)) | |
5652 (setq timpos (point)) | |
5653 (if verilog-date-scientific-format | |
5654 (shell-command "date \"+@%Y/%m/%d\"" t) | |
5655 (shell-command "date \"+@%d.%m.%Y\"" t)) | |
5656 (search-forward "@") | |
5657 (delete-region timpos (point)) | |
5658 (end-of-line)) | |
5659 (delete-char 1)) | |
5660 | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
5661 (defun verilog-insert-year () |
79545 | 5662 "Insert year from the system." |
5663 (interactive) | |
5664 (let ((timpos)) | |
5665 (setq timpos (point)) | |
5666 (shell-command "date \"+@%Y\"" t) | |
5667 (search-forward "@") | |
5668 (delete-region timpos (point)) | |
5669 (end-of-line)) | |
5670 (delete-char 1)) | |
5671 | |
5672 | |
5673 ;; | |
5674 ;; Signal list parsing | |
5675 ;; | |
5676 | |
5677 ;; Elements of a signal list | |
5678 (defsubst verilog-sig-name (sig) | |
5679 (car sig)) | |
5680 (defsubst verilog-sig-bits (sig) | |
5681 (nth 1 sig)) | |
5682 (defsubst verilog-sig-comment (sig) | |
5683 (nth 2 sig)) | |
5684 (defsubst verilog-sig-memory (sig) | |
5685 (nth 3 sig)) | |
5686 (defsubst verilog-sig-enum (sig) | |
5687 (nth 4 sig)) | |
5688 (defsubst verilog-sig-signed (sig) | |
5689 (nth 5 sig)) | |
5690 (defsubst verilog-sig-type (sig) | |
5691 (nth 6 sig)) | |
5692 (defsubst verilog-sig-multidim (sig) | |
5693 (nth 7 sig)) | |
5694 (defsubst verilog-sig-multidim-string (sig) | |
5695 (if (verilog-sig-multidim sig) | |
5696 (let ((str "") (args (verilog-sig-multidim sig))) | |
5697 (while args | |
5698 (setq str (concat str (car args))) | |
5699 (setq args (cdr args))) | |
5700 str))) | |
5701 (defsubst verilog-sig-width (sig) | |
5702 (verilog-make-width-expression (verilog-sig-bits sig))) | |
5703 | |
5704 (defsubst verilog-alw-get-inputs (sigs) | |
5705 (nth 2 sigs)) | |
5706 (defsubst verilog-alw-get-outputs (sigs) | |
5707 (nth 0 sigs)) | |
5708 (defsubst verilog-alw-get-uses-delayed (sigs) | |
5709 (nth 3 sigs)) | |
5710 | |
5711 (defun verilog-signals-not-in (in-list not-list) | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5712 "Return list of signals in IN-LIST that aren't also in NOT-LIST. |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
5713 Also remove any duplicates in IN-LIST. |
79545 | 5714 Signals must be in standard (base vector) form." |
5715 (let (out-list) | |
5716 (while in-list | |
5717 (if (not (or (assoc (car (car in-list)) not-list) | |
5718 (assoc (car (car in-list)) out-list))) | |
5719 (setq out-list (cons (car in-list) out-list))) | |
5720 (setq in-list (cdr in-list))) | |
5721 (nreverse out-list))) | |
5722 ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" ""))) | |
5723 | |
5724 (defun verilog-signals-in (in-list other-list) | |
5725 "Return list of signals in IN-LIST that are also in OTHER-LIST. | |
5726 Signals must be in standard (base vector) form." | |
5727 (let (out-list) | |
5728 (while in-list | |
5729 (if (assoc (car (car in-list)) other-list) | |
5730 (setq out-list (cons (car in-list) out-list))) | |
5731 (setq in-list (cdr in-list))) | |
5732 (nreverse out-list))) | |
5733 ;;(verilog-signals-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" ""))) | |
5734 | |
5735 (defun verilog-signals-memory (in-list) | |
5736 "Return list of signals in IN-LIST that are memoried (multidimensional)." | |
5737 (let (out-list) | |
5738 (while in-list | |
5739 (if (nth 3 (car in-list)) | |
5740 (setq out-list (cons (car in-list) out-list))) | |
5741 (setq in-list (cdr in-list))) | |
5742 out-list)) | |
5743 ;;(verilog-signals-memory '(("A" nil nil "[3:0]")) '(("B" nil nil nil))) | |
5744 | |
5745 (defun verilog-signals-sort-compare (a b) | |
5746 "Compare signal A and B for sorting." | |
5747 (string< (car a) (car b))) | |
5748 | |
5749 (defun verilog-signals-not-params (in-list) | |
5750 "Return list of signals in IN-LIST that aren't parameters or numeric constants." | |
5751 (let (out-list) | |
5752 (while in-list | |
5753 (unless (boundp (intern (concat "vh-" (car (car in-list))))) | |
5754 (setq out-list (cons (car in-list) out-list))) | |
5755 (setq in-list (cdr in-list))) | |
5756 (nreverse out-list))) | |
5757 | |
5758 (defun verilog-signals-combine-bus (in-list) | |
5759 "Return a list of signals in IN-LIST, with busses combined. | |
5760 Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]." | |
5761 (let (combo buswarn | |
5762 out-list | |
5763 sig highbit lowbit ; Temp information about current signal | |
5764 sv-name sv-highbit sv-lowbit ; Details about signal we are forming | |
5765 sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring | |
5766 bus) | |
5767 ;; Shove signals so duplicated signals will be adjacent | |
5768 (setq in-list (sort in-list `verilog-signals-sort-compare)) | |
5769 (while in-list | |
5770 (setq sig (car in-list)) | |
5771 ;; No current signal; form from existing details | |
5772 (unless sv-name | |
5773 (setq sv-name (verilog-sig-name sig) | |
5774 sv-highbit nil | |
5775 sv-busstring nil | |
5776 sv-comment (verilog-sig-comment sig) | |
5777 sv-memory (verilog-sig-memory sig) | |
5778 sv-enum (verilog-sig-enum sig) | |
5779 sv-signed (verilog-sig-signed sig) | |
5780 sv-type (verilog-sig-type sig) | |
5781 sv-multidim (verilog-sig-multidim sig) | |
5782 combo "" | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5783 buswarn "")) |
79545 | 5784 ;; Extract bus details |
5785 (setq bus (verilog-sig-bits sig)) | |
5786 (cond ((and bus | |
5787 (or (and (string-match "\\[\\([0-9]+\\):\\([0-9]+\\)\\]" bus) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5788 (setq highbit (string-to-number (match-string 1 bus)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5789 lowbit (string-to-number |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5790 (match-string 2 bus)))) |
79545 | 5791 (and (string-match "\\[\\([0-9]+\\)\\]" bus) |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5792 (setq highbit (string-to-number (match-string 1 bus)) |
79545 | 5793 lowbit highbit)))) |
5794 ;; Combine bits in bus | |
5795 (if sv-highbit | |
5796 (setq sv-highbit (max highbit sv-highbit) | |
5797 sv-lowbit (min lowbit sv-lowbit)) | |
5798 (setq sv-highbit highbit | |
5799 sv-lowbit lowbit))) | |
5800 (bus | |
5801 ;; String, probably something like `preproc:0 | |
5802 (setq sv-busstring bus))) | |
5803 ;; Peek ahead to next signal | |
5804 (setq in-list (cdr in-list)) | |
5805 (setq sig (car in-list)) | |
5806 (cond ((and sig (equal sv-name (verilog-sig-name sig))) | |
5807 ;; Combine with this signal | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5808 (when (and sv-busstring |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5809 (not (equal sv-busstring (verilog-sig-bits sig)))) |
79545 | 5810 (when nil ;; Debugging |
5811 (message (concat "Warning, can't merge into single bus " | |
5812 sv-name bus | |
5813 ", the AUTOs may be wrong"))) | |
5814 (setq buswarn ", Couldn't Merge")) | |
5815 (if (verilog-sig-comment sig) (setq combo ", ...")) | |
5816 (setq sv-memory (or sv-memory (verilog-sig-memory sig)) | |
5817 sv-enum (or sv-enum (verilog-sig-enum sig)) | |
5818 sv-signed (or sv-signed (verilog-sig-signed sig)) | |
5819 sv-type (or sv-type (verilog-sig-type sig)) | |
5820 sv-multidim (or sv-multidim (verilog-sig-multidim sig)))) | |
5821 ;; Doesn't match next signal, add to queue, zero in prep for next | |
5822 ;; Note sig may also be nil for the last signal in the list | |
5823 (t | |
5824 (setq out-list | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5825 (cons |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5826 (list sv-name |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5827 (or sv-busstring |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5828 (if sv-highbit |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5829 (concat "[" (int-to-string sv-highbit) ":" |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5830 (int-to-string sv-lowbit) "]"))) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5831 (concat sv-comment combo buswarn) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5832 sv-memory sv-enum sv-signed sv-type sv-multidim) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5833 out-list) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5834 sv-name nil)))) |
79545 | 5835 ;; |
5836 out-list)) | |
5837 | |
5838 (defun verilog-sig-tieoff (sig &optional no-width) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5839 "Return tieoff expression for given SIG, with appropriate width. |
79545 | 5840 Ignore width if optional NO-WIDTH is set." |
5841 (let* ((width (if no-width nil (verilog-sig-width sig)))) | |
5842 (concat | |
5843 (if (and verilog-active-low-regexp | |
5844 (string-match verilog-active-low-regexp (verilog-sig-name sig))) | |
5845 "~" "") | |
5846 (cond ((not width) | |
5847 "0") | |
5848 ((string-match "^[0-9]+$" width) | |
5849 (concat width (if (verilog-sig-signed sig) "'sh0" "'h0"))) | |
5850 (t | |
5851 (concat "{" width "{1'b0}}")))))) | |
5852 | |
5853 ;; | |
5854 ;; Port/Wire/Etc Reading | |
5855 ;; | |
5856 | |
5857 (defun verilog-read-inst-backward-name () | |
5858 "Internal. Move point back to beginning of inst-name." | |
5859 (verilog-backward-open-paren) | |
5860 (let (done) | |
5861 (while (not done) | |
5862 (verilog-re-search-backward-quick "\\()\\|\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil) ; ] isn't word boundary | |
5863 (cond ((looking-at ")") | |
5864 (verilog-backward-open-paren)) | |
5865 (t (setq done t))))) | |
5866 (while (looking-at "\\]") | |
5867 (verilog-backward-open-bracket) | |
5868 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil)) | |
5869 (skip-chars-backward "a-zA-Z0-9`_$")) | |
5870 | |
5871 (defun verilog-read-inst-module () | |
5872 "Return module_name when point is inside instantiation." | |
5873 (save-excursion | |
5874 (verilog-read-inst-backward-name) | |
5875 ;; Skip over instantiation name | |
5876 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary | |
5877 ;; Check for parameterized instantiations | |
5878 (when (looking-at ")") | |
5879 (verilog-backward-open-paren) | |
5880 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil)) | |
5881 (skip-chars-backward "a-zA-Z0-9'_$") | |
5882 (looking-at "[a-zA-Z0-9`_\$]+") | |
5883 ;; Important: don't use match string, this must work with emacs 19 font-lock on | |
5884 (buffer-substring-no-properties (match-beginning 0) (match-end 0)))) | |
5885 | |
5886 (defun verilog-read-inst-name () | |
5887 "Return instance_name when point is inside instantiation." | |
5888 (save-excursion | |
5889 (verilog-read-inst-backward-name) | |
5890 (looking-at "[a-zA-Z0-9`_\$]+") | |
5891 ;; Important: don't use match string, this must work with emacs 19 font-lock on | |
5892 (buffer-substring-no-properties (match-beginning 0) (match-end 0)))) | |
5893 | |
5894 (defun verilog-read-module-name () | |
5895 "Return module name when after its ( or ;." | |
5896 (save-excursion | |
5897 (re-search-backward "[(;]") | |
5898 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil) | |
5899 (skip-chars-backward "a-zA-Z0-9`_$") | |
5900 (looking-at "[a-zA-Z0-9`_\$]+") | |
5901 ;; Important: don't use match string, this must work with emacs 19 font-lock on | |
5902 (buffer-substring-no-properties (match-beginning 0) (match-end 0)))) | |
5903 | |
5904 (defun verilog-read-auto-params (num-param &optional max-param) | |
5905 "Return parameter list inside auto. | |
5906 Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters." | |
5907 (let ((olist)) | |
5908 (save-excursion | |
5909 ;; /*AUTOPUNT("parameter", "parameter")*/ | |
5910 (search-backward "(") | |
5911 (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?") | |
5912 (setq olist (cons (match-string 1) olist)) | |
5913 (goto-char (match-end 0)))) | |
5914 (or (eq nil num-param) | |
5915 (<= num-param (length olist)) | |
5916 (error "%s: Expected %d parameters" (verilog-point-text) num-param)) | |
5917 (if (eq max-param nil) (setq max-param num-param)) | |
5918 (or (eq nil max-param) | |
5919 (>= max-param (length olist)) | |
5920 (error "%s: Expected <= %d parameters" (verilog-point-text) max-param)) | |
5921 (nreverse olist))) | |
5922 | |
5923 (defun verilog-read-decls () | |
5924 "Compute signal declaration information for the current module at point. | |
5925 Return a array of [outputs inouts inputs wire reg assign const]." | |
5926 (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max))) | |
5927 (functask 0) (paren 0) (sig-paren 0) | |
5928 sigs-in sigs-out sigs-inout sigs-wire sigs-reg sigs-assign sigs-const sigs-gparam | |
5929 vec expect-signal keywd newsig rvalue enum io signed typedefed multidim) | |
5930 (save-excursion | |
5931 (verilog-beg-of-defun) | |
5932 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point)) | |
5933 (while (< (point) end-mod-point) | |
5934 ;;(if dbg (setq dbg (cons (format "Pt %s Vec %s Kwd'%s'\n" (point) vec keywd) dbg))) | |
5935 (cond | |
5936 ((looking-at "//") | |
5937 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") | |
5938 (setq enum (match-string 1))) | |
5939 (search-forward "\n")) | |
5940 ((looking-at "/\\*") | |
5941 (forward-char 2) | |
5942 (if (looking-at "[^*]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") | |
5943 (setq enum (match-string 1))) | |
5944 (or (search-forward "*/") | |
5945 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point)))) | |
5946 ((looking-at "(\\*") | |
5947 (forward-char 2) | |
5948 (or (looking-at "\\s-*)") ; It's a "always @ (*)" | |
5949 (search-forward "*)") | |
5950 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point)))) | |
5951 ((eq ?\" (following-char)) | |
5952 (or (re-search-forward "[^\\]\"" nil t) ;; don't forward-char first, since we look for a non backslash first | |
5953 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point)))) | |
5954 ((eq ?\; (following-char)) | |
5955 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil) | |
5956 (forward-char 1)) | |
5957 ((eq ?= (following-char)) | |
5958 (setq rvalue t newsig nil) | |
5959 (forward-char 1)) | |
5960 ((and (or rvalue sig-paren) | |
5961 (cond ((and (eq ?, (following-char)) | |
5962 (eq paren sig-paren)) | |
5963 (setq rvalue nil) | |
5964 (forward-char 1) | |
5965 t) | |
5966 ;; ,'s can occur inside {} & funcs | |
5967 ((looking-at "[{(]") | |
5968 (setq paren (1+ paren)) | |
5969 (forward-char 1) | |
5970 t) | |
5971 ((looking-at "[})]") | |
5972 (setq paren (1- paren)) | |
5973 (forward-char 1) | |
5974 (when (< paren sig-paren) | |
5975 (setq expect-signal nil)) ; ) that ends variables inside v2k arg list | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5976 t)))) |
79545 | 5977 ((looking-at "\\s-*\\(\\[[^]]+\\]\\)") |
5978 (goto-char (match-end 0)) | |
5979 (cond (newsig ; Memory, not just width. Patch last signal added's memory (nth 3) | |
5980 (setcar (cdr (cdr (cdr newsig))) (match-string 1))) | |
5981 (vec ;; Multidimensional | |
5982 (setq multidim (cons vec multidim)) | |
5983 (setq vec (verilog-string-replace-matches | |
5984 "\\s-+" "" nil nil (match-string 1)))) | |
5985 (t ;; Bit width | |
5986 (setq vec (verilog-string-replace-matches | |
5987 "\\s-+" "" nil nil (match-string 1)))))) | |
5988 ;; Normal or escaped identifier -- note we remember the \ if escaped | |
5989 ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)") | |
5990 (goto-char (match-end 0)) | |
5991 (setq keywd (match-string 1)) | |
5992 (when (string-match "^\\\\" keywd) | |
5993 (setq keywd (concat keywd " "))) ;; Escaped ID needs space at end | |
5994 (cond ((equal keywd "input") | |
5995 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren | |
5996 expect-signal 'sigs-in io t)) | |
5997 ((equal keywd "output") | |
5998 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren | |
5999 expect-signal 'sigs-out io t)) | |
6000 ((equal keywd "inout") | |
6001 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren | |
6002 expect-signal 'sigs-inout io t)) | |
6003 ((or (equal keywd "wire") | |
6004 (equal keywd "tri") | |
6005 (equal keywd "tri0") | |
6006 (equal keywd "tri1")) | |
6007 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren | |
6008 expect-signal 'sigs-wire))) | |
6009 ((or (equal keywd "reg") | |
6010 (equal keywd "trireg")) | |
6011 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren | |
6012 expect-signal 'sigs-reg))) | |
6013 ((equal keywd "assign") | |
6014 (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren | |
6015 expect-signal 'sigs-assign)) | |
6016 ((or (equal keywd "supply0") | |
6017 (equal keywd "supply1") | |
6018 (equal keywd "supply") | |
6019 (equal keywd "localparam")) | |
6020 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren | |
6021 expect-signal 'sigs-const))) | |
6022 ((or (equal keywd "parameter")) | |
6023 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren | |
6024 expect-signal 'sigs-gparam))) | |
6025 ((equal keywd "signed") | |
6026 (setq signed "signed")) | |
6027 ((or (equal keywd "function") | |
6028 (equal keywd "task")) | |
6029 (setq functask (1+ functask))) | |
6030 ((or (equal keywd "endfunction") | |
6031 (equal keywd "endtask")) | |
6032 (setq functask (1- functask))) | |
6033 ((or (equal keywd "`ifdef") | |
6034 (equal keywd "`ifndef")) | |
6035 (setq rvalue t)) | |
6036 ((verilog-typedef-name-p keywd) | |
6037 (setq typedefed keywd)) | |
6038 ((and expect-signal | |
6039 (eq functask 0) | |
6040 (not rvalue) | |
6041 (eq paren sig-paren) | |
6042 (not (member keywd verilog-keywords))) | |
6043 ;; Add new signal to expect-signal's variable | |
6044 (setq newsig (list keywd vec nil nil enum signed typedefed multidim)) | |
6045 (set expect-signal (cons newsig | |
6046 (symbol-value expect-signal)))))) | |
6047 (t | |
6048 (forward-char 1))) | |
6049 (skip-syntax-forward " ")) | |
6050 ;; Return arguments | |
6051 (vector (nreverse sigs-out) | |
6052 (nreverse sigs-inout) | |
6053 (nreverse sigs-in) | |
6054 (nreverse sigs-wire) | |
6055 (nreverse sigs-reg) | |
6056 (nreverse sigs-assign) | |
6057 (nreverse sigs-const) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6058 (nreverse sigs-gparam))))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6059 |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6060 (eval-when-compile |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6061 ;; Prevent compile warnings; these are let's, not globals |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6062 ;; Do not remove the eval-when-compile |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6063 ;; - we want a error when we are debugging this code if they are refed. |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6064 (defvar sigs-in) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6065 (defvar sigs-inout) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6066 (defvar sigs-out)) |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6067 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6068 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6069 (defsubst verilog-modi-get-decls (modi) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6070 (verilog-modi-cache-results modi 'verilog-read-decls)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6071 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6072 (defsubst verilog-modi-get-sub-decls (modi) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6073 (verilog-modi-cache-results modi 'verilog-read-sub-decls)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6074 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6075 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6076 ;; Signal reading for given module |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6077 ;; Note these all take modi's - as returned from the |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6078 ;; verilog-modi-current function. |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6079 (defsubst verilog-modi-get-outputs (modi) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6080 (aref (verilog-modi-get-decls modi) 0)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6081 (defsubst verilog-modi-get-inouts (modi) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6082 (aref (verilog-modi-get-decls modi) 1)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6083 (defsubst verilog-modi-get-inputs (modi) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6084 (aref (verilog-modi-get-decls modi) 2)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6085 (defsubst verilog-modi-get-wires (modi) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6086 (aref (verilog-modi-get-decls modi) 3)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6087 (defsubst verilog-modi-get-regs (modi) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6088 (aref (verilog-modi-get-decls modi) 4)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6089 (defsubst verilog-modi-get-assigns (modi) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6090 (aref (verilog-modi-get-decls modi) 5)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6091 (defsubst verilog-modi-get-consts (modi) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6092 (aref (verilog-modi-get-decls modi) 6)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6093 (defsubst verilog-modi-get-gparams (modi) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6094 (aref (verilog-modi-get-decls modi) 7)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6095 (defsubst verilog-modi-get-sub-outputs (modi) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6096 (aref (verilog-modi-get-sub-decls modi) 0)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6097 (defsubst verilog-modi-get-sub-inouts (modi) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6098 (aref (verilog-modi-get-sub-decls modi) 1)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6099 (defsubst verilog-modi-get-sub-inputs (modi) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6100 (aref (verilog-modi-get-sub-decls modi) 2)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6101 |
79545 | 6102 |
6103 (defun verilog-read-sub-decls-sig (submodi comment port sig vec multidim) | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
6104 "For `verilog-read-sub-decls-line', add a signal." |
79545 | 6105 (let (portdata) |
6106 (when sig | |
6107 (setq port (verilog-symbol-detick-denumber port)) | |
6108 (setq sig (verilog-symbol-detick-denumber sig)) | |
6109 (if sig (setq sig (verilog-string-replace-matches "^[---+~!|&]+" "" nil nil sig))) | |
6110 (if vec (setq vec (verilog-symbol-detick-denumber vec))) | |
6111 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim))) | |
6112 (unless (or (not sig) | |
6113 (equal sig "")) ;; Ignore .foo(1'b1) assignments | |
6114 (cond ((setq portdata (assoc port (verilog-modi-get-inouts submodi))) | |
6115 (setq sigs-inout (cons (list sig vec (concat "To/From " comment) nil nil | |
6116 (verilog-sig-signed portdata) | |
6117 (verilog-sig-type portdata) | |
6118 multidim) | |
6119 sigs-inout))) | |
6120 ((setq portdata (assoc port (verilog-modi-get-outputs submodi))) | |
6121 (setq sigs-out (cons (list sig vec (concat "From " comment) nil nil | |
6122 (verilog-sig-signed portdata) | |
6123 (verilog-sig-type portdata) | |
6124 multidim) | |
6125 sigs-out))) | |
6126 ((setq portdata (assoc port (verilog-modi-get-inputs submodi))) | |
6127 (setq sigs-in (cons (list sig vec (concat "To " comment) nil nil | |
6128 (verilog-sig-signed portdata) | |
6129 (verilog-sig-type portdata) | |
6130 multidim) | |
6131 sigs-in))) | |
6132 ;; (t -- warning pin isn't defined.) ; Leave for lint tool | |
6133 ))))) | |
6134 | |
6135 (defun verilog-read-sub-decls-line (submodi comment) | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
6136 "For `verilog-read-sub-decls', read lines of port defs until none match anymore. |
79545 | 6137 Return the list of signals found, using submodi to look up each port." |
6138 (let (done port sig vec multidim) | |
6139 (save-excursion | |
6140 (forward-line 1) | |
6141 (while (not done) | |
6142 ;; Get port name | |
6143 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*") | |
6144 (setq port (match-string 1)) | |
6145 (goto-char (match-end 0))) | |
6146 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*") | |
6147 (setq port (concat (match-string 1) " ")) ;; escaped id's need trailing space | |
6148 (goto-char (match-end 0))) | |
6149 ((looking-at "\\s-*\\.[^(]*(") | |
6150 (setq port nil) ;; skip this line | |
6151 (goto-char (match-end 0))) | |
6152 (t | |
6153 (setq port nil done t))) ;; Unknown, ignore rest of line | |
6154 ;; Get signal name | |
6155 (when port | |
6156 (setq multidim nil) | |
6157 (cond ((looking-at "\\(\\\\[^ \t\n\f]*\\)\\s-*)") | |
6158 (setq sig (concat (match-string 1) " ") ;; escaped id's need trailing space | |
6159 vec nil)) | |
6160 ; We intentionally ignore (non-escaped) signals with .s in them | |
6161 ; this prevents AUTOWIRE etc from noticing hierarchical sigs. | |
6162 ((looking-at "\\([^[({).]*\\)\\s-*)") | |
6163 (setq sig (verilog-string-remove-spaces (match-string 1)) | |
6164 vec nil)) | |
6165 ((looking-at "\\([^[({).]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)") | |
6166 (setq sig (verilog-string-remove-spaces (match-string 1)) | |
6167 vec (match-string 2))) | |
6168 ((looking-at "\\([^[({).]*\\)\\s-*/\\*\\(\\[[^*]+\\]\\)\\*/\\s-*)") | |
6169 (setq sig (verilog-string-remove-spaces (match-string 1)) | |
6170 vec nil) | |
6171 (let ((parse (match-string 2))) | |
6172 (while (string-match "^\\(\\[[^]]+\\]\\)\\(.*\\)$" parse) | |
6173 (when vec (setq multidim (cons vec multidim))) | |
6174 (setq vec (match-string 1 parse)) | |
6175 (setq parse (match-string 2 parse))))) | |
6176 ((looking-at "{\\(.*\\)}.*\\s-*)") | |
6177 (let ((mlst (split-string (match-string 1) ",")) | |
6178 mstr) | |
6179 (while (setq mstr (pop mlst)) | |
6180 ;;(unless noninteractive (message "sig: %s " mstr)) | |
6181 (cond | |
6182 ((string-match "\\(['`a-zA-Z0-9_$]+\\)\\s-*$" mstr) | |
6183 (setq sig (verilog-string-remove-spaces (match-string 1 mstr)) | |
6184 vec nil) | |
6185 ;;(unless noninteractive (message "concat sig1: %s %s" mstr (match-string 1 mstr))) | |
6186 ) | |
6187 ((string-match "\\([^[({).]+\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*" mstr) | |
6188 (setq sig (verilog-string-remove-spaces (match-string 1 mstr)) | |
6189 vec (match-string 2 mstr)) | |
6190 ;;(unless noninteractive (message "concat sig2: '%s' '%s' '%s'" mstr (match-string 1 mstr) (match-string 2 mstr))) | |
6191 ) | |
6192 (t | |
6193 (setq sig nil))) | |
6194 ;; Process signals | |
6195 (verilog-read-sub-decls-sig submodi comment port sig vec multidim)))) | |
6196 (t | |
6197 (setq sig nil))) | |
6198 ;; Process signals | |
6199 (verilog-read-sub-decls-sig submodi comment port sig vec multidim)) | |
6200 ;; | |
6201 (forward-line 1))))) | |
6202 | |
6203 (defun verilog-read-sub-decls () | |
6204 "Internally parse signals going to modules under this module. | |
6205 Return a array of [ outputs inouts inputs ] signals for modules that are | |
6206 instantiated in this module. For example if declare A A (.B(SIG)) and SIG | |
6207 is a output, then SIG will be included in the list. | |
6208 | |
6209 This only works on instantiations created with /*AUTOINST*/ converted by | |
6210 \\[verilog-auto-inst]. Otherwise, it would have to read in the whole | |
6211 component library to determine connectivity of the design. | |
6212 | |
6213 One work around for this problem is to manually create // Inputs and // | |
6214 Outputs comments above subcell signals, for example: | |
6215 | |
6216 module1 instance1x ( | |
6217 // Outputs | |
6218 .out (out), | |
6219 // Inputs | |
6220 .in (in));" | |
6221 (save-excursion | |
6222 (let ((end-mod-point (verilog-get-end-of-defun t)) | |
6223 st-point end-inst-point | |
6224 ;; below 3 modified by verilog-read-sub-decls-line | |
6225 sigs-out sigs-inout sigs-in) | |
6226 (verilog-beg-of-defun) | |
6227 (while (re-search-forward "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t) | |
6228 (save-excursion | |
6229 (goto-char (match-beginning 0)) | |
6230 (unless (verilog-inside-comment-p) | |
6231 ;; Attempt to snarf a comment | |
6232 (let* ((submod (verilog-read-inst-module)) | |
6233 (inst (verilog-read-inst-name)) | |
6234 (comment (concat inst " of " submod ".v")) submodi) | |
6235 (when (setq submodi (verilog-modi-lookup submod t)) | |
6236 ;; This could have used a list created by verilog-auto-inst | |
6237 ;; However I want it to be runnable even on user's manually added signals | |
6238 (verilog-backward-open-paren) | |
6239 (setq end-inst-point (save-excursion (forward-sexp 1) (point)) | |
6240 st-point (point)) | |
6241 (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t) | |
6242 (verilog-read-sub-decls-line submodi comment)) ;; Modifies sigs-out | |
6243 (goto-char st-point) | |
6244 (while (re-search-forward "\\s *// Inouts" end-inst-point t) | |
6245 (verilog-read-sub-decls-line submodi comment)) ;; Modifies sigs-inout | |
6246 (goto-char st-point) | |
6247 (while (re-search-forward "\\s *// Inputs" end-inst-point t) | |
6248 (verilog-read-sub-decls-line submodi comment)) ;; Modifies sigs-in | |
6249 ))))) | |
6250 ;; Combine duplicate bits | |
6251 ;;(setq rr (vector sigs-out sigs-inout sigs-in)) | |
6252 (vector (verilog-signals-combine-bus (nreverse sigs-out)) | |
6253 (verilog-signals-combine-bus (nreverse sigs-inout)) | |
6254 (verilog-signals-combine-bus (nreverse sigs-in)))))) | |
6255 | |
6256 (defun verilog-read-inst-pins () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
6257 "Return an array of [ pins ] for the current instantiation at point. |
79545 | 6258 For example if declare A A (.B(SIG)) then B will be included in the list." |
6259 (save-excursion | |
6260 (let ((end-mod-point (point)) ;; presume at /*AUTOINST*/ point | |
6261 pins pin) | |
6262 (verilog-backward-open-paren) | |
6263 (while (re-search-forward "\\.\\([^(,) \t\n\f]*\\)\\s-*" end-mod-point t) | |
6264 (setq pin (match-string 1)) | |
6265 (unless (verilog-inside-comment-p) | |
6266 (setq pins (cons (list pin) pins)) | |
6267 (when (looking-at "(") | |
6268 (forward-sexp 1)))) | |
6269 (vector pins)))) | |
6270 | |
6271 (defun verilog-read-arg-pins () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
6272 "Return an array of [ pins ] for the current argument declaration at point." |
79545 | 6273 (save-excursion |
6274 (let ((end-mod-point (point)) ;; presume at /*AUTOARG*/ point | |
6275 pins pin) | |
6276 (verilog-backward-open-paren) | |
6277 (while (re-search-forward "\\([a-zA-Z0-9$_.%`]+\\)" end-mod-point t) | |
6278 (setq pin (match-string 1)) | |
6279 (unless (verilog-inside-comment-p) | |
6280 (setq pins (cons (list pin) pins)))) | |
6281 (vector pins)))) | |
6282 | |
6283 (defun verilog-read-auto-constants (beg end-mod-point) | |
6284 "Return a list of AUTO_CONSTANTs used in the region from BEG to END-MOD-POINT." | |
6285 ;; Insert new | |
6286 (save-excursion | |
6287 (let (sig-list tpl-end-pt) | |
6288 (goto-char beg) | |
6289 (while (re-search-forward "\\<AUTO_CONSTANT" end-mod-point t) | |
6290 (if (not (looking-at "\\s *(")) | |
6291 (error "%s: Missing () after AUTO_CONSTANT" (verilog-point-text))) | |
6292 (search-forward "(" end-mod-point) | |
6293 (setq tpl-end-pt (save-excursion | |
6294 (backward-char 1) | |
6295 (forward-sexp 1) ;; Moves to paren that closes argdecl's | |
6296 (backward-char 1) | |
6297 (point))) | |
6298 (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t) | |
6299 (setq sig-list (cons (list (match-string 1) nil nil) sig-list)))) | |
6300 sig-list))) | |
6301 | |
6302 (defun verilog-read-auto-lisp (start end) | |
6303 "Look for and evaluate a AUTO_LISP between START and END." | |
6304 (save-excursion | |
6305 (goto-char start) | |
6306 (while (re-search-forward "\\<AUTO_LISP(" end t) | |
6307 (backward-char) | |
6308 (let* ((beg-pt (prog1 (point) | |
6309 (forward-sexp 1))) ;; Closing paren | |
6310 (end-pt (point))) | |
6311 (eval-region beg-pt end-pt nil))))) | |
6312 | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6313 (eval-when-compile |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6314 ;; Prevent compile warnings; these are let's, not globals |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6315 ;; Do not remove the eval-when-compile |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6316 ;; - we want a error when we are debugging this code if they are refed. |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6317 (defvar sigs-in) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6318 (defvar sigs-out) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6319 (defvar got-sig) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6320 (defvar got-rvalue) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6321 (defvar uses-delayed) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6322 (defvar vector-skip-list)) |
79545 | 6323 |
6324 (defun verilog-read-always-signals-recurse | |
6325 (exit-keywd rvalue ignore-next) | |
6326 "Recursive routine for parentheses/bracket matching. | |
6327 EXIT-KEYWD is expression to stop at, nil if top level. | |
6328 RVALUE is true if at right hand side of equal. | |
6329 IGNORE-NEXT is true to ignore next token, fake from inside case statement." | |
6330 (let* ((semi-rvalue (equal "endcase" exit-keywd)) ;; true if after a ; we are looking for rvalue | |
6331 keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-rvalue end-else-check) | |
6332 ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue ignore-next)))) | |
6333 (while (not (or (eobp) gotend)) | |
6334 (cond | |
6335 ((looking-at "//") | |
6336 (search-forward "\n")) | |
6337 ((looking-at "/\\*") | |
6338 (or (search-forward "*/") | |
6339 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point)))) | |
6340 ((looking-at "(\\*") | |
6341 (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)" | |
6342 (search-forward "*)") | |
6343 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point)))) | |
6344 (t (setq keywd (buffer-substring-no-properties | |
6345 (point) | |
6346 (save-excursion (when (eq 0 (skip-chars-forward "a-zA-Z0-9$_.%`")) | |
6347 (forward-char 1)) | |
6348 (point))) | |
6349 sig-last-tolk sig-tolk | |
6350 sig-tolk nil) | |
6351 ;;(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)))) | |
6352 (cond | |
6353 ((equal keywd "\"") | |
6354 (or (re-search-forward "[^\\]\"" nil t) | |
6355 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point)))) | |
6356 ;; else at top level loop, keep parsing | |
6357 ((and end-else-check (equal keywd "else")) | |
6358 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else %s\n" keywd)))) | |
6359 ;; no forward movement, want to see else in lower loop | |
6360 (setq end-else-check nil)) | |
6361 ;; End at top level loop | |
6362 ((and end-else-check (looking-at "[^ \t\n\f]")) | |
6363 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else-other %s\n" keywd)))) | |
6364 (setq gotend t)) | |
6365 ;; Final statement? | |
6366 ((and exit-keywd (equal keywd exit-keywd)) | |
6367 (setq gotend t) | |
6368 (forward-char (length keywd))) | |
6369 ;; Standard tokens... | |
6370 ((equal keywd ";") | |
6371 (setq ignore-next nil rvalue semi-rvalue) | |
6372 ;; Final statement at top level loop? | |
6373 (when (not exit-keywd) | |
6374 ;;(if dbg (setq dbg (concat dbg (format "\ttop-end-check %s\n" keywd)))) | |
6375 (setq end-else-check t)) | |
6376 (forward-char 1)) | |
6377 ((equal keywd "'") | |
6378 (if (looking-at "'s?[hdxbo][0-9a-fA-F_xz? \t]*") | |
6379 (goto-char (match-end 0)) | |
6380 (forward-char 1))) | |
6381 ((equal keywd ":") ;; Case statement, begin/end label, x?y:z | |
6382 (cond ((equal "endcase" exit-keywd) ;; case x: y=z; statement next | |
6383 (setq ignore-next nil rvalue nil)) | |
6384 ((equal "?" exit-keywd) ;; x?y:z rvalue | |
6385 ) ;; NOP | |
6386 (got-sig ;; label: statement | |
6387 (setq ignore-next nil rvalue semi-rvalue got-sig nil)) | |
6388 ((not rvalue) ;; begin label | |
6389 (setq ignore-next t rvalue nil))) | |
6390 (forward-char 1)) | |
6391 ((equal keywd "=") | |
6392 (if (eq (char-before) ?< ) | |
6393 (setq uses-delayed 1)) | |
6394 (setq ignore-next nil rvalue t) | |
6395 (forward-char 1)) | |
6396 ((equal keywd "?") | |
6397 (forward-char 1) | |
6398 (verilog-read-always-signals-recurse ":" rvalue nil)) | |
6399 ((equal keywd "[") | |
6400 (forward-char 1) | |
6401 (verilog-read-always-signals-recurse "]" t nil)) | |
6402 ((equal keywd "(") | |
6403 (forward-char 1) | |
6404 (cond (sig-last-tolk ;; Function call; zap last signal | |
6405 (setq got-sig nil))) | |
6406 (cond ((equal last-keywd "for") | |
6407 (verilog-read-always-signals-recurse ";" nil nil) | |
6408 (verilog-read-always-signals-recurse ";" t nil) | |
6409 (verilog-read-always-signals-recurse ")" nil nil)) | |
6410 (t (verilog-read-always-signals-recurse ")" t nil)))) | |
6411 ((equal keywd "begin") | |
6412 (skip-syntax-forward "w_") | |
6413 (verilog-read-always-signals-recurse "end" nil nil) | |
6414 ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd)))) | |
6415 (setq ignore-next nil rvalue semi-rvalue) | |
6416 (if (not exit-keywd) (setq end-else-check t))) | |
6417 ((or (equal keywd "case") | |
6418 (equal keywd "casex") | |
6419 (equal keywd "casez")) | |
6420 (skip-syntax-forward "w_") | |
6421 (verilog-read-always-signals-recurse "endcase" t nil) | |
6422 (setq ignore-next nil rvalue semi-rvalue) | |
6423 (if (not exit-keywd) (setq gotend t))) ;; top level begin/end | |
6424 ((string-match "^[$`a-zA-Z_]" keywd) ;; not exactly word constituent | |
6425 (cond ((or (equal keywd "`ifdef") | |
6426 (equal keywd "`ifndef")) | |
6427 (setq ignore-next t)) | |
6428 ((or ignore-next | |
6429 (member keywd verilog-keywords) | |
6430 (string-match "^\\$" keywd)) ;; PLI task | |
6431 (setq ignore-next nil)) | |
6432 (t | |
6433 (setq keywd (verilog-symbol-detick-denumber keywd)) | |
6434 (when got-sig | |
6435 (if got-rvalue (setq sigs-in (cons got-sig sigs-in)) | |
6436 (setq sigs-out (cons got-sig sigs-out))) | |
6437 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S rv=%S\n" got-sig got-rvalue)))) | |
6438 ) | |
6439 (setq got-rvalue rvalue | |
6440 got-sig (if (or (not keywd) | |
6441 (assoc keywd (if got-rvalue sigs-in sigs-out))) | |
6442 nil (list keywd nil nil)) | |
6443 sig-tolk t))) | |
6444 (skip-chars-forward "a-zA-Z0-9$_.%`")) | |
6445 (t | |
6446 (forward-char 1))) | |
6447 ;; End of non-comment token | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6448 (setq last-keywd keywd))) |
79545 | 6449 (skip-syntax-forward " ")) |
6450 ;; Append the final pending signal | |
6451 (when got-sig | |
6452 (if got-rvalue (setq sigs-in (cons got-sig sigs-in)) | |
6453 (setq sigs-out (cons got-sig sigs-out))) | |
6454 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S rv=%S\n" got-sig got-rvalue)))) | |
6455 (setq got-sig nil)) | |
6456 ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd)))) | |
6457 )) | |
6458 | |
6459 (defun verilog-read-always-signals () | |
6460 "Parse always block at point and return list of (outputs inout inputs)." | |
6461 ;; Insert new | |
6462 (save-excursion | |
6463 (let* (;;(dbg "") | |
6464 sigs-in sigs-out | |
6465 uses-delayed) ;; Found signal/rvalue; push if not function | |
6466 (search-forward ")") | |
6467 (verilog-read-always-signals-recurse nil nil nil) | |
6468 ;;(if dbg (save-excursion (set-buffer (get-buffer-create "*vl-dbg*")) (delete-region (point-min) (point-max)) (insert dbg) (setq dbg ""))) | |
6469 ;; Return what was found | |
6470 (list sigs-out nil sigs-in uses-delayed)))) | |
6471 | |
6472 (defun verilog-read-instants () | |
6473 "Parse module at point and return list of ( ( file instance ) ... )." | |
6474 (verilog-beg-of-defun) | |
6475 (let* ((end-mod-point (verilog-get-end-of-defun t)) | |
6476 (state nil) | |
6477 (instants-list nil)) | |
6478 (save-excursion | |
6479 (while (< (point) end-mod-point) | |
6480 ;; Stay at level 0, no comments | |
6481 (while (progn | |
6482 (setq state (parse-partial-sexp (point) end-mod-point 0 t nil)) | |
6483 (or (> (car state) 0) ; in parens | |
6484 (nth 5 state) ; comment | |
6485 )) | |
6486 (forward-line 1)) | |
6487 (beginning-of-line) | |
6488 (if (looking-at "^\\s-*\\([a-zA-Z0-9`_$]+\\)\\s-+\\([a-zA-Z0-9`_$]+\\)\\s-*(") | |
6489 ;;(if (looking-at "^\\(.+\\)$") | |
6490 (let ((module (match-string 1)) | |
6491 (instant (match-string 2))) | |
6492 (if (not (member module verilog-keywords)) | |
6493 (setq instants-list (cons (list module instant) instants-list))))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6494 (forward-line 1))) |
79545 | 6495 instants-list)) |
6496 | |
6497 | |
6498 (defun verilog-read-auto-template (module) | |
6499 "Look for a auto_template for the instantiation of the given MODULE. | |
6500 If found returns the signal name connections. Return REGEXP and | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
6501 list of ( (signal_name connection_name)... )." |
79545 | 6502 (save-excursion |
6503 ;; Find beginning | |
6504 (let ((tpl-regexp "\\([0-9]+\\)") | |
6505 (lineno 0) | |
6506 (templateno 0) | |
6507 tpl-sig-list tpl-wild-list tpl-end-pt rep) | |
6508 (cond ((or | |
6509 (re-search-backward (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t) | |
6510 (progn | |
6511 (goto-char (point-min)) | |
6512 (re-search-forward (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t))) | |
6513 (goto-char (match-end 0)) | |
6514 ;; Parse "REGEXP" | |
6515 ;; We reserve @"..." for future lisp expressions that evaluate once-per-AUTOINST | |
6516 (when (looking-at "\\s-*\"\\([^\"]*)\\)\"") | |
6517 (setq tpl-regexp (match-string 1)) | |
6518 (goto-char (match-end 0))) | |
6519 (search-forward "(") | |
6520 ;; Parse lines in the template | |
6521 (when verilog-auto-inst-template-numbers | |
6522 (save-excursion | |
6523 (goto-char (point-min)) | |
6524 (while (search-forward "AUTO_TEMPLATE" nil t) | |
6525 (setq templateno (1+ templateno))))) | |
6526 (setq tpl-end-pt (save-excursion | |
6527 (backward-char 1) | |
6528 (forward-sexp 1) ;; Moves to paren that closes argdecl's | |
6529 (backward-char 1) | |
6530 (point))) | |
6531 ;; | |
6532 (while (< (point) tpl-end-pt) | |
6533 (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)") | |
6534 (setq tpl-sig-list (cons (list | |
6535 (match-string-no-properties 1) | |
6536 (match-string-no-properties 2) | |
6537 templateno lineno) | |
6538 tpl-sig-list)) | |
6539 (goto-char (match-end 0))) | |
6540 ;; Regexp form?? | |
6541 ((looking-at | |
6542 ;; Regexp bug in xemacs disallows ][ inside [], and wants + last | |
6543 "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]+\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)") | |
6544 (setq rep (match-string-no-properties 3)) | |
6545 (goto-char (match-end 0)) | |
6546 (setq tpl-wild-list | |
6547 (cons (list | |
6548 (concat "^" | |
6549 (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil | |
6550 (match-string 1)) | |
6551 "$") | |
6552 rep | |
6553 templateno lineno) | |
6554 tpl-wild-list))) | |
6555 ((looking-at "[ \t\f]+") | |
6556 (goto-char (match-end 0))) | |
6557 ((looking-at "\n") | |
6558 (setq lineno (1+ lineno)) | |
6559 (goto-char (match-end 0))) | |
6560 ((looking-at "//") | |
6561 (search-forward "\n")) | |
6562 ((looking-at "/\\*") | |
6563 (forward-char 2) | |
6564 (or (search-forward "*/") | |
6565 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point)))) | |
6566 (t | |
6567 (error "%s: AUTO_TEMPLATE parsing error: %s" | |
6568 (verilog-point-text) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6569 (progn (looking-at ".*$") (match-string 0)))))) |
79545 | 6570 ;; Return |
6571 (vector tpl-regexp | |
6572 (list tpl-sig-list tpl-wild-list))) | |
6573 ;; If no template found | |
6574 (t (vector tpl-regexp nil)))))) | |
6575 ;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry")) | |
6576 | |
6577 (defun verilog-set-define (defname defvalue &optional buffer enumname) | |
6578 "Set the definition DEFNAME to the DEFVALUE in the given BUFFER. | |
6579 Optionally associate it with the specified enumeration ENUMNAME." | |
6580 (save-excursion | |
6581 (set-buffer (or buffer (current-buffer))) | |
6582 (let ((mac (intern (concat "vh-" defname)))) | |
6583 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1) | |
6584 ;; Need to define to a constant if no value given | |
6585 (set (make-variable-buffer-local mac) | |
6586 (if (equal defvalue "") "1" defvalue))) | |
6587 (if enumname | |
6588 (let ((enumvar (intern (concat "venum-" enumname)))) | |
6589 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1) | |
6590 (make-variable-buffer-local enumvar) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6591 (add-to-list enumvar defname))))) |
79545 | 6592 |
6593 (defun verilog-read-defines (&optional filename recurse subcall) | |
6594 "Read `defines and parameters for the current file, or optional FILENAME. | |
6595 If the filename is provided, `verilog-library-flags' will be used to | |
6596 resolve it. If optional RECURSE is non-nil, recurse through `includes. | |
6597 | |
6598 Parameters must be simple assignments to constants, or have their own | |
6599 \"parameter\" label rather than a list of parameters. Thus: | |
6600 | |
6601 parameter X = 5, Y = 10; // Ok | |
6602 parameter X = {1'b1, 2'h2}; // Ok | |
6603 parameter X = {1'b1, 2'h2}, Y = 10; // Bad, make into 2 parameter lines | |
6604 | |
6605 Defines must be simple text substitutions, one on a line, starting | |
6606 at the beginning of the line. Any ifdefs or multiline comments around the | |
6607 define are ignored. | |
6608 | |
6609 Defines are stored inside Emacs variables using the name vh-{definename}. | |
6610 | |
6611 This function is useful for setting vh-* variables. The file variables | |
6612 feature can be used to set defines that `verilog-mode' can see; put at the | |
6613 *END* of your file something like: | |
6614 | |
6615 // Local Variables: | |
6616 // vh-macro:\"macro_definition\" | |
6617 // End: | |
6618 | |
6619 If macros are defined earlier in the same file and you want their values, | |
6620 you can read them automatically (provided `enable-local-eval' is on): | |
6621 | |
6622 // Local Variables: | |
6623 // eval:(verilog-read-defines) | |
6624 // eval:(verilog-read-defines \"group_standard_includes.v\") | |
6625 // End: | |
6626 | |
6627 Note these are only read when the file is first visited, you must use | |
6628 \\[find-alternate-file] RET to have these take effect after editing them! | |
6629 | |
6630 If you want to disable the \"Process `eval' or hook local variables\" | |
6631 warning message, you need to add to your .emacs file: | |
6632 | |
6633 (setq enable-local-eval t)" | |
6634 (let ((origbuf (current-buffer))) | |
6635 (save-excursion | |
6636 (unless subcall (verilog-getopt-flags)) | |
6637 (when filename | |
6638 (let ((fns (verilog-library-filenames filename (buffer-file-name)))) | |
6639 (if fns | |
6640 (set-buffer (find-file-noselect (car fns))) | |
6641 (error (concat (verilog-point-text) | |
6642 ": Can't find verilog-read-defines file: " filename))))) | |
6643 (when recurse | |
6644 (goto-char (point-min)) | |
6645 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t) | |
6646 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string-no-properties 1)))) | |
6647 (unless (verilog-inside-comment-p) | |
6648 (verilog-read-defines inc recurse t))))) | |
6649 ;; Read `defines | |
6650 ;; note we don't use verilog-re... it's faster this way, and that | |
6651 ;; function has problems when comments are at the end of the define | |
6652 (goto-char (point-min)) | |
6653 (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t) | |
6654 (let ((defname (match-string-no-properties 1)) | |
6655 (defvalue (match-string-no-properties 2))) | |
6656 (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue)) | |
6657 (verilog-set-define defname defvalue origbuf))) | |
6658 ;; Hack: Read parameters | |
6659 (goto-char (point-min)) | |
6660 (while (re-search-forward | |
6661 "^\\s-*\\(parameter\\|localparam\\)\\(\\(\\s-*\\[[^]]*\\]\\|\\)\\s-+\\([a-zA-Z0-9_$]+\\)\\s-*=\\s-*\\([^;,]*\\),?\\|\\)\\s-*" nil t) | |
6662 (let ((var (match-string-no-properties 4)) | |
6663 (val (match-string-no-properties 5)) | |
6664 enumname) | |
6665 ;; The primary way of getting defines is verilog-read-decls | |
6666 ;; However, that isn't called yet for included files, so we'll add another scheme | |
6667 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") | |
6668 (setq enumname (match-string-no-properties 1))) | |
6669 (if var | |
6670 (verilog-set-define var val origbuf enumname)) | |
6671 (forward-comment 999) | |
6672 (while (looking-at "\\s-*,?\\s-*\\([a-zA-Z0-9_$]+\\)\\s-*=\\s-*\\([^;,]*\\),?\\s-*") | |
6673 (verilog-set-define (match-string-no-properties 1) (match-string-no-properties 2) origbuf enumname) | |
6674 (goto-char (match-end 0)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6675 (forward-comment 999))))))) |
79545 | 6676 |
6677 (defun verilog-read-includes () | |
6678 "Read `includes for the current file. | |
6679 This will find all of the `includes which are at the beginning of lines, | |
6680 ignoring any ifdefs or multiline comments around them. | |
6681 `verilog-read-defines' is then performed on the current and each included | |
6682 file. | |
6683 | |
6684 It is often useful put at the *END* of your file something like: | |
6685 | |
6686 // Local Variables: | |
6687 // eval:(verilog-read-defines) | |
6688 // eval:(verilog-read-includes) | |
6689 // End: | |
6690 | |
6691 Note includes are only read when the file is first visited, you must use | |
6692 \\[find-alternate-file] RET to have these take effect after editing them! | |
6693 | |
6694 It is good to get in the habit of including all needed files in each .v | |
6695 file that needs it, rather than waiting for compile time. This will aid | |
6696 this process, Verilint, and readability. To prevent defining the same | |
6697 variable over and over when many modules are compiled together, put a test | |
6698 around the inside each include file: | |
6699 | |
6700 foo.v (a include): | |
6701 `ifdef _FOO_V // include if not already included | |
6702 `else | |
6703 `define _FOO_V | |
6704 ... contents of file | |
6705 `endif // _FOO_V" | |
6706 ;;slow: (verilog-read-defines nil t)) | |
6707 (save-excursion | |
6708 (verilog-getopt-flags) | |
6709 (goto-char (point-min)) | |
6710 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t) | |
6711 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string 1)))) | |
6712 (verilog-read-defines inc nil t))))) | |
6713 | |
6714 (defun verilog-read-signals (&optional start end) | |
6715 "Return a simple list of all possible signals in the file. | |
6716 Bounded by optional region from START to END. Overly aggressive but fast. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
6717 Some macros and such are also found and included. For dinotrace.el." |
79545 | 6718 (let (sigs-all keywd) |
6719 (progn;save-excursion | |
6720 (goto-char (or start (point-min))) | |
6721 (setq end (or end (point-max))) | |
6722 (while (re-search-forward "[\"/a-zA-Z_.%`]" end t) | |
6723 (forward-char -1) | |
6724 (cond | |
6725 ((looking-at "//") | |
6726 (search-forward "\n")) | |
6727 ((looking-at "/\\*") | |
6728 (search-forward "*/")) | |
6729 ((looking-at "(\\*") | |
6730 (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)" | |
6731 (search-forward "*)"))) | |
6732 ((eq ?\" (following-char)) | |
6733 (re-search-forward "[^\\]\"")) ;; don't forward-char first, since we look for a non backslash first | |
6734 ((looking-at "\\s-*\\([a-zA-Z0-9$_.%`]+\\)") | |
6735 (goto-char (match-end 0)) | |
6736 (setq keywd (match-string-no-properties 1)) | |
6737 (or (member keywd verilog-keywords) | |
6738 (member keywd sigs-all) | |
6739 (setq sigs-all (cons keywd sigs-all)))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6740 (t (forward-char 1)))) |
79545 | 6741 ;; Return list |
6742 sigs-all))) | |
6743 | |
6744 ;; | |
6745 ;; Argument file parsing | |
6746 ;; | |
6747 | |
6748 (defun verilog-getopt (arglist) | |
6749 "Parse -f, -v etc arguments in ARGLIST list or string." | |
6750 (unless (listp arglist) (setq arglist (list arglist))) | |
6751 (let ((space-args '()) | |
6752 arg next-param) | |
6753 ;; Split on spaces, so users can pass whole command lines | |
6754 (while arglist | |
6755 (setq arg (car arglist) | |
6756 arglist (cdr arglist)) | |
6757 (while (string-match "^\\([^ \t\n\f]+\\)[ \t\n\f]*\\(.*$\\)" arg) | |
6758 (setq space-args (append space-args | |
6759 (list (match-string-no-properties 1 arg)))) | |
6760 (setq arg (match-string 2 arg)))) | |
6761 ;; Parse arguments | |
6762 (while space-args | |
6763 (setq arg (car space-args) | |
6764 space-args (cdr space-args)) | |
6765 (cond | |
6766 ;; Need another arg | |
6767 ((equal arg "-f") | |
6768 (setq next-param arg)) | |
6769 ((equal arg "-v") | |
6770 (setq next-param arg)) | |
6771 ((equal arg "-y") | |
6772 (setq next-param arg)) | |
6773 ;; +libext+(ext1)+(ext2)... | |
6774 ((string-match "^\\+libext\\+\\(.*\\)" arg) | |
6775 (setq arg (match-string 1 arg)) | |
6776 (while (string-match "\\([^+]+\\)\\+?\\(.*\\)" arg) | |
6777 (verilog-add-list-unique `verilog-library-extensions | |
6778 (match-string 1 arg)) | |
6779 (setq arg (match-string 2 arg)))) | |
6780 ;; | |
6781 ((or (string-match "^-D\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; -Ddefine=val | |
6782 (string-match "^-D\\([^+=]*\\)\\(\\)" arg) ;; -Ddefine | |
6783 (string-match "^\\+define\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; +define+val | |
6784 (string-match "^\\+define\\([^+=]*\\)\\(\\)" arg)) ;; +define+define | |
6785 (verilog-set-define (match-string 1 arg) (match-string 2 arg))) | |
6786 ;; | |
6787 ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ;; +incdir+dir | |
6788 (string-match "^-I\\(.*\\)" arg)) ;; -Idir | |
6789 (verilog-add-list-unique `verilog-library-directories | |
6790 (match-string 1 arg))) | |
6791 ;; Ignore | |
6792 ((equal "+librescan" arg)) | |
6793 ((string-match "^-U\\(.*\\)" arg)) ;; -Udefine | |
6794 ;; Second parameters | |
6795 ((equal next-param "-f") | |
6796 (setq next-param nil) | |
6797 (verilog-getopt-file arg)) | |
6798 ((equal next-param "-v") | |
6799 (setq next-param nil) | |
6800 (verilog-add-list-unique `verilog-library-files arg)) | |
6801 ((equal next-param "-y") | |
6802 (setq next-param nil) | |
6803 (verilog-add-list-unique `verilog-library-directories arg)) | |
6804 ;; Filename | |
6805 ((string-match "^[^-+]" arg) | |
6806 (verilog-add-list-unique `verilog-library-files arg)) | |
6807 ;; Default - ignore; no warning | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6808 )))) |
79545 | 6809 ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir")) |
6810 | |
6811 (defun verilog-getopt-file (filename) | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
6812 "Read Verilog options from the specified FILENAME." |
79545 | 6813 (save-excursion |
6814 (let ((fns (verilog-library-filenames filename (buffer-file-name))) | |
6815 (orig-buffer (current-buffer)) | |
6816 line) | |
6817 (if fns | |
6818 (set-buffer (find-file-noselect (car fns))) | |
6819 (error (concat (verilog-point-text) | |
6820 "Can't find verilog-getopt-file -f file: " filename))) | |
6821 (goto-char (point-min)) | |
6822 (while (not (eobp)) | |
6823 (setq line (buffer-substring (point) | |
6824 (save-excursion (end-of-line) (point)))) | |
6825 (forward-line 1) | |
6826 (when (string-match "//" line) | |
6827 (setq line (substring line 0 (match-beginning 0)))) | |
6828 (save-excursion | |
6829 (set-buffer orig-buffer) ; Variables are buffer-local, so need right context. | |
6830 (verilog-getopt line)))))) | |
6831 | |
6832 (defun verilog-getopt-flags () | |
6833 "Convert `verilog-library-flags' into standard library variables." | |
6834 ;; If the flags are local, then all the outputs should be local also | |
6835 (when (local-variable-p `verilog-library-flags (current-buffer)) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6836 (mapc 'make-local-variable '(verilog-library-extensions |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6837 verilog-library-directories |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6838 verilog-library-files |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6839 verilog-library-flags))) |
79545 | 6840 ;; Allow user to customize |
6841 (run-hooks 'verilog-before-getopt-flags-hook) | |
6842 ;; Process arguments | |
6843 (verilog-getopt verilog-library-flags) | |
6844 ;; Allow user to customize | |
6845 (run-hooks 'verilog-getopt-flags-hook)) | |
6846 | |
6847 (defun verilog-add-list-unique (varref object) | |
6848 "Append to VARREF list the given OBJECT, | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
6849 unless it is already a member of the variable's list." |
79545 | 6850 (unless (member object (symbol-value varref)) |
6851 (set varref (append (symbol-value varref) (list object)))) | |
6852 varref) | |
6853 ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l) | |
6854 | |
6855 | |
6856 ;; | |
6857 ;; Module name lookup | |
6858 ;; | |
6859 | |
6860 (defun verilog-module-inside-filename-p (module filename) | |
6861 "Return point if MODULE is specified inside FILENAME, else nil. | |
6862 Allows version control to check out the file if need be." | |
6863 (and (or (file-exists-p filename) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6864 (and (fboundp 'vc-backend) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6865 (vc-backend filename))) |
79545 | 6866 (let (pt) |
6867 (save-excursion | |
6868 (set-buffer (find-file-noselect filename)) | |
6869 (goto-char (point-min)) | |
6870 (while (and | |
6871 ;; It may be tempting to look for verilog-defun-re, don't, it slows things down a lot! | |
6872 (verilog-re-search-forward-quick "\\<module\\>" nil t) | |
6873 (verilog-re-search-forward-quick "[(;]" nil t)) | |
6874 (if (equal module (verilog-read-module-name)) | |
6875 (setq pt (point)))) | |
6876 pt)))) | |
6877 | |
6878 (defun verilog-is-number (symbol) | |
6879 "Return true if SYMBOL is number-like." | |
6880 (or (string-match "^[0-9 \t:]+$" symbol) | |
6881 (string-match "^[---]*[0-9]+$" symbol) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6882 (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol))) |
79545 | 6883 |
6884 (defun verilog-symbol-detick (symbol wing-it) | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
6885 "Return an expanded SYMBOL name without any defines. |
79545 | 6886 If the variable vh-{symbol} is defined, return that value. |
6887 If undefined, and WING-IT, return just SYMBOL without the tick, else nil." | |
6888 (while (and symbol (string-match "^`" symbol)) | |
6889 (setq symbol (substring symbol 1)) | |
6890 (setq symbol | |
6891 (if (boundp (intern (concat "vh-" symbol))) | |
6892 ;; Emacs has a bug where boundp on a buffer-local | |
6893 ;; variable in only one buffer returns t in another. | |
6894 ;; This can confuse, so check for nil. | |
6895 (let ((val (eval (intern (concat "vh-" symbol))))) | |
6896 (if (eq val nil) | |
6897 (if wing-it symbol nil) | |
6898 val)) | |
6899 (if wing-it symbol nil)))) | |
6900 symbol) | |
6901 ;;(verilog-symbol-detick "`mod" nil) | |
6902 | |
6903 (defun verilog-symbol-detick-denumber (symbol) | |
6904 "Return SYMBOL with defines converted and any numbers dropped to nil." | |
6905 (when (string-match "^`" symbol) | |
6906 ;; This only will work if the define is a simple signal, not | |
6907 ;; something like a[b]. Sorry, it should be substituted into the parser | |
6908 (setq symbol | |
6909 (verilog-string-replace-matches | |
6910 "\[[^0-9: \t]+\]" "" nil nil | |
6911 (or (verilog-symbol-detick symbol nil) | |
6912 (if verilog-auto-sense-defines-constant | |
6913 "0" | |
6914 symbol))))) | |
6915 (if (verilog-is-number symbol) | |
6916 nil | |
6917 symbol)) | |
6918 | |
6919 (defun verilog-symbol-detick-text (text) | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
6920 "Return TEXT without any known defines. |
79545 | 6921 If the variable vh-{symbol} is defined, substitute that value." |
6922 (let ((ok t) symbol val) | |
6923 (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text)) | |
6924 (setq symbol (match-string 1 text)) | |
6925 (message symbol) | |
6926 (cond ((and | |
6927 (boundp (intern (concat "vh-" symbol))) | |
6928 ;; Emacs has a bug where boundp on a buffer-local | |
6929 ;; variable in only one buffer returns t in another. | |
6930 ;; This can confuse, so check for nil. | |
6931 (setq val (eval (intern (concat "vh-" symbol))))) | |
6932 (setq text (replace-match val nil nil text))) | |
6933 (t (setq ok nil))))) | |
6934 text) | |
6935 ;;(progn (setq vh-mod "`foo" vh-foo "bar") (verilog-symbol-detick-text "bar `mod `undefed")) | |
6936 | |
6937 (defun verilog-expand-dirnames (&optional dirnames) | |
6938 "Return a list of existing directories given a list of wildcarded DIRNAMES. | |
6939 Or, just the existing dirnames themselves if there are no wildcards." | |
6940 (interactive) | |
6941 (unless dirnames (error "`verilog-library-directories' should include at least '.'")) | |
6942 (setq dirnames (reverse dirnames)) ; not nreverse | |
6943 (let ((dirlist nil) | |
6944 pattern dirfile dirfiles dirname root filename rest) | |
6945 (while dirnames | |
6946 (setq dirname (substitute-in-file-name (car dirnames)) | |
6947 dirnames (cdr dirnames)) | |
6948 (cond ((string-match (concat "^\\(\\|[/\\]*[^*?]*[/\\]\\)" ;; root | |
6949 "\\([^/\\]*[*?][^/\\]*\\)" ;; filename with *? | |
6950 "\\(.*\\)") ;; rest | |
6951 dirname) | |
6952 (setq root (match-string 1 dirname) | |
6953 filename (match-string 2 dirname) | |
6954 rest (match-string 3 dirname) | |
6955 pattern filename) | |
6956 ;; now replace those * and ? with .+ and . | |
6957 ;; use ^ and /> to get only whole file names | |
6958 ;;verilog-string-replace-matches | |
6959 (setq pattern (verilog-string-replace-matches "[*]" ".+" nil nil pattern) | |
6960 pattern (verilog-string-replace-matches "[?]" "." nil nil pattern) | |
6961 | |
6962 ;; Unfortunately allows abc/*/rtl to match abc/rtl | |
6963 ;; because abc/.. shows up in dirfiles. Solutions welcome. | |
6964 dirfiles (if (file-directory-p root) ; Ignore version control external | |
6965 (directory-files root t pattern nil))) | |
6966 (while dirfiles | |
6967 (setq dirfile (expand-file-name (concat (car dirfiles) rest)) | |
6968 dirfiles (cdr dirfiles)) | |
6969 (if (file-directory-p dirfile) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6970 (setq dirlist (cons dirfile dirlist))))) |
79545 | 6971 ;; Defaults |
6972 (t | |
6973 (if (file-directory-p dirname) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6974 (setq dirlist (cons dirname dirlist)))))) |
79545 | 6975 dirlist)) |
6976 ;;(verilog-expand-dirnames (list "." ".." "nonexist" "../*" "/home/wsnyder/*/v")) | |
6977 | |
6978 (defun verilog-library-filenames (filename current &optional check-ext) | |
6979 "Return a search path to find the given FILENAME name. | |
6980 Uses the CURRENT filename, `verilog-library-directories' and | |
6981 `verilog-library-extensions' variables to build the path. | |
6982 With optional CHECK-EXT also check `verilog-library-extensions'." | |
6983 (let ((ckdir (verilog-expand-dirnames verilog-library-directories)) | |
6984 fn outlist) | |
6985 (while ckdir | |
6986 (let ((ckext (if check-ext verilog-library-extensions `("")))) | |
6987 (while ckext | |
6988 (setq fn (expand-file-name | |
6989 (concat filename (car ckext)) | |
6990 (expand-file-name (car ckdir) (file-name-directory current)))) | |
6991 (if (file-exists-p fn) | |
6992 (setq outlist (cons fn outlist))) | |
6993 (setq ckext (cdr ckext)))) | |
6994 (setq ckdir (cdr ckdir))) | |
6995 (nreverse outlist))) | |
6996 | |
6997 (defun verilog-module-filenames (module current) | |
6998 "Return a search path to find the given MODULE name. | |
6999 Uses the CURRENT filename, `verilog-library-extensions', | |
7000 `verilog-library-directories' and `verilog-library-files' | |
7001 variables to build the path." | |
7002 ;; Return search locations for it | |
7003 (append (list current) ; first, current buffer | |
7004 (verilog-library-filenames module current t) | |
7005 verilog-library-files)) ; finally, any libraries | |
7006 | |
7007 ;; | |
7008 ;; Module Information | |
7009 ;; | |
7010 ;; Many of these functions work on "modi" a module information structure | |
7011 ;; A modi is: [module-name-string file-name begin-point] | |
7012 | |
7013 (defvar verilog-cache-enabled t | |
7014 "If true, enable caching of signals, etc. Set to nil for debugging to make things SLOW!") | |
7015 | |
7016 (defvar verilog-modi-cache-list nil | |
7017 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)... | |
7018 For speeding up verilog-modi-get-* commands. | |
7019 Buffer-local.") | |
7020 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
7021 (make-variable-buffer-local 'verilog-modi-cache-list) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
7022 |
79545 | 7023 (defvar verilog-modi-cache-preserve-tick nil |
7024 "Modification tick after which the cache is still considered valid. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7025 Use `verilog-preserve-cache' to set it.") |
79545 | 7026 (defvar verilog-modi-cache-preserve-buffer nil |
7027 "Modification tick after which the cache is still considered valid. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7028 Use `verilog-preserve-cache' to set it.") |
79545 | 7029 |
7030 (defun verilog-modi-current () | |
7031 "Return the modi structure for the module currently at point." | |
7032 (let* (name pt) | |
7033 ;; read current module's name | |
7034 (save-excursion | |
7035 (verilog-re-search-backward-quick verilog-defun-re nil nil) | |
7036 (verilog-re-search-forward-quick "(" nil nil) | |
7037 (setq name (verilog-read-module-name)) | |
7038 (setq pt (point))) | |
7039 ;; return | |
7040 (vector name (or (buffer-file-name) (current-buffer)) pt))) | |
7041 | |
7042 (defvar verilog-modi-lookup-last-mod nil "Cache of last module looked up.") | |
7043 (defvar verilog-modi-lookup-last-modi nil "Cache of last modi returned.") | |
7044 (defvar verilog-modi-lookup-last-current nil "Cache of last `current-buffer' looked up.") | |
7045 (defvar verilog-modi-lookup-last-tick nil "Cache of last `buffer-modified-tick' looked up.") | |
7046 | |
7047 (defun verilog-modi-lookup (module allow-cache &optional ignore-error) | |
7048 "Find the file and point at which MODULE is defined. | |
7049 If ALLOW-CACHE is set, check and remember cache of previous lookups. | |
7050 Return modi if successful, else print message unless IGNORE-ERROR is true." | |
7051 (let* ((current (or (buffer-file-name) (current-buffer)))) | |
7052 (cond ((and verilog-modi-lookup-last-modi | |
7053 verilog-cache-enabled | |
7054 allow-cache | |
7055 (equal verilog-modi-lookup-last-mod module) | |
7056 (equal verilog-modi-lookup-last-current current) | |
7057 (equal verilog-modi-lookup-last-tick (buffer-modified-tick))) | |
7058 ;; ok as is | |
7059 ) | |
7060 (t (let* ((realmod (verilog-symbol-detick module t)) | |
7061 (orig-filenames (verilog-module-filenames realmod current)) | |
7062 (filenames orig-filenames) | |
7063 pt) | |
7064 (while (and filenames (not pt)) | |
7065 (if (not (setq pt (verilog-module-inside-filename-p realmod (car filenames)))) | |
7066 (setq filenames (cdr filenames)))) | |
7067 (cond (pt (setq verilog-modi-lookup-last-modi | |
7068 (vector realmod (car filenames) pt))) | |
7069 (t (setq verilog-modi-lookup-last-modi nil) | |
7070 (or ignore-error | |
7071 (error (concat (verilog-point-text) | |
7072 ": Can't locate " module " module definition" | |
7073 (if (not (equal module realmod)) | |
7074 (concat " (Expanded macro to " realmod ")") | |
7075 "") | |
7076 "\n Check the verilog-library-directories variable." | |
7077 "\n I looked in (if not listed, doesn't exist):\n\t" | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7078 (mapconcat 'concat orig-filenames "\n\t")))))) |
79545 | 7079 (setq verilog-modi-lookup-last-mod module |
7080 verilog-modi-lookup-last-current current | |
7081 verilog-modi-lookup-last-tick (buffer-modified-tick))))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7082 verilog-modi-lookup-last-modi)) |
79545 | 7083 |
7084 (defsubst verilog-modi-name (modi) | |
7085 (aref modi 0)) | |
7086 (defsubst verilog-modi-file-or-buffer (modi) | |
7087 (aref modi 1)) | |
7088 (defsubst verilog-modi-point (modi) | |
7089 (aref modi 2)) | |
7090 | |
7091 (defun verilog-modi-filename (modi) | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7092 "Filename of MODI, or name of buffer if it's never been saved." |
79545 | 7093 (if (bufferp (verilog-modi-file-or-buffer modi)) |
7094 (or (buffer-file-name (verilog-modi-file-or-buffer modi)) | |
7095 (buffer-name (verilog-modi-file-or-buffer modi))) | |
7096 (verilog-modi-file-or-buffer modi))) | |
7097 | |
7098 (defun verilog-modi-goto (modi) | |
7099 "Move point/buffer to specified MODI." | |
7100 (or modi (error "Passed unfound modi to goto, check earlier")) | |
7101 (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi)) | |
7102 (verilog-modi-file-or-buffer modi) | |
7103 (find-file-noselect (verilog-modi-file-or-buffer modi)))) | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7104 (or (equal major-mode `verilog-mode) ;; Put into Verilog mode to get syntax |
79545 | 7105 (verilog-mode)) |
7106 (goto-char (verilog-modi-point modi))) | |
7107 | |
7108 (defun verilog-goto-defun-file (module) | |
7109 "Move point to the file at which a given MODULE is defined." | |
7110 (interactive "sGoto File for Module: ") | |
7111 (let* ((modi (verilog-modi-lookup module nil))) | |
7112 (when modi | |
7113 (verilog-modi-goto modi) | |
7114 (switch-to-buffer (current-buffer))))) | |
7115 | |
7116 (defun verilog-modi-cache-results (modi function) | |
7117 "Run on MODI the given FUNCTION. Locate the module in a file. | |
7118 Cache the output of function so next call may have faster access." | |
7119 (let (func-returns fass) | |
7120 (save-excursion | |
7121 (verilog-modi-goto modi) | |
7122 (if (and (setq fass (assoc (list (verilog-modi-name modi) function) | |
7123 verilog-modi-cache-list)) | |
7124 ;; Destroy caching when incorrect; Modified or file changed | |
7125 (not (and verilog-cache-enabled | |
7126 (or (equal (buffer-modified-tick) (nth 1 fass)) | |
7127 (and verilog-modi-cache-preserve-tick | |
7128 (<= verilog-modi-cache-preserve-tick (nth 1 fass)) | |
7129 (equal verilog-modi-cache-preserve-buffer (current-buffer)))) | |
7130 (equal (visited-file-modtime) (nth 2 fass))))) | |
7131 (setq verilog-modi-cache-list nil | |
7132 fass nil)) | |
7133 (cond (fass | |
7134 ;; Found | |
7135 (setq func-returns (nth 3 fass))) | |
7136 (t | |
7137 ;; Read from file | |
7138 ;; Clear then restore any hilighting to make emacs19 happy | |
7139 (let ((fontlocked (when (and (boundp 'font-lock-mode) | |
7140 font-lock-mode) | |
7141 (font-lock-mode nil) | |
7142 t))) | |
7143 (setq func-returns (funcall function)) | |
7144 (when fontlocked (font-lock-mode t))) | |
7145 ;; Cache for next time | |
7146 (setq verilog-modi-cache-list | |
7147 (cons (list (list (verilog-modi-name modi) function) | |
7148 (buffer-modified-tick) | |
7149 (visited-file-modtime) | |
7150 func-returns) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7151 verilog-modi-cache-list))))) |
79545 | 7152 ;; |
7153 func-returns)) | |
7154 | |
7155 (defun verilog-modi-cache-add (modi function element sig-list) | |
7156 "Add function return results to the module cache. | |
7157 Update MODI's cache for given FUNCTION so that the return ELEMENT of that | |
7158 function now contains the additional SIG-LIST parameters." | |
7159 (let (fass) | |
7160 (save-excursion | |
7161 (verilog-modi-goto modi) | |
7162 (if (setq fass (assoc (list (verilog-modi-name modi) function) | |
7163 verilog-modi-cache-list)) | |
7164 (let ((func-returns (nth 3 fass))) | |
7165 (aset func-returns element | |
7166 (append sig-list (aref func-returns element)))))))) | |
7167 | |
7168 (defmacro verilog-preserve-cache (&rest body) | |
7169 "Execute the BODY forms, allowing cache preservation within BODY. | |
7170 This means that changes to the buffer will not result in the cache being | |
7171 flushed. If the changes affect the modsig state, they must call the | |
7172 modsig-cache-add-* function, else the results of later calls may be | |
7173 incorrect. Without this, changes are assumed to be adding/removing signals | |
7174 and invalidating the cache." | |
7175 `(let ((verilog-modi-cache-preserve-tick (buffer-modified-tick)) | |
7176 (verilog-modi-cache-preserve-buffer (current-buffer))) | |
7177 (progn ,@body))) | |
7178 | |
7179 | |
7180 (defun verilog-signals-matching-enum (in-list enum) | |
7181 "Return all signals in IN-LIST matching the given ENUM." | |
7182 (let (out-list) | |
7183 (while in-list | |
7184 (if (equal (verilog-sig-enum (car in-list)) enum) | |
7185 (setq out-list (cons (car in-list) out-list))) | |
7186 (setq in-list (cdr in-list))) | |
7187 ;; New scheme | |
7188 (let* ((enumvar (intern (concat "venum-" enum))) | |
7189 (enumlist (and (boundp enumvar) (eval enumvar)))) | |
7190 (while enumlist | |
7191 (add-to-list 'out-list (list (car enumlist))) | |
7192 (setq enumlist (cdr enumlist)))) | |
7193 (nreverse out-list))) | |
7194 | |
7195 (defun verilog-signals-not-matching-regexp (in-list regexp) | |
7196 "Return all signals in IN-LIST not matching the given REGEXP, if non-nil." | |
7197 (if (not regexp) | |
7198 in-list | |
7199 (let (out-list) | |
7200 (while in-list | |
7201 (if (not (string-match regexp (verilog-sig-name (car in-list)))) | |
7202 (setq out-list (cons (car in-list) out-list))) | |
7203 (setq in-list (cdr in-list))) | |
7204 (nreverse out-list)))) | |
7205 | |
7206 ;; Combined | |
7207 (defun verilog-modi-get-signals (modi) | |
7208 (append | |
7209 (verilog-modi-get-outputs modi) | |
7210 (verilog-modi-get-inouts modi) | |
7211 (verilog-modi-get-inputs modi) | |
7212 (verilog-modi-get-wires modi) | |
7213 (verilog-modi-get-regs modi) | |
7214 (verilog-modi-get-assigns modi) | |
7215 (verilog-modi-get-consts modi) | |
7216 (verilog-modi-get-gparams modi))) | |
7217 | |
7218 (defun verilog-modi-get-ports (modi) | |
7219 (append | |
7220 (verilog-modi-get-outputs modi) | |
7221 (verilog-modi-get-inouts modi) | |
7222 (verilog-modi-get-inputs modi))) | |
7223 | |
7224 (defsubst verilog-modi-cache-add-outputs (modi sig-list) | |
7225 (verilog-modi-cache-add modi 'verilog-read-decls 0 sig-list)) | |
7226 (defsubst verilog-modi-cache-add-inouts (modi sig-list) | |
7227 (verilog-modi-cache-add modi 'verilog-read-decls 1 sig-list)) | |
7228 (defsubst verilog-modi-cache-add-inputs (modi sig-list) | |
7229 (verilog-modi-cache-add modi 'verilog-read-decls 2 sig-list)) | |
7230 (defsubst verilog-modi-cache-add-wires (modi sig-list) | |
7231 (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list)) | |
7232 (defsubst verilog-modi-cache-add-regs (modi sig-list) | |
7233 (verilog-modi-cache-add modi 'verilog-read-decls 4 sig-list)) | |
7234 | |
7235 (defun verilog-signals-from-signame (signame-list) | |
7236 "Return signals in standard form from SIGNAME-LIST, a simple list of signal names." | |
7237 (mapcar (function (lambda (name) (list name nil nil))) | |
7238 signame-list)) | |
7239 | |
7240 ;; | |
7241 ;; Auto creation utilities | |
7242 ;; | |
7243 | |
7244 (defun verilog-auto-search-do (search-for func) | |
7245 "Search for the given auto text SEARCH-FOR, and perform FUNC where it occurs." | |
7246 (goto-char (point-min)) | |
7247 (while (search-forward search-for nil t) | |
7248 (if (not (save-excursion | |
7249 (goto-char (match-beginning 0)) | |
7250 (verilog-inside-comment-p))) | |
7251 (funcall func)))) | |
7252 | |
7253 (defun verilog-auto-re-search-do (search-for func) | |
7254 "Search for the given auto text SEARCH-FOR, and perform FUNC where it occurs." | |
7255 (goto-char (point-min)) | |
7256 (while (re-search-forward search-for nil t) | |
7257 (if (not (save-excursion | |
7258 (goto-char (match-beginning 0)) | |
7259 (verilog-inside-comment-p))) | |
7260 (funcall func)))) | |
7261 | |
7262 (defun verilog-insert-one-definition (sig type indent-pt) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7263 "Print out a definition for SIG of the given TYPE, |
79545 | 7264 with appropriate INDENT-PT indentation." |
7265 (indent-to indent-pt) | |
7266 (insert type) | |
7267 (when (verilog-sig-signed sig) | |
7268 (insert " " (verilog-sig-signed sig))) | |
7269 (when (verilog-sig-multidim sig) | |
7270 (insert " " (verilog-sig-multidim-string sig))) | |
7271 (when (verilog-sig-bits sig) | |
7272 (insert " " (verilog-sig-bits sig))) | |
7273 (indent-to (max 24 (+ indent-pt 16))) | |
7274 (unless (= (char-syntax (preceding-char)) ?\ ) | |
7275 (insert " ")) ; Need space between "]name" if indent-to did nothing | |
7276 (insert (verilog-sig-name sig))) | |
7277 | |
7278 (defun verilog-insert-definition (sigs direction indent-pt v2k &optional dont-sort) | |
7279 "Print out a definition for a list of SIGS of the given DIRECTION, | |
7280 with appropriate INDENT-PT indentation. If V2K, use Verilog 2001 I/O | |
7281 format. Sort unless DONT-SORT. DIRECTION is normally wire/reg/output." | |
7282 (or dont-sort | |
7283 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare))) | |
7284 (while sigs | |
7285 (let ((sig (car sigs))) | |
7286 (verilog-insert-one-definition | |
7287 sig | |
7288 ;; Want "type x" or "output type x", not "wire type x" | |
7289 (cond ((verilog-sig-type sig) | |
7290 (concat | |
7291 (if (not (equal direction "wire")) | |
7292 (concat direction " ")) | |
7293 (verilog-sig-type sig))) | |
7294 (t direction)) | |
7295 indent-pt) | |
7296 (insert (if v2k "," ";")) | |
7297 (if (or (not (verilog-sig-comment sig)) | |
7298 (equal "" (verilog-sig-comment sig))) | |
7299 (insert "\n") | |
7300 (indent-to (max 48 (+ indent-pt 40))) | |
7301 (insert (concat "// " (verilog-sig-comment sig) "\n"))) | |
7302 (setq sigs (cdr sigs))))) | |
7303 | |
7304 (eval-when-compile | |
7305 (if (not (boundp 'indent-pt)) | |
7306 (defvar indent-pt nil "Local used by insert-indent"))) | |
7307 | |
7308 (defun verilog-insert-indent (&rest stuff) | |
7309 "Indent to position stored in local `indent-pt' variable, then insert STUFF. | |
7310 Presumes that any newlines end a list element." | |
7311 (let ((need-indent t)) | |
7312 (while stuff | |
7313 (if need-indent (indent-to indent-pt)) | |
7314 (setq need-indent nil) | |
7315 (insert (car stuff)) | |
7316 (setq need-indent (string-match "\n$" (car stuff)) | |
7317 stuff (cdr stuff))))) | |
7318 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n")) | |
7319 | |
7320 (defun verilog-repair-open-comma () | |
7321 "If backwards-from-point is other than a open parenthesis insert comma." | |
7322 (save-excursion | |
7323 (verilog-backward-syntactic-ws) | |
7324 (when (save-excursion | |
7325 (backward-char 1) | |
7326 (and (not (looking-at "[(,]")) | |
7327 (progn | |
7328 (verilog-re-search-backward "[(`]" nil t) | |
7329 (looking-at "(")))) | |
7330 (insert ",")))) | |
7331 | |
7332 (defun verilog-repair-close-comma () | |
7333 "If point is at a comma followed by a close parenthesis, fix it. | |
7334 This repairs those mis-inserted by a AUTOARG." | |
7335 ;; It would be much nicer if Verilog allowed extra commas like Perl does! | |
7336 (save-excursion | |
7337 (verilog-forward-close-paren) | |
7338 (backward-char 1) | |
7339 (verilog-backward-syntactic-ws) | |
7340 (backward-char 1) | |
7341 (when (looking-at ",") | |
7342 (delete-char 1)))) | |
7343 | |
7344 (defun verilog-get-list (start end) | |
7345 "Return the elements of a comma separated list between START and END." | |
7346 (interactive) | |
7347 (let ((my-list (list)) | |
7348 my-string) | |
7349 (save-excursion | |
7350 (while (< (point) end) | |
7351 (when (re-search-forward "\\([^,{]+\\)" end t) | |
7352 (setq my-string (verilog-string-remove-spaces (match-string 1))) | |
7353 (setq my-list (nconc my-list (list my-string) )) | |
7354 (goto-char (match-end 0)))) | |
7355 my-list))) | |
7356 | |
7357 (defun verilog-make-width-expression (range-exp) | |
7358 "Return an expression calculating the length of a range [x:y] in RANGE-EXP." | |
7359 ;; strip off the [] | |
7360 (cond ((not range-exp) | |
7361 "1") | |
7362 (t | |
7363 (if (string-match "^\\[\\(.*\\)\\]$" range-exp) | |
7364 (setq range-exp (match-string 1 range-exp))) | |
7365 (cond ((not range-exp) | |
7366 "1") | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
7367 ((string-match "^\\s *\\([0-9]+\\)\\s *:\\s *\\([0-9]+\\)\\s *$" |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
7368 range-exp) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
7369 (int-to-string |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
7370 (1+ (abs (- (string-to-number (match-string 1 range-exp)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
7371 (string-to-number (match-string 2 range-exp))))))) |
79545 | 7372 ((string-match "^\\(.*\\)\\s *:\\s *\\(.*\\)\\s *$" range-exp) |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
7373 (concat "(1+(" (match-string 1 range-exp) ")" |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7374 (if (equal "0" (match-string 2 range-exp)) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7375 "" ;; Don't bother with -(0) |
79545 | 7376 (concat "-(" (match-string 2 range-exp) ")")) |
7377 ")")) | |
7378 (t nil))))) | |
7379 ;;(verilog-make-width-expression "`A:`B") | |
7380 | |
7381 (defun verilog-typedef-name-p (variable-name) | |
7382 "Return true if the VARIABLE-NAME is a type definition." | |
7383 (when verilog-typedef-regexp | |
7384 (string-match verilog-typedef-regexp variable-name))) | |
7385 | |
7386 ;; | |
7387 ;; Auto deletion | |
7388 ;; | |
7389 | |
7390 (defun verilog-delete-autos-lined () | |
7391 "Delete autos that occupy multiple lines, between begin and end comments." | |
7392 (let ((pt (point))) | |
7393 (forward-line 1) | |
7394 (when (and | |
7395 (looking-at "\\s-*// Beginning") | |
7396 (search-forward "// End of automatic" nil t)) | |
7397 ;; End exists | |
7398 (end-of-line) | |
7399 (delete-region pt (point)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7400 (forward-line 1)))) |
79545 | 7401 |
7402 (defun verilog-forward-close-paren () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7403 "Find the close parenthesis that match the current point. |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7404 Ignore other close parenthesis with matching open parens." |
79545 | 7405 (let ((parens 1)) |
7406 (while (> parens 0) | |
7407 (unless (verilog-re-search-forward-quick "[()]" nil t) | |
7408 (error "%s: Mismatching ()" (verilog-point-text))) | |
7409 (cond ((= (preceding-char) ?\( ) | |
7410 (setq parens (1+ parens))) | |
7411 ((= (preceding-char) ?\) ) | |
7412 (setq parens (1- parens))))))) | |
7413 | |
7414 (defun verilog-backward-open-paren () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7415 "Find the open parenthesis that match the current point. |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7416 Ignore other open parenthesis with matching close parens." |
79545 | 7417 (let ((parens 1)) |
7418 (while (> parens 0) | |
7419 (unless (verilog-re-search-backward-quick "[()]" nil t) | |
7420 (error "%s: Mismatching ()" (verilog-point-text))) | |
7421 (cond ((= (following-char) ?\) ) | |
7422 (setq parens (1+ parens))) | |
7423 ((= (following-char) ?\( ) | |
7424 (setq parens (1- parens))))))) | |
7425 | |
7426 (defun verilog-backward-open-bracket () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7427 "Find the open bracket that match the current point. |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7428 Ignore other open bracket with matching close bracket." |
79545 | 7429 (let ((parens 1)) |
7430 (while (> parens 0) | |
7431 (unless (verilog-re-search-backward-quick "[][]" nil t) | |
7432 (error "%s: Mismatching []" (verilog-point-text))) | |
7433 (cond ((= (following-char) ?\] ) | |
7434 (setq parens (1+ parens))) | |
7435 ((= (following-char) ?\[ ) | |
7436 (setq parens (1- parens))))))) | |
7437 | |
7438 (defun verilog-delete-to-paren () | |
7439 "Delete the automatic inst/sense/arg created by autos. | |
7440 Deletion stops at the matching end parenthesis." | |
7441 (delete-region (point) | |
7442 (save-excursion | |
7443 (verilog-backward-open-paren) | |
7444 (forward-sexp 1) ;; Moves to paren that closes argdecl's | |
7445 (backward-char 1) | |
7446 (point)))) | |
7447 | |
7448 (defun verilog-auto-star-safe () | |
7449 "Return if a .* AUTOINST is safe to delete or expand. | |
7450 It was created by the AUTOS themselves, or by the user." | |
7451 (and verilog-auto-star-expand | |
7452 (looking-at "[ \t\n\f,]*\\([)]\\|// \\(Outputs\\|Inouts\\|Inputs\\)\\)"))) | |
7453 | |
7454 (defun verilog-delete-auto-star-all () | |
7455 "Delete a .* AUTOINST, if it is safe." | |
7456 (when (verilog-auto-star-safe) | |
7457 (verilog-delete-to-paren))) | |
7458 | |
7459 (defun verilog-delete-auto-star-implicit () | |
7460 "Delete all .* implicit connections created by `verilog-auto-star'. | |
7461 This function will be called automatically at save unless | |
7462 `verilog-auto-star-save' is set, any non-templated expanded pins will be | |
7463 removed." | |
7464 (interactive) | |
7465 (let (paren-pt indent have-close-paren) | |
7466 (save-excursion | |
7467 (goto-char (point-min)) | |
7468 ;; We need to match these even outside of comments. | |
7469 ;; For reasonable performance, we don't check if inside comments, sorry. | |
7470 (while (re-search-forward "// Implicit \\.\\*" nil t) | |
7471 (setq paren-pt (point)) | |
7472 (beginning-of-line) | |
7473 (setq have-close-paren | |
7474 (save-excursion | |
7475 (when (search-forward ");" paren-pt t) | |
7476 (setq indent (current-indentation)) | |
7477 t))) | |
7478 (delete-region (point) (+ 1 paren-pt)) ; Nuke line incl CR | |
7479 (when have-close-paren | |
7480 ;; Delete extra commentary | |
7481 (save-excursion | |
7482 (while (progn | |
7483 (forward-line -1) | |
7484 (looking-at "\\s *//\\s *\\(Outputs\\|Inouts\\|Inputs\\)\n")) | |
7485 (delete-region (match-beginning 0) (match-end 0)))) | |
7486 ;; If it is simple, we can put the ); on the same line as the last text | |
7487 (let ((rtn-pt (point))) | |
7488 (save-excursion | |
7489 (while (progn (backward-char 1) | |
7490 (looking-at "[ \t\n\f]"))) | |
7491 (when (looking-at ",") | |
7492 (delete-region (+ 1 (point)) rtn-pt)))) | |
7493 (when (bolp) | |
7494 (indent-to indent)) | |
7495 (insert ");\n") | |
7496 ;; Still need to kill final comma - always is one as we put one after the .* | |
7497 (re-search-backward ",") | |
7498 (delete-char 1)))))) | |
7499 | |
7500 (defun verilog-delete-auto () | |
7501 "Delete the automatic outputs, regs, and wires created by \\[verilog-auto]. | |
7502 Use \\[verilog-auto] to re-insert the updated AUTOs. | |
7503 | |
7504 The hooks `verilog-before-delete-auto-hook' and `verilog-delete-auto-hook' are | |
7505 called before and after this function, respectively." | |
7506 (interactive) | |
7507 (save-excursion | |
7508 (if (buffer-file-name) | |
7509 (find-file-noselect (buffer-file-name))) ;; To check we have latest version | |
7510 ;; Allow user to customize | |
7511 (run-hooks 'verilog-before-delete-auto-hook) | |
7512 | |
7513 ;; Remove those that have multi-line insertions | |
7514 (verilog-auto-re-search-do "/\\*AUTO\\(OUTPUTEVERY\\|CONCATCOMMENT\\|WIRE\\|REG\\|DEFINEVALUE\\|REGINPUT\\|INPUT\\|OUTPUT\\|INOUT\\|RESET\\|TIEOFF\\|UNUSED\\)\\*/" | |
7515 'verilog-delete-autos-lined) | |
7516 ;; Remove those that have multi-line insertions with parameters | |
7517 (verilog-auto-re-search-do "/\\*AUTO\\(INOUTMODULE\\|ASCIIENUM\\)([^)]*)\\*/" | |
7518 'verilog-delete-autos-lined) | |
7519 ;; Remove those that are in parenthesis | |
7520 (verilog-auto-re-search-do "/\\*\\(AS\\|AUTO\\(ARG\\|CONCATWIDTH\\|INST\\|INSTPARAM\\|SENSE\\)\\)\\*/" | |
7521 'verilog-delete-to-paren) | |
7522 ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments | |
7523 (verilog-auto-re-search-do "\\.\\*" | |
7524 'verilog-delete-auto-star-all) | |
7525 ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed | |
7526 (goto-char (point-min)) | |
7527 (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)[ \tLT0-9]*$" nil t) | |
7528 (replace-match "")) | |
7529 | |
7530 ;; Final customize | |
7531 (run-hooks 'verilog-delete-auto-hook))) | |
7532 | |
7533 ;; | |
7534 ;; Auto inject | |
7535 ;; | |
7536 | |
7537 (defun verilog-inject-auto () | |
7538 "Examine legacy non-AUTO code and insert AUTOs in appropriate places. | |
7539 | |
7540 Any always @ blocks with sensitivity lists that match computed lists will | |
7541 be replaced with /*AS*/ comments. | |
7542 | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7543 Any cells will get /*AUTOINST*/ added to the end of the pin list. |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7544 Pins with have identical names will be deleted. |
79545 | 7545 |
7546 Argument lists will not be deleted, /*AUTOARG*/ will only be inserted to | |
7547 support adding new ports. You may wish to delete older ports yourself. | |
7548 | |
7549 For example: | |
7550 | |
7551 module ex_inject (i, o); | |
7552 input i; | |
7553 input j; | |
7554 output o; | |
7555 always @ (i or j) | |
7556 o = i | j; | |
7557 cell cell (.foobar(baz), | |
7558 .j(j)); | |
7559 endmodule | |
7560 | |
7561 Typing \\[verilog-inject-auto] will make this into: | |
7562 | |
7563 module ex_inject (i, o/*AUTOARG*/ | |
7564 // Inputs | |
7565 j); | |
7566 input i; | |
7567 output o; | |
7568 always @ (/*AS*/i or j) | |
7569 o = i | j; | |
7570 cell cell (.foobar(baz), | |
7571 /*AUTOINST*/ | |
7572 // Outputs | |
7573 .j(j)); | |
7574 endmodule" | |
7575 (interactive) | |
7576 (verilog-auto t)) | |
7577 | |
7578 (defun verilog-inject-arg () | |
7579 "Inject AUTOARG into new code. See `verilog-inject-auto'." | |
7580 ;; Presume one module per file. | |
7581 (save-excursion | |
7582 (goto-char (point-min)) | |
7583 (while (verilog-re-search-forward-quick "\\<module\\>" nil t) | |
7584 (let ((endmodp (save-excursion | |
7585 (verilog-re-search-forward-quick "\\<endmodule\\>" nil t) | |
7586 (point)))) | |
7587 ;; See if there's already a comment .. inside a comment so not verilog-re-search | |
7588 (when (not (re-search-forward "/\\*AUTOARG\\*/" endmodp t)) | |
7589 (verilog-re-search-forward-quick ";" nil t) | |
7590 (backward-char 1) | |
7591 (verilog-backward-syntactic-ws) | |
7592 (backward-char 1) ; Moves to paren that closes argdecl's | |
7593 (when (looking-at ")") | |
7594 (insert "/*AUTOARG*/"))))))) | |
7595 | |
7596 (defun verilog-inject-sense () | |
7597 "Inject AUTOSENSE into new code. See `verilog-inject-auto'." | |
7598 (save-excursion | |
7599 (goto-char (point-min)) | |
7600 (while (verilog-re-search-forward-quick "\\<always\\s *@\\s *(" nil t) | |
7601 (let ((start-pt (point)) | |
7602 (modi (verilog-modi-current)) | |
7603 pre-sigs | |
7604 got-sigs) | |
7605 (backward-char 1) | |
7606 (forward-sexp 1) | |
7607 (backward-char 1) ;; End ) | |
7608 (when (not (verilog-re-search-backward "/\\*\\(AUTOSENSE\\|AS\\)\\*/" start-pt t)) | |
7609 (setq pre-sigs (verilog-signals-from-signame | |
7610 (verilog-read-signals start-pt (point))) | |
7611 got-sigs (verilog-auto-sense-sigs modi nil)) | |
7612 (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal? | |
7613 (verilog-signals-not-in got-sigs pre-sigs))) | |
7614 (delete-region start-pt (point)) | |
7615 (insert "/*AS*/"))))))) | |
7616 | |
7617 (defun verilog-inject-inst () | |
7618 "Inject AUTOINST into new code. See `verilog-inject-auto'." | |
7619 (save-excursion | |
7620 (goto-char (point-min)) | |
7621 ;; It's hard to distinguish modules; we'll instead search for pins. | |
7622 (while (verilog-re-search-forward-quick "\\.\\s *[a-zA-Z0-9`_\$]+\\s *(\\s *[a-zA-Z0-9`_\$]+\\s *)" nil t) | |
7623 (verilog-backward-open-paren) ;; Inst start | |
7624 (cond | |
7625 ((= (preceding-char) ?\#) ;; #(...) parameter section, not pin. Skip. | |
7626 (forward-char 1) | |
7627 (verilog-forward-close-paren)) ;; Parameters done | |
7628 (t | |
7629 (forward-char 1) | |
7630 (let ((indent-pt (+ (current-column))) | |
7631 (end-pt (save-excursion (verilog-forward-close-paren) (point)))) | |
7632 (cond ((verilog-re-search-forward "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-pt t) | |
7633 (goto-char end-pt)) ;; Already there, continue search with next instance | |
7634 (t | |
7635 ;; Delete identical interconnect | |
7636 (let ((case-fold-search nil)) ;; So we don't convert upper-to-lower, etc | |
7637 (while (verilog-re-search-forward "\\.\\s *\\([a-zA-Z0-9`_\$]+\\)*\\s *(\\s *\\1\\s *)\\s *" end-pt t) | |
7638 (delete-region (match-beginning 0) (match-end 0)) | |
7639 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))) ;; Keep it correct | |
7640 (while (or (looking-at "[ \t\n\f,]+") | |
7641 (looking-at "//[^\n]*")) | |
7642 (delete-region (match-beginning 0) (match-end 0)) | |
7643 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0))))))) | |
7644 (verilog-forward-close-paren) | |
7645 (backward-char 1) | |
7646 ;; Not verilog-re-search, as we don't want to strip comments | |
7647 (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t) | |
7648 (delete-region (match-beginning 0) (match-end 0))) | |
7649 (insert "\n") | |
7650 (indent-to indent-pt) | |
7651 (insert "/*AUTOINST*/"))))))))) | |
7652 | |
7653 ;; | |
7654 ;; Auto save | |
7655 ;; | |
7656 | |
7657 (defun verilog-auto-save-check () | |
7658 "On saving see if we need auto update." | |
7659 (cond ((not verilog-auto-save-policy)) ; disabled | |
7660 ((not (save-excursion | |
7661 (save-match-data | |
7662 (let ((case-fold-search nil)) | |
7663 (goto-char (point-min)) | |
7664 (re-search-forward "AUTO" nil t)))))) | |
7665 ((eq verilog-auto-save-policy 'force) | |
7666 (verilog-auto)) | |
7667 ((not (buffer-modified-p))) | |
7668 ((eq verilog-auto-update-tick (buffer-modified-tick))) ; up-to-date | |
7669 ((eq verilog-auto-save-policy 'detect) | |
7670 (verilog-auto)) | |
7671 (t | |
7672 (when (yes-or-no-p "AUTO statements not recomputed, do it now? ") | |
7673 (verilog-auto)) | |
7674 ;; Don't ask again if didn't update | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7675 (set (make-local-variable 'verilog-auto-update-tick) (buffer-modified-tick)))) |
79545 | 7676 (when (not verilog-auto-star-save) |
7677 (verilog-delete-auto-star-implicit)) | |
7678 nil) ;; Always return nil -- we don't write the file ourselves | |
7679 | |
7680 (defun verilog-auto-read-locals () | |
7681 "Return file local variable segment at bottom of file." | |
7682 (save-excursion | |
7683 (goto-char (point-max)) | |
7684 (if (re-search-backward "Local Variables:" nil t) | |
7685 (buffer-substring-no-properties (point) (point-max)) | |
7686 ""))) | |
7687 | |
7688 (defun verilog-auto-reeval-locals (&optional force) | |
7689 "Read file local variable segment at bottom of file if it has changed. | |
7690 If FORCE, always reread it." | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
7691 (make-local-variable 'verilog-auto-last-file-locals) |
79545 | 7692 (let ((curlocal (verilog-auto-read-locals))) |
7693 (when (or force (not (equal verilog-auto-last-file-locals curlocal))) | |
7694 (setq verilog-auto-last-file-locals curlocal) | |
7695 ;; Note this may cause this function to be recursively invoked. | |
7696 ;; The above when statement will prevent it from recursing forever. | |
7697 (hack-local-variables) | |
7698 t))) | |
7699 | |
7700 ;; | |
7701 ;; Auto creation | |
7702 ;; | |
7703 | |
7704 (defun verilog-auto-arg-ports (sigs message indent-pt) | |
7705 "Print a list of ports for a AUTOINST. | |
7706 Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT." | |
7707 (when sigs | |
7708 (insert "\n") | |
7709 (indent-to indent-pt) | |
7710 (insert message) | |
7711 (insert "\n") | |
7712 (let ((space "")) | |
7713 (indent-to indent-pt) | |
7714 (while sigs | |
7715 (cond ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column) | |
7716 (insert "\n") | |
7717 (indent-to indent-pt)) | |
7718 (t (insert space))) | |
7719 (insert (verilog-sig-name (car sigs)) ",") | |
7720 (setq sigs (cdr sigs) | |
7721 space " "))))) | |
7722 | |
7723 (defun verilog-auto-arg () | |
7724 "Expand AUTOARG statements. | |
7725 Replace the argument declarations at the beginning of the | |
7726 module with ones automatically derived from input and output | |
7727 statements. This can be dangerous if the module is instantiated | |
7728 using position-based connections, so use only name-based when | |
7729 instantiating the resulting module. Long lines are split based | |
7730 on the `fill-column', see \\[set-fill-column]. | |
7731 | |
7732 Limitations: | |
7733 Concatenation and outputting partial busses is not supported. | |
7734 | |
7735 Typedefs must match `verilog-typedef-regexp', which is disabled by default. | |
7736 | |
7737 For example: | |
7738 | |
7739 module ex_arg (/*AUTOARG*/); | |
7740 input i; | |
7741 output o; | |
7742 endmodule | |
7743 | |
7744 Typing \\[verilog-auto] will make this into: | |
7745 | |
7746 module ex_arg (/*AUTOARG*/ | |
7747 // Outputs | |
7748 o, | |
7749 // Inputs | |
7750 i | |
7751 ); | |
7752 input i; | |
7753 output o; | |
7754 endmodule | |
7755 | |
7756 Any ports declared between the ( and /*AUTOARG*/ are presumed to be | |
7757 predeclared and are not redeclared by AUTOARG. AUTOARG will make a | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7758 conservative guess on adding a comma for the first signal, if you have |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7759 any ifdefs or complicated expressions before the AUTOARG you will need |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7760 to choose the comma yourself. |
79545 | 7761 |
7762 Avoid declaring ports manually, as it makes code harder to maintain." | |
7763 (save-excursion | |
7764 (let ((modi (verilog-modi-current)) | |
7765 (skip-pins (aref (verilog-read-arg-pins) 0))) | |
7766 (verilog-repair-open-comma) | |
7767 (verilog-auto-arg-ports (verilog-signals-not-in | |
7768 (verilog-modi-get-outputs modi) | |
7769 skip-pins) | |
7770 "// Outputs" | |
7771 verilog-indent-level-declaration) | |
7772 (verilog-auto-arg-ports (verilog-signals-not-in | |
7773 (verilog-modi-get-inouts modi) | |
7774 skip-pins) | |
7775 "// Inouts" | |
7776 verilog-indent-level-declaration) | |
7777 (verilog-auto-arg-ports (verilog-signals-not-in | |
7778 (verilog-modi-get-inputs modi) | |
7779 skip-pins) | |
7780 "// Inputs" | |
7781 verilog-indent-level-declaration) | |
7782 (verilog-repair-close-comma) | |
7783 (unless (eq (char-before) ?/ ) | |
7784 (insert "\n")) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7785 (indent-to verilog-indent-level-declaration)))) |
79545 | 7786 |
7787 (defun verilog-auto-inst-port-map (port-st) | |
7788 nil) | |
7789 | |
7790 (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning | |
7791 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning | |
7792 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning | |
7793 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning | |
7794 (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning | |
7795 | |
7796 (defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star) | |
7797 "Print out a instantiation connection for this PORT-ST. | |
7798 Insert to INDENT-PT, use template TPL-LIST. | |
7799 @ are instantiation numbers, replaced with TPL-NUM. | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7800 @\"(expression @)\" are evaluated, with @ as a variable. |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7801 If FOR-STAR add comment it is a .* expansion." |
79545 | 7802 (let* ((port (verilog-sig-name port-st)) |
7803 (tpl-ass (or (assoc port (car tpl-list)) | |
7804 (verilog-auto-inst-port-map port-st))) | |
7805 ;; vl-* are documented for user use | |
7806 (vl-name (verilog-sig-name port-st)) | |
7807 (vl-width (verilog-sig-width port-st)) | |
7808 (vl-bits (if (or verilog-auto-inst-vector | |
7809 (not (assoc port vector-skip-list)) | |
7810 (not (equal (verilog-sig-bits port-st) | |
7811 (verilog-sig-bits (assoc port vector-skip-list))))) | |
7812 (or (verilog-sig-bits port-st) "") | |
7813 "")) | |
7814 ;; Default if not found | |
7815 (tpl-net (if (verilog-sig-multidim port-st) | |
7816 (concat port "/*" (verilog-sig-multidim-string port-st) | |
7817 vl-bits "*/") | |
7818 (concat port vl-bits))) | |
7819 (case-fold-search nil)) | |
7820 ;; Find template | |
7821 (cond (tpl-ass ; Template of exact port name | |
7822 (setq tpl-net (nth 1 tpl-ass))) | |
7823 ((nth 1 tpl-list) ; Wildcards in template, search them | |
7824 (let ((wildcards (nth 1 tpl-list))) | |
7825 (while wildcards | |
7826 (when (string-match (nth 0 (car wildcards)) port) | |
7827 (setq tpl-ass (car wildcards) ; so allow @ parsing | |
7828 tpl-net (replace-match (nth 1 (car wildcards)) | |
7829 t nil port))) | |
7830 (setq wildcards (cdr wildcards)))))) | |
7831 ;; Parse Templated variable | |
7832 (when tpl-ass | |
7833 ;; Evaluate @"(lispcode)" | |
7834 (when (string-match "@\".*[^\\]\"" tpl-net) | |
7835 (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net) | |
7836 (setq tpl-net | |
7837 (concat | |
7838 (substring tpl-net 0 (match-beginning 0)) | |
7839 (save-match-data | |
7840 (let* ((expr (match-string 1 tpl-net)) | |
7841 (value | |
7842 (progn | |
7843 (setq expr (verilog-string-replace-matches "\\\\\"" "\"" nil nil expr)) | |
7844 (setq expr (verilog-string-replace-matches "@" tpl-num nil nil expr)) | |
7845 (prin1 (eval (car (read-from-string expr))) | |
7846 (lambda (ch) ()))))) | |
7847 (if (numberp value) (setq value (number-to-string value))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7848 value)) |
79545 | 7849 (substring tpl-net (match-end 0)))))) |
7850 ;; Replace @ and [] magic variables in final output | |
7851 (setq tpl-net (verilog-string-replace-matches "@" tpl-num nil nil tpl-net)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7852 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net))) |
79545 | 7853 (indent-to indent-pt) |
7854 (insert "." port) | |
7855 (indent-to verilog-auto-inst-column) | |
7856 (insert "(" tpl-net "),") | |
7857 (cond (tpl-ass | |
7858 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16) | |
7859 verilog-auto-inst-column)) | |
7860 (insert " // Templated") | |
7861 (when verilog-auto-inst-template-numbers | |
7862 (insert " T" (int-to-string (nth 2 tpl-ass)) | |
7863 " L" (int-to-string (nth 3 tpl-ass))))) | |
7864 (for-star | |
7865 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16) | |
7866 verilog-auto-inst-column)) | |
7867 (insert " // Implicit .\*"))) ;For some reason the . or * must be escaped... | |
7868 (insert "\n"))) | |
7869 ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3") | |
7870 ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]") | |
7871 ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));") | |
7872 | |
7873 (defun verilog-auto-inst-first () | |
7874 "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]." | |
7875 ;; Do we need a trailing comma? | |
7876 ;; There maybe a ifdef or something similar before us. What a mess. Thus | |
7877 ;; to avoid trouble we only insert on preceeding ) or *. | |
7878 ;; Insert first port on new line | |
7879 (insert "\n") ;; Must insert before search, so point will move forward if insert comma | |
7880 (save-excursion | |
7881 (verilog-re-search-backward "[^ \t\n\f]" nil nil) | |
7882 (when (looking-at ")\\|\\*") ;; Generally don't insert, unless we are fairly sure | |
7883 (forward-char 1) | |
7884 (insert ",")))) | |
7885 | |
7886 (defun verilog-auto-star () | |
7887 "Expand SystemVerilog .* pins, as part of \\[verilog-auto]. | |
7888 | |
7889 If `verilog-auto-star-expand' is set, .* pins are treated if they were | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7890 AUTOINST statements, otherwise they are ignored. For safety, Verilog mode |
79545 | 7891 will also ignore any .* that are not last in your pin list (this prevents |
7892 it from deleting pins following the .* when it expands the AUTOINST.) | |
7893 | |
7894 On writing your file, unless `verilog-auto-star-save' is set, any | |
7895 non-templated expanded pins will be removed. You may do this at any time | |
7896 with \\[verilog-delete-auto-star-implicit]. | |
7897 | |
7898 If you are converting a module to use .* for the first time, you may wish | |
7899 to use \\[verilog-inject-auto] and then replace the created AUTOINST with .*. | |
7900 | |
7901 See `verilog-auto-inst' for examples, templates, and more information." | |
7902 (when (verilog-auto-star-safe) | |
7903 (verilog-auto-inst))) | |
7904 | |
7905 (defun verilog-auto-inst () | |
7906 "Expand AUTOINST statements, as part of \\[verilog-auto]. | |
7907 Replace the pin connections to an instantiation with ones | |
7908 automatically derived from the module header of the instantiated netlist. | |
7909 | |
7910 If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports, | |
7911 and delete them before saving unless `verilog-auto-star-save' is set. | |
7912 See `verilog-auto-star' for more information. | |
7913 | |
7914 Limitations: | |
7915 Module names must be resolvable to filenames by adding a | |
7916 `verilog-library-extensions', and being found in the same directory, or | |
7917 by changing the variable `verilog-library-flags' or | |
7918 `verilog-library-directories'. Macros `modname are translated through the | |
7919 vh-{name} Emacs variable, if that is not found, it just ignores the `. | |
7920 | |
7921 In templates you must have one signal per line, ending in a ), or ));, | |
7922 and have proper () nesting, including a final ); to end the template. | |
7923 | |
7924 Typedefs must match `verilog-typedef-regexp', which is disabled by default. | |
7925 | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7926 SystemVerilog multidimensional input/output has only experimental support. |
79545 | 7927 |
7928 For example, first take the submodule inst.v: | |
7929 | |
7930 module inst (o,i) | |
7931 output [31:0] o; | |
7932 input i; | |
7933 wire [31:0] o = {32{i}}; | |
7934 endmodule | |
7935 | |
7936 This is then used in a upper level module: | |
7937 | |
7938 module ex_inst (o,i) | |
7939 output o; | |
7940 input i; | |
7941 inst inst (/*AUTOINST*/); | |
7942 endmodule | |
7943 | |
7944 Typing \\[verilog-auto] will make this into: | |
7945 | |
7946 module ex_inst (o,i) | |
7947 output o; | |
7948 input i; | |
7949 inst inst (/*AUTOINST*/ | |
7950 // Outputs | |
7951 .ov (ov[31:0]), | |
7952 // Inputs | |
7953 .i (i)); | |
7954 endmodule | |
7955 | |
7956 Where the list of inputs and outputs came from the inst module. | |
7957 | |
7958 Exceptions: | |
7959 | |
7960 Unless you are instantiating a module multiple times, or the module is | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7961 something trivial like an adder, DO NOT CHANGE SIGNAL NAMES ACROSS HIERARCHY. |
79545 | 7962 It just makes for unmaintainable code. To sanitize signal names, try |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7963 vrename from http://www.veripool.com. |
79545 | 7964 |
7965 When you need to violate this suggestion there are two ways to list | |
7966 exceptions, placing them before the AUTOINST, or using templates. | |
7967 | |
7968 Any ports defined before the /*AUTOINST*/ are not included in the list of | |
7969 automatics. This is similar to making a template as described below, but | |
7970 is restricted to simple connections just like you normally make. Also note | |
7971 that any signals before the AUTOINST will only be picked up by AUTOWIRE if | |
7972 you have the appropriate // Input or // Output comment, and exactly the | |
7973 same line formatting as AUTOINST itself uses. | |
7974 | |
7975 inst inst (// Inputs | |
7976 .i (my_i_dont_mess_with_it), | |
7977 /*AUTOINST*/ | |
7978 // Outputs | |
7979 .ov (ov[31:0])); | |
7980 | |
7981 | |
7982 Templates: | |
7983 | |
7984 For multiple instantiations based upon a single template, create a | |
7985 commented out template: | |
7986 | |
7987 /* instantiating_module_name AUTO_TEMPLATE ( | |
7988 .sig3 (sigz[]), | |
7989 ); | |
7990 */ | |
7991 | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7992 Templates go ABOVE the instantiation(s). When an instantiation is |
79545 | 7993 expanded `verilog-mode' simply searches up for the closest template. |
7994 Thus you can have multiple templates for the same module, just alternate | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
7995 between the template for an instantiation and the instantiation itself. |
79545 | 7996 |
7997 The module name must be the same as the name of the module in the | |
7998 instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact | |
7999 words and capitalized. Only signals that must be different for each | |
8000 instantiation need to be listed. | |
8001 | |
8002 Inside a template, a [] in a connection name (with nothing else inside | |
8003 the brackets) will be replaced by the same bus subscript as it is being | |
8004 connected to, or the [] will be removed if it is a single bit signal. | |
8005 Generally it is a good idea to do this for all connections in a template, | |
8006 as then they will work for any width signal, and with AUTOWIRE. See | |
8007 PTL_BUS becoming PTL_BUSNEW below. | |
8008 | |
8009 If you have a complicated template, set `verilog-auto-inst-template-numbers' | |
8010 to see which regexps are matching. Don't leave that mode set after | |
8011 debugging is completed though, it will result in lots of extra differences | |
8012 and merge conflicts. | |
8013 | |
8014 For example: | |
8015 | |
8016 /* psm_mas AUTO_TEMPLATE ( | |
8017 .ptl_bus (ptl_busnew[]), | |
8018 ); | |
8019 */ | |
8020 psm_mas ms2m (/*AUTOINST*/); | |
8021 | |
8022 Typing \\[verilog-auto] will make this into: | |
8023 | |
8024 psm_mas ms2m (/*AUTOINST*/ | |
8025 // Outputs | |
8026 .NotInTemplate (NotInTemplate), | |
8027 .ptl_bus (ptl_busnew[3:0]), // Templated | |
8028 .... | |
8029 | |
8030 @ Templates: | |
8031 | |
8032 It is common to instantiate a cell multiple times, so templates make it | |
8033 trivial to substitute part of the cell name into the connection name. | |
8034 | |
8035 /* cell_type AUTO_TEMPLATE <optional \"REGEXP\"> ( | |
8036 .sig1 (sigx[@]), | |
8037 .sig2 (sigy[@\"(% (+ 1 @) 4)\"]), | |
8038 ); | |
8039 */ | |
8040 | |
8041 If no regular expression is provided immediately after the AUTO_TEMPLATE | |
8042 keyword, then the @ character in any connection names will be replaced | |
8043 with the instantiation number; the first digits found in the cell's | |
8044 instantiation name. | |
8045 | |
8046 If a regular expression is provided, the @ character will be replaced | |
8047 with the first \(\) grouping that matches against the cell name. Using a | |
8048 regexp of \"\\([0-9]+\\)\" provides identical values for @ as when no | |
8049 regexp is provided. If you use multiple layers of parenthesis, | |
8050 \"test\\([^0-9]+\\)_\\([0-9]+\\)\" would replace @ with non-number | |
8051 characters after test and before _, whereas | |
8052 \"\\(test\\([a-z]+\\)_\\([0-9]+\\)\\)\" would replace @ with the entire | |
8053 match. | |
8054 | |
8055 For example: | |
8056 | |
8057 /* psm_mas AUTO_TEMPLATE ( | |
8058 .ptl_mapvalidx (ptl_mapvalid[@]), | |
8059 .ptl_mapvalidp1x (ptl_mapvalid[@\"(% (+ 1 @) 4)\"]), | |
8060 ); | |
8061 */ | |
8062 psm_mas ms2m (/*AUTOINST*/); | |
8063 | |
8064 Typing \\[verilog-auto] will make this into: | |
8065 | |
8066 psm_mas ms2m (/*AUTOINST*/ | |
8067 // Outputs | |
8068 .ptl_mapvalidx (ptl_mapvalid[2]), | |
8069 .ptl_mapvalidp1x (ptl_mapvalid[3])); | |
8070 | |
8071 Note the @ character was replaced with the 2 from \"ms2m\". | |
8072 | |
8073 Alternatively, using a regular expression for @: | |
8074 | |
8075 /* psm_mas AUTO_TEMPLATE \"_\\([a-z]+\\)\" ( | |
8076 .ptl_mapvalidx (@_ptl_mapvalid), | |
8077 .ptl_mapvalidp1x (ptl_mapvalid_@), | |
8078 ); | |
8079 */ | |
8080 psm_mas ms2_FOO (/*AUTOINST*/); | |
8081 psm_mas ms2_BAR (/*AUTOINST*/); | |
8082 | |
8083 Typing \\[verilog-auto] will make this into: | |
8084 | |
8085 psm_mas ms2_FOO (/*AUTOINST*/ | |
8086 // Outputs | |
8087 .ptl_mapvalidx (FOO_ptl_mapvalid), | |
8088 .ptl_mapvalidp1x (ptl_mapvalid_FOO)); | |
8089 psm_mas ms2_BAR (/*AUTOINST*/ | |
8090 // Outputs | |
8091 .ptl_mapvalidx (BAR_ptl_mapvalid), | |
8092 .ptl_mapvalidp1x (ptl_mapvalid_BAR)); | |
8093 | |
8094 | |
8095 Regexp Templates: | |
8096 | |
8097 A template entry of the form | |
8098 | |
8099 .pci_req\\([0-9]+\\)_l (pci_req_jtag_[\\1]), | |
8100 | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
8101 will apply an Emacs style regular expression search for any port beginning |
79545 | 8102 in pci_req followed by numbers and ending in _l and connecting that to |
8103 the pci_req_jtag_[] net, with the bus subscript coming from what matches | |
8104 inside the first set of \\( \\). Thus pci_req2_l becomes pci_req_jtag_[2]. | |
8105 | |
8106 Since \\([0-9]+\\) is so common and ugly to read, a @ in the port name | |
8107 does the same thing. (Note a @ in the connection/replacement text is | |
8108 completely different -- still use \\1 there!) Thus this is the same as | |
8109 the above template: | |
8110 | |
8111 .pci_req@_l (pci_req_jtag_[\\1]), | |
8112 | |
8113 Here's another example to remove the _l, useful when naming conventions | |
8114 specify _ alone to mean active low. Note the use of [] to keep the bus | |
8115 subscript: | |
8116 | |
8117 .\\(.*\\)_l (\\1_[]), | |
8118 | |
8119 Lisp Templates: | |
8120 | |
8121 First any regular expression template is expanded. | |
8122 | |
8123 If the syntax @\"( ... )\" is found in a connection, the expression in | |
8124 quotes will be evaluated as a Lisp expression, with @ replaced by the | |
8125 instantiation number. The MAPVALIDP1X example above would put @+1 modulo | |
8126 4 into the brackets. Quote all double-quotes inside the expression with | |
8127 a leading backslash (\\\"). There are special variables defined that are | |
8128 useful in these Lisp functions: | |
8129 | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
8130 vl-name Name portion of the input/output port. |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
8131 vl-bits Bus bits portion of the input/output port ('[2:0]'). |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
8132 vl-width Width of the input/output port ('3' for [2:0]). |
79545 | 8133 May be a (...) expression if bits isn't a constant. |
8134 vl-dir Direction of the pin input/output/inout. | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
8135 vl-cell-type Module name/type of the cell ('psm_mas'). |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
8136 vl-cell-name Instance name of the cell ('ms2m'). |
79545 | 8137 |
8138 Normal Lisp variables may be used in expressions. See | |
8139 `verilog-read-defines' which can set vh-{definename} variables for use | |
8140 here. Also, any comments of the form: | |
8141 | |
8142 /*AUTO_LISP(setq foo 1)*/ | |
8143 | |
8144 will evaluate any Lisp expression inside the parenthesis between the | |
8145 beginning of the buffer and the point of the AUTOINST. This allows | |
8146 functions to be defined or variables to be changed between instantiations. | |
8147 | |
8148 Note that when using lisp expressions errors may occur when @ is not a | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
8149 number; you may need to use the standard Emacs Lisp functions |
79545 | 8150 `number-to-string' and `string-to-number'. |
8151 | |
8152 After the evaluation is completed, @ substitution and [] substitution | |
8153 occur." | |
8154 (save-excursion | |
8155 ;; Find beginning | |
8156 (let* ((pt (point)) | |
8157 (for-star (save-excursion (backward-char 2) (looking-at "\\.\\*"))) | |
8158 (indent-pt (save-excursion (verilog-backward-open-paren) | |
8159 (1+ (current-column)))) | |
8160 (verilog-auto-inst-column (max verilog-auto-inst-column | |
8161 (+ 16 (* 8 (/ (+ indent-pt 7) 8))))) | |
8162 (modi (verilog-modi-current)) | |
8163 (vector-skip-list (unless verilog-auto-inst-vector | |
8164 (verilog-modi-get-signals modi))) | |
8165 submod submodi inst skip-pins tpl-list tpl-num did-first) | |
8166 ;; Find module name that is instantiated | |
8167 (setq submod (verilog-read-inst-module) | |
8168 inst (verilog-read-inst-name) | |
8169 vl-cell-type submod | |
8170 vl-cell-name inst | |
8171 skip-pins (aref (verilog-read-inst-pins) 0)) | |
8172 | |
8173 ;; Parse any AUTO_LISP() before here | |
8174 (verilog-read-auto-lisp (point-min) pt) | |
8175 | |
8176 ;; Lookup position, etc of submodule | |
8177 ;; Note this may raise an error | |
8178 (when (setq submodi (verilog-modi-lookup submod t)) | |
8179 ;; If there's a number in the instantiation, it may be a argument to the | |
8180 ;; automatic variable instantiation program. | |
8181 (let* ((tpl-info (verilog-read-auto-template submod)) | |
8182 (tpl-regexp (aref tpl-info 0))) | |
8183 (setq tpl-num (if (string-match tpl-regexp inst) | |
8184 (match-string 1 inst) | |
8185 "") | |
8186 tpl-list (aref tpl-info 1))) | |
8187 ;; Find submodule's signals and dump | |
8188 (let ((sig-list (verilog-signals-not-in | |
8189 (verilog-modi-get-outputs submodi) | |
8190 skip-pins)) | |
8191 (vl-dir "output")) | |
8192 (when sig-list | |
8193 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) | |
8194 (indent-to indent-pt) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8195 ;; Note these are searched for in verilog-read-sub-decls. |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8196 (insert "// Outputs\n") |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8197 (mapc (lambda (port) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8198 (verilog-auto-inst-port port indent-pt |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8199 tpl-list tpl-num for-star)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8200 sig-list))) |
79545 | 8201 (let ((sig-list (verilog-signals-not-in |
8202 (verilog-modi-get-inouts submodi) | |
8203 skip-pins)) | |
8204 (vl-dir "inout")) | |
8205 (when sig-list | |
8206 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) | |
8207 (indent-to indent-pt) | |
8208 (insert "// Inouts\n") | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8209 (mapc (lambda (port) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8210 (verilog-auto-inst-port port indent-pt |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8211 tpl-list tpl-num for-star)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8212 sig-list))) |
79545 | 8213 (let ((sig-list (verilog-signals-not-in |
8214 (verilog-modi-get-inputs submodi) | |
8215 skip-pins)) | |
8216 (vl-dir "input")) | |
8217 (when sig-list | |
8218 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) | |
8219 (indent-to indent-pt) | |
8220 (insert "// Inputs\n") | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8221 (mapc (lambda (port) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8222 (verilog-auto-inst-port port indent-pt |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8223 tpl-list tpl-num for-star)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8224 sig-list))) |
79545 | 8225 ;; Kill extra semi |
8226 (save-excursion | |
8227 (cond (did-first | |
8228 (re-search-backward "," pt t) | |
8229 (delete-char 1) | |
8230 (insert ");") | |
8231 (search-forward "\n") ;; Added by inst-port | |
8232 (delete-backward-char 1) | |
8233 (if (search-forward ")" nil t) ;; From user, moved up a line | |
8234 (delete-backward-char 1)) | |
8235 (if (search-forward ";" nil t) ;; Don't error if user had syntax error and forgot it | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8236 (delete-backward-char 1))))))))) |
79545 | 8237 |
8238 (defun verilog-auto-inst-param () | |
8239 "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto]. | |
8240 Replace the parameter connections to an instantiation with ones | |
8241 automatically derived from the module header of the instantiated netlist. | |
8242 | |
8243 See \\[verilog-auto-inst] for limitations, and templates to customize the | |
8244 output. | |
8245 | |
8246 For example, first take the submodule inst.v: | |
8247 | |
8248 module inst (o,i) | |
8249 parameter PAR; | |
8250 endmodule | |
8251 | |
8252 This is then used in a upper level module: | |
8253 | |
8254 module ex_inst (o,i) | |
8255 parameter PAR; | |
8256 inst #(/*AUTOINSTPARAM*/) | |
8257 inst (/*AUTOINST*/); | |
8258 endmodule | |
8259 | |
8260 Typing \\[verilog-auto] will make this into: | |
8261 | |
8262 module ex_inst (o,i) | |
8263 output o; | |
8264 input i; | |
8265 inst (/*AUTOINSTPARAM*/ | |
8266 // Parameters | |
8267 .PAR (PAR)); | |
8268 inst (/*AUTOINST*/); | |
8269 endmodule | |
8270 | |
8271 Where the list of parameter connections come from the inst module. | |
8272 | |
8273 Templates: | |
8274 | |
8275 You can customize the parameter connections using AUTO_TEMPLATEs, | |
8276 just as you would with \\[verilog-auto-inst]." | |
8277 (save-excursion | |
8278 ;; Find beginning | |
8279 (let* ((pt (point)) | |
8280 (indent-pt (save-excursion (verilog-backward-open-paren) | |
8281 (1+ (current-column)))) | |
8282 (verilog-auto-inst-column (max verilog-auto-inst-column | |
8283 (+ 16 (* 8 (/ (+ indent-pt 7) 8))))) | |
8284 (modi (verilog-modi-current)) | |
8285 (vector-skip-list (unless verilog-auto-inst-vector | |
8286 (verilog-modi-get-signals modi))) | |
8287 submod submodi inst skip-pins tpl-list tpl-num did-first) | |
8288 ;; Find module name that is instantiated | |
8289 (setq submod (save-excursion | |
8290 ;; Get to the point where AUTOINST normally is to read the module | |
8291 (verilog-re-search-forward-quick "[(;]" nil nil) | |
8292 (verilog-read-inst-module)) | |
8293 inst (save-excursion | |
8294 ;; Get to the point where AUTOINST normally is to read the module | |
8295 (verilog-re-search-forward-quick "[(;]" nil nil) | |
8296 (verilog-read-inst-name)) | |
8297 vl-cell-type submod | |
8298 vl-cell-name inst | |
8299 skip-pins (aref (verilog-read-inst-pins) 0)) | |
8300 | |
8301 ;; Parse any AUTO_LISP() before here | |
8302 (verilog-read-auto-lisp (point-min) pt) | |
8303 | |
8304 ;; Lookup position, etc of submodule | |
8305 ;; Note this may raise an error | |
8306 (when (setq submodi (verilog-modi-lookup submod t)) | |
8307 ;; If there's a number in the instantiation, it may be a argument to the | |
8308 ;; automatic variable instantiation program. | |
8309 (let* ((tpl-info (verilog-read-auto-template submod)) | |
8310 (tpl-regexp (aref tpl-info 0))) | |
8311 (setq tpl-num (if (string-match tpl-regexp inst) | |
8312 (match-string 1 inst) | |
8313 "") | |
8314 tpl-list (aref tpl-info 1))) | |
8315 ;; Find submodule's signals and dump | |
8316 (let ((sig-list (verilog-signals-not-in | |
8317 (verilog-modi-get-gparams submodi) | |
8318 skip-pins)) | |
8319 (vl-dir "parameter")) | |
8320 (when sig-list | |
8321 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) | |
8322 (indent-to indent-pt) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8323 ;; Note these are searched for in verilog-read-sub-decls. |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8324 (insert "// Parameters\n") |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8325 (mapc (lambda (port) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8326 (verilog-auto-inst-port port indent-pt |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8327 tpl-list tpl-num nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8328 sig-list))) |
79545 | 8329 ;; Kill extra semi |
8330 (save-excursion | |
8331 (cond (did-first | |
8332 (re-search-backward "," pt t) | |
8333 (delete-char 1) | |
8334 (insert ")") | |
8335 (search-forward "\n") ;; Added by inst-port | |
8336 (delete-backward-char 1) | |
8337 (if (search-forward ")" nil t) ;; From user, moved up a line | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8338 (delete-backward-char 1))))))))) |
79545 | 8339 |
8340 (defun verilog-auto-reg () | |
8341 "Expand AUTOREG statements, as part of \\[verilog-auto]. | |
8342 Make reg statements for any output that isn't already declared, | |
8343 and isn't a wire output from a block. | |
8344 | |
8345 Limitations: | |
8346 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'). | |
8347 | |
8348 This does NOT work on memories, declare those yourself. | |
8349 | |
8350 An example: | |
8351 | |
8352 module ex_reg (o,i) | |
8353 output o; | |
8354 input i; | |
8355 /*AUTOREG*/ | |
8356 always o = i; | |
8357 endmodule | |
8358 | |
8359 Typing \\[verilog-auto] will make this into: | |
8360 | |
8361 module ex_reg (o,i) | |
8362 output o; | |
8363 input i; | |
8364 /*AUTOREG*/ | |
8365 // Beginning of automatic regs (for this module's undeclared outputs) | |
8366 reg o; | |
8367 // End of automatics | |
8368 always o = i; | |
8369 endmodule" | |
8370 (save-excursion | |
8371 ;; Point must be at insertion point. | |
8372 (let* ((indent-pt (current-indentation)) | |
8373 (modi (verilog-modi-current)) | |
8374 (sig-list (verilog-signals-not-in | |
8375 (verilog-modi-get-outputs modi) | |
8376 (append (verilog-modi-get-wires modi) | |
8377 (verilog-modi-get-regs modi) | |
8378 (verilog-modi-get-assigns modi) | |
8379 (verilog-modi-get-consts modi) | |
8380 (verilog-modi-get-gparams modi) | |
8381 (verilog-modi-get-sub-outputs modi) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8382 (verilog-modi-get-sub-inouts modi))))) |
79545 | 8383 (forward-line 1) |
8384 (when sig-list | |
8385 (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n") | |
8386 (verilog-insert-definition sig-list "reg" indent-pt nil) | |
8387 (verilog-modi-cache-add-regs modi sig-list) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8388 (verilog-insert-indent "// End of automatics\n"))))) |
79545 | 8389 |
8390 (defun verilog-auto-reg-input () | |
8391 "Expand AUTOREGINPUT statements, as part of \\[verilog-auto]. | |
8392 Make reg statements instantiation inputs that aren't already declared. | |
8393 This is useful for making a top level shell for testing the module that is | |
8394 to be instantiated. | |
8395 | |
8396 Limitations: | |
8397 This ONLY detects inputs of AUTOINSTants (see `verilog-read-sub-decls'). | |
8398 | |
8399 This does NOT work on memories, declare those yourself. | |
8400 | |
8401 An example (see `verilog-auto-inst' for what else is going on here): | |
8402 | |
8403 module ex_reg_input (o,i) | |
8404 output o; | |
8405 input i; | |
8406 /*AUTOREGINPUT*/ | |
8407 inst inst (/*AUTOINST*/); | |
8408 endmodule | |
8409 | |
8410 Typing \\[verilog-auto] will make this into: | |
8411 | |
8412 module ex_reg_input (o,i) | |
8413 output o; | |
8414 input i; | |
8415 /*AUTOREGINPUT*/ | |
8416 // Beginning of automatic reg inputs (for undeclared ... | |
8417 reg [31:0] iv; // From inst of inst.v | |
8418 // End of automatics | |
8419 inst inst (/*AUTOINST*/ | |
8420 // Outputs | |
8421 .o (o[31:0]), | |
8422 // Inputs | |
8423 .iv (iv)); | |
8424 endmodule" | |
8425 (save-excursion | |
8426 ;; Point must be at insertion point. | |
8427 (let* ((indent-pt (current-indentation)) | |
8428 (modi (verilog-modi-current)) | |
8429 (sig-list (verilog-signals-combine-bus | |
8430 (verilog-signals-not-in | |
8431 (append (verilog-modi-get-sub-inputs modi) | |
8432 (verilog-modi-get-sub-inouts modi)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8433 (verilog-modi-get-signals modi))))) |
79545 | 8434 (forward-line 1) |
8435 (when sig-list | |
8436 (verilog-insert-indent "// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)\n") | |
8437 (verilog-insert-definition sig-list "reg" indent-pt nil) | |
8438 (verilog-modi-cache-add-regs modi sig-list) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8439 (verilog-insert-indent "// End of automatics\n"))))) |
79545 | 8440 |
8441 (defun verilog-auto-wire () | |
8442 "Expand AUTOWIRE statements, as part of \\[verilog-auto]. | |
8443 Make wire statements for instantiations outputs that aren't | |
8444 already declared. | |
8445 | |
8446 Limitations: | |
8447 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'), | |
8448 and all busses must have widths, such as those from AUTOINST, or using [] | |
8449 in AUTO_TEMPLATEs. | |
8450 | |
8451 This does NOT work on memories or SystemVerilog .name connections, | |
8452 declare those yourself. | |
8453 | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
8454 Verilog mode will add \"Couldn't Merge\" comments to signals it cannot |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
8455 determine how to bus together. This occurs when you have ports with |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
8456 non-numeric or non-sequential bus subscripts. If Verilog mode |
79545 | 8457 mis-guessed, you'll have to declare them yourself. |
8458 | |
8459 An example (see `verilog-auto-inst' for what else is going on here): | |
8460 | |
8461 module ex_wire (o,i) | |
8462 output o; | |
8463 input i; | |
8464 /*AUTOWIRE*/ | |
8465 inst inst (/*AUTOINST*/); | |
8466 endmodule | |
8467 | |
8468 Typing \\[verilog-auto] will make this into: | |
8469 | |
8470 module ex_wire (o,i) | |
8471 output o; | |
8472 input i; | |
8473 /*AUTOWIRE*/ | |
8474 // Beginning of automatic wires | |
8475 wire [31:0] ov; // From inst of inst.v | |
8476 // End of automatics | |
8477 inst inst (/*AUTOINST*/ | |
8478 // Outputs | |
8479 .ov (ov[31:0]), | |
8480 // Inputs | |
8481 .i (i)); | |
8482 wire o = | ov; | |
8483 endmodule" | |
8484 (save-excursion | |
8485 ;; Point must be at insertion point. | |
8486 (let* ((indent-pt (current-indentation)) | |
8487 (modi (verilog-modi-current)) | |
8488 (sig-list (verilog-signals-combine-bus | |
8489 (verilog-signals-not-in | |
8490 (append (verilog-modi-get-sub-outputs modi) | |
8491 (verilog-modi-get-sub-inouts modi)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8492 (verilog-modi-get-signals modi))))) |
79545 | 8493 (forward-line 1) |
8494 (when sig-list | |
8495 (verilog-insert-indent "// Beginning of automatic wires (for undeclared instantiated-module outputs)\n") | |
8496 (verilog-insert-definition sig-list "wire" indent-pt nil) | |
8497 (verilog-modi-cache-add-wires modi sig-list) | |
8498 (verilog-insert-indent "// End of automatics\n") | |
8499 (when nil ;; Too slow on huge modules, plus makes everyone's module change | |
8500 (beginning-of-line) | |
8501 (setq pnt (point)) | |
8502 (verilog-pretty-declarations) | |
8503 (goto-char pnt) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8504 (verilog-pretty-expr "//")))))) |
79545 | 8505 |
8506 (defun verilog-auto-output () | |
8507 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto]. | |
8508 Make output statements for any output signal from an /*AUTOINST*/ that | |
8509 isn't a input to another AUTOINST. This is useful for modules which | |
8510 only instantiate other modules. | |
8511 | |
8512 Limitations: | |
8513 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'). | |
8514 | |
8515 If placed inside the parenthesis of a module declaration, it creates | |
8516 Verilog 2001 style, else uses Verilog 1995 style. | |
8517 | |
8518 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's | |
8519 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE). | |
8520 | |
8521 Typedefs must match `verilog-typedef-regexp', which is disabled by default. | |
8522 | |
8523 Signals matching `verilog-auto-output-ignore-regexp' are not included. | |
8524 | |
8525 An example (see `verilog-auto-inst' for what else is going on here): | |
8526 | |
8527 module ex_output (ov,i) | |
8528 input i; | |
8529 /*AUTOOUTPUT*/ | |
8530 inst inst (/*AUTOINST*/); | |
8531 endmodule | |
8532 | |
8533 Typing \\[verilog-auto] will make this into: | |
8534 | |
8535 module ex_output (ov,i) | |
8536 input i; | |
8537 /*AUTOOUTPUT*/ | |
8538 // Beginning of automatic outputs (from unused autoinst outputs) | |
8539 output [31:0] ov; // From inst of inst.v | |
8540 // End of automatics | |
8541 inst inst (/*AUTOINST*/ | |
8542 // Outputs | |
8543 .ov (ov[31:0]), | |
8544 // Inputs | |
8545 .i (i)); | |
8546 endmodule" | |
8547 (save-excursion | |
8548 ;; Point must be at insertion point. | |
8549 (let* ((indent-pt (current-indentation)) | |
8550 (v2k (verilog-in-paren)) | |
8551 (modi (verilog-modi-current)) | |
8552 (sig-list (verilog-signals-not-in | |
8553 (verilog-modi-get-sub-outputs modi) | |
8554 (append (verilog-modi-get-outputs modi) | |
8555 (verilog-modi-get-inouts modi) | |
8556 (verilog-modi-get-sub-inputs modi) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8557 (verilog-modi-get-sub-inouts modi))))) |
79545 | 8558 (setq sig-list (verilog-signals-not-matching-regexp |
8559 sig-list verilog-auto-output-ignore-regexp)) | |
8560 (forward-line 1) | |
8561 (when v2k (verilog-repair-open-comma)) | |
8562 (when sig-list | |
8563 (verilog-insert-indent "// Beginning of automatic outputs (from unused autoinst outputs)\n") | |
8564 (verilog-insert-definition sig-list "output" indent-pt v2k) | |
8565 (verilog-modi-cache-add-outputs modi sig-list) | |
8566 (verilog-insert-indent "// End of automatics\n")) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8567 (when v2k (verilog-repair-close-comma))))) |
79545 | 8568 |
8569 (defun verilog-auto-output-every () | |
8570 "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto]. | |
8571 Make output statements for any signals that aren't primary inputs or | |
8572 outputs already. This makes every signal in the design a output. This is | |
8573 useful to get Synopsys to preserve every signal in the design, since it | |
8574 won't optimize away the outputs. | |
8575 | |
8576 An example: | |
8577 | |
8578 module ex_output_every (o,i,tempa,tempb) | |
8579 output o; | |
8580 input i; | |
8581 /*AUTOOUTPUTEVERY*/ | |
8582 wire tempa = i; | |
8583 wire tempb = tempa; | |
8584 wire o = tempb; | |
8585 endmodule | |
8586 | |
8587 Typing \\[verilog-auto] will make this into: | |
8588 | |
8589 module ex_output_every (o,i,tempa,tempb) | |
8590 output o; | |
8591 input i; | |
8592 /*AUTOOUTPUTEVERY*/ | |
8593 // Beginning of automatic outputs (every signal) | |
8594 output tempb; | |
8595 output tempa; | |
8596 // End of automatics | |
8597 wire tempa = i; | |
8598 wire tempb = tempa; | |
8599 wire o = tempb; | |
8600 endmodule" | |
8601 (save-excursion | |
8602 ;;Point must be at insertion point | |
8603 (let* ((indent-pt (current-indentation)) | |
8604 (v2k (verilog-in-paren)) | |
8605 (modi (verilog-modi-current)) | |
8606 (sig-list (verilog-signals-combine-bus | |
8607 (verilog-signals-not-in | |
8608 (verilog-modi-get-signals modi) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8609 (verilog-modi-get-ports modi))))) |
79545 | 8610 (forward-line 1) |
8611 (when v2k (verilog-repair-open-comma)) | |
8612 (when sig-list | |
8613 (verilog-insert-indent "// Beginning of automatic outputs (every signal)\n") | |
8614 (verilog-insert-definition sig-list "output" indent-pt v2k) | |
8615 (verilog-modi-cache-add-outputs modi sig-list) | |
8616 (verilog-insert-indent "// End of automatics\n")) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8617 (when v2k (verilog-repair-close-comma))))) |
79545 | 8618 |
8619 (defun verilog-auto-input () | |
8620 "Expand AUTOINPUT statements, as part of \\[verilog-auto]. | |
8621 Make input statements for any input signal into an /*AUTOINST*/ that | |
8622 isn't declared elsewhere inside the module. This is useful for modules which | |
8623 only instantiate other modules. | |
8624 | |
8625 Limitations: | |
8626 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'). | |
8627 | |
8628 If placed inside the parenthesis of a module declaration, it creates | |
8629 Verilog 2001 style, else uses Verilog 1995 style. | |
8630 | |
8631 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's | |
8632 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE). | |
8633 | |
8634 Typedefs must match `verilog-typedef-regexp', which is disabled by default. | |
8635 | |
8636 Signals matching `verilog-auto-input-ignore-regexp' are not included. | |
8637 | |
8638 An example (see `verilog-auto-inst' for what else is going on here): | |
8639 | |
8640 module ex_input (ov,i) | |
8641 output [31:0] ov; | |
8642 /*AUTOINPUT*/ | |
8643 inst inst (/*AUTOINST*/); | |
8644 endmodule | |
8645 | |
8646 Typing \\[verilog-auto] will make this into: | |
8647 | |
8648 module ex_input (ov,i) | |
8649 output [31:0] ov; | |
8650 /*AUTOINPUT*/ | |
8651 // Beginning of automatic inputs (from unused autoinst inputs) | |
8652 input i; // From inst of inst.v | |
8653 // End of automatics | |
8654 inst inst (/*AUTOINST*/ | |
8655 // Outputs | |
8656 .ov (ov[31:0]), | |
8657 // Inputs | |
8658 .i (i)); | |
8659 endmodule" | |
8660 (save-excursion | |
8661 (let* ((indent-pt (current-indentation)) | |
8662 (v2k (verilog-in-paren)) | |
8663 (modi (verilog-modi-current)) | |
8664 (sig-list (verilog-signals-not-in | |
8665 (verilog-modi-get-sub-inputs modi) | |
8666 (append (verilog-modi-get-inputs modi) | |
8667 (verilog-modi-get-inouts modi) | |
8668 (verilog-modi-get-wires modi) | |
8669 (verilog-modi-get-regs modi) | |
8670 (verilog-modi-get-consts modi) | |
8671 (verilog-modi-get-gparams modi) | |
8672 (verilog-modi-get-sub-outputs modi) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8673 (verilog-modi-get-sub-inouts modi))))) |
79545 | 8674 (setq sig-list (verilog-signals-not-matching-regexp |
8675 sig-list verilog-auto-input-ignore-regexp)) | |
8676 (forward-line 1) | |
8677 (when v2k (verilog-repair-open-comma)) | |
8678 (when sig-list | |
8679 (verilog-insert-indent "// Beginning of automatic inputs (from unused autoinst inputs)\n") | |
8680 (verilog-insert-definition sig-list "input" indent-pt v2k) | |
8681 (verilog-modi-cache-add-inputs modi sig-list) | |
8682 (verilog-insert-indent "// End of automatics\n")) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8683 (when v2k (verilog-repair-close-comma))))) |
79545 | 8684 |
8685 (defun verilog-auto-inout () | |
8686 "Expand AUTOINOUT statements, as part of \\[verilog-auto]. | |
8687 Make inout statements for any inout signal in an /*AUTOINST*/ that | |
8688 isn't declared elsewhere inside the module. | |
8689 | |
8690 Limitations: | |
8691 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'). | |
8692 | |
8693 If placed inside the parenthesis of a module declaration, it creates | |
8694 Verilog 2001 style, else uses Verilog 1995 style. | |
8695 | |
8696 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's | |
8697 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE). | |
8698 | |
8699 Typedefs must match `verilog-typedef-regexp', which is disabled by default. | |
8700 | |
8701 Signals matching `verilog-auto-inout-ignore-regexp' are not included. | |
8702 | |
8703 An example (see `verilog-auto-inst' for what else is going on here): | |
8704 | |
8705 module ex_inout (ov,i) | |
8706 input i; | |
8707 /*AUTOINOUT*/ | |
8708 inst inst (/*AUTOINST*/); | |
8709 endmodule | |
8710 | |
8711 Typing \\[verilog-auto] will make this into: | |
8712 | |
8713 module ex_inout (ov,i) | |
8714 input i; | |
8715 /*AUTOINOUT*/ | |
8716 // Beginning of automatic inouts (from unused autoinst inouts) | |
8717 inout [31:0] ov; // From inst of inst.v | |
8718 // End of automatics | |
8719 inst inst (/*AUTOINST*/ | |
8720 // Inouts | |
8721 .ov (ov[31:0]), | |
8722 // Inputs | |
8723 .i (i)); | |
8724 endmodule" | |
8725 (save-excursion | |
8726 ;; Point must be at insertion point. | |
8727 (let* ((indent-pt (current-indentation)) | |
8728 (v2k (verilog-in-paren)) | |
8729 (modi (verilog-modi-current)) | |
8730 (sig-list (verilog-signals-not-in | |
8731 (verilog-modi-get-sub-inouts modi) | |
8732 (append (verilog-modi-get-outputs modi) | |
8733 (verilog-modi-get-inouts modi) | |
8734 (verilog-modi-get-inputs modi) | |
8735 (verilog-modi-get-sub-inputs modi) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8736 (verilog-modi-get-sub-outputs modi))))) |
79545 | 8737 (setq sig-list (verilog-signals-not-matching-regexp |
8738 sig-list verilog-auto-inout-ignore-regexp)) | |
8739 (forward-line 1) | |
8740 (when v2k (verilog-repair-open-comma)) | |
8741 (when sig-list | |
8742 (verilog-insert-indent "// Beginning of automatic inouts (from unused autoinst inouts)\n") | |
8743 (verilog-insert-definition sig-list "inout" indent-pt v2k) | |
8744 (verilog-modi-cache-add-inouts modi sig-list) | |
8745 (verilog-insert-indent "// End of automatics\n")) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8746 (when v2k (verilog-repair-close-comma))))) |
79545 | 8747 |
8748 (defun verilog-auto-inout-module () | |
8749 "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto]. | |
8750 Take input/output/inout statements from the specified module and insert | |
8751 into the current module. This is useful for making null templates and | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
8752 shell modules which need to have identical I/O with another module. |
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
8753 Any I/O which are already defined in this module will not be redefined. |
79545 | 8754 |
8755 Limitations: | |
8756 If placed inside the parenthesis of a module declaration, it creates | |
8757 Verilog 2001 style, else uses Verilog 1995 style. | |
8758 | |
8759 Concatenation and outputting partial busses is not supported. | |
8760 | |
8761 Module names must be resolvable to filenames. See `verilog-auto-inst'. | |
8762 | |
8763 Signals are not inserted in the same order as in the original module, | |
8764 though they will appear to be in the same order to a AUTOINST | |
8765 instantiating either module. | |
8766 | |
8767 An example: | |
8768 | |
8769 module ex_shell (/*AUTOARG*/) | |
8770 /*AUTOINOUTMODULE(\"ex_main\")*/ | |
8771 endmodule | |
8772 | |
8773 module ex_main (i,o,io) | |
8774 input i; | |
8775 output o; | |
8776 inout io; | |
8777 endmodule | |
8778 | |
8779 Typing \\[verilog-auto] will make this into: | |
8780 | |
8781 module ex_shell (/*AUTOARG*/i,o,io) | |
8782 /*AUTOINOUTMODULE(\"ex_main\")*/ | |
8783 // Beginning of automatic in/out/inouts (from specific module) | |
8784 input i; | |
8785 output o; | |
8786 inout io; | |
8787 // End of automatics | |
8788 endmodule" | |
8789 (save-excursion | |
8790 (let* ((submod (car (verilog-read-auto-params 1))) submodi) | |
8791 ;; Lookup position, etc of co-module | |
8792 ;; Note this may raise an error | |
8793 (when (setq submodi (verilog-modi-lookup submod t)) | |
8794 (let* ((indent-pt (current-indentation)) | |
8795 (v2k (verilog-in-paren)) | |
8796 (modi (verilog-modi-current)) | |
8797 (sig-list-i (verilog-signals-not-in | |
8798 (verilog-modi-get-inputs submodi) | |
8799 (append (verilog-modi-get-inputs modi)))) | |
8800 (sig-list-o (verilog-signals-not-in | |
8801 (verilog-modi-get-outputs submodi) | |
8802 (append (verilog-modi-get-outputs modi)))) | |
8803 (sig-list-io (verilog-signals-not-in | |
8804 (verilog-modi-get-inouts submodi) | |
8805 (append (verilog-modi-get-inouts modi))))) | |
8806 (forward-line 1) | |
8807 (when v2k (verilog-repair-open-comma)) | |
8808 (when (or sig-list-i sig-list-o sig-list-io) | |
8809 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n") | |
8810 ;; Don't sort them so a upper AUTOINST will match the main module | |
8811 (verilog-insert-definition sig-list-o "output" indent-pt v2k t) | |
8812 (verilog-insert-definition sig-list-io "inout" indent-pt v2k t) | |
8813 (verilog-insert-definition sig-list-i "input" indent-pt v2k t) | |
8814 (verilog-modi-cache-add-inputs modi sig-list-i) | |
8815 (verilog-modi-cache-add-outputs modi sig-list-o) | |
8816 (verilog-modi-cache-add-inouts modi sig-list-io) | |
8817 (verilog-insert-indent "// End of automatics\n")) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8818 (when v2k (verilog-repair-close-comma))))))) |
79545 | 8819 |
8820 (defun verilog-auto-sense-sigs (modi presense-sigs) | |
8821 "Return list of signals for current AUTOSENSE block." | |
8822 (let* ((sigss (verilog-read-always-signals)) | |
8823 (sig-list (verilog-signals-not-params | |
8824 (verilog-signals-not-in (verilog-alw-get-inputs sigss) | |
8825 (append (and (not verilog-auto-sense-include-inputs) | |
8826 (verilog-alw-get-outputs sigss)) | |
8827 (verilog-modi-get-consts modi) | |
8828 (verilog-modi-get-gparams modi) | |
8829 presense-sigs))))) | |
8830 sig-list)) | |
8831 | |
8832 (defun verilog-auto-sense () | |
8833 "Expand AUTOSENSE statements, as part of \\[verilog-auto]. | |
8834 Replace the always (/*AUTOSENSE*/) sensitivity list (/*AS*/ for short) | |
8835 with one automatically derived from all inputs declared in the always | |
8836 statement. Signals that are generated within the same always block are NOT | |
8837 placed into the sensitivity list (see `verilog-auto-sense-include-inputs'). | |
8838 Long lines are split based on the `fill-column', see \\[set-fill-column]. | |
8839 | |
8840 Limitations: | |
8841 Verilog does not allow memories (multidimensional arrays) in sensitivity | |
8842 lists. AUTOSENSE will thus exclude them, and add a /*memory or*/ comment. | |
8843 | |
8844 Constant signals: | |
8845 AUTOSENSE cannot always determine if a `define is a constant or a signal | |
8846 (it could be in a include file for example). If a `define or other signal | |
8847 is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT | |
8848 declaration anywhere in the module (parenthesis are required): | |
8849 | |
8850 /* AUTO_CONSTANT ( `this_is_really_constant_dont_autosense_it ) */ | |
8851 | |
8852 Better yet, use a parameter, which will be understood to be constant | |
8853 automatically. | |
8854 | |
8855 OOps! | |
8856 If AUTOSENSE makes a mistake, please report it. (First try putting | |
8857 a begin/end after your always!) As a workaround, if a signal that | |
8858 shouldn't be in the sensitivity list was, use the AUTO_CONSTANT above. | |
8859 If a signal should be in the sensitivity list wasn't, placing it before | |
8860 the /*AUTOSENSE*/ comment will prevent it from being deleted when the | |
8861 autos are updated (or added if it occurs there already). | |
8862 | |
8863 An example: | |
8864 | |
8865 always @ (/*AUTOSENSE*/) begin | |
8866 /* AUTO_CONSTANT (`constant) */ | |
8867 outin = ina | inb | `constant; | |
8868 out = outin; | |
8869 end | |
8870 | |
8871 Typing \\[verilog-auto] will make this into: | |
8872 | |
8873 always @ (/*AUTOSENSE*/ina or inb) begin | |
8874 /* AUTO_CONSTANT (`constant) */ | |
8875 outin = ina | inb | `constant; | |
8876 out = outin; | |
8877 end" | |
8878 (save-excursion | |
8879 ;; Find beginning | |
8880 (let* ((start-pt (save-excursion | |
8881 (verilog-re-search-backward "(" nil t) | |
8882 (point))) | |
8883 (indent-pt (save-excursion | |
8884 (or (and (goto-char start-pt) (1+ (current-column))) | |
8885 (current-indentation)))) | |
8886 (modi (verilog-modi-current)) | |
8887 (sig-memories (verilog-signals-memory | |
8888 (append | |
8889 (verilog-modi-get-regs modi) | |
8890 (verilog-modi-get-wires modi)))) | |
8891 sig-list not-first presense-sigs) | |
8892 ;; Read signals in always, eliminate outputs from sense list | |
8893 (setq presense-sigs (verilog-signals-from-signame | |
8894 (save-excursion | |
8895 (verilog-read-signals start-pt (point))))) | |
8896 (setq sig-list (verilog-auto-sense-sigs modi presense-sigs)) | |
8897 (when sig-memories | |
8898 (let ((tlen (length sig-list))) | |
8899 (setq sig-list (verilog-signals-not-in sig-list sig-memories)) | |
8900 (if (not (eq tlen (length sig-list))) (insert " /*memory or*/ ")))) | |
8901 (if (and presense-sigs ;; Add a "or" if not "(.... or /*AUTOSENSE*/" | |
8902 (save-excursion (goto-char (point)) | |
8903 (verilog-re-search-backward "[a-zA-Z0-9$_.%`]+" start-pt t) | |
8904 (verilog-re-search-backward "\\s-" start-pt t) | |
8905 (while (looking-at "\\s-`endif") | |
8906 (verilog-re-search-backward "[a-zA-Z0-9$_.%`]+" start-pt t) | |
8907 (verilog-re-search-backward "\\s-" start-pt t)) | |
8908 (not (looking-at "\\s-or\\b")))) | |
8909 (setq not-first t)) | |
8910 (setq sig-list (sort sig-list `verilog-signals-sort-compare)) | |
8911 (while sig-list | |
8912 (cond ((> (+ 4 (current-column) (length (verilog-sig-name (car sig-list)))) fill-column) ;+4 for width of or | |
8913 (insert "\n") | |
8914 (indent-to indent-pt) | |
8915 (if not-first (insert "or "))) | |
8916 (not-first (insert " or "))) | |
8917 (insert (verilog-sig-name (car sig-list))) | |
8918 (setq sig-list (cdr sig-list) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8919 not-first t))))) |
79545 | 8920 |
8921 (defun verilog-auto-reset () | |
8922 "Expand AUTORESET statements, as part of \\[verilog-auto]. | |
8923 Replace the /*AUTORESET*/ comment with code to initialize all | |
8924 registers set elsewhere in the always block. | |
8925 | |
8926 Limitations: | |
8927 AUTORESET will not clear memories. | |
8928 | |
8929 AUTORESET uses <= if there are any <= in the block, else it uses =. | |
8930 | |
8931 /*AUTORESET*/ presumes that any signals mentioned between the previous | |
8932 begin/case/if statement and the AUTORESET comment are being reset manually | |
8933 and should not be automatically reset. This includes omitting any signals | |
8934 used on the right hand side of assignments. | |
8935 | |
8936 By default, AUTORESET will include the width of the signal in the autos, | |
8937 this is a recent change. To control this behavior, see | |
8938 `verilog-auto-reset-widths'. | |
8939 | |
8940 AUTORESET ties signals to deasserted, which is presumed to be zero. | |
8941 Signals that match `verilog-active-low-regexp' will be deasserted by tieing | |
8942 them to a one. | |
8943 | |
8944 An example: | |
8945 | |
8946 always @(posedge clk or negedge reset_l) begin | |
8947 if (!reset_l) begin | |
8948 c <= 1; | |
8949 /*AUTORESET*/ | |
8950 end | |
8951 else begin | |
8952 a <= in_a; | |
8953 b <= in_b; | |
8954 c <= in_c; | |
8955 end | |
8956 end | |
8957 | |
8958 Typing \\[verilog-auto] will make this into: | |
8959 | |
8960 always @(posedge core_clk or negedge reset_l) begin | |
8961 if (!reset_l) begin | |
8962 c <= 1; | |
8963 /*AUTORESET*/ | |
8964 // Beginning of autoreset for uninitialized flops | |
8965 a <= 0; | |
8966 b <= 0; | |
8967 // End of automatics | |
8968 end | |
8969 else begin | |
8970 a <= in_a; | |
8971 b <= in_b; | |
8972 c <= in_c; | |
8973 end | |
8974 end" | |
8975 | |
8976 (interactive) | |
8977 (save-excursion | |
8978 ;; Find beginning | |
8979 (let* ((indent-pt (current-indentation)) | |
8980 (modi (verilog-modi-current)) | |
8981 (all-list (verilog-modi-get-signals modi)) | |
8982 sigss sig-list prereset-sigs assignment-str) | |
8983 ;; Read signals in always, eliminate outputs from reset list | |
8984 (setq prereset-sigs (verilog-signals-from-signame | |
8985 (save-excursion | |
8986 (verilog-read-signals | |
8987 (save-excursion | |
8988 (verilog-re-search-backward "\\(@\\|\\<begin\\>\\|\\<if\\>\\|\\<case\\>\\)" nil t) | |
8989 (point)) | |
8990 (point))))) | |
8991 (save-excursion | |
8992 (verilog-re-search-backward "@" nil t) | |
8993 (setq sigss (verilog-read-always-signals))) | |
8994 (setq assignment-str (if (verilog-alw-get-uses-delayed sigss) | |
8995 (concat " <= " verilog-assignment-delay) | |
8996 " = ")) | |
8997 (setq sig-list (verilog-signals-not-in (verilog-alw-get-outputs sigss) | |
8998 prereset-sigs)) | |
8999 (setq sig-list (sort sig-list `verilog-signals-sort-compare)) | |
9000 (when sig-list | |
9001 (insert "\n"); | |
9002 (indent-to indent-pt) | |
9003 (insert "// Beginning of autoreset for uninitialized flops\n"); | |
9004 (indent-to indent-pt) | |
9005 (while sig-list | |
9006 (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ;; As sig-list has no widths | |
9007 (car sig-list)))) | |
9008 (insert (verilog-sig-name sig) | |
9009 assignment-str | |
9010 (verilog-sig-tieoff sig (not verilog-auto-reset-widths)) | |
9011 ";\n") | |
9012 (indent-to indent-pt) | |
9013 (setq sig-list (cdr sig-list)))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9014 (insert "// End of automatics"))))) |
79545 | 9015 |
9016 (defun verilog-auto-tieoff () | |
9017 "Expand AUTOTIEOFF statements, as part of \\[verilog-auto]. | |
9018 Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output | |
9019 signals to deasserted. | |
9020 | |
9021 /*AUTOTIEOFF*/ is used to make stub modules; modules that have the same | |
9022 input/output list as another module, but no internals. Specifically, it | |
9023 finds all outputs in the module, and if that input is not otherwise declared | |
9024 as a register or wire, creates a tieoff. | |
9025 | |
9026 AUTORESET ties signals to deasserted, which is presumed to be zero. | |
9027 Signals that match `verilog-active-low-regexp' will be deasserted by tieing | |
9028 them to a one. | |
9029 | |
9030 An example of making a stub for another module: | |
9031 | |
9032 module FooStub (/*AUTOINST*/); | |
9033 /*AUTOINOUTMODULE(\"Foo\")*/ | |
9034 /*AUTOTIEOFF*/ | |
9035 // verilator lint_off UNUSED | |
9036 wire _unused_ok = &{1'b0, | |
9037 /*AUTOUNUSED*/ | |
9038 1'b0}; | |
9039 // verilator lint_on UNUSED | |
9040 endmodule | |
9041 | |
9042 Typing \\[verilog-auto] will make this into: | |
9043 | |
9044 module FooStub (/*AUTOINST*/...); | |
9045 /*AUTOINOUTMODULE(\"Foo\")*/ | |
9046 // Beginning of autotieoff | |
9047 output [2:0] foo; | |
9048 // End of automatics | |
9049 | |
9050 /*AUTOTIEOFF*/ | |
9051 // Beginning of autotieoff | |
9052 wire [2:0] foo = 3'b0; | |
9053 // End of automatics | |
9054 ... | |
9055 endmodule" | |
9056 (interactive) | |
9057 (save-excursion | |
9058 ;; Find beginning | |
9059 (let* ((indent-pt (current-indentation)) | |
9060 (modi (verilog-modi-current)) | |
9061 (sig-list (verilog-signals-not-in | |
9062 (verilog-modi-get-outputs modi) | |
9063 (append (verilog-modi-get-wires modi) | |
9064 (verilog-modi-get-regs modi) | |
9065 (verilog-modi-get-assigns modi) | |
9066 (verilog-modi-get-consts modi) | |
9067 (verilog-modi-get-gparams modi) | |
9068 (verilog-modi-get-sub-outputs modi) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9069 (verilog-modi-get-sub-inouts modi))))) |
79545 | 9070 (when sig-list |
9071 (forward-line 1) | |
9072 (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n") | |
9073 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)) | |
9074 (verilog-modi-cache-add-wires modi sig-list) ; Before we trash list | |
9075 (while sig-list | |
9076 (let ((sig (car sig-list))) | |
9077 (verilog-insert-one-definition sig "wire" indent-pt) | |
9078 (indent-to (max 48 (+ indent-pt 40))) | |
9079 (insert "= " (verilog-sig-tieoff sig) | |
9080 ";\n") | |
9081 (setq sig-list (cdr sig-list)))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9082 (verilog-insert-indent "// End of automatics\n"))))) |
79545 | 9083 |
9084 (defun verilog-auto-unused () | |
9085 "Expand AUTOUNUSED statements, as part of \\[verilog-auto]. | |
9086 Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused | |
9087 input and inout signals. | |
9088 | |
9089 /*AUTOUNUSED*/ is used to make stub modules; modules that have the same | |
9090 input/output list as another module, but no internals. Specifically, it | |
9091 finds all inputs and inouts in the module, and if that input is not otherwise | |
9092 used, adds it to a comma separated list. | |
9093 | |
9094 The comma separated list is intended to be used to create a _unused_ok | |
9095 signal. Using the exact name \"_unused_ok\" for name of the temporary | |
9096 signal is recommended as it will insure maximum forward compatibility, it | |
9097 also makes lint warnings easy to understand; ignore any unused warnings | |
9098 with \"unused\" in the signal name. | |
9099 | |
9100 To reduce simulation time, the _unused_ok signal should be forced to a | |
9101 constant to prevent wiggling. The easiest thing to do is use a | |
9102 reduction-and with 1'b0 as shown. | |
9103 | |
9104 This way all unused signals are in one place, making it convenient to add | |
9105 your tool's specific pragmas around the assignment to disable any unused | |
9106 warnings. | |
9107 | |
9108 You can add signals you do not want included in AUTOUNUSED with | |
9109 `verilog-auto-unused-ignore-regexp'. | |
9110 | |
9111 An example of making a stub for another module: | |
9112 | |
9113 module FooStub (/*AUTOINST*/); | |
9114 /*AUTOINOUTMODULE(\"Foo\")*/ | |
9115 /*AUTOTIEOFF*/ | |
9116 // verilator lint_off UNUSED | |
9117 wire _unused_ok = &{1'b0, | |
9118 /*AUTOUNUSED*/ | |
9119 1'b0}; | |
9120 // verilator lint_on UNUSED | |
9121 endmodule | |
9122 | |
9123 Typing \\[verilog-auto] will make this into: | |
9124 | |
9125 ... | |
9126 // verilator lint_off UNUSED | |
9127 wire _unused_ok = &{1'b0, | |
9128 /*AUTOUNUSED*/ | |
9129 // Beginning of automatics | |
9130 unused_input_a, | |
9131 unused_input_b, | |
9132 unused_input_c, | |
9133 // End of automatics | |
9134 1'b0}; | |
9135 // verilator lint_on UNUSED | |
9136 endmodule" | |
9137 (interactive) | |
9138 (save-excursion | |
9139 ;; Find beginning | |
9140 (let* ((indent-pt (progn (search-backward "/*") (current-column))) | |
9141 (modi (verilog-modi-current)) | |
9142 (sig-list (verilog-signals-not-in | |
9143 (append (verilog-modi-get-inputs modi) | |
9144 (verilog-modi-get-inouts modi)) | |
9145 (append (verilog-modi-get-sub-inputs modi) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9146 (verilog-modi-get-sub-inouts modi))))) |
79545 | 9147 (setq sig-list (verilog-signals-not-matching-regexp |
9148 sig-list verilog-auto-unused-ignore-regexp)) | |
9149 (when sig-list | |
9150 (forward-line 1) | |
9151 (verilog-insert-indent "// Beginning of automatic unused inputs\n") | |
9152 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)) | |
9153 (while sig-list | |
9154 (let ((sig (car sig-list))) | |
9155 (indent-to indent-pt) | |
9156 (insert (verilog-sig-name sig) ",\n") | |
9157 (setq sig-list (cdr sig-list)))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9158 (verilog-insert-indent "// End of automatics\n"))))) |
79545 | 9159 |
9160 (defun verilog-enum-ascii (signm elim-regexp) | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
9161 "Convert an enum name SIGNM to an ascii string for insertion. |
79545 | 9162 Remove user provided prefix ELIM-REGEXP." |
9163 (or elim-regexp (setq elim-regexp "_ DONT MATCH IT_")) | |
9164 (let ((case-fold-search t)) | |
9165 ;; All upper becomes all lower for readability | |
9166 (downcase (verilog-string-replace-matches elim-regexp "" nil nil signm)))) | |
9167 | |
9168 (defun verilog-auto-ascii-enum () | |
9169 "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto]. | |
9170 Create a register to contain the ASCII decode of a enumerated signal type. | |
9171 This will allow trace viewers to show the ASCII name of states. | |
9172 | |
9173 First, parameters are built into a enumeration using the synopsys enum | |
9174 comment. The comment must be between the keyword and the symbol. | |
79546 | 9175 \(Annoying, but that's what Synopsys's dc_shell FSM reader requires.) |
79545 | 9176 |
9177 Next, registers which that enum applies to are also tagged with the same | |
9178 enum. Synopsys also suggests labeling state vectors, but `verilog-mode' | |
9179 doesn't care. | |
9180 | |
9181 Finally, a AUTOASCIIENUM command is used. | |
9182 | |
9183 The first parameter is the name of the signal to be decoded. | |
9184 | |
9185 The second parameter is the name to store the ASCII code into. For the | |
9186 signal foo, I suggest the name _foo__ascii, where the leading _ indicates | |
9187 a signal that is just for simulation, and the magic characters _ascii | |
9188 tell viewers like Dinotrace to display in ASCII format. | |
9189 | |
9190 The final optional parameter is a string which will be removed from the | |
9191 state names. | |
9192 | |
9193 An example: | |
9194 | |
9195 //== State enumeration | |
9196 parameter [2:0] // synopsys enum state_info | |
9197 SM_IDLE = 3'b000, | |
9198 SM_SEND = 3'b001, | |
9199 SM_WAIT1 = 3'b010; | |
9200 //== State variables | |
9201 reg [2:0] /* synopsys enum state_info */ | |
9202 state_r; /* synopsys state_vector state_r */ | |
9203 reg [2:0] /* synopsys enum state_info */ | |
9204 state_e1; | |
9205 | |
9206 //== ASCII state decoding | |
9207 | |
9208 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/ | |
9209 | |
9210 Typing \\[verilog-auto] will make this into: | |
9211 | |
9212 ... same front matter ... | |
9213 | |
9214 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/ | |
9215 // Beginning of automatic ASCII enum decoding | |
9216 reg [39:0] state_ascii_r; // Decode of state_r | |
9217 always @(state_r) begin | |
9218 case ({state_r}) | |
9219 SM_IDLE: state_ascii_r = \"idle \"; | |
9220 SM_SEND: state_ascii_r = \"send \"; | |
9221 SM_WAIT1: state_ascii_r = \"wait1\"; | |
9222 default: state_ascii_r = \"%Erro\"; | |
9223 endcase | |
9224 end | |
9225 // End of automatics" | |
9226 (save-excursion | |
9227 (let* ((params (verilog-read-auto-params 2 3)) | |
9228 (undecode-name (nth 0 params)) | |
9229 (ascii-name (nth 1 params)) | |
9230 (elim-regexp (nth 2 params)) | |
9231 ;; | |
9232 (indent-pt (current-indentation)) | |
9233 (modi (verilog-modi-current)) | |
9234 ;; | |
9235 (sig-list-consts (append (verilog-modi-get-consts modi) | |
9236 (verilog-modi-get-gparams modi))) | |
9237 (sig-list-all (append (verilog-modi-get-regs modi) | |
9238 (verilog-modi-get-outputs modi) | |
9239 (verilog-modi-get-inouts modi) | |
9240 (verilog-modi-get-inputs modi) | |
9241 (verilog-modi-get-wires modi))) | |
9242 ;; | |
9243 (undecode-sig (or (assoc undecode-name sig-list-all) | |
9244 (error "%s: Signal %s not found in design" (verilog-point-text) undecode-name))) | |
9245 (undecode-enum (or (verilog-sig-enum undecode-sig) | |
9246 (error "%s: Signal %s does not have a enum tag" (verilog-point-text) undecode-name))) | |
9247 ;; | |
9248 (enum-sigs (or (verilog-signals-matching-enum sig-list-consts undecode-enum) | |
9249 (error "%s: No state definitions for %s" (verilog-point-text) undecode-enum))) | |
9250 ;; | |
9251 (enum-chars 0) | |
9252 (ascii-chars 0)) | |
9253 ;; | |
9254 ;; Find number of ascii chars needed | |
9255 (let ((tmp-sigs enum-sigs)) | |
9256 (while tmp-sigs | |
9257 (setq enum-chars (max enum-chars (length (verilog-sig-name (car tmp-sigs)))) | |
9258 ascii-chars (max ascii-chars (length (verilog-enum-ascii | |
9259 (verilog-sig-name (car tmp-sigs)) | |
9260 elim-regexp))) | |
9261 tmp-sigs (cdr tmp-sigs)))) | |
9262 ;; | |
9263 (forward-line 1) | |
9264 (verilog-insert-indent "// Beginning of automatic ASCII enum decoding\n") | |
9265 (let ((decode-sig-list (list (list ascii-name (format "[%d:0]" (- (* ascii-chars 8) 1)) | |
9266 (concat "Decode of " undecode-name) nil nil)))) | |
9267 (verilog-insert-definition decode-sig-list "reg" indent-pt nil) | |
9268 (verilog-modi-cache-add-regs modi decode-sig-list)) | |
9269 ;; | |
9270 (verilog-insert-indent "always @(" undecode-name ") begin\n") | |
9271 (setq indent-pt (+ indent-pt verilog-indent-level)) | |
9272 (indent-to indent-pt) | |
9273 (insert "case ({" undecode-name "})\n") | |
9274 (setq indent-pt (+ indent-pt verilog-case-indent)) | |
9275 ;; | |
9276 (let ((tmp-sigs enum-sigs) | |
9277 (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n" (1+ (max 8 enum-chars)) | |
9278 ascii-name ascii-chars)) | |
9279 (errname (substring "%Error" 0 (min 6 ascii-chars)))) | |
9280 (while tmp-sigs | |
9281 (verilog-insert-indent | |
9282 (format chrfmt (concat (verilog-sig-name (car tmp-sigs)) ":") | |
9283 (verilog-enum-ascii (verilog-sig-name (car tmp-sigs)) | |
9284 elim-regexp))) | |
9285 (setq tmp-sigs (cdr tmp-sigs))) | |
9286 (verilog-insert-indent (format chrfmt "default:" errname))) | |
9287 ;; | |
9288 (setq indent-pt (- indent-pt verilog-case-indent)) | |
9289 (verilog-insert-indent "endcase\n") | |
9290 (setq indent-pt (- indent-pt verilog-indent-level)) | |
9291 (verilog-insert-indent "end\n" | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9292 "// End of automatics\n")))) |
79545 | 9293 |
9294 (defun verilog-auto-templated-rel () | |
9295 "Replace Templated relative line numbers with absolute line numbers. | |
9296 Internal use only. This hacks around the line numbers in AUTOINST Templates | |
9297 being different from the final output's line numbering." | |
9298 (let ((templateno 0) (template-line (list 0))) | |
9299 ;; Find line number each template is on | |
9300 (goto-char (point-min)) | |
9301 (while (search-forward "AUTO_TEMPLATE" nil t) | |
9302 (setq templateno (1+ templateno)) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9303 (setq template-line |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9304 (cons (count-lines (point-min) (point)) template-line))) |
79545 | 9305 (setq template-line (nreverse template-line)) |
9306 ;; Replace T# L# with absolute line number | |
9307 (goto-char (point-min)) | |
9308 (while (re-search-forward " Templated T\\([0-9]+\\) L\\([0-9]+\\)" nil t) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9309 (replace-match |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9310 (concat " Templated " |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9311 (int-to-string (+ (nth (string-to-number (match-string 1)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9312 template-line) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9313 (string-to-number (match-string 2))))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9314 t t)))) |
79545 | 9315 |
9316 | |
9317 ;; | |
9318 ;; Auto top level | |
9319 ;; | |
9320 | |
9321 (defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing a arg | |
9322 "Expand AUTO statements. | |
9323 Look for any /*AUTO...*/ commands in the code, as used in | |
9324 instantiations or argument headers. Update the list of signals | |
9325 following the /*AUTO...*/ command. | |
9326 | |
9327 Use \\[verilog-delete-auto] to remove the AUTOs. | |
9328 | |
9329 Use \\[verilog-inject-auto] to insert AUTOs for the first time. | |
9330 | |
9331 Use \\[verilog-faq] for a pointer to frequently asked questions. | |
9332 | |
9333 The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are | |
9334 called before and after this function, respectively. | |
9335 | |
9336 For example: | |
9337 module (/*AUTOARG*/) | |
9338 /*AUTOINPUT*/ | |
9339 /*AUTOOUTPUT*/ | |
9340 /*AUTOWIRE*/ | |
9341 /*AUTOREG*/ | |
9342 somesub sub #(/*AUTOINSTPARAM*/) (/*AUTOINST*/); | |
9343 | |
9344 You can also update the AUTOs from the shell using: | |
9345 emacs --batch <filenames.v> -f verilog-batch-auto | |
9346 Or fix indentation with: | |
9347 emacs --batch <filenames.v> -f verilog-batch-indent | |
9348 Likewise, you can delete or inject AUTOs with: | |
9349 emacs --batch <filenames.v> -f verilog-batch-delete-auto | |
9350 emacs --batch <filenames.v> -f verilog-batch-inject-auto | |
9351 | |
9352 Using \\[describe-function], see also: | |
9353 `verilog-auto-arg' for AUTOARG module instantiations | |
9354 `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding | |
9355 `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere | |
9356 `verilog-auto-inout' for AUTOINOUT making hierarchy inouts | |
9357 `verilog-auto-input' for AUTOINPUT making hierarchy inputs | |
9358 `verilog-auto-inst' for AUTOINST instantiation pins | |
9359 `verilog-auto-star' for AUTOINST .* SystemVerilog pins | |
9360 `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params | |
9361 `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs | |
9362 `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs | |
9363 `verilog-auto-reg' for AUTOREG registers | |
9364 `verilog-auto-reg-input' for AUTOREGINPUT instantiation registers | |
9365 `verilog-auto-reset' for AUTORESET flop resets | |
9366 `verilog-auto-sense' for AUTOSENSE always sensitivity lists | |
9367 `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs | |
9368 `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts | |
9369 `verilog-auto-wire' for AUTOWIRE instantiation wires | |
9370 | |
9371 `verilog-read-defines' for reading `define values | |
9372 `verilog-read-includes' for reading `includes | |
9373 | |
9374 If you have bugs with these autos, try contacting the AUTOAUTHOR | |
9375 Wilson Snyder (wsnyder@wsnyder.org), and/or see http://www.veripool.com." | |
9376 (interactive) | |
9377 (unless noninteractive (message "Updating AUTOs...")) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9378 (if (fboundp 'dinotrace-unannotate-all) |
79545 | 9379 (dinotrace-unannotate-all)) |
9380 (let ((oldbuf (if (not (buffer-modified-p)) | |
9381 (buffer-string))) | |
9382 ;; Before version 20, match-string with font-lock returns a | |
9383 ;; vector that is not equal to the string. IE if on "input" | |
9384 ;; nil==(equal "input" (progn (looking-at "input") (match-string 0))) | |
9385 (fontlocked (when (and (boundp 'font-lock-mode) | |
9386 font-lock-mode) | |
9387 (font-lock-mode nil) | |
9388 t))) | |
9389 (unwind-protect | |
9390 (save-excursion | |
9391 ;; If we're not in verilog-mode, change syntax table so parsing works right | |
9392 (unless (eq major-mode `verilog-mode) (verilog-mode)) | |
9393 ;; Allow user to customize | |
9394 (run-hooks 'verilog-before-auto-hook) | |
9395 ;; Try to save the user from needing to revert-file to reread file local-variables | |
9396 (verilog-auto-reeval-locals) | |
9397 (verilog-read-auto-lisp (point-min) (point-max)) | |
9398 (verilog-getopt-flags) | |
9399 ;; These two may seem obvious to do always, but on large includes it can be way too slow | |
9400 (when verilog-auto-read-includes | |
9401 (verilog-read-includes) | |
9402 (verilog-read-defines nil nil t)) | |
9403 ;; This particular ordering is important | |
9404 ;; INST: Lower modules correct, no internal dependencies, FIRST | |
9405 (verilog-preserve-cache | |
9406 ;; Clear existing autos else we'll be screwed by existing ones | |
9407 (verilog-delete-auto) | |
9408 ;; Injection if appropriate | |
9409 (when inject | |
9410 (verilog-inject-inst) | |
9411 (verilog-inject-sense) | |
9412 (verilog-inject-arg)) | |
9413 ;; | |
9414 (verilog-auto-search-do "/*AUTOINSTPARAM*/" 'verilog-auto-inst-param) | |
9415 (verilog-auto-search-do "/*AUTOINST*/" 'verilog-auto-inst) | |
9416 (verilog-auto-search-do ".*" 'verilog-auto-star) | |
9417 ;; Doesn't matter when done, but combine it with a common changer | |
9418 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense) | |
9419 (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset) | |
9420 ;; Must be done before autoin/out as creates a reg | |
9421 (verilog-auto-re-search-do "/\\*AUTOASCIIENUM([^)]*)\\*/" 'verilog-auto-ascii-enum) | |
9422 ;; | |
9423 ;; first in/outs from other files | |
9424 (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE([^)]*)\\*/" 'verilog-auto-inout-module) | |
9425 ;; next in/outs which need previous sucked inputs first | |
9426 (verilog-auto-search-do "/*AUTOOUTPUT*/" 'verilog-auto-output) | |
9427 (verilog-auto-search-do "/*AUTOINPUT*/" 'verilog-auto-input) | |
9428 (verilog-auto-search-do "/*AUTOINOUT*/" 'verilog-auto-inout) | |
9429 ;; Then tie off those in/outs | |
9430 (verilog-auto-search-do "/*AUTOTIEOFF*/" 'verilog-auto-tieoff) | |
9431 ;; Wires/regs must be after inputs/outputs | |
9432 (verilog-auto-search-do "/*AUTOWIRE*/" 'verilog-auto-wire) | |
9433 (verilog-auto-search-do "/*AUTOREG*/" 'verilog-auto-reg) | |
9434 (verilog-auto-search-do "/*AUTOREGINPUT*/" 'verilog-auto-reg-input) | |
9435 ;; outputevery needs AUTOOUTPUTs done first | |
9436 (verilog-auto-search-do "/*AUTOOUTPUTEVERY*/" 'verilog-auto-output-every) | |
9437 ;; After we've created all new variables | |
9438 (verilog-auto-search-do "/*AUTOUNUSED*/" 'verilog-auto-unused) | |
9439 ;; Must be after all inputs outputs are generated | |
9440 (verilog-auto-search-do "/*AUTOARG*/" 'verilog-auto-arg) | |
9441 ;; Fix line numbers (comments only) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9442 (verilog-auto-templated-rel)) |
79545 | 9443 ;; |
9444 (run-hooks 'verilog-auto-hook) | |
9445 ;; | |
9446 (set (make-local-variable 'verilog-auto-update-tick) (buffer-modified-tick)) | |
9447 ;; | |
9448 ;; If end result is same as when started, clear modified flag | |
9449 (cond ((and oldbuf (equal oldbuf (buffer-string))) | |
9450 (set-buffer-modified-p nil) | |
9451 (unless noninteractive (message "Updating AUTOs...done (no changes)"))) | |
9452 (t (unless noninteractive (message "Updating AUTOs...done"))))) | |
9453 ;; Unwind forms | |
9454 (progn | |
9455 ;; Restore font-lock | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9456 (when fontlocked (font-lock-mode t)))))) |
79545 | 9457 |
9458 | |
9459 ;; | |
9460 ;; Skeleton based code insertion | |
9461 ;; | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9462 (defvar verilog-template-map |
79546 | 9463 (let ((map (make-sparse-keymap))) |
9464 (define-key map "a" 'verilog-sk-always) | |
9465 (define-key map "b" 'verilog-sk-begin) | |
9466 (define-key map "c" 'verilog-sk-case) | |
9467 (define-key map "f" 'verilog-sk-for) | |
9468 (define-key map "g" 'verilog-sk-generate) | |
9469 (define-key map "h" 'verilog-sk-header) | |
9470 (define-key map "i" 'verilog-sk-initial) | |
9471 (define-key map "j" 'verilog-sk-fork) | |
9472 (define-key map "m" 'verilog-sk-module) | |
9473 (define-key map "p" 'verilog-sk-primitive) | |
9474 (define-key map "r" 'verilog-sk-repeat) | |
9475 (define-key map "s" 'verilog-sk-specify) | |
9476 (define-key map "t" 'verilog-sk-task) | |
9477 (define-key map "w" 'verilog-sk-while) | |
9478 (define-key map "x" 'verilog-sk-casex) | |
9479 (define-key map "z" 'verilog-sk-casez) | |
9480 (define-key map "?" 'verilog-sk-if) | |
9481 (define-key map ":" 'verilog-sk-else-if) | |
9482 (define-key map "/" 'verilog-sk-comment) | |
9483 (define-key map "A" 'verilog-sk-assign) | |
9484 (define-key map "F" 'verilog-sk-function) | |
9485 (define-key map "I" 'verilog-sk-input) | |
9486 (define-key map "O" 'verilog-sk-output) | |
9487 (define-key map "S" 'verilog-sk-state-machine) | |
9488 (define-key map "=" 'verilog-sk-inout) | |
9489 (define-key map "W" 'verilog-sk-wire) | |
9490 (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
|
9491 (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
|
9492 map) |
79545 | 9493 "Keymap used in Verilog mode for smart template operations.") |
9494 | |
9495 | |
9496 ;; | |
9497 ;; Place the templates into Verilog Mode. They may be inserted under any key. | |
9498 ;; C-c C-t will be the default. If you use templates a lot, you | |
9499 ;; may want to consider moving the binding to another key in your .emacs | |
9500 ;; file. | |
9501 ;; | |
9502 ;(define-key verilog-mode-map "\C-ct" verilog-template-map) | |
9503 (define-key verilog-mode-map "\C-c\C-t" verilog-template-map) | |
9504 | |
9505 ;;; ---- statement skeletons ------------------------------------------ | |
9506 | |
9507 (define-skeleton verilog-sk-prompt-condition | |
9508 "Prompt for the loop condition." | |
9509 "[condition]: " str ) | |
9510 | |
9511 (define-skeleton verilog-sk-prompt-init | |
9512 "Prompt for the loop init statement." | |
9513 "[initial statement]: " str ) | |
9514 | |
9515 (define-skeleton verilog-sk-prompt-inc | |
9516 "Prompt for the loop increment statement." | |
9517 "[increment statement]: " str ) | |
9518 | |
9519 (define-skeleton verilog-sk-prompt-name | |
9520 "Prompt for the name of something." | |
9521 "[name]: " str) | |
9522 | |
9523 (define-skeleton verilog-sk-prompt-clock | |
9524 "Prompt for the name of something." | |
9525 "name and edge of clock(s): " str) | |
9526 | |
9527 (defvar verilog-sk-reset nil) | |
9528 (defun verilog-sk-prompt-reset () | |
9529 "Prompt for the name of a state machine reset." | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9530 (setq verilog-sk-reset (read-string "name of reset: " "rst"))) |
79545 | 9531 |
9532 | |
9533 (define-skeleton verilog-sk-prompt-state-selector | |
9534 "Prompt for the name of a state machine selector." | |
9535 "name of selector (eg {a,b,c,d}): " str ) | |
9536 | |
9537 (define-skeleton verilog-sk-prompt-output | |
9538 "Prompt for the name of something." | |
9539 "output: " str) | |
9540 | |
9541 (define-skeleton verilog-sk-prompt-msb | |
9542 "Prompt for least significant bit specification." | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9543 "msb:" str & ?: & '(verilog-sk-prompt-lsb) | -1 ) |
79545 | 9544 |
9545 (define-skeleton verilog-sk-prompt-lsb | |
9546 "Prompt for least significant bit specification." | |
9547 "lsb:" str ) | |
9548 | |
9549 (defvar verilog-sk-p nil) | |
9550 (define-skeleton verilog-sk-prompt-width | |
9551 "Prompt for a width specification." | |
9552 () | |
9553 (progn | |
9554 (setq verilog-sk-p (point)) | |
9555 (verilog-sk-prompt-msb) | |
9556 (if (> (point) verilog-sk-p) "] " " "))) | |
9557 | |
9558 (defun verilog-sk-header () | |
9559 "Insert a descriptive header at the top of the file." | |
9560 (interactive "*") | |
9561 (save-excursion | |
9562 (goto-char (point-min)) | |
9563 (verilog-sk-header-tmpl))) | |
9564 | |
9565 (define-skeleton verilog-sk-header-tmpl | |
9566 "Insert a comment block containing the module title, author, etc." | |
9567 "[Description]: " | |
9568 "// -*- Mode: Verilog -*-" | |
9569 "\n// Filename : " (buffer-name) | |
9570 "\n// Description : " str | |
9571 "\n// Author : " (user-full-name) | |
9572 "\n// Created On : " (current-time-string) | |
9573 "\n// Last Modified By: ." | |
9574 "\n// Last Modified On: ." | |
9575 "\n// Update Count : 0" | |
9576 "\n// Status : Unknown, Use with caution!" | |
9577 "\n") | |
9578 | |
9579 (define-skeleton verilog-sk-module | |
9580 "Insert a module definition." | |
9581 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9582 > "module " '(verilog-sk-prompt-name) " (/*AUTOARG*/ ) ;" \n |
79545 | 9583 > _ \n |
9584 > (- verilog-indent-level-behavioral) "endmodule" (progn (electric-verilog-terminate-line) nil)) | |
9585 | |
9586 (define-skeleton verilog-sk-primitive | |
9587 "Insert a task definition." | |
9588 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9589 > "primitive " '(verilog-sk-prompt-name) " ( " '(verilog-sk-prompt-output) ("input:" ", " str ) " );"\n |
79545 | 9590 > _ \n |
9591 > (- verilog-indent-level-behavioral) "endprimitive" (progn (electric-verilog-terminate-line) nil)) | |
9592 | |
9593 (define-skeleton verilog-sk-task | |
9594 "Insert a task definition." | |
9595 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9596 > "task " '(verilog-sk-prompt-name) & ?; \n |
79545 | 9597 > _ \n |
9598 > "begin" \n | |
9599 > \n | |
9600 > (- verilog-indent-level-behavioral) "end" \n | |
9601 > (- verilog-indent-level-behavioral) "endtask" (progn (electric-verilog-terminate-line) nil)) | |
9602 | |
9603 (define-skeleton verilog-sk-function | |
9604 "Insert a function definition." | |
9605 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9606 > "function [" '(verilog-sk-prompt-width) | -1 '(verilog-sk-prompt-name) ?; \n |
79545 | 9607 > _ \n |
9608 > "begin" \n | |
9609 > \n | |
9610 > (- verilog-indent-level-behavioral) "end" \n | |
9611 > (- verilog-indent-level-behavioral) "endfunction" (progn (electric-verilog-terminate-line) nil)) | |
9612 | |
9613 (define-skeleton verilog-sk-always | |
9614 "Insert always block. Uses the minibuffer to prompt | |
9615 for sensitivity list." | |
9616 () | |
9617 > "always @ ( /*AUTOSENSE*/ ) begin\n" | |
9618 > _ \n | |
9619 > (- verilog-indent-level-behavioral) "end" \n > | |
9620 ) | |
9621 | |
9622 (define-skeleton verilog-sk-initial | |
9623 "Insert an initial block." | |
9624 () | |
9625 > "initial begin\n" | |
9626 > _ \n | |
9627 > (- verilog-indent-level-behavioral) "end" \n > ) | |
9628 | |
9629 (define-skeleton verilog-sk-specify | |
9630 "Insert specify block. " | |
9631 () | |
9632 > "specify\n" | |
9633 > _ \n | |
9634 > (- verilog-indent-level-behavioral) "endspecify" \n > ) | |
9635 | |
9636 (define-skeleton verilog-sk-generate | |
9637 "Insert generate block. " | |
9638 () | |
9639 > "generate\n" | |
9640 > _ \n | |
9641 > (- verilog-indent-level-behavioral) "endgenerate" \n > ) | |
9642 | |
9643 (define-skeleton verilog-sk-begin | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
9644 "Insert begin end block. Uses the minibuffer to prompt for name." |
79545 | 9645 () |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9646 > "begin" '(verilog-sk-prompt-name) \n |
79545 | 9647 > _ \n |
9648 > (- verilog-indent-level-behavioral) "end" | |
9649 ) | |
9650 | |
9651 (define-skeleton verilog-sk-fork | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
9652 "Insert a fork join block." |
79545 | 9653 () |
9654 > "fork\n" | |
9655 > "begin" \n | |
9656 > _ \n | |
9657 > (- verilog-indent-level-behavioral) "end" \n | |
9658 > "begin" \n | |
9659 > \n | |
9660 > (- verilog-indent-level-behavioral) "end" \n | |
9661 > (- verilog-indent-level-behavioral) "join" \n | |
9662 > ) | |
9663 | |
9664 | |
9665 (define-skeleton verilog-sk-case | |
9666 "Build skeleton case statement, prompting for the selector expression, | |
9667 and the case items." | |
9668 "[selector expression]: " | |
9669 > "case (" str ") " \n | |
9670 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n ) | |
9671 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)) | |
9672 | |
9673 (define-skeleton verilog-sk-casex | |
9674 "Build skeleton casex statement, prompting for the selector expression, | |
9675 and the case items." | |
9676 "[selector expression]: " | |
9677 > "casex (" str ") " \n | |
9678 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n ) | |
9679 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)) | |
9680 | |
9681 (define-skeleton verilog-sk-casez | |
9682 "Build skeleton casez statement, prompting for the selector expression, | |
9683 and the case items." | |
9684 "[selector expression]: " | |
9685 > "casez (" str ") " \n | |
9686 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n ) | |
9687 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)) | |
9688 | |
9689 (define-skeleton verilog-sk-if | |
9690 "Insert a skeleton if statement." | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9691 > "if (" '(verilog-sk-prompt-condition) & ")" " begin" \n |
79545 | 9692 > _ \n |
9693 > (- verilog-indent-level-behavioral) "end " \n ) | |
9694 | |
9695 (define-skeleton verilog-sk-else-if | |
9696 "Insert a skeleton else if statement." | |
9697 > (verilog-indent-line) "else if (" | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9698 (progn (setq verilog-sk-p (point)) nil) '(verilog-sk-prompt-condition) (if (> (point) verilog-sk-p) ") " -1 ) & " begin" \n |
79545 | 9699 > _ \n |
9700 > "end" (progn (electric-verilog-terminate-line) nil)) | |
9701 | |
9702 (define-skeleton verilog-sk-datadef | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
9703 "Common routine to get data definition." |
79545 | 9704 () |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9705 '(verilog-sk-prompt-width) | -1 ("name (RET to end):" str ", ") -2 ";" \n) |
79545 | 9706 |
9707 (define-skeleton verilog-sk-input | |
9708 "Insert an input definition." | |
9709 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9710 > "input [" '(verilog-sk-datadef)) |
79545 | 9711 |
9712 (define-skeleton verilog-sk-output | |
9713 "Insert an output definition." | |
9714 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9715 > "output [" '(verilog-sk-datadef)) |
79545 | 9716 |
9717 (define-skeleton verilog-sk-inout | |
9718 "Insert an inout definition." | |
9719 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9720 > "inout [" '(verilog-sk-datadef)) |
79545 | 9721 |
9722 (defvar verilog-sk-signal nil) | |
9723 (define-skeleton verilog-sk-def-reg | |
9724 "Insert a reg definition." | |
9725 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9726 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations) ) |
79545 | 9727 |
9728 (defun verilog-sk-define-signal () | |
9729 "Insert a definition of signal under point at top of module." | |
9730 (interactive "*") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9731 (let* ((sig-re "[a-zA-Z0-9_]*") |
79545 | 9732 (v1 (buffer-substring |
9733 (save-excursion | |
9734 (skip-chars-backward sig-re) | |
9735 (point)) | |
9736 (save-excursion | |
9737 (skip-chars-forward sig-re) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9738 (point))))) |
79545 | 9739 (if (not (member v1 verilog-keywords)) |
9740 (save-excursion | |
9741 (setq verilog-sk-signal v1) | |
9742 (verilog-beg-of-defun) | |
9743 (verilog-end-of-statement) | |
9744 (verilog-forward-syntactic-ws) | |
9745 (verilog-sk-def-reg) | |
9746 (message "signal at point is %s" v1)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9747 (message "object at point (%s) is a keyword" v1)))) |
79545 | 9748 |
9749 (define-skeleton verilog-sk-wire | |
9750 "Insert a wire definition." | |
9751 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9752 > "wire [" '(verilog-sk-datadef)) |
79545 | 9753 |
9754 (define-skeleton verilog-sk-reg | |
9755 "Insert a reg definition." | |
9756 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9757 > "reg [" '(verilog-sk-datadef)) |
79545 | 9758 |
9759 (define-skeleton verilog-sk-assign | |
9760 "Insert a skeleton assign statement." | |
9761 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9762 > "assign " '(verilog-sk-prompt-name) " = " _ ";" \n) |
79545 | 9763 |
9764 (define-skeleton verilog-sk-while | |
9765 "Insert a skeleton while loop statement." | |
9766 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9767 > "while (" '(verilog-sk-prompt-condition) ") begin" \n |
79545 | 9768 > _ \n |
9769 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil)) | |
9770 | |
9771 (define-skeleton verilog-sk-repeat | |
9772 "Insert a skeleton repeat loop statement." | |
9773 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9774 > "repeat (" '(verilog-sk-prompt-condition) ") begin" \n |
79545 | 9775 > _ \n |
9776 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil)) | |
9777 | |
9778 (define-skeleton verilog-sk-for | |
9779 "Insert a skeleton while loop statement." | |
9780 () | |
9781 > "for (" | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9782 '(verilog-sk-prompt-init) "; " |
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9783 '(verilog-sk-prompt-condition) "; " |
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9784 '(verilog-sk-prompt-inc) |
79545 | 9785 ") begin" \n |
9786 > _ \n | |
9787 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil)) | |
9788 | |
9789 (define-skeleton verilog-sk-comment | |
9790 "Inserts three comment lines, making a display comment." | |
9791 () | |
9792 > "/*\n" | |
9793 > "* " _ \n | |
9794 > "*/") | |
9795 | |
9796 (define-skeleton verilog-sk-state-machine | |
9797 "Insert a state machine definition." | |
9798 "Name of state variable: " | |
9799 '(setq input "state") | |
9800 > "// State registers for " str | -23 \n | |
9801 '(setq verilog-sk-state str) | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9802 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-state ", next_" verilog-sk-state ?; \n |
79545 | 9803 '(setq input nil) |
9804 > \n | |
9805 > "// State FF for " verilog-sk-state \n | |
9806 > "always @ ( " (read-string "clock:" "posedge clk") " or " (verilog-sk-prompt-reset) " ) begin" \n | |
9807 > "if ( " verilog-sk-reset " ) " verilog-sk-state " = 0; else" \n | |
9808 > verilog-sk-state " = next_" verilog-sk-state ?; \n | |
9809 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil) | |
9810 > \n | |
9811 > "// Next State Logic for " verilog-sk-state \n | |
9812 > "always @ ( /*AUTOSENSE*/ ) begin\n" | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9813 > "case (" '(verilog-sk-prompt-state-selector) ") " \n |
79545 | 9814 > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n ) |
9815 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil) | |
9816 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil)) | |
9817 | |
9818 ;; Eliminate compile warning | |
9819 (eval-when-compile | |
9820 (if (not (boundp 'mode-popup-menu)) | |
9821 (defvar mode-popup-menu nil "Compatibility with XEmacs."))) | |
9822 | |
9823 ;; ---- add menu 'Statements' in Verilog mode (MH) | |
9824 (defun verilog-add-statement-menu () | |
9825 "Add the menu 'Statements' to the menu bar in Verilog mode." | |
9826 (if (featurep 'xemacs) | |
9827 (progn | |
9828 (easy-menu-add verilog-stmt-menu) | |
9829 (easy-menu-add verilog-menu) | |
9830 (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu))))) | |
9831 | |
9832 (add-hook 'verilog-mode-hook 'verilog-add-statement-menu) | |
9833 | |
9834 | |
9835 | |
9836 ;; | |
9837 ;; Include file loading with mouse/return event | |
9838 ;; | |
9839 ;; idea & first impl.: M. Rouat (eldo-mode.el) | |
9840 ;; second (emacs/xemacs) impl.: G. Van der Plas (spice-mode.el) | |
9841 | |
9842 (if (featurep 'xemacs) | |
9843 (require 'overlay) | |
9844 (require 'lucid)) ;; what else can we do ?? | |
9845 | |
9846 (defconst verilog-include-file-regexp | |
9847 "^`include\\s-+\"\\([^\n\"]*\\)\"" | |
9848 "Regexp that matches the include file.") | |
9849 | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9850 (defvar verilog-mode-mouse-map |
79545 | 9851 (let ((map (make-sparse-keymap))) ; as described in info pages, make a map |
9852 (set-keymap-parent map verilog-mode-map) | |
9853 ;; mouse button bindings | |
9854 (define-key map "\r" 'verilog-load-file-at-point) | |
9855 (if (featurep 'xemacs) | |
9856 (define-key map 'button2 'verilog-load-file-at-mouse);ffap-at-mouse ? | |
9857 (define-key map [mouse-2] 'verilog-load-file-at-mouse)) | |
9858 (if (featurep 'xemacs) | |
9859 (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
|
9860 (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
|
9861 map) |
79546 | 9862 "Map containing mouse bindings for `verilog-mode'.") |
9863 | |
79545 | 9864 |
9865 (defun verilog-colorize-include-files (beg end old-len) | |
9866 "This function colorizes included files when the mouse passes over them. | |
9867 Clicking on the middle-mouse button loads them in a buffer (as in dired)." | |
9868 (save-excursion | |
9869 (save-match-data | |
9870 (let (end-point) | |
9871 (goto-char end) | |
9872 (setq end-point (verilog-get-end-of-line)) | |
9873 (goto-char beg) | |
9874 (beginning-of-line) ; scan entire line ! | |
9875 ;; delete overlays existing on this line | |
9876 (let ((overlays (overlays-in (point) end-point))) | |
9877 (while overlays | |
9878 (if (and | |
9879 (overlay-get (car overlays) 'detachable) | |
9880 (overlay-get (car overlays) 'verilog-include-file)) | |
9881 (delete-overlay (car overlays))) | |
9882 (setq overlays (cdr overlays)))) ; let | |
9883 ;; make new ones, could reuse deleted one ? | |
9884 (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
|
9885 (let (ov) |
79545 | 9886 (goto-char (match-beginning 1)) |
79550
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
9887 (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
|
9888 (overlay-put ov 'start-closed 't) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
9889 (overlay-put ov 'end-closed 't) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
9890 (overlay-put ov 'evaporate 't) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
9891 (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
|
9892 (overlay-put ov 'mouse-face 'highlight) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
9893 (overlay-put ov 'local-map verilog-mode-mouse-map))))))) |
79545 | 9894 |
9895 | |
9896 (defun verilog-colorize-include-files-buffer () | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
9897 "Colorize an include file." |
79545 | 9898 (interactive) |
9899 ;; delete overlays | |
9900 (let ((overlays (overlays-in (point-min) (point-max)))) | |
9901 (while overlays | |
9902 (if (and | |
9903 (overlay-get (car overlays) 'detachable) | |
9904 (overlay-get (car overlays) 'verilog-include-file)) | |
9905 (delete-overlay (car overlays))) | |
9906 (setq overlays (cdr overlays)))) ; let | |
9907 ;; remake overlays | |
9908 (verilog-colorize-include-files (point-min) (point-max) nil)) | |
9909 | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
9910 ;; ffap-at-mouse isn't useful for Verilog mode. It uses library paths. |
79545 | 9911 ;; so define this function to do more or less the same as ffap-at-mouse |
9912 ;; but first resolve filename... | |
9913 (defun verilog-load-file-at-mouse (event) | |
9914 "Load file under button 2 click's EVENT. | |
9915 Files are checked based on `verilog-library-directories'." | |
9916 (interactive "@e") | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
9917 (save-excursion ;; implement a Verilog specific ffap-at-mouse |
79545 | 9918 (mouse-set-point event) |
9919 (beginning-of-line) | |
9920 (if (looking-at verilog-include-file-regexp) | |
9921 (if (and (car (verilog-library-filenames | |
9922 (match-string 1) (buffer-file-name))) | |
9923 (file-readable-p (car (verilog-library-filenames | |
9924 (match-string 1) (buffer-file-name))))) | |
9925 (find-file (car (verilog-library-filenames | |
9926 (match-string 1) (buffer-file-name)))) | |
9927 (progn | |
9928 (message | |
9929 "File '%s' isn't readable, use shift-mouse2 to paste in this field" | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9930 (match-string 1))))))) |
79545 | 9931 |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
9932 ;; ffap isn't useable for Verilog mode. It uses library paths. |
79545 | 9933 ;; so define this function to do more or less the same as ffap |
9934 ;; but first resolve filename... | |
9935 (defun verilog-load-file-at-point () | |
9936 "Load file under point. | |
9937 Files are checked based on `verilog-library-directories'." | |
9938 (interactive) | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
9939 (save-excursion ;; implement a Verilog specific ffap |
79545 | 9940 (beginning-of-line) |
9941 (if (looking-at verilog-include-file-regexp) | |
9942 (if (and | |
9943 (car (verilog-library-filenames | |
9944 (match-string 1) (buffer-file-name))) | |
9945 (file-readable-p (car (verilog-library-filenames | |
9946 (match-string 1) (buffer-file-name))))) | |
9947 (find-file (car (verilog-library-filenames | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9948 (match-string 1) (buffer-file-name)))))))) |
79545 | 9949 |
9950 | |
9951 ;; | |
9952 ;; Bug reporting | |
9953 ;; | |
9954 | |
9955 (defun verilog-faq () | |
9956 "Tell the user their current version, and where to get the FAQ etc." | |
9957 (interactive) | |
9958 (with-output-to-temp-buffer "*verilog-mode help*" | |
9959 (princ (format "You are using verilog-mode %s\n" verilog-mode-version)) | |
9960 (princ "\n") | |
9961 (princ "For new releases, see http://www.verilog.com\n") | |
9962 (princ "\n") | |
9963 (princ "For frequently asked questions, see http://www.veripool.com/verilog-mode-faq.html\n") | |
9964 (princ "\n") | |
9965 (princ "To submit a bug, use M-x verilog-submit-bug-report\n") | |
9966 (princ "\n"))) | |
9967 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9968 (autoload 'reporter-submit-bug-report "reporter") |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9969 (defvar reporter-prompt-for-summary-p) |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9970 |
79545 | 9971 (defun verilog-submit-bug-report () |
9972 "Submit via mail a bug report on verilog-mode.el." | |
9973 (interactive) | |
9974 (let ((reporter-prompt-for-summary-p t)) | |
9975 (reporter-submit-bug-report | |
9976 "mac@verilog.com" | |
9977 (concat "verilog-mode v" verilog-mode-version) | |
9978 '( | |
9979 verilog-align-ifelse | |
9980 verilog-auto-endcomments | |
9981 verilog-auto-hook | |
9982 verilog-auto-indent-on-newline | |
9983 verilog-auto-inst-vector | |
9984 verilog-auto-inst-template-numbers | |
9985 verilog-auto-lineup | |
9986 verilog-auto-newline | |
9987 verilog-auto-save-policy | |
9988 verilog-auto-sense-defines-constant | |
9989 verilog-auto-sense-include-inputs | |
9990 verilog-before-auto-hook | |
9991 verilog-case-indent | |
9992 verilog-cexp-indent | |
9993 verilog-compiler | |
9994 verilog-coverage | |
9995 verilog-highlight-translate-off | |
9996 verilog-indent-begin-after-if | |
9997 verilog-indent-declaration-macros | |
9998 verilog-indent-level | |
9999 verilog-indent-level-behavioral | |
10000 verilog-indent-level-declaration | |
10001 verilog-indent-level-directive | |
10002 verilog-indent-level-module | |
10003 verilog-indent-lists | |
10004 verilog-library-flags | |
10005 verilog-library-directories | |
10006 verilog-library-extensions | |
10007 verilog-library-files | |
10008 verilog-linter | |
10009 verilog-minimum-comment-distance | |
10010 verilog-mode-hook | |
10011 verilog-simulator | |
10012 verilog-tab-always-indent | |
10013 verilog-tab-to-comment | |
10014 ) | |
10015 nil nil | |
10016 (concat "Hi Mac, | |
10017 | |
10018 I want to report a bug. I've read the `Bugs' section of `Info' on | |
10019 Emacs, so I know how to make a clear and unambiguous report. To get | |
10020 to that Info section, I typed | |
10021 | |
10022 M-x info RET m " invocation-name " RET m bugs RET | |
10023 | |
10024 Before I go further, I want to say that Verilog mode has changed my life. | |
10025 I save so much time, my files are colored nicely, my co workers respect | |
10026 my coding ability... until now. I'd really appreciate anything you | |
10027 could do to help me out with this minor deficiency in the product. | |
10028 | |
10029 If you have bugs with the AUTO functions, please CC the AUTOAUTHOR Wilson | |
10030 Snyder (wsnyder@wsnyder.org) and/or see http://www.veripool.com. | |
10031 You may also want to look at the Verilog-Mode FAQ, see | |
10032 http://www.veripool.com/verilog-mode-faq.html. | |
10033 | |
10034 To reproduce the bug, start a fresh Emacs via " invocation-name " | |
91941
125866467ba5
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
88107
diff
changeset
|
10035 -no-init-file -no-site-file'. In a new buffer, in Verilog mode, type |
79545 | 10036 the code included below. |
10037 | |
10038 Given those lines, I expected [[Fill in here]] to happen; | |
10039 but instead, [[Fill in here]] happens!. | |
10040 | |
10041 == The code: ==")))) | |
10042 | |
79546 | 10043 (provide 'verilog-mode) |
10044 | |
79545 | 10045 ;; Local Variables: |
10046 ;; checkdoc-permit-comma-termination-flag:t | |
10047 ;; checkdoc-force-docstrings-flag:nil | |
10048 ;; End: | |
10049 | |
79552 | 10050 ;; arch-tag: 87923725-57b3-41b5-9494-be21118c6a6f |
79545 | 10051 ;;; verilog-mode.el ends here |