Mercurial > emacs
annotate lisp/progmodes/verilog-mode.el @ 92676:6984f0acb7d8
*** empty log message ***
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sun, 09 Mar 2008 03:42:20 +0000 |
parents | f991f10f15ec |
children | d999f30304bc |
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 | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
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: | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
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 | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
118 (defconst verilog-mode-version "399" |
80143
adbd1e116992
(verilog-mode-version, verilog-mode-release-date, erilog-mode-release-emacs,
Juanma Barranquero <lekktu@gmail.com>
parents:
80141
diff
changeset
|
119 "Version of this Verilog mode.") |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
120 (defconst verilog-mode-release-date "2008-02-19-GNU" |
80143
adbd1e116992
(verilog-mode-version, verilog-mode-release-date, erilog-mode-release-emacs,
Juanma Barranquero <lekktu@gmail.com>
parents:
80141
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 |
80143
adbd1e116992
(verilog-mode-version, verilog-mode-release-date, erilog-mode-release-emacs,
Juanma Barranquero <lekktu@gmail.com>
parents:
80141
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 (fboundp 'char-before) |
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 (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
|
167 (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
|
168 (error nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
169 (condition-case nil |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
170 (require 'custom) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
171 (error nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
172 (condition-case nil |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
173 (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
|
174 nil ;; great |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
175 (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
|
176 "Return string of text matched by last search, without text properties. |
79545 | 177 NUM specifies which parenthesized expression in the last regexp. |
178 Value is nil if NUMth pair didn't match, or there were less than NUM pairs. | |
179 Zero means the entire text matched by the whole regexp or whole string. | |
180 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
|
181 (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
|
182 (if string |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
183 (let ((result |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
184 (substring string |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
185 (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
|
186 (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
|
187 result) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
188 (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
|
189 (match-end num) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
190 (current-buffer))))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
191 ) |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
192 (error nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
193 (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
|
194 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
|
195 ;; 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
|
196 (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
|
197 (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
|
198 (message |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
199 "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
|
200 (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
|
201 `(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
|
202 ) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
203 (if (fboundp 'defface) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
204 nil ; great! |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
205 (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
|
206 `(make-face ,var)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
207 ) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
208 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
209 (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
|
210 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
|
211 ;; 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
|
212 (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
|
213 `(customize ,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 |
79545 | 216 ;; Provide a regular expression optimization routine, using regexp-opt |
217 ;; if provided by the user's elisp libraries | |
218 (eval-and-compile | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
219 ;; 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
|
220 ;; 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
|
221 (if (featurep 'xemacs) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
222 (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
|
223 ;; 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
|
224 (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
|
225 (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
|
226 (cond |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
227 ((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
|
228 (condition-case nil ; Hide this defun from emacses |
79545 | 229 ;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
|
230 (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
|
231 "Deal with differing number of required arguments for `regexp-opt'. |
79545 | 232 Call 'regexp-opt' on A and B." |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
233 (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
|
234 (error nil)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
235 ) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
236 ((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
|
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 "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
|
239 (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
|
240 ) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
241 (t nil))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
242 ;; 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
|
243 (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
|
244 "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
|
245 (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
|
246 ) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
247 ;; 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
|
248 (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
|
249 (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
|
250 (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
|
251 ) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
252 ;; Emacs. |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
253 (defalias 'verilog-regexp-opt 'regexp-opt))) |
79545 | 254 |
79555
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
255 (eval-when-compile |
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
256 (defun verilog-regexp-words (a) |
52d2889ab3d8
(set-buffer-menubar): Remove unused
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79554
diff
changeset
|
257 "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
|
258 (concat "\\<" (verilog-regexp-opt a t) "\\>"))) |
79545 | 259 |
260 (defun verilog-customize () | |
261 "Link to customize screen for Verilog." | |
262 (interactive) | |
263 (customize-group 'verilog-mode)) | |
264 | |
265 (defun verilog-font-customize () | |
266 "Link to customize fonts used for Verilog." | |
267 (interactive) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
268 (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
|
269 (customize-apropos "font-lock-*" 'faces))) |
79545 | 270 |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
271 (defun verilog-booleanp (value) |
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
272 "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
|
273 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
|
274 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
|
275 (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
|
276 |
79545 | 277 (defgroup verilog-mode nil |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
278 "Facilitates easy editing of Verilog source text." |
79545 | 279 :group 'languages) |
280 | |
281 ; (defgroup verilog-mode-fonts nil | |
282 ; "Facilitates easy customization fonts used in Verilog source text" | |
283 ; :link '(customize-apropos "font-lock-*" 'faces) | |
284 ; :group 'verilog-mode) | |
285 | |
286 (defgroup verilog-mode-indent nil | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
287 "Customize indentation and highlighting of Verilog source text." |
79545 | 288 :group 'verilog-mode) |
289 | |
290 (defgroup verilog-mode-actions nil | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
291 "Customize actions on Verilog source text." |
79545 | 292 :group 'verilog-mode) |
293 | |
294 (defgroup verilog-mode-auto nil | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
295 "Customize AUTO actions when expanding Verilog source text." |
79545 | 296 :group 'verilog-mode) |
297 | |
298 (defcustom verilog-linter | |
299 "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'" | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
300 "*Unix program and arguments to call to run a lint checker on Verilog source. |
79545 | 301 Depending on the `verilog-set-compile-command', this may be invoked when |
302 you type \\[compile]. When the compile completes, \\[next-error] will take | |
303 you to the next lint error." | |
304 :type 'string | |
305 :group 'verilog-mode-actions) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
306 ;; We don't mark it safe, as it's used as a shell command |
79545 | 307 |
308 (defcustom verilog-coverage | |
309 "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'" | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
310 "*Program and arguments to use to annotate for coverage Verilog source. |
79545 | 311 Depending on the `verilog-set-compile-command', this may be invoked when |
312 you type \\[compile]. When the compile completes, \\[next-error] will take | |
313 you to the next lint error." | |
314 :type 'string | |
315 :group 'verilog-mode-actions) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
316 ;; We don't mark it safe, as it's used as a shell command |
79545 | 317 |
318 (defcustom verilog-simulator | |
319 "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'" | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
320 "*Program and arguments to use to interpret Verilog source. |
79545 | 321 Depending on the `verilog-set-compile-command', this may be invoked when |
322 you type \\[compile]. When the compile completes, \\[next-error] will take | |
323 you to the next lint error." | |
324 :type 'string | |
325 :group 'verilog-mode-actions) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
326 ;; We don't mark it safe, as it's used as a shell command |
79545 | 327 |
328 (defcustom verilog-compiler | |
329 "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'" | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
330 "*Program and arguments to use to compile Verilog source. |
79545 | 331 Depending on the `verilog-set-compile-command', this may be invoked when |
332 you type \\[compile]. When the compile completes, \\[next-error] will take | |
333 you to the next lint error." | |
334 :type 'string | |
335 :group 'verilog-mode-actions) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
336 ;; We don't mark it safe, as it's used as a shell command |
79545 | 337 |
338 (defvar verilog-tool 'verilog-linter | |
339 "Which tool to use for building compiler-command. | |
340 Either nil, `verilog-linter, `verilog-coverage, `verilog-simulator, or | |
341 `verilog-compiler. Alternatively use the \"Choose Compilation Action\" | |
342 menu. See `verilog-set-compile-command' for more information.") | |
343 | |
344 (defcustom verilog-highlight-translate-off nil | |
345 "*Non-nil means background-highlight code excluded from translation. | |
346 That is, all code between \"// synopsys translate_off\" and | |
347 \"// synopsys translate_on\" is highlighted using a different background color | |
348 \(face `verilog-font-lock-translate-off-face'). | |
349 | |
350 Note: This will slow down on-the-fly fontification (and thus editing). | |
351 | |
352 Note: Activate the new setting in a Verilog buffer by re-fontifying it (menu | |
353 entry \"Fontify Buffer\"). XEmacs: turn off and on font locking." | |
354 :type 'boolean | |
355 :group 'verilog-mode-indent) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
356 ;; 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
|
357 (put 'verilog-highlight-translate-off 'safe-local-variable 'verilog-booleanp) |
79545 | 358 |
359 (defcustom verilog-indent-level 3 | |
360 "*Indentation of Verilog statements with respect to containing block." | |
361 :group 'verilog-mode-indent | |
362 :type 'integer) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
363 (put 'verilog-indent-level 'safe-local-variable 'integerp) |
79545 | 364 |
365 (defcustom verilog-indent-level-module 3 | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
366 "*Indentation of Module level Verilog statements (eg always, initial). |
79545 | 367 Set to 0 to get initial and always statements lined up on the left side of |
368 your screen." | |
369 :group 'verilog-mode-indent | |
370 :type 'integer) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
371 (put 'verilog-indent-level-module 'safe-local-variable 'integerp) |
79545 | 372 |
373 (defcustom verilog-indent-level-declaration 3 | |
374 "*Indentation of declarations with respect to containing block. | |
375 Set to 0 to get them list right under containing block." | |
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-declaration 'safe-local-variable 'integerp) |
79545 | 379 |
380 (defcustom verilog-indent-declaration-macros nil | |
381 "*How to treat macro expansions in a declaration. | |
382 If nil, indent as: | |
383 input [31:0] a; | |
384 input `CP; | |
385 output c; | |
386 If non nil, treat as: | |
387 input [31:0] a; | |
388 input `CP ; | |
389 output c;" | |
390 :group 'verilog-mode-indent | |
391 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
392 (put 'verilog-indent-declaration-macros 'safe-local-variable 'verilog-booleanp) |
79545 | 393 |
394 (defcustom verilog-indent-lists t | |
395 "*How to treat indenting items in a list. | |
396 If t (the default), indent as: | |
397 always @( posedge a or | |
398 reset ) begin | |
399 | |
400 If nil, treat as: | |
401 always @( posedge a or | |
402 reset ) begin" | |
403 :group 'verilog-mode-indent | |
404 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
405 (put 'verilog-indent-lists 'safe-local-variable 'verilog-booleanp) |
79545 | 406 |
407 (defcustom verilog-indent-level-behavioral 3 | |
408 "*Absolute indentation of first begin in a task or function block. | |
409 Set to 0 to get such code to start at the left side of the screen." | |
410 :group 'verilog-mode-indent | |
411 :type 'integer) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
412 (put 'verilog-indent-level-behavioral 'safe-local-variable 'integerp) |
79545 | 413 |
414 (defcustom verilog-indent-level-directive 1 | |
415 "*Indentation to add to each level of `ifdef declarations. | |
416 Set to 0 to have all directives 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-directive 'safe-local-variable 'integerp) |
79545 | 420 |
421 (defcustom verilog-cexp-indent 2 | |
422 "*Indentation of Verilog statements split across lines." | |
423 :group 'verilog-mode-indent | |
424 :type 'integer) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
425 (put 'verilog-cexp-indent 'safe-local-variable 'integerp) |
79545 | 426 |
427 (defcustom verilog-case-indent 2 | |
428 "*Indentation for case statements." | |
429 :group 'verilog-mode-indent | |
430 :type 'integer) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
431 (put 'verilog-case-indent 'safe-local-variable 'integerp) |
79545 | 432 |
433 (defcustom verilog-auto-newline t | |
434 "*True means automatically newline after semicolons." | |
435 :group 'verilog-mode-indent | |
436 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
437 (put 'verilog-auto-newline 'safe-local-variable 'verilog-booleanp) |
79545 | 438 |
439 (defcustom verilog-auto-indent-on-newline t | |
440 "*True means automatically indent line after newline." | |
441 :group 'verilog-mode-indent | |
442 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
443 (put 'verilog-auto-indent-on-newline 'safe-local-variable 'verilog-booleanp) |
79545 | 444 |
445 (defcustom verilog-tab-always-indent t | |
446 "*True means TAB should always re-indent the current line. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
447 A nil value means TAB will only reindent when at the beginning of the line." |
79545 | 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-tab-always-indent 'safe-local-variable 'verilog-booleanp) |
79545 | 451 |
452 (defcustom verilog-tab-to-comment nil | |
453 "*True means TAB moves to the right hand column in preparation for a comment." | |
454 :group 'verilog-mode-actions | |
455 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
456 (put 'verilog-tab-to-comment 'safe-local-variable 'verilog-booleanp) |
79545 | 457 |
458 (defcustom verilog-indent-begin-after-if t | |
459 "*If true, indent begin statements following if, else, while, for and repeat. | |
460 Otherwise, line them up." | |
461 :group 'verilog-mode-indent | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
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-indent-begin-after-if 'safe-local-variable 'verilog-booleanp) |
79545 | 464 |
465 | |
466 (defcustom verilog-align-ifelse nil | |
467 "*If true, align `else' under matching `if'. | |
468 Otherwise else is lined up with first character on line holding matching if." | |
469 :group 'verilog-mode-indent | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
470 :type 'boolean) |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
471 (put 'verilog-align-ifelse 'safe-local-variable 'verilog-booleanp) |
79545 | 472 |
473 (defcustom verilog-minimum-comment-distance 10 | |
474 "*Minimum distance (in lines) between begin and end required before a comment. | |
475 Setting this variable to zero results in every end acquiring a comment; the | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
476 default avoids too many redundant comments in tight quarters." |
79545 | 477 :group 'verilog-mode-indent |
478 :type 'integer) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
479 (put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp) |
79545 | 480 |
481 (defcustom verilog-auto-lineup '(declaration) | |
482 "*Algorithm for lining up statements on multiple lines. | |
483 | |
484 If this list contains the symbol 'all', then all line ups described below | |
485 are done. | |
486 | |
487 If this list contains the symbol 'declaration', then declarations are lined up | |
488 with any preceding declarations, taking into account widths and the like, so | |
489 for example the code: | |
490 reg [31:0] a; | |
491 reg b; | |
492 would become | |
493 reg [31:0] a; | |
494 reg b; | |
495 | |
496 If this list contains the symbol 'assignment', then assignments are lined up | |
497 with any preceding assignments, so for example the code | |
498 a_long_variable = b + c; | |
499 d = e + f; | |
500 would become | |
501 a_long_variable = b + c; | |
502 d = e + f;" | |
503 | |
504 ;; The following is not implemented: | |
505 ;If this list contains the symbol 'case', then case items are lined up | |
506 ;with any preceding case items, so for example the code | |
507 ; case (a) begin | |
508 ; a_long_state : a = 3; | |
509 ; b: a = 4; | |
510 ; endcase | |
511 ;would become | |
512 ; case (a) begin | |
513 ; a_long_state : a = 3; | |
514 ; b : a = 4; | |
515 ; endcase | |
516 ; | |
517 | |
518 :group 'verilog-mode-indent | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
519 :type 'list) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
520 (put 'verilog-auto-lineup 'safe-local-variable 'listp) |
79545 | 521 |
522 (defcustom verilog-highlight-p1800-keywords nil | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
523 "*True means highlight words newly reserved by IEEE-1800. |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
524 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
|
525 suggest changing where these words are used as variables to something else. |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
526 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
|
527 IEEE-1800 standard. Note that changing this will require restarting Emacs |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
528 to see the effect as font color choices are cached by Emacs." |
79545 | 529 :group 'verilog-mode-indent |
530 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
531 (put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp) |
79545 | 532 |
533 (defcustom verilog-auto-endcomments t | |
534 "*True means insert a comment /* ... */ after 'end's. | |
535 The name of the function or case will be set between the braces." | |
536 :group 'verilog-mode-actions | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
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-auto-endcomments 'safe-local-variable 'verilog-booleanp) |
79545 | 539 |
540 (defcustom verilog-auto-read-includes nil | |
541 "*True means to automatically read includes before AUTOs. | |
542 This will do a `verilog-read-defines' and `verilog-read-includes' before | |
543 each AUTO expansion. This makes it easier to embed defines and includes, | |
544 but can result in very slow reading times if there are many or large | |
545 include files." | |
546 :group 'verilog-mode-actions | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
547 :type 'boolean) |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
548 (put 'verilog-auto-read-includes 'safe-local-variable 'verilog-booleanp) |
79545 | 549 |
550 (defcustom verilog-auto-save-policy nil | |
551 "*Non-nil indicates action to take when saving a Verilog buffer with AUTOs. | |
552 A value of `force' will always do a \\[verilog-auto] automatically if | |
553 needed on every save. A value of `detect' will do \\[verilog-auto] | |
554 automatically when it thinks necessary. A value of `ask' will query the | |
555 user when it thinks updating is needed. | |
556 | |
557 You should not rely on the 'ask or 'detect policies, they are safeguards | |
558 only. They do not detect when AUTOINSTs need to be updated because a | |
559 sub-module's port list has changed." | |
560 :group 'verilog-mode-actions | |
561 :type '(choice (const nil) (const ask) (const detect) (const force))) | |
562 | |
563 (defcustom verilog-auto-star-expand t | |
564 "*Non-nil indicates to expand a SystemVerilog .* instance ports. | |
565 They will be expanded in the same way as if there was a AUTOINST in the | |
566 instantiation. See also `verilog-auto-star' and `verilog-auto-star-save'." | |
567 :group 'verilog-mode-actions | |
568 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
569 (put 'verilog-auto-star-expand 'safe-local-variable 'verilog-booleanp) |
79545 | 570 |
571 (defcustom verilog-auto-star-save nil | |
572 "*Non-nil indicates to save to disk SystemVerilog .* instance expansions. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
573 A nil value indicates direct connections will be removed before saving. |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
574 Only meaningful to those created due to `verilog-auto-star-expand' being set. |
79545 | 575 |
576 Instead of setting this, you may want to use /*AUTOINST*/, which will | |
577 always be saved." | |
578 :group 'verilog-mode-actions | |
579 :type 'boolean) | |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
580 (put 'verilog-auto-star-save 'safe-local-variable 'verilog-booleanp) |
79545 | 581 |
582 (defvar verilog-auto-update-tick nil | |
583 "Modification tick at which autos were last performed.") | |
584 | |
585 (defvar verilog-auto-last-file-locals nil | |
586 "Text from file-local-variables during last evaluation.") | |
587 | |
588 (defvar verilog-error-regexp-add-didit nil) | |
589 (defvar verilog-error-regexp nil) | |
590 (setq verilog-error-regexp-add-didit nil | |
591 verilog-error-regexp | |
592 '( | |
593 ; SureLint | |
594 ;; ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2) | |
595 ; Most SureFire tools | |
596 ("\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\), \\(line \\|\\)\\([0-9]+\\):" 2 4 ) | |
597 ("\ | |
598 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\ | |
599 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5) | |
600 ; xsim | |
601 ; Error! in file /homes/mac/Axis/Xsim/test.v at line 13 [OBJ_NOT_DECLARED] | |
602 ("\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3) | |
603 ; vcs | |
604 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3) | |
605 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2) | |
606 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3) | |
607 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2) | |
608 ; Verilator | |
609 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4) | |
610 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4) | |
611 ; vxl | |
612 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3) | |
613 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 1 2) ; vxl | |
614 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 1 2) | |
615 ; nc-verilog | |
616 (".*\\*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 1 2) | |
617 ; Leda | |
618 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 1 2) | |
619 ) | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
620 ; "*List of regexps for Verilog compilers, like verilint. See compilation-error-regexp-alist for the formatting." |
79545 | 621 ) |
622 | |
623 (defvar verilog-error-font-lock-keywords | |
624 '( | |
625 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t) | |
626 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t) | |
627 | |
628 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t) | |
629 ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t) | |
630 | |
631 ("\ | |
632 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\ | |
633 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t) | |
634 ("\ | |
635 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\ | |
636 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t) | |
637 | |
638 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t) | |
639 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t) | |
640 | |
641 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t) | |
642 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t) | |
643 | |
644 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t) | |
645 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t) | |
646 | |
647 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t) | |
648 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t) | |
649 | |
650 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t) | |
651 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t) | |
652 ; vxl | |
653 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t) | |
654 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t) | |
655 | |
656 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 1 bold t) | |
657 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 2 bold t) | |
658 | |
659 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 1 bold t) | |
660 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 2 bold t) | |
661 ; nc-verilog | |
662 (".*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 1 bold t) | |
663 (".*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t) | |
664 ; Leda | |
665 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 1 bold t) | |
666 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 2 bold t) | |
667 ) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
668 "*Keywords to also highlight in Verilog *compilation* buffers.") |
79545 | 669 |
670 (defcustom verilog-library-flags '("") | |
671 "*List of standard Verilog arguments to use for /*AUTOINST*/. | |
672 These arguments are used to find files for `verilog-auto', and match | |
673 the flags accepted by a standard Verilog-XL simulator. | |
674 | |
675 -f filename Reads more `verilog-library-flags' from the filename. | |
676 +incdir+dir Adds the directory to `verilog-library-directories'. | |
677 -Idir Adds the directory to `verilog-library-directories'. | |
678 -y dir Adds the directory to `verilog-library-directories'. | |
679 +libext+.v Adds the extensions to `verilog-library-extensions'. | |
680 -v filename Adds the filename to `verilog-library-files'. | |
681 | |
682 filename Adds the filename to `verilog-library-files'. | |
683 This is not recommended, -v is a better choice. | |
684 | |
685 You might want these defined in each file; put at the *END* of your file | |
686 something like: | |
687 | |
688 // Local Variables: | |
689 // verilog-library-flags:(\"-y dir -y otherdir\") | |
690 // End: | |
691 | |
692 Verilog-mode attempts to detect changes to this local variable, but they | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
693 are only insured to be correct when the file is first visited. Thus if you |
79545 | 694 have problems, use \\[find-alternate-file] RET to have these take effect. |
695 | |
696 See also the variables mentioned above." | |
697 :group 'verilog-mode-auto | |
698 :type '(repeat string)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
699 (put 'verilog-library-flags 'safe-local-variable 'listp) |
79545 | 700 |
701 (defcustom verilog-library-directories '(".") | |
702 "*List of directories when looking for files for /*AUTOINST*/. | |
703 The directory may be relative to the current file, or absolute. | |
704 Environment variables are also expanded in the directory names. | |
705 Having at least the current directory is a good idea. | |
706 | |
707 You might want these defined in each file; put at the *END* of your file | |
708 something like: | |
709 | |
710 // Local Variables: | |
711 // verilog-library-directories:(\".\" \"subdir\" \"subdir2\") | |
712 // End: | |
713 | |
714 Verilog-mode attempts to detect changes to this local variable, but they | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
715 are only insured to be correct when the file is first visited. Thus if you |
79545 | 716 have problems, use \\[find-alternate-file] RET to have these take effect. |
717 | |
718 See also `verilog-library-flags', `verilog-library-files' | |
719 and `verilog-library-extensions'." | |
720 :group 'verilog-mode-auto | |
721 :type '(repeat file)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
722 (put 'verilog-library-directories 'safe-local-variable 'listp) |
79545 | 723 |
724 (defcustom verilog-library-files '() | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
725 "*List of files to search for modules. |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
726 AUTOINST will use this when it needs to resolve a module name. |
79545 | 727 This is a complete path, usually to a technology file with many standard |
728 cells defined in it. | |
729 | |
730 You might want these defined in each file; put at the *END* of your file | |
731 something like: | |
732 | |
733 // Local Variables: | |
734 // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\") | |
735 // End: | |
736 | |
737 Verilog-mode attempts to detect changes to this local variable, but they | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
738 are only insured to be correct when the file is first visited. Thus if you |
79545 | 739 have problems, use \\[find-alternate-file] RET to have these take effect. |
740 | |
741 See also `verilog-library-flags', `verilog-library-directories'." | |
742 :group 'verilog-mode-auto | |
743 :type '(repeat directory)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
744 (put 'verilog-library-files 'safe-local-variable 'listp) |
79545 | 745 |
746 (defcustom verilog-library-extensions '(".v") | |
747 "*List of extensions to use when looking for files for /*AUTOINST*/. | |
748 See also `verilog-library-flags', `verilog-library-directories'." | |
749 :type '(repeat string) | |
750 :group 'verilog-mode-auto) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
751 (put 'verilog-library-extensions 'safe-local-variable 'listp) |
79545 | 752 |
753 (defcustom verilog-active-low-regexp nil | |
754 "*If set, treat signals matching this regexp as active low. | |
755 This is used for AUTORESET and AUTOTIEOFF. For proper behavior, | |
756 you will probably also need `verilog-auto-reset-widths' set." | |
757 :group 'verilog-mode-auto | |
758 :type 'string) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
759 (put 'verilog-active-low-regexp 'safe-local-variable 'stringp) |
79545 | 760 |
761 (defcustom verilog-auto-sense-include-inputs nil | |
762 "*If true, AUTOSENSE should include all inputs. | |
763 If nil, only inputs that are NOT output signals in the same block are | |
764 included." | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
765 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
766 :type 'boolean) |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
767 (put 'verilog-auto-sense-include-inputs 'safe-local-variable 'verilog-booleanp) |
79545 | 768 |
769 (defcustom verilog-auto-sense-defines-constant nil | |
770 "*If true, AUTOSENSE should assume all defines represent constants. | |
771 When true, the defines will not be included in sensitivity lists. To | |
772 maintain compatibility with other sites, this should be set at the bottom | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
773 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
|
774 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
775 :type 'boolean) |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
776 (put 'verilog-auto-sense-defines-constant 'safe-local-variable 'verilog-booleanp) |
79545 | 777 |
778 (defcustom verilog-auto-reset-widths t | |
779 "*If true, AUTORESET should determine the width of signals. | |
780 This is then used to set the width of the zero (32'h0 for example). This | |
781 is required by some lint tools that aren't smart enough to ignore widths of | |
782 the constant zero. This may result in ugly code when parameters determine | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
783 the MSB or LSB of a signal inside an AUTORESET." |
79545 | 784 :type 'boolean |
785 :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
|
786 (put 'verilog-auto-reset-widths 'safe-local-variable 'verilog-booleanp) |
79545 | 787 |
788 (defcustom verilog-assignment-delay "" | |
789 "*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
|
790 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
791 :type 'string) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
792 (put 'verilog-assignment-delay 'safe-local-variable 'stringp) |
79545 | 793 |
794 (defcustom verilog-auto-inst-vector t | |
795 "*If true, when creating default ports with AUTOINST, use bus subscripts. | |
796 If nil, skip the subscript when it matches the entire bus as declared in | |
797 the module (AUTOWIRE signals always are subscripted, you must manually | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
798 declare the wire to have the subscripts removed.) Setting this to nil may |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
799 speed up some simulators, but is less general and harder to read, so avoid." |
79545 | 800 :group 'verilog-mode-auto |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
801 :type 'boolean) |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
802 (put 'verilog-auto-inst-vector 'safe-local-variable 'verilog-booleanp) |
79545 | 803 |
804 (defcustom verilog-auto-inst-template-numbers nil | |
805 "*If true, when creating templated ports with AUTOINST, add a comment. | |
806 The comment will add the line number of the template that was used for that | |
807 port declaration. Setting this aids in debugging, but nil is suggested for | |
808 regular use to prevent large numbers of merge conflicts." | |
809 :group 'verilog-mode-auto | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
810 :type 'boolean) |
79801
1fc1252447c5
* progmodes/verilog-mode.el (verilog-booleanp): New function for
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79799
diff
changeset
|
811 (put 'verilog-auto-inst-template-numbers 'safe-local-variable 'verilog-booleanp) |
79545 | 812 |
813 (defvar verilog-auto-inst-column 40 | |
814 "Column number for first part of auto-inst.") | |
815 | |
816 (defcustom verilog-auto-input-ignore-regexp nil | |
817 "*If set, when creating AUTOINPUT list, ignore signals matching this regexp. | |
818 See the \\[verilog-faq] for examples on using this." | |
819 :group 'verilog-mode-auto | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
820 :type 'string) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
821 (put 'verilog-auto-input-ignore-regexp 'safe-local-variable 'stringp) |
79545 | 822 |
823 (defcustom verilog-auto-inout-ignore-regexp nil | |
824 "*If set, when creating AUTOINOUT 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-inout-ignore-regexp 'safe-local-variable 'stringp) |
79545 | 829 |
830 (defcustom verilog-auto-output-ignore-regexp nil | |
831 "*If set, when creating AUTOOUTPUT 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-output-ignore-regexp 'safe-local-variable 'stringp) |
79545 | 836 |
837 (defcustom verilog-auto-unused-ignore-regexp nil | |
838 "*If set, when creating AUTOUNUSED 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-unused-ignore-regexp 'safe-local-variable 'stringp) |
79545 | 843 |
844 (defcustom verilog-typedef-regexp nil | |
845 "*If non-nil, regular expression that matches Verilog-2001 typedef names. | |
846 For example, \"_t$\" matches typedefs named with _t, as in the C language." | |
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-typedef-regexp 'safe-local-variable 'stringp) |
79545 | 850 |
851 (defcustom verilog-mode-hook 'verilog-set-compile-command | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
852 "*Hook run after Verilog mode is loaded." |
79545 | 853 :type 'hook |
854 :group 'verilog-mode) | |
855 | |
856 (defcustom verilog-auto-hook nil | |
857 "*Hook run after `verilog-mode' updates AUTOs." | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
858 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
859 :type 'hook) |
79545 | 860 |
861 (defcustom verilog-before-auto-hook nil | |
862 "*Hook run before `verilog-mode' updates AUTOs." | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
863 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
864 :type 'hook) |
79545 | 865 |
866 (defcustom verilog-delete-auto-hook nil | |
867 "*Hook run after `verilog-mode' deletes AUTOs." | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
868 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
869 :type 'hook) |
79545 | 870 |
871 (defcustom verilog-before-delete-auto-hook nil | |
872 "*Hook run before `verilog-mode' deletes AUTOs." | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
873 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
874 :type 'hook) |
79545 | 875 |
876 (defcustom verilog-getopt-flags-hook nil | |
877 "*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
|
878 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
879 :type 'hook) |
79545 | 880 |
881 (defcustom verilog-before-getopt-flags-hook nil | |
882 "*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
|
883 :group 'verilog-mode-auto |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
884 :type 'hook) |
79545 | 885 |
886 (defvar verilog-imenu-generic-expression | |
887 '((nil "^\\s-*\\(\\(m\\(odule\\|acromodule\\)\\)\\|primitive\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 4) | |
888 ("*Vars*" "^\\s-*\\(reg\\|wire\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3)) | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
889 "Imenu expression for Verilog mode. See `imenu-generic-expression'.") |
79545 | 890 |
891 ;; | |
892 ;; provide a verilog-header function. | |
893 ;; Customization variables: | |
894 ;; | |
895 (defvar verilog-date-scientific-format nil | |
896 "*If non-nil, dates are written in scientific format (e.g. 1997/09/17). | |
897 If nil, in European format (e.g. 17.09.1997). The brain-dead American | |
898 format (e.g. 09/17/1997) is not supported.") | |
899 | |
900 (defvar verilog-company nil | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
901 "*Default name of Company for Verilog header. |
79545 | 902 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
|
903 (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
|
904 |
79545 | 905 (defvar verilog-project nil |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
906 "*Default name of Project for Verilog header. |
79545 | 907 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
|
908 (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
|
909 |
79549
d9595ed9b084
* progmodes/verilog-mode.el (verilog-mode-map): Fix typo.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79547
diff
changeset
|
910 (defvar verilog-mode-map |
79546 | 911 (let ((map (make-sparse-keymap))) |
912 (define-key map ";" 'electric-verilog-semi) | |
913 (define-key map [(control 59)] 'electric-verilog-semi-with-comment) | |
914 (define-key map ":" 'electric-verilog-colon) | |
915 ;;(define-key map "=" 'electric-verilog-equal) | |
916 (define-key map "\`" 'electric-verilog-tick) | |
917 (define-key map "\t" 'electric-verilog-tab) | |
918 (define-key map "\r" 'electric-verilog-terminate-line) | |
919 ;; backspace/delete key bindings | |
920 (define-key map [backspace] 'backward-delete-char-untabify) | |
921 (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable | |
922 (define-key map [delete] 'delete-char) | |
923 (define-key map [(meta delete)] 'kill-word)) | |
924 (define-key map "\M-\C-b" 'electric-verilog-backward-sexp) | |
925 (define-key map "\M-\C-f" 'electric-verilog-forward-sexp) | |
926 (define-key map "\M-\r" `electric-verilog-terminate-and-indent) | |
927 (define-key map "\M-\t" 'verilog-complete-word) | |
928 (define-key map "\M-?" 'verilog-show-completions) | |
929 (define-key map "\C-c\`" 'verilog-lint-off) | |
930 (define-key map "\C-c\*" 'verilog-delete-auto-star-implicit) | |
931 (define-key map "\C-c\C-r" 'verilog-label-be) | |
932 (define-key map "\C-c\C-i" 'verilog-pretty-declarations) | |
933 (define-key map "\C-c=" 'verilog-pretty-expr) | |
934 (define-key map "\C-c\C-b" 'verilog-submit-bug-report) | |
935 (define-key map "\M-*" 'verilog-star-comment) | |
936 (define-key map "\C-c\C-c" 'verilog-comment-region) | |
937 (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
|
938 (when (featurep 'xemacs) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
939 (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
|
940 (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
|
941 (define-key map "\M-\C-e" 'verilog-end-of-defun)) |
79546 | 942 (define-key map "\C-c\C-d" 'verilog-goto-defun) |
943 (define-key map "\C-c\C-k" 'verilog-delete-auto) | |
944 (define-key map "\C-c\C-a" 'verilog-auto) | |
945 (define-key map "\C-c\C-s" 'verilog-auto-save-compile) | |
946 (define-key map "\C-c\C-z" 'verilog-inject-auto) | |
947 (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
|
948 (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
|
949 map) |
79545 | 950 "Keymap used in Verilog mode.") |
951 | |
952 ;; menus | |
80172
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
953 (easy-menu-define |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
954 verilog-menu verilog-mode-map "Menu for Verilog mode" |
79810
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
955 `("Verilog" |
79545 | 956 ("Choose Compilation Action" |
957 ["None" | |
958 (progn | |
959 (setq verilog-tool nil) | |
960 (verilog-set-compile-command)) | |
961 :style radio | |
962 :selected (equal verilog-tool nil)] | |
963 ["Lint" | |
964 (progn | |
965 (setq verilog-tool 'verilog-linter) | |
966 (verilog-set-compile-command)) | |
967 :style radio | |
968 :selected (equal verilog-tool `verilog-linter)] | |
969 ["Coverage" | |
970 (progn | |
971 (setq verilog-tool 'verilog-coverage) | |
972 (verilog-set-compile-command)) | |
973 :style radio | |
974 :selected (equal verilog-tool `verilog-coverage)] | |
975 ["Simulator" | |
976 (progn | |
977 (setq verilog-tool 'verilog-simulator) | |
978 (verilog-set-compile-command)) | |
979 :style radio | |
980 :selected (equal verilog-tool `verilog-simulator)] | |
981 ["Compiler" | |
982 (progn | |
983 (setq verilog-tool 'verilog-compiler) | |
984 (verilog-set-compile-command)) | |
985 :style radio | |
986 :selected (equal verilog-tool `verilog-compiler)] | |
987 ) | |
988 ("Move" | |
80172
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
989 ["Beginning of function" verilog-beg-of-defun |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
990 :keys "C-M-a"] |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
991 ["End of function" verilog-end-of-defun |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
992 :keys "C-M-e"] |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
993 ["Mark function" verilog-mark-defun |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
994 :keys "C-M-h"] |
79545 | 995 ["Goto function/module" verilog-goto-defun t] |
996 ["Move to beginning of block" electric-verilog-backward-sexp t] | |
997 ["Move to end of block" electric-verilog-forward-sexp t] | |
998 ) | |
999 ("Comments" | |
1000 ["Comment Region" verilog-comment-region t] | |
1001 ["UnComment Region" verilog-uncomment-region t] | |
1002 ["Multi-line comment insert" verilog-star-comment t] | |
1003 ["Lint error to comment" verilog-lint-off t] | |
1004 ) | |
1005 "----" | |
1006 ["Compile" compile t] | |
1007 ["AUTO, Save, Compile" verilog-auto-save-compile t] | |
1008 ["Next Compile Error" next-error t] | |
1009 ["Ignore Lint Warning at point" verilog-lint-off t] | |
1010 "----" | |
1011 ["Line up declarations around point" verilog-pretty-declarations t] | |
1012 ["Line up equations around point" verilog-pretty-expr t] | |
1013 ["Redo/insert comments on every end" verilog-label-be t] | |
1014 ["Expand [x:y] vector line" verilog-expand-vector t] | |
1015 ["Insert begin-end block" verilog-insert-block t] | |
1016 ["Complete word" verilog-complete-word t] | |
1017 "----" | |
1018 ["Recompute AUTOs" verilog-auto t] | |
1019 ["Kill AUTOs" verilog-delete-auto t] | |
1020 ["Inject AUTOs" verilog-inject-auto t] | |
1021 ("AUTO Help..." | |
1022 ["AUTO General" (describe-function 'verilog-auto) t] | |
1023 ["AUTO Library Flags" (describe-variable 'verilog-library-flags) t] | |
1024 ["AUTO Library Path" (describe-variable 'verilog-library-directories) t] | |
1025 ["AUTO Library Files" (describe-variable 'verilog-library-files) t] | |
1026 ["AUTO Library Extensions" (describe-variable 'verilog-library-extensions) t] | |
1027 ["AUTO `define Reading" (describe-function 'verilog-read-defines) t] | |
1028 ["AUTO `include Reading" (describe-function 'verilog-read-includes) t] | |
1029 ["AUTOARG" (describe-function 'verilog-auto-arg) t] | |
1030 ["AUTOASCIIENUM" (describe-function 'verilog-auto-ascii-enum) t] | |
1031 ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module) t] | |
1032 ["AUTOINOUT" (describe-function 'verilog-auto-inout) t] | |
1033 ["AUTOINPUT" (describe-function 'verilog-auto-input) t] | |
1034 ["AUTOINST" (describe-function 'verilog-auto-inst) t] | |
1035 ["AUTOINST (.*)" (describe-function 'verilog-auto-star) t] | |
1036 ["AUTOINSTPARAM" (describe-function 'verilog-auto-inst-param) t] | |
1037 ["AUTOOUTPUT" (describe-function 'verilog-auto-output) t] | |
1038 ["AUTOOUTPUTEVERY" (describe-function 'verilog-auto-output-every) t] | |
1039 ["AUTOREG" (describe-function 'verilog-auto-reg) t] | |
1040 ["AUTOREGINPUT" (describe-function 'verilog-auto-reg-input) t] | |
1041 ["AUTORESET" (describe-function 'verilog-auto-reset) t] | |
1042 ["AUTOSENSE" (describe-function 'verilog-auto-sense) t] | |
1043 ["AUTOTIEOFF" (describe-function 'verilog-auto-tieoff) t] | |
1044 ["AUTOUNUSED" (describe-function 'verilog-auto-unused) t] | |
1045 ["AUTOWIRE" (describe-function 'verilog-auto-wire) t] | |
1046 ) | |
1047 "----" | |
1048 ["Submit bug report" verilog-submit-bug-report t] | |
1049 ["Version and FAQ" verilog-faq t] | |
1050 ["Customize Verilog Mode..." verilog-customize t] | |
80172
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
1051 ["Customize Verilog Fonts & Colors" verilog-font-customize t])) |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
1052 |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
1053 (easy-menu-define |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
1054 verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog." |
79545 | 1055 '("Statements" |
1056 ["Header" verilog-sk-header t] | |
1057 ["Comment" verilog-sk-comment t] | |
1058 "----" | |
1059 ["Module" verilog-sk-module t] | |
1060 ["Primitive" verilog-sk-primitive t] | |
1061 "----" | |
1062 ["Input" verilog-sk-input t] | |
1063 ["Output" verilog-sk-output t] | |
1064 ["Inout" verilog-sk-inout t] | |
1065 ["Wire" verilog-sk-wire t] | |
1066 ["Reg" verilog-sk-reg t] | |
1067 ["Define thing under point as a register" verilog-sk-define-signal t] | |
1068 "----" | |
1069 ["Initial" verilog-sk-initial t] | |
1070 ["Always" verilog-sk-always t] | |
1071 ["Function" verilog-sk-function t] | |
1072 ["Task" verilog-sk-task t] | |
1073 ["Specify" verilog-sk-specify t] | |
1074 ["Generate" verilog-sk-generate t] | |
1075 "----" | |
1076 ["Begin" verilog-sk-begin t] | |
1077 ["If" verilog-sk-if t] | |
1078 ["(if) else" verilog-sk-else-if t] | |
1079 ["For" verilog-sk-for t] | |
1080 ["While" verilog-sk-while t] | |
1081 ["Fork" verilog-sk-fork t] | |
1082 ["Repeat" verilog-sk-repeat t] | |
1083 ["Case" verilog-sk-case t] | |
1084 ["Casex" verilog-sk-casex t] | |
80172
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
1085 ["Casez" verilog-sk-casez t])) |
79545 | 1086 |
1087 (defvar verilog-mode-abbrev-table nil | |
1088 "Abbrev table in use in Verilog-mode buffers.") | |
1089 | |
1090 (define-abbrev-table 'verilog-mode-abbrev-table ()) | |
1091 | |
79547
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1092 ;; |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1093 ;; Macros |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1094 ;; |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1095 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1096 (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
|
1097 "Replace occurrences of FROM-STRING with TO-STRING. |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1098 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
|
1099 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
|
1100 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
|
1101 ;; Hopefully soon to a emacs built-in |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1102 (let ((start 0)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1103 (while (string-match from-string string start) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1104 (setq string (replace-match to-string fixedcase literal string) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1105 start (min (length string) (match-end 0)))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1106 string)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1107 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1108 (defsubst verilog-string-remove-spaces (string) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1109 "Remove spaces surrounding STRING." |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1110 (save-match-data |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1111 (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
|
1112 (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
|
1113 string)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1114 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1115 (defsubst verilog-re-search-forward (REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1116 ; checkdoc-params: (REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1117 "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
|
1118 (store-match-data '(nil nil)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1119 (while (and |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1120 (re-search-forward REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1121 (and (verilog-skip-forward-comment-or-string) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1122 (progn |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1123 (store-match-data '(nil nil)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1124 (if BOUND |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1125 (< (point) BOUND) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1126 t))))) |
79547
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1127 (match-end 0)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1128 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1129 (defsubst verilog-re-search-backward (REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1130 ; checkdoc-params: (REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1131 "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
|
1132 (store-match-data '(nil nil)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1133 (while (and |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1134 (re-search-backward REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1135 (and (verilog-skip-backward-comment-or-string) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1136 (progn |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1137 (store-match-data '(nil nil)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1138 (if BOUND |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1139 (> (point) BOUND) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1140 t))))) |
79547
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1141 (match-end 0)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1142 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1143 (defsubst verilog-re-search-forward-quick (regexp bound noerror) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1144 "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
|
1145 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
|
1146 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
|
1147 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
|
1148 (let (pt) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1149 (while (and (not pt) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1150 (re-search-forward regexp bound noerror)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1151 (if (not (verilog-inside-comment-p)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1152 (setq pt (match-end 0)))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1153 pt)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1154 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1155 (defsubst verilog-re-search-backward-quick (regexp bound noerror) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1156 ; checkdoc-params: (REGEXP BOUND NOERROR) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1157 "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
|
1158 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
|
1159 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
|
1160 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
|
1161 (let (pt) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1162 (while (and (not pt) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1163 (re-search-backward regexp bound noerror)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1164 (if (not (verilog-inside-comment-p)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1165 (setq pt (match-end 0)))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1166 pt)) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1167 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1168 (defsubst verilog-get-beg-of-line (&optional arg) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1169 (save-excursion |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1170 (beginning-of-line arg) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1171 (point))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1172 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1173 (defsubst verilog-get-end-of-line (&optional arg) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1174 (save-excursion |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1175 (end-of-line arg) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1176 (point))) |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1177 |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1178 (defsubst verilog-within-string () |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1179 (save-excursion |
46725aa288e8
(verilog-string-replace-matches)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79546
diff
changeset
|
1180 (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
|
1181 |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1182 (defvar compile-command) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1183 |
79545 | 1184 ;; compilation program |
1185 (defun verilog-set-compile-command () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
1186 "Function to compute shell command to compile Verilog. |
79545 | 1187 |
1188 This reads `verilog-tool' and sets `compile-command'. This specifies the | |
1189 program that executes when you type \\[compile] or | |
1190 \\[verilog-auto-save-compile]. | |
1191 | |
1192 By default `verilog-tool' uses a Makefile if one exists in the current | |
1193 directory. If not, it is set to the `verilog-linter', `verilog-coverage', | |
1194 `verilog-simulator', or `verilog-compiler' variables, as selected with the | |
1195 Verilog -> \"Choose Compilation Action\" menu. | |
1196 | |
1197 You should set `verilog-tool' or the other variables to the path and | |
1198 arguments for your Verilog simulator. For example: | |
1199 \"vcs -p123 -O\" | |
1200 or a string like: | |
1201 \"(cd /tmp; surecov %s)\". | |
1202 | |
1203 In the former case, the path to the current buffer is concat'ed to the | |
1204 value of `verilog-tool'; in the later, the path to the current buffer is | |
1205 substituted for the %s. | |
1206 | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
1207 Where __FILE__ appears in the string, the `buffer-file-name' of the |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
1208 current buffer, without the directory portion, will be substituted." |
79545 | 1209 (interactive) |
1210 (cond | |
1211 ((or (file-exists-p "makefile") ;If there is a makefile, use it | |
1212 (file-exists-p "Makefile")) | |
1213 (make-local-variable 'compile-command) | |
1214 (setq compile-command "make ")) | |
1215 (t | |
1216 (make-local-variable 'compile-command) | |
1217 (setq compile-command | |
1218 (if verilog-tool | |
1219 (if (string-match "%s" (eval verilog-tool)) | |
1220 (format (eval verilog-tool) (or buffer-file-name "")) | |
1221 (concat (eval verilog-tool) " " (or buffer-file-name ""))) | |
1222 "")))) | |
1223 (verilog-modify-compile-command)) | |
1224 | |
1225 (defun verilog-modify-compile-command () | |
1226 "Replace meta-information in `compile-command'. | |
1227 Where __FILE__ appears in the string, the current buffer's file-name, | |
1228 without the directory portion, will be substituted." | |
1229 (when (and | |
1230 (stringp compile-command) | |
1231 (string-match "\\b__FILE__\\b" compile-command)) | |
1232 (make-local-variable 'compile-command) | |
1233 (setq compile-command | |
1234 (verilog-string-replace-matches | |
1235 "\\b__FILE__\\b" (file-name-nondirectory (buffer-file-name)) | |
1236 t t compile-command)))) | |
1237 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1238 ;; 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
|
1239 (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
|
1240 |
79545 | 1241 (defun verilog-error-regexp-add () |
1242 "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
|
1243 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
|
1244 find the errors." |
79545 | 1245 (if (not verilog-error-regexp-add-didit) |
1246 (progn | |
1247 (setq verilog-error-regexp-add-didit t) | |
1248 (setq-default compilation-error-regexp-alist | |
1249 (append verilog-error-regexp | |
1250 (default-value 'compilation-error-regexp-alist))) | |
1251 ;; 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
|
1252 (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
|
1253 (default-value 'compilation-error-regexp-alist)) |
79545 | 1254 (set (make-local-variable 'compilation-error-regexp-alist) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1255 (default-value 'compilation-error-regexp-alist))))) |
79545 | 1256 |
1257 (add-hook 'compilation-mode-hook 'verilog-error-regexp-add) | |
1258 | |
1259 (defconst verilog-directive-re | |
1260 ;; "`case" "`default" "`define" "`define" "`else" "`endfor" "`endif" | |
1261 ;; "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef" | |
1262 ;; "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale" | |
1263 ;; "`time_scale" "`undef" "`while" | |
1264 "\\<`\\(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\\)\\>") | |
1265 | |
1266 (defconst verilog-directive-begin | |
1267 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>") | |
1268 | |
1269 (defconst verilog-directive-middle | |
1270 "\\<`\\(else\\|default\\|case\\)\\>") | |
1271 | |
1272 (defconst verilog-directive-end | |
1273 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>") | |
1274 | |
1275 (defconst verilog-directive-re-1 | |
1276 (concat "[ \t]*" verilog-directive-re)) | |
1277 | |
1278 ;; | |
1279 ;; Regular expressions used to calculate indent, etc. | |
1280 ;; | |
1281 (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>") | |
1282 (defconst verilog-case-re "\\(\\<case[xz]?\\>\\|\\<randcase\\>\\)") | |
1283 ;; Want to match | |
1284 ;; aa : | |
1285 ;; aa,bb : | |
1286 ;; a[34:32] : | |
1287 ;; a, | |
1288 ;; b : | |
1289 | |
1290 (defconst verilog-no-indent-begin-re | |
1291 "\\<\\(if\\|else\\|while\\|for\\|repeat\\|always\\|always_comb\\|always_ff\\|always_latch\\)\\>") | |
1292 | |
1293 (defconst verilog-ends-re | |
1294 ;; Parenthesis indicate type of keyword found | |
1295 (concat | |
1296 "\\(\\<else\\>\\)\\|" ; 1 | |
1297 "\\(\\<if\\>\\)\\|" ; 2 | |
1298 "\\(\\<end\\>\\)\\|" ; 3 | |
1299 "\\(\\<endcase\\>\\)\\|" ; 4 | |
1300 "\\(\\<endfunction\\>\\)\\|" ; 5 | |
1301 "\\(\\<endtask\\>\\)\\|" ; 6 | |
1302 "\\(\\<endspecify\\>\\)\\|" ; 7 | |
1303 "\\(\\<endtable\\>\\)\\|" ; 8 | |
1304 "\\(\\<endgenerate\\>\\)\\|" ; 9 | |
1305 "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10 | |
1306 "\\(\\<endclass\\>\\)\\|" ; 11 | |
1307 "\\(\\<endgroup\\>\\)" ; 12 | |
1308 )) | |
1309 | |
1310 (defconst verilog-auto-end-comment-lines-re | |
1311 ;; Matches to names in this list cause auto-end-commentation | |
1312 (concat "\\(" | |
1313 verilog-directive-re "\\)\\|\\(" | |
1314 (eval-when-compile | |
1315 (verilog-regexp-words | |
1316 `( "begin" | |
1317 "else" | |
1318 "end" | |
1319 "endcase" | |
1320 "endclass" | |
1321 "endclocking" | |
1322 "endgroup" | |
1323 "endfunction" | |
1324 "endmodule" | |
1325 "endprogram" | |
1326 "endprimitive" | |
1327 "endinterface" | |
1328 "endpackage" | |
1329 "endsequence" | |
1330 "endspecify" | |
1331 "endtable" | |
1332 "endtask" | |
1333 "join" | |
1334 "join_any" | |
1335 "join_none" | |
1336 "module" | |
1337 "macromodule" | |
1338 "primitive" | |
1339 "interface" | |
1340 "package"))) | |
1341 "\\)")) | |
1342 | |
1343 ;;; NOTE: verilog-leap-to-head expects that verilog-end-block-re and | |
1344 ;;; verilog-end-block-ordered-re matches exactly the same strings. | |
1345 (defconst verilog-end-block-ordered-re | |
1346 ;; Parenthesis indicate type of keyword found | |
1347 (concat "\\(\\<endcase\\>\\)\\|" ; 1 | |
1348 "\\(\\<end\\>\\)\\|" ; 2 | |
1349 "\\(\\<end" ; 3, but not used | |
1350 "\\(" ; 4, but not used | |
1351 "\\(function\\)\\|" ; 5 | |
1352 "\\(task\\)\\|" ; 6 | |
1353 "\\(module\\)\\|" ; 7 | |
1354 "\\(primitive\\)\\|" ; 8 | |
1355 "\\(interface\\)\\|" ; 9 | |
1356 "\\(package\\)\\|" ; 10 | |
1357 "\\(class\\)\\|" ; 11 | |
1358 "\\(group\\)\\|" ; 12 | |
1359 "\\(program\\)\\|" ; 13 | |
1360 "\\(sequence\\)\\|" ; 14 | |
1361 "\\(clocking\\)\\|" ; 15 | |
1362 "\\)\\>\\)")) | |
1363 (defconst verilog-end-block-re | |
1364 (eval-when-compile | |
1365 (verilog-regexp-words | |
1366 | |
1367 `("end" ;; closes begin | |
1368 "endcase" ;; closes any of case, casex casez or randcase | |
1369 "join" "join_any" "join_none" ;; closes fork | |
1370 "endclass" | |
1371 "endtable" | |
1372 "endspecify" | |
1373 "endfunction" | |
1374 "endgenerate" | |
1375 "endtask" | |
1376 "endgroup" | |
1377 "endproperty" | |
1378 "endinterface" | |
1379 "endpackage" | |
1380 "endprogram" | |
1381 "endsequence" | |
1382 "endclocking" | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1383 )))) |
79545 | 1384 |
1385 | |
1386 (defconst verilog-endcomment-reason-re | |
1387 ;; Parenthesis indicate type of keyword found | |
1388 (concat | |
1389 "\\(\\<fork\\>\\)\\|" | |
1390 "\\(\\<begin\\>\\)\\|" | |
1391 "\\(\\<if\\>\\)\\|" | |
1392 "\\(\\<clocking\\>\\)\\|" | |
1393 "\\(\\<else\\>\\)\\|" | |
1394 "\\(\\<end\\>.*\\<else\\>\\)\\|" | |
1395 "\\(\\<task\\>\\)\\|" | |
1396 "\\(\\<function\\>\\)\\|" | |
1397 "\\(\\<initial\\>\\)\\|" | |
1398 "\\(\\<interface\\>\\)\\|" | |
1399 "\\(\\<package\\>\\)\\|" | |
1400 "\\(\\<final\\>\\)\\|" | |
1401 "\\(\\<always\\>\\(\[ \t\]*@\\)?\\)\\|" | |
1402 "\\(\\<always_comb\\>\\(\[ \t\]*@\\)?\\)\\|" | |
1403 "\\(\\<always_ff\\>\\(\[ \t\]*@\\)?\\)\\|" | |
1404 "\\(\\<always_latch\\>\\(\[ \t\]*@\\)?\\)\\|" | |
1405 "\\(@\\)\\|" | |
1406 "\\(\\<while\\>\\)\\|" | |
1407 "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|" | |
1408 "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|" | |
1409 "#")) | |
1410 | |
1411 (defconst verilog-named-block-re "begin[ \t]*:") | |
1412 | |
1413 ;; These words begin a block which can occur inside a module which should be indented, | |
1414 ;; and closed with the respective word from the end-block list | |
1415 | |
1416 (defconst verilog-beg-block-re | |
1417 (eval-when-compile | |
1418 (verilog-regexp-words | |
1419 `("begin" | |
1420 "case" "casex" "casez" "randcase" | |
1421 "clocking" | |
1422 "generate" | |
1423 "fork" | |
1424 "function" | |
1425 "property" | |
1426 "specify" | |
1427 "table" | |
1428 "task" | |
1429 )))) | |
1430 ;; These are the same words, in a specific order in the regular | |
1431 ;; expression so that matching will work nicely for | |
1432 ;; verilog-forward-sexp and verilog-calc-indent | |
1433 | |
1434 (defconst verilog-beg-block-re-ordered | |
1435 ( concat "\\<" | |
1436 "\\(begin\\)" ;1 | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1437 "\\|\\(randcase\\|\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)" ; 2,3 |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1438 "\\|\\(\\(disable\\s-+\\)?fork\\)" ;4 |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1439 "\\|\\(class\\)" ;5 |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1440 "\\|\\(table\\)" ;6 |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1441 "\\|\\(specify\\)" ;7 |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1442 "\\|\\(function\\)" ;8 |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1443 "\\|\\(task\\)" ;9 |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1444 "\\|\\(generate\\)" ;10 |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1445 "\\|\\(covergroup\\)" ;11 |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1446 "\\|\\(property\\)" ;12 |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1447 "\\|\\(\\(rand\\)?sequence\\)" ;13 |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1448 "\\|\\(clocking\\)" ;14 |
79545 | 1449 "\\>")) |
1450 | |
1451 (defconst verilog-end-block-ordered-rry | |
1452 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" | |
1453 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)" | |
1454 "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" | |
1455 "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" | |
1456 "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" | |
1457 "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" | |
1458 "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" | |
1459 "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" | |
1460 "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" | |
1461 "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" | |
1462 "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" | |
1463 "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" | |
1464 "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" | |
1465 ] ) | |
1466 | |
1467 (defconst verilog-nameable-item-re | |
1468 (eval-when-compile | |
1469 (verilog-regexp-words | |
1470 `("begin" | |
1471 "fork" | |
1472 "join" "join_any" "join_none" | |
1473 "end" | |
1474 "endcase" | |
1475 "endconfig" | |
1476 "endclass" | |
1477 "endclocking" | |
1478 "endfunction" | |
1479 "endgenerate" | |
1480 "endmodule" | |
1481 "endprimative" | |
1482 "endinterface" | |
1483 "endpackage" | |
1484 "endspecify" | |
1485 "endtable" | |
1486 "endtask" ) | |
1487 ))) | |
1488 | |
1489 (defconst verilog-declaration-opener | |
1490 (eval-when-compile | |
1491 (verilog-regexp-words | |
1492 `("module" "begin" "task" "function")))) | |
1493 | |
1494 (defconst verilog-declaration-prefix-re | |
1495 (eval-when-compile | |
1496 (verilog-regexp-words | |
1497 `( | |
1498 ;; port direction | |
79546 | 1499 "inout" "input" "output" "ref" |
79545 | 1500 ;; changeableness |
1501 "const" "static" "protected" "local" | |
1502 ;; parameters | |
79546 | 1503 "localparam" "parameter" "var" |
79545 | 1504 ;; type creation |
1505 "typedef" | |
1506 )))) | |
1507 (defconst verilog-declaration-core-re | |
1508 (eval-when-compile | |
1509 (verilog-regexp-words | |
1510 `( | |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
1511 ;; port direction (by themselves) |
80141
00b853b0f933
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
80024
diff
changeset
|
1512 "inout" "input" "output" |
79545 | 1513 ;; integer_atom_type |
1514 "byte" "shortint" "int" "longint" "integer" "time" | |
1515 ;; integer_vector_type | |
1516 "bit" "logic" "reg" | |
1517 ;; non_integer_type | |
1518 "shortreal" "real" "realtime" | |
1519 ;; net_type | |
1520 "supply0" "supply1" "tri" "triand" "trior" "trireg" "tri0" "tri1" "uwire" "wire" "wand" "wor" | |
1521 ;; misc | |
1522 "string" "event" "chandle" "virtual" "enum" "genvar" | |
1523 "struct" "union" | |
1524 ;; builtin classes | |
79546 | 1525 "mailbox" "semaphore" |
79545 | 1526 )))) |
79546 | 1527 (defconst verilog-declaration-re |
79545 | 1528 (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re)) |
1529 (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+") | |
1530 (defconst verilog-optional-signed-re "\\s-*\\(signed\\)?") | |
1531 (defconst verilog-optional-signed-range-re | |
1532 (concat | |
1533 "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\<signed\\>\\s-*\\)?\\(" verilog-range-re "\\)?")) | |
1534 (defconst verilog-macroexp-re "`\\sw+") | |
1535 | |
1536 (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)") | |
1537 (defconst verilog-declaration-re-2-no-macro | |
1538 (concat "\\s-*" verilog-declaration-re | |
1539 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)" | |
1540 "\\)?")) | |
1541 (defconst verilog-declaration-re-2-macro | |
1542 (concat "\\s-*" verilog-declaration-re | |
1543 "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)" | |
1544 "\\|\\(" verilog-macroexp-re "\\)" | |
1545 "\\)?")) | |
1546 (defconst verilog-declaration-re-1-macro | |
1547 (concat "^" verilog-declaration-re-2-macro)) | |
1548 | |
1549 (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro)) | |
1550 | |
1551 (defconst verilog-defun-re | |
1552 (eval-when-compile (verilog-regexp-words `("macromodule" "module" "class" "program" "interface" "package" "primitive" "config")))) | |
1553 (defconst verilog-end-defun-re | |
1554 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig")))) | |
1555 (defconst verilog-zero-indent-re | |
1556 (concat verilog-defun-re "\\|" verilog-end-defun-re)) | |
1557 | |
1558 (defconst verilog-behavioral-block-beg-re | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1559 (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff" |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1560 "function" "task")))) |
79545 | 1561 |
1562 (defconst verilog-indent-re | |
1563 (eval-when-compile | |
1564 (verilog-regexp-words | |
1565 `( | |
1566 "{" | |
1567 "always" "always_latch" "always_ff" "always_comb" | |
1568 "begin" "end" | |
1569 ; "unique" "priority" | |
1570 "case" "casex" "casez" "randcase" "endcase" | |
1571 "class" "endclass" | |
1572 "clocking" "endclocking" | |
1573 "config" "endconfig" | |
1574 "covergroup" "endgroup" | |
1575 "fork" "join" "join_any" "join_none" | |
1576 "function" "endfunction" | |
1577 "final" | |
1578 "generate" "endgenerate" | |
1579 "initial" | |
1580 "interface" "endinterface" | |
1581 "module" "macromodule" "endmodule" | |
1582 "package" "endpackage" | |
1583 "primitive" "endprimative" | |
1584 "program" "endprogram" | |
1585 "property" "endproperty" | |
1586 "sequence" "randsequence" "endsequence" | |
1587 "specify" "endspecify" | |
1588 "table" "endtable" | |
1589 "task" "endtask" | |
1590 "`case" | |
1591 "`default" | |
1592 "`define" "`undef" | |
1593 "`if" "`ifdef" "`ifndef" "`else" "`endif" | |
1594 "`while" "`endwhile" | |
1595 "`for" "`endfor" | |
1596 "`format" | |
1597 "`include" | |
1598 "`let" | |
1599 "`protect" "`endprotect" | |
1600 "`switch" "`endswitch" | |
1601 "`timescale" | |
1602 "`time_scale" | |
1603 )))) | |
1604 | |
1605 (defconst verilog-defun-level-re | |
1606 (eval-when-compile | |
1607 (verilog-regexp-words | |
1608 `( | |
1609 "module" "macromodule" "primitive" "class" "program" "initial" "final" "always" "always_comb" | |
1610 "always_ff" "always_latch" "endtask" "endfunction" "interface" "package" | |
1611 "config")))) | |
1612 | |
1613 (defconst verilog-defun-level-not-generate-re | |
1614 (eval-when-compile | |
1615 (verilog-regexp-words | |
1616 `( | |
1617 "module" "macromodule" "primitive" "class" "program" "interface" "package" "config")))) | |
1618 | |
1619 (defconst verilog-cpp-level-re | |
1620 (eval-when-compile | |
1621 (verilog-regexp-words | |
1622 `( | |
1623 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass" | |
1624 )))) | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1625 (defconst verilog-disable-fork-re "disable\\s-+fork") |
79545 | 1626 (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?") |
1627 (defconst verilog-extended-complete-re | |
1628 (concat "\\(\\<extern\\s-+\\|\\<virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)" | |
1629 "\\|\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)" | |
1630 "\\|" verilog-extended-case-re )) | |
1631 (defconst verilog-basic-complete-re | |
1632 (eval-when-compile | |
1633 (verilog-regexp-words | |
1634 `( | |
1635 "always" "assign" "always_latch" "always_ff" "always_comb" "constraint" | |
1636 "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while" | |
1637 "if" "for" "forever" "foreach" "else" "parameter" "do" | |
1638 )))) | |
1639 (defconst verilog-complete-reg | |
1640 (concat | |
1641 verilog-extended-complete-re | |
1642 "\\|" | |
1643 verilog-basic-complete-re)) | |
1644 | |
1645 (defconst verilog-end-statement-re | |
1646 (concat "\\(" verilog-beg-block-re "\\)\\|\\(" | |
1647 verilog-end-block-re "\\)")) | |
1648 | |
1649 (defconst verilog-endcase-re | |
1650 (concat verilog-case-re "\\|" | |
1651 "\\(endcase\\)\\|" | |
1652 verilog-defun-re | |
1653 )) | |
1654 | |
1655 (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----" | |
1656 "String used to mark beginning of excluded text.") | |
1657 (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */" | |
1658 "String used to mark end of excluded text.") | |
1659 (defconst verilog-preprocessor-re | |
1660 (eval-when-compile | |
1661 (verilog-regexp-words | |
1662 `( | |
1663 "`define" "`include" "`ifdef" "`ifndef" "`if" "`endif" "`else" | |
1664 )))) | |
1665 | |
1666 (defconst verilog-keywords | |
1667 '( "`case" "`default" "`define" "`else" "`endfor" "`endif" | |
1668 "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef" | |
1669 "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale" | |
1670 "`time_scale" "`undef" "`while" | |
1671 | |
1672 "after" "alias" "always" "always_comb" "always_ff" "always_latch" "and" | |
1673 "assert" "assign" "assume" "automatic" "before" "begin" "bind" | |
1674 "bins" "binsof" "bit" "break" "buf" "bufif0" "bufif1" "byte" | |
1675 "case" "casex" "casez" "cell" "chandle" "class" "clocking" "cmos" | |
1676 "config" "const" "constraint" "context" "continue" "cover" | |
1677 "covergroup" "coverpoint" "cross" "deassign" "default" "defparam" | |
1678 "design" "disable" "dist" "do" "edge" "else" "end" "endcase" | |
1679 "endclass" "endclocking" "endconfig" "endfunction" "endgenerate" | |
1680 "endgroup" "endinterface" "endmodule" "endpackage" "endprimitive" | |
1681 "endprogram" "endproperty" "endspecify" "endsequence" "endtable" | |
1682 "endtask" "enum" "event" "expect" "export" "extends" "extern" | |
1683 "final" "first_match" "for" "force" "foreach" "forever" "fork" | |
1684 "forkjoin" "function" "generate" "genvar" "highz0" "highz1" "if" | |
1685 "iff" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir" | |
1686 "include" "initial" "inout" "input" "inside" "instance" "int" | |
1687 "integer" "interface" "intersect" "join" "join_any" "join_none" | |
1688 "large" "liblist" "library" "local" "localparam" "logic" | |
1689 "longint" "macromodule" "mailbox" "matches" "medium" "modport" "module" | |
1690 "nand" "negedge" "new" "nmos" "nor" "noshowcancelled" "not" | |
1691 "notif0" "notif1" "null" "or" "output" "package" "packed" | |
1692 "parameter" "pmos" "posedge" "primitive" "priority" "program" | |
1693 "property" "protected" "pull0" "pull1" "pulldown" "pullup" | |
1694 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc" | |
1695 "randcase" "randsequence" "rcmos" "real" "realtime" "ref" "reg" | |
1696 "release" "repeat" "return" "rnmos" "rpmos" "rtran" "rtranif0" | |
1697 "rtranif1" "scalared" "semaphore" "sequence" "shortint" "shortreal" | |
1698 "showcancelled" "signed" "small" "solve" "specify" "specparam" | |
1699 "static" "string" "strong0" "strong1" "struct" "super" "supply0" | |
1700 "supply1" "table" "tagged" "task" "this" "throughout" "time" | |
1701 "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri" | |
1702 "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union" | |
1703 "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void" | |
1704 "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard" | |
1705 "wire" "with" "within" "wor" "xnor" "xor" | |
1706 ) | |
1707 "List of Verilog keywords.") | |
1708 | |
1709 (defconst verilog-comment-start-regexp "//\\|/\\*" | |
1710 "Dual comment value for `comment-start-regexp'.") | |
1711 | |
79810
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1712 (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
|
1713 (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
|
1714 ;; Populate the syntax TABLE. |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1715 (modify-syntax-entry ?\\ "\\" table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1716 (modify-syntax-entry ?+ "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1717 (modify-syntax-entry ?- "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1718 (modify-syntax-entry ?= "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1719 (modify-syntax-entry ?% "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1720 (modify-syntax-entry ?< "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1721 (modify-syntax-entry ?> "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1722 (modify-syntax-entry ?& "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1723 (modify-syntax-entry ?| "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1724 (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
|
1725 (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
|
1726 (modify-syntax-entry ?\' "." table) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1727 |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1728 ;; 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
|
1729 (if (featurep 'xemacs) |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1730 (progn |
606faa750dd7
(verilog-mode-map): Don't bind C-M-a,
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79801
diff
changeset
|
1731 ;; 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
|
1732 (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
|
1733 (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
|
1734 (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
|
1735 ;; 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
|
1736 (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
|
1737 (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
|
1738 (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
|
1739 table) |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
1740 "Syntax table used in Verilog mode buffers.") |
79545 | 1741 |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1742 (defvar verilog-font-lock-keywords nil |
79545 | 1743 "Default highlighting for Verilog mode.") |
1744 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1745 (defvar verilog-font-lock-keywords-1 nil |
79545 | 1746 "Subdued level highlighting for Verilog mode.") |
1747 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1748 (defvar verilog-font-lock-keywords-2 nil |
79545 | 1749 "Medium level highlighting for Verilog mode. |
1750 See also `verilog-font-lock-extra-types'.") | |
1751 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1752 (defvar verilog-font-lock-keywords-3 nil |
79545 | 1753 "Gaudy level highlighting for Verilog mode. |
1754 See also `verilog-font-lock-extra-types'.") | |
1755 (defvar verilog-font-lock-translate-off-face | |
1756 'verilog-font-lock-translate-off-face | |
1757 "Font to use for translated off regions.") | |
1758 (defface verilog-font-lock-translate-off-face | |
1759 '((((class color) | |
1760 (background light)) | |
1761 (:background "gray90" :italic t )) | |
1762 (((class color) | |
1763 (background dark)) | |
1764 (:background "gray10" :italic t )) | |
1765 (((class grayscale) (background light)) | |
1766 (:foreground "DimGray" :italic t)) | |
1767 (((class grayscale) (background dark)) | |
1768 (:foreground "LightGray" :italic t)) | |
1769 (t (:italis t))) | |
1770 "Font lock mode face used to background highlight translate-off regions." | |
1771 :group 'font-lock-highlighting-faces) | |
1772 | |
1773 (defvar verilog-font-lock-p1800-face | |
1774 'verilog-font-lock-p1800-face | |
1775 "Font to use for p1800 keywords.") | |
1776 (defface verilog-font-lock-p1800-face | |
1777 '((((class color) | |
1778 (background light)) | |
1779 (:foreground "DarkOrange3" :bold t )) | |
1780 (((class color) | |
1781 (background dark)) | |
1782 (:foreground "orange1" :bold t )) | |
1783 (t (:italic t))) | |
1784 "Font lock mode face used to highlight P1800 keywords." | |
1785 :group 'font-lock-highlighting-faces) | |
1786 | |
1787 (defvar verilog-font-lock-ams-face | |
1788 'verilog-font-lock-ams-face | |
1789 "Font to use for Analog/Mixed Signal keywords.") | |
1790 (defface verilog-font-lock-ams-face | |
1791 '((((class color) | |
1792 (background light)) | |
1793 (:foreground "Purple" :bold t )) | |
1794 (((class color) | |
1795 (background dark)) | |
1796 (:foreground "orange1" :bold t )) | |
1797 (t (:italic t))) | |
1798 "Font lock mode face used to highlight AMS keywords." | |
1799 :group 'font-lock-highlighting-faces) | |
1800 | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1801 (defvar verilog-font-grouping-keywords-face |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1802 'verilog-font-lock-grouping-keywords-face |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1803 "Font to use for Verilog Grouping Keywords (such as begin..end).") |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1804 (defface verilog-font-lock-grouping-keywords-face |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1805 '((((class color) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1806 (background light)) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1807 (:foreground "red4" :bold t )) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1808 (((class color) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1809 (background dark)) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1810 (:foreground "red4" :bold t )) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1811 (t (:italic t))) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1812 "Font lock mode face used to highlight verilog grouping keywords." |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1813 :group 'font-lock-highlighting-faces) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1814 |
79545 | 1815 (let* ((verilog-type-font-keywords |
1816 (eval-when-compile | |
1817 (verilog-regexp-opt | |
1818 '( | |
1819 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam" | |
1820 "event" "genvar" "inout" "input" "integer" "localparam" | |
1821 "logic" "mailbox" "nand" "nmos" "not" "notif0" "notif1" "or" | |
1822 "output" "parameter" "pmos" "pull0" "pull1" "pullup" | |
1823 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" | |
1824 "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply" | |
1825 "supply0" "supply1" "time" "tran" "tranif0" "tranif1" | |
1826 "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef" | |
1827 "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor" | |
1828 ) nil ))) | |
1829 | |
1830 (verilog-pragma-keywords | |
1831 (eval-when-compile | |
1832 (verilog-regexp-opt | |
1833 '("surefire" "synopsys" "rtl_synthesis" "verilint" ) nil | |
1834 ))) | |
1835 | |
1836 (verilog-p1800-keywords | |
1837 (eval-when-compile | |
1838 (verilog-regexp-opt | |
1839 '("alias" "assert" "assume" "automatic" "before" "bind" | |
1840 "bins" "binsof" "break" "byte" "cell" "chandle" "class" | |
1841 "clocking" "config" "const" "constraint" "context" "continue" | |
1842 "cover" "covergroup" "coverpoint" "cross" "deassign" "design" | |
1843 "dist" "do" "edge" "endclass" "endclocking" "endconfig" | |
1844 "endgroup" "endprogram" "endproperty" "endsequence" "enum" | |
1845 "expect" "export" "extends" "extern" "first_match" "foreach" | |
1846 "forkjoin" "genvar" "highz0" "highz1" "ifnone" "ignore_bins" | |
1847 "illegal_bins" "import" "incdir" "include" "inside" "instance" | |
1848 "int" "intersect" "large" "liblist" "library" "local" "longint" | |
1849 "matches" "medium" "modport" "new" "noshowcancelled" "null" | |
1850 "packed" "program" "property" "protected" "pull0" "pull1" | |
1851 "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc" | |
1852 "randcase" "randsequence" "ref" "release" "return" "scalared" | |
1853 "sequence" "shortint" "shortreal" "showcancelled" "small" "solve" | |
1854 "specparam" "static" "string" "strong0" "strong1" "struct" | |
1855 "super" "tagged" "this" "throughout" "timeprecision" "timeunit" | |
1856 "type" "union" "unsigned" "use" "var" "virtual" "void" | |
1857 "wait_order" "weak0" "weak1" "wildcard" "with" "within" | |
1858 ) nil ))) | |
1859 | |
1860 (verilog-ams-keywords | |
1861 (eval-when-compile | |
1862 (verilog-regexp-opt | |
1863 '("above" "abs" "absdelay" "acos" "acosh" "ac_stim" | |
1864 "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh" | |
1865 "branch" "ceil" "connectmodule" "connectrules" "cos" "cosh" "ddt" | |
1866 "ddx" "discipline" "driver_update" "enddiscipline" "endconnectrules" | |
1867 "endnature" "endparamset" "exclude" "exp" "final_step" "flicker_noise" | |
1868 "floor" "flow" "from" "ground" "hypot" "idt" "idtmod" "inf" | |
1869 "initial_step" "laplace_nd" "laplace_np" "laplace_zd" "laplace_zp" | |
1870 "last_crossing" "limexp" "ln" "log" "max" "min" "nature" | |
1871 "net_resolution" "noise_table" "paramset" "potential" "pow" "sin" | |
1872 "sinh" "slew" "sqrt" "tan" "tanh" "timer" "transition" "white_noise" | |
1873 "wreal" "zi_nd" "zi_np" "zi_zd" ) nil ))) | |
1874 | |
1875 (verilog-font-keywords | |
1876 (eval-when-compile | |
1877 (verilog-regexp-opt | |
1878 '( | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1879 "assign" "case" "casex" "casez" "randcase" "deassign" |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1880 "default" "disable" "else" "endcase" "endfunction" |
79545 | 1881 "endgenerate" "endinterface" "endmodule" "endprimitive" |
1882 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break" | |
1883 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial" | |
1884 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge" | |
1885 "package" "endpackage" "always" "always_comb" "always_ff" | |
1886 "always_latch" "posedge" "primitive" "priority" "release" | |
1887 "repeat" "specify" "table" "task" "unique" "wait" "while" | |
1888 "class" "program" "endclass" "endprogram" | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1889 ) nil ))) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1890 |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1891 (verilog-font-grouping-keywords |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1892 (eval-when-compile |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1893 (verilog-regexp-opt |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1894 '( "begin" "end" ) nil )))) |
79545 | 1895 |
1896 (setq verilog-font-lock-keywords | |
1897 (list | |
1898 ;; Fontify all builtin keywords | |
1899 (concat "\\<\\(" verilog-font-keywords "\\|" | |
1900 ;; And user/system tasks and functions | |
1901 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*" | |
1902 "\\)\\>") | |
1903 ;; Fontify all types | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1904 (cons (concat "\\(\\<" verilog-font-grouping-keywords "\\)\\>") |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1905 'verilog-font-lock-ams-face) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
1906 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>") |
79545 | 1907 'font-lock-type-face) |
1908 ;; Fontify IEEE-P1800 keywords appropriately | |
1909 (if verilog-highlight-p1800-keywords | |
1910 (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>") | |
1911 'verilog-font-lock-p1800-face) | |
1912 (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>") | |
1913 'font-lock-type-face)) | |
1914 ;; Fontify Verilog-AMS keywords | |
1915 (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1916 'verilog-font-lock-ams-face))) |
79545 | 1917 |
1918 (setq verilog-font-lock-keywords-1 | |
1919 (append verilog-font-lock-keywords | |
1920 (list | |
1921 ;; Fontify module definitions | |
1922 (list | |
1923 "\\<\\(\\(macro\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)" | |
1924 '(1 font-lock-keyword-face) | |
1925 '(3 font-lock-function-name-face 'prepend)) | |
1926 ;; Fontify function definitions | |
1927 (list | |
1928 (concat "\\<function\\>\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" ) | |
1929 '(1 font-lock-keyword-face) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1930 '(3 font-lock-reference-face prepend)) |
79545 | 1931 '("\\<function\\>\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)" |
1932 (1 font-lock-keyword-face) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1933 (2 font-lock-reference-face append)) |
79545 | 1934 '("\\<function\\>\\s-+\\(\\sw+\\)" |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1935 1 'font-lock-reference-face append)))) |
79545 | 1936 |
1937 (setq verilog-font-lock-keywords-2 | |
1938 (append verilog-font-lock-keywords-1 | |
1939 (list | |
1940 ;; Fontify pragmas | |
1941 (concat "\\(//\\s-*" verilog-pragma-keywords "\\s-.*\\)") | |
1942 ;; Fontify escaped names | |
1943 '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face) | |
1944 ;; Fontify macro definitions/ uses | |
1945 '("`\\s-*[A-Za-z][A-Za-z0-9_]*" 0 (if (boundp 'font-lock-preprocessor-face) | |
1946 'font-lock-preprocessor-face | |
1947 'font-lock-type-face)) | |
1948 ;; Fontify delays/numbers | |
1949 '("\\(@\\)\\|\\(#\\s-*\\(\\(\[0-9_.\]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)" | |
1950 0 font-lock-type-face append) | |
1951 ;; Fontify instantiation names | |
1952 '("\\([A-Za-z][A-Za-z0-9_]+\\)\\s-*(" 1 font-lock-function-name-face) | |
1953 ))) | |
1954 | |
1955 (setq verilog-font-lock-keywords-3 | |
1956 (append verilog-font-lock-keywords-2 | |
1957 (when verilog-highlight-translate-off | |
1958 (list | |
1959 ;; 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
|
1960 '(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
|
1961 (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
|
1962 ))))) |
79545 | 1963 |
1964 | |
1965 (defun verilog-inside-comment-p () | |
1966 "Check if point inside a nested comment." | |
1967 (save-excursion | |
1968 (let ((st-point (point)) hitbeg) | |
1969 (or (search-backward "//" (verilog-get-beg-of-line) t) | |
1970 (if (progn | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1971 ;; This is for tricky case //*, we keep searching if /* |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1972 ;; 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
|
1973 (while |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1974 (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
|
1975 (progn |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1976 (forward-char 1) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
1977 (search-backward "//" (verilog-get-beg-of-line) t)))) |
79545 | 1978 hitbeg) |
1979 (not (search-forward "*/" st-point t))))))) | |
1980 | |
1981 (defun verilog-declaration-end () | |
1982 (search-forward ";")) | |
1983 | |
1984 (defun verilog-point-text (&optional pointnum) | |
1985 "Return text describing where POINTNUM or current point is (for errors). | |
1986 Use filename, if current buffer being edited shorten to just buffer name." | |
1987 (concat (or (and (equal (window-buffer (selected-window)) (current-buffer)) | |
1988 (buffer-name)) | |
1989 buffer-file-name | |
1990 (buffer-name)) | |
1991 ":" (int-to-string (count-lines (point-min) (or pointnum (point)))))) | |
1992 | |
1993 (defun electric-verilog-backward-sexp () | |
1994 "Move backward over a sexp." | |
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-backward-sexp)) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
1998 |
79545 | 1999 (defun electric-verilog-forward-sexp () |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
2000 "Move forward over a sexp." |
79545 | 2001 (interactive) |
2002 ;; 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
|
2003 (verilog-forward-sexp)) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2004 |
79545 | 2005 ;;;used by hs-minor-mode |
2006 (defun verilog-forward-sexp-function (arg) | |
2007 (if (< arg 0) | |
2008 (verilog-backward-sexp) | |
2009 (verilog-forward-sexp))) | |
2010 | |
2011 | |
2012 (defun verilog-backward-sexp () | |
2013 (let ((reg) | |
2014 (elsec 1) | |
2015 (found nil) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2016 (st (point))) |
79545 | 2017 (if (not (looking-at "\\<")) |
2018 (forward-word -1)) | |
2019 (cond | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2020 ((verilog-skip-backward-comment-or-string)) |
79545 | 2021 ((looking-at "\\<else\\>") |
2022 (setq reg (concat | |
2023 verilog-end-block-re | |
2024 "\\|\\(\\<else\\>\\)" | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2025 "\\|\\(\\<if\\>\\)")) |
79545 | 2026 (while (and (not found) |
2027 (verilog-re-search-backward reg nil 'move)) | |
2028 (cond | |
2029 ((match-end 1) ; matched verilog-end-block-re | |
2030 ; try to leap back to matching outward block by striding across | |
2031 ; indent level changing tokens then immediately | |
2032 ; previous line governs indentation. | |
2033 (verilog-leap-to-head)) | |
2034 ((match-end 2) ; else, we're in deep | |
2035 (setq elsec (1+ elsec))) | |
2036 ((match-end 3) ; found it | |
2037 (setq elsec (1- elsec)) | |
2038 (if (= 0 elsec) | |
2039 ;; Now previous line describes syntax | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2040 (setq found 't)))))) |
79545 | 2041 ((looking-at verilog-end-block-re) |
2042 (verilog-leap-to-head)) | |
2043 ((looking-at "\\(endmodule\\>\\)\\|\\(\\<endprimitive\\>\\)\\|\\(\\<endclass\\>\\)\\|\\(\\<endprogram\\>\\)\\|\\(\\<endinterface\\>\\)\\|\\(\\<endpackage\\>\\)") | |
2044 (cond | |
2045 ((match-end 1) | |
2046 (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move)) | |
2047 ((match-end 2) | |
2048 (verilog-re-search-backward "\\<primitive\\>" nil 'move)) | |
2049 ((match-end 3) | |
2050 (verilog-re-search-backward "\\<class\\>" nil 'move)) | |
2051 ((match-end 4) | |
2052 (verilog-re-search-backward "\\<program\\>" nil 'move)) | |
2053 ((match-end 5) | |
2054 (verilog-re-search-backward "\\<interface\\>" nil 'move)) | |
2055 ((match-end 6) | |
2056 (verilog-re-search-backward "\\<package\\>" nil 'move)) | |
2057 (t | |
2058 (goto-char st) | |
2059 (backward-sexp 1)))) | |
2060 (t | |
2061 (goto-char st) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2062 (backward-sexp))))) |
79545 | 2063 |
2064 (defun verilog-forward-sexp () | |
2065 (let ((reg) | |
2066 (md 2) | |
2067 (st (point))) | |
2068 (if (not (looking-at "\\<")) | |
2069 (forward-word -1)) | |
2070 (cond | |
2071 ((verilog-skip-forward-comment-or-string) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2072 (verilog-forward-syntactic-ws)) |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2073 ((looking-at verilog-beg-block-re-ordered) ;; begin|(case)|xx|(fork)|class|table|specify|function|task|generate|covergroup|property|sequence|clocking |
79545 | 2074 (cond |
2075 ((match-end 1) ; end | |
2076 ;; Search forward for matching begin | |
2077 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" )) | |
2078 ((match-end 2) ; endcase | |
2079 ;; Search forward for matching case | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2080 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2081 (setq md 3) ;; ender is third item in regexp |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2082 ) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2083 ((match-end 4) ; join |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2084 ;; might be "disable fork" |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2085 (if (or |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2086 (looking-at verilog-disable-fork-re) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2087 (and (looking-at "fork") |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2088 (progn |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2089 (forward-word -1) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2090 (looking-at verilog-disable-fork-re)))) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2091 (progn |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2092 (goto-char (match-end 0)) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2093 (forward-word) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2094 (setq reg nil)) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2095 (progn |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2096 ;; Search forward for matching fork |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2097 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2098 ((match-end 5) ; endclass |
79545 | 2099 ;; Search forward for matching class |
2100 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" )) | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2101 ((match-end 6) ; endtable |
79545 | 2102 ;; Search forward for matching table |
2103 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )) | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2104 ((match-end 7) ; endspecify |
79545 | 2105 ;; Search forward for matching specify |
2106 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )) | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2107 ((match-end 8) ; endfunction |
79545 | 2108 ;; Search forward for matching function |
2109 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )) | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2110 ((match-end 9) ; endtask |
79545 | 2111 ;; Search forward for matching task |
2112 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" )) | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2113 ((match-end 10) ; endgenerate |
79545 | 2114 ;; Search forward for matching generate |
2115 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" )) | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2116 ((match-end 11) ; endgroup |
79545 | 2117 ;; Search forward for matching covergroup |
2118 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )) | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2119 ((match-end 12) ; endproperty |
79545 | 2120 ;; Search forward for matching property |
2121 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" )) | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2122 ((match-end 13) ; endsequence |
79545 | 2123 ;; Search forward for matching sequence |
2124 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2125 (setq md 3)) ; 3 to get to endsequence in the reg above |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2126 ((match-end 14) ; endclocking |
79545 | 2127 ;; Search forward for matching clocking |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2128 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" ))) |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2129 (if (and reg |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
2130 (forward-word 1)) |
79545 | 2131 (catch 'skip |
2132 (let ((nest 1)) | |
2133 (while (verilog-re-search-forward reg nil 'move) | |
2134 (cond | |
2135 ((match-end md) ; the closer in reg, so we are climbing out | |
2136 (setq nest (1- nest)) | |
2137 (if (= 0 nest) ; we are out! | |
2138 (throw 'skip 1))) | |
2139 ((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
|
2140 (setq nest (1+ nest))))))))) |
79545 | 2141 ((looking-at (concat |
2142 "\\(\\<\\(macro\\)?module\\>\\)\\|" | |
2143 "\\(\\<primitive\\>\\)\\|" | |
2144 "\\(\\<class\\>\\)\\|" | |
2145 "\\(\\<program\\>\\)\\|" | |
2146 "\\(\\<interface\\>\\)\\|" | |
2147 "\\(\\<package\\>\\)")) | |
2148 (cond | |
2149 ((match-end 1) | |
2150 (verilog-re-search-forward "\\<endmodule\\>" nil 'move)) | |
2151 ((match-end 2) | |
2152 (verilog-re-search-forward "\\<endprimitive\\>" nil 'move)) | |
2153 ((match-end 3) | |
2154 (verilog-re-search-forward "\\<endclass\\>" nil 'move)) | |
2155 ((match-end 4) | |
2156 (verilog-re-search-forward "\\<endprogram\\>" nil 'move)) | |
2157 ((match-end 5) | |
2158 (verilog-re-search-forward "\\<endinterface\\>" nil 'move)) | |
2159 ((match-end 6) | |
2160 (verilog-re-search-forward "\\<endpackage\\>" nil 'move)) | |
2161 (t | |
2162 (goto-char st) | |
2163 (if (= (following-char) ?\) ) | |
2164 (forward-char 1) | |
2165 (forward-sexp 1))))) | |
2166 (t | |
2167 (goto-char st) | |
2168 (if (= (following-char) ?\) ) | |
2169 (forward-char 1) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2170 (forward-sexp 1)))))) |
79545 | 2171 |
2172 (defun verilog-declaration-beg () | |
2173 (verilog-re-search-backward verilog-declaration-re (bobp) t)) | |
2174 | |
2175 (defun verilog-font-lock-init () | |
2176 "Initialize fontification." | |
2177 ;; highlight keywords and standardized types, attributes, enumeration | |
2178 ;; values, and subprograms | |
2179 (setq verilog-font-lock-keywords-3 | |
2180 (append verilog-font-lock-keywords-2 | |
2181 (when verilog-highlight-translate-off | |
2182 (list | |
2183 ;; 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
|
2184 '(verilog-match-translate-off |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2185 (0 'verilog-font-lock-translate-off-face prepend)))))) |
79545 | 2186 (put 'verilog-mode 'font-lock-defaults |
2187 '((verilog-font-lock-keywords | |
2188 verilog-font-lock-keywords-1 | |
2189 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
|
2190 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
|
2191 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
|
2192 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
|
2193 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
|
2194 ;; 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
|
2195 verilog-beg-of-defun))) |
79545 | 2196 |
2197 ;; initialize fontification for Verilog Mode | |
2198 (verilog-font-lock-init) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2199 |
79545 | 2200 ;; |
2201 ;; | |
2202 ;; Mode | |
2203 ;; | |
2204 (defvar verilog-which-tool 1) | |
79546 | 2205 ;;;###autoload |
79545 | 2206 (defun verilog-mode () |
2207 "Major mode for editing Verilog code. | |
2208 \\<verilog-mode-map> | |
2209 See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how | |
2210 AUTOs can improve coding efficiency. | |
2211 | |
2212 Use \\[verilog-faq] for a pointer to frequently asked questions. | |
2213 | |
2214 NEWLINE, TAB indents for Verilog code. | |
2215 Delete converts tabs to spaces as it moves back. | |
2216 | |
2217 Supports highlighting. | |
2218 | |
2219 Turning on Verilog mode calls the value of the variable `verilog-mode-hook' | |
2220 with no args, if that value is non-nil. | |
2221 | |
2222 Variables controlling indentation/edit style: | |
2223 | |
2224 variable `verilog-indent-level' (default 3) | |
2225 Indentation of Verilog statements with respect to containing block. | |
2226 `verilog-indent-level-module' (default 3) | |
2227 Absolute indentation of Module level Verilog statements. | |
2228 Set to 0 to get initial and always statements lined up | |
2229 on the left side of your screen. | |
2230 `verilog-indent-level-declaration' (default 3) | |
2231 Indentation of declarations with respect to containing block. | |
2232 Set to 0 to get them list right under containing block. | |
2233 `verilog-indent-level-behavioral' (default 3) | |
2234 Indentation of first begin in a task or function block | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
2235 Set to 0 to get such code to lined up underneath the task or |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
2236 function keyword. |
79545 | 2237 `verilog-indent-level-directive' (default 1) |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
2238 Indentation of `ifdef/`endif blocks. |
79545 | 2239 `verilog-cexp-indent' (default 1) |
2240 Indentation of Verilog statements broken across lines i.e.: | |
2241 if (a) | |
2242 begin | |
2243 `verilog-case-indent' (default 2) | |
2244 Indentation for case statements. | |
2245 `verilog-auto-newline' (default nil) | |
2246 Non-nil means automatically newline after semicolons and the punctuation | |
2247 mark after an end. | |
2248 `verilog-auto-indent-on-newline' (default t) | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
2249 Non-nil means automatically indent line after newline. |
79545 | 2250 `verilog-tab-always-indent' (default t) |
2251 Non-nil means TAB in Verilog mode should always reindent the current line, | |
2252 regardless of where in the line point is when the TAB command is used. | |
2253 `verilog-indent-begin-after-if' (default t) | |
2254 Non-nil means to indent begin statements following a preceding | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
2255 if, else, while, for and repeat statements, if any. Otherwise, |
79545 | 2256 the begin is lined up with the preceding token. If t, you get: |
2257 if (a) | |
2258 begin // amount of indent based on `verilog-cexp-indent' | |
2259 otherwise you get: | |
2260 if (a) | |
2261 begin | |
2262 `verilog-auto-endcomments' (default t) | |
2263 Non-nil means a comment /* ... */ is set after the ends which ends | |
2264 cases, tasks, functions and modules. | |
2265 The type and name of the object will be set between the braces. | |
2266 `verilog-minimum-comment-distance' (default 10) | |
2267 Minimum distance (in lines) between begin and end required before a comment | |
2268 will be inserted. Setting this variable to zero results in every | |
2269 end acquiring a comment; the default avoids too many redundant | |
2270 comments in tight quarters. | |
2271 `verilog-auto-lineup' (default `(all)) | |
2272 List of contexts where auto lineup of code should be done. | |
2273 | |
2274 Variables controlling other actions: | |
2275 | |
2276 `verilog-linter' (default surelint) | |
2277 Unix program to call to run the lint checker. This is the default | |
2278 command for \\[compile-command] and \\[verilog-auto-save-compile]. | |
2279 | |
2280 See \\[customize] for the complete list of variables. | |
2281 | |
2282 AUTO expansion functions are, in part: | |
2283 | |
2284 \\[verilog-auto] Expand AUTO statements. | |
2285 \\[verilog-delete-auto] Remove the AUTOs. | |
2286 \\[verilog-inject-auto] Insert AUTOs for the first time. | |
2287 | |
2288 Some other functions are: | |
2289 | |
2290 \\[verilog-complete-word] Complete word with appropriate possibilities. | |
2291 \\[verilog-mark-defun] Mark function. | |
2292 \\[verilog-beg-of-defun] Move to beginning of current function. | |
2293 \\[verilog-end-of-defun] Move to end of current function. | |
2294 \\[verilog-label-be] Label matching begin ... end, fork ... join, etc statements. | |
2295 | |
2296 \\[verilog-comment-region] Put marked area in a comment. | |
2297 \\[verilog-uncomment-region] Uncomment an area commented with \\[verilog-comment-region]. | |
2298 \\[verilog-insert-block] Insert begin ... end;. | |
2299 \\[verilog-star-comment] Insert /* ... */. | |
2300 | |
2301 \\[verilog-sk-always] Insert a always @(AS) begin .. end block. | |
2302 \\[verilog-sk-begin] Insert a begin .. end block. | |
2303 \\[verilog-sk-case] Insert a case block, prompting for details. | |
2304 \\[verilog-sk-for] Insert a for (...) begin .. end block, prompting for details. | |
2305 \\[verilog-sk-generate] Insert a generate .. endgenerate block. | |
2306 \\[verilog-sk-header] Insert a nice header block at the top of file. | |
2307 \\[verilog-sk-initial] Insert an initial begin .. end block. | |
2308 \\[verilog-sk-fork] Insert a fork begin .. end .. join block. | |
2309 \\[verilog-sk-module] Insert a module .. (/*AUTOARG*/);.. endmodule block. | |
2310 \\[verilog-sk-primitive] Insert a primitive .. (.. );.. endprimitive block. | |
2311 \\[verilog-sk-repeat] Insert a repeat (..) begin .. end block. | |
2312 \\[verilog-sk-specify] Insert a specify .. endspecify block. | |
2313 \\[verilog-sk-task] Insert a task .. begin .. end endtask block. | |
2314 \\[verilog-sk-while] Insert a while (...) begin .. end block, prompting for details. | |
2315 \\[verilog-sk-casex] Insert a casex (...) item: begin.. end endcase block, prompting for details. | |
2316 \\[verilog-sk-casez] Insert a casez (...) item: begin.. end endcase block, prompting for details. | |
2317 \\[verilog-sk-if] Insert an if (..) begin .. end block. | |
2318 \\[verilog-sk-else-if] Insert an else if (..) begin .. end block. | |
2319 \\[verilog-sk-comment] Insert a comment block. | |
2320 \\[verilog-sk-assign] Insert an assign .. = ..; statement. | |
2321 \\[verilog-sk-function] Insert a function .. begin .. end endfunction block. | |
2322 \\[verilog-sk-input] Insert an input declaration, prompting for details. | |
2323 \\[verilog-sk-output] Insert an output declaration, prompting for details. | |
2324 \\[verilog-sk-state-machine] Insert a state machine definition, prompting for details. | |
2325 \\[verilog-sk-inout] Insert an inout declaration, prompting for details. | |
2326 \\[verilog-sk-wire] Insert a wire declaration, prompting for details. | |
2327 \\[verilog-sk-reg] Insert a register declaration, prompting for details. | |
2328 \\[verilog-sk-define-signal] Define signal under point as a register at the top of the module. | |
2329 | |
2330 All key bindings can be seen in a Verilog-buffer with \\[describe-bindings]. | |
2331 Key bindings specific to `verilog-mode-map' are: | |
2332 | |
2333 \\{verilog-mode-map}" | |
2334 (interactive) | |
2335 (kill-all-local-variables) | |
2336 (use-local-map verilog-mode-map) | |
2337 (setq major-mode 'verilog-mode) | |
2338 (setq mode-name "Verilog") | |
2339 (setq local-abbrev-table verilog-mode-abbrev-table) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2340 (set (make-local-variable 'beginning-of-defun-function) |
79546 | 2341 'verilog-beg-of-defun) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2342 (set (make-local-variable 'end-of-defun-function) |
79546 | 2343 'verilog-end-of-defun) |
79545 | 2344 (set-syntax-table verilog-mode-syntax-table) |
2345 (make-local-variable 'indent-line-function) | |
2346 (setq indent-line-function 'verilog-indent-line-relative) | |
2347 (setq comment-indent-function 'verilog-comment-indent) | |
2348 (make-local-variable 'parse-sexp-ignore-comments) | |
2349 (setq parse-sexp-ignore-comments nil) | |
2350 (make-local-variable 'comment-start) | |
2351 (make-local-variable 'comment-end) | |
2352 (make-local-variable 'comment-multi-line) | |
2353 (make-local-variable 'comment-start-skip) | |
2354 (setq comment-start "// " | |
2355 comment-end "" | |
2356 comment-start-skip "/\\*+ *\\|// *" | |
2357 comment-multi-line nil) | |
2358 ;; Set up for compilation | |
2359 (setq verilog-which-tool 1) | |
2360 (setq verilog-tool 'verilog-linter) | |
2361 (verilog-set-compile-command) | |
2362 (when (boundp 'hack-local-variables-hook) ;; Also modify any file-local-variables | |
2363 (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t)) | |
2364 | |
2365 ;; Setting up menus | |
79546 | 2366 (when (featurep 'xemacs) |
80172
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
2367 (easy-menu-add verilog-stmt-menu) |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
2368 (easy-menu-add verilog-menu) |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
2369 (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu))) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2370 |
79545 | 2371 ;; 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
|
2372 (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
|
2373 '((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
|
2374 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
|
2375 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
|
2376 nil nil nil verilog-beg-of-defun)) |
79545 | 2377 ;;------------------------------------------------------------ |
2378 ;; now hook in 'verilog-colorize-include-files (eldo-mode.el&spice-mode.el) | |
2379 ;; 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
|
2380 (when (featurep 'xemacs) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2381 (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
|
2382 (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
|
2383 (make-local-hook 'after-change-functions)) |
79545 | 2384 (add-hook 'font-lock-mode-hook 'verilog-colorize-include-files-buffer t t) |
2385 (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-colorize-include-files-buffer t t) ; not in emacs 20 | |
2386 (add-hook 'after-change-functions 'verilog-colorize-include-files t t) | |
2387 | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
2388 ;; Tell imenu how to handle Verilog. |
79545 | 2389 (make-local-variable 'imenu-generic-expression) |
2390 (setq imenu-generic-expression verilog-imenu-generic-expression) | |
2391 ;; hideshow support | |
2392 (unless (assq 'verilog-mode hs-special-modes-alist) | |
2393 (setq hs-special-modes-alist | |
2394 (cons '(verilog-mode-mode "\\<begin\\>" "\\<end\\>" nil | |
2395 verilog-forward-sexp-function) | |
2396 hs-special-modes-alist))) | |
2397 | |
2398 ;; Stuff for autos | |
2399 (add-hook 'write-contents-hooks 'verilog-auto-save-check) ; already local | |
2400 ;; (verilog-auto-reeval-locals t) ; Save locals in case user changes them | |
2401 ;; (verilog-getopt-flags) | |
2402 (run-hooks 'verilog-mode-hook)) | |
2403 | |
2404 | |
2405 ;; | |
2406 ;; Electric functions | |
2407 ;; | |
2408 (defun electric-verilog-terminate-line (&optional arg) | |
2409 "Terminate line and indent next line. | |
2410 With optional ARG, remove existing end of line comments." | |
2411 (interactive) | |
2412 ;; before that see if we are in a comment | |
2413 (let ((state | |
2414 (save-excursion | |
2415 (parse-partial-sexp (point-min) (point))))) | |
2416 (cond | |
2417 ((nth 7 state) ; Inside // comment | |
2418 (if (eolp) | |
2419 (progn | |
2420 (delete-horizontal-space) | |
2421 (newline)) | |
2422 (progn | |
2423 (newline) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2424 (insert "// ") |
79545 | 2425 (beginning-of-line))) |
2426 (verilog-indent-line)) | |
2427 ((nth 4 state) ; Inside any comment (hence /**/) | |
2428 (newline) | |
2429 (verilog-more-comment)) | |
2430 ((eolp) | |
2431 ;; First, check if current line should be indented | |
2432 (if (save-excursion | |
2433 (delete-horizontal-space) | |
2434 (beginning-of-line) | |
2435 (skip-chars-forward " \t") | |
2436 (if (looking-at verilog-auto-end-comment-lines-re) | |
2437 (let ((indent-str (verilog-indent-line))) | |
2438 ;; Maybe we should set some endcomments | |
2439 (if verilog-auto-endcomments | |
2440 (verilog-set-auto-endcomments indent-str arg)) | |
2441 (end-of-line) | |
2442 (delete-horizontal-space) | |
2443 (if arg | |
2444 () | |
2445 (newline)) | |
2446 nil) | |
2447 (progn | |
2448 (end-of-line) | |
2449 (delete-horizontal-space) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2450 't))) |
79545 | 2451 ;; see if we should line up assignments |
2452 (progn | |
2453 (if (or (memq 'all verilog-auto-lineup) | |
2454 (memq 'assignments verilog-auto-lineup)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2455 (verilog-pretty-expr)) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2456 (newline)) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2457 (forward-line 1)) |
79545 | 2458 ;; Indent next line |
2459 (if verilog-auto-indent-on-newline | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2460 (verilog-indent-line))) |
79545 | 2461 (t |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2462 (newline))))) |
79545 | 2463 |
2464 (defun electric-verilog-terminate-and-indent () | |
2465 "Insert a newline and indent for the next statement." | |
2466 (interactive) | |
2467 (electric-verilog-terminate-line 1)) | |
2468 | |
2469 (defun electric-verilog-semi () | |
2470 "Insert `;' character and reindent the line." | |
2471 (interactive) | |
2472 (insert last-command-char) | |
2473 | |
2474 (if (or (verilog-in-comment-or-string-p) | |
2475 (verilog-in-escaped-name-p)) | |
2476 () | |
2477 (save-excursion | |
2478 (beginning-of-line) | |
2479 (verilog-forward-ws&directives) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2480 (verilog-indent-line)) |
79545 | 2481 (if (and verilog-auto-newline |
2482 (not (verilog-parenthesis-depth))) | |
2483 (electric-verilog-terminate-line)))) | |
2484 | |
2485 (defun electric-verilog-semi-with-comment () | |
2486 "Insert `;' character, reindent the line and indent for comment." | |
2487 (interactive) | |
2488 (insert "\;") | |
2489 (save-excursion | |
2490 (beginning-of-line) | |
2491 (verilog-indent-line)) | |
2492 (indent-for-comment)) | |
2493 | |
2494 (defun electric-verilog-colon () | |
2495 "Insert `:' and do all indentations except line indent on this line." | |
2496 (interactive) | |
2497 (insert last-command-char) | |
2498 ;; Do nothing if within string. | |
2499 (if (or | |
2500 (verilog-within-string) | |
2501 (not (verilog-in-case-region-p))) | |
2502 () | |
2503 (save-excursion | |
2504 (let ((p (point)) | |
2505 (lim (progn (verilog-beg-of-statement) (point)))) | |
2506 (goto-char p) | |
2507 (verilog-backward-case-item lim) | |
2508 (verilog-indent-line))) | |
2509 ;; (let ((verilog-tab-always-indent nil)) | |
2510 ;; (verilog-indent-line)) | |
2511 )) | |
2512 | |
2513 ;;(defun electric-verilog-equal () | |
2514 ;; "Insert `=', and do indentation if within block." | |
2515 ;; (interactive) | |
2516 ;; (insert last-command-char) | |
2517 ;; Could auto line up expressions, but not yet | |
2518 ;; (if (eq (car (verilog-calculate-indent)) 'block) | |
2519 ;; (let ((verilog-tab-always-indent nil)) | |
2520 ;; (verilog-indent-command))) | |
2521 ;; ) | |
2522 | |
2523 (defun electric-verilog-tick () | |
2524 "Insert back-tick, and indent to column 0 if this is a CPP directive." | |
2525 (interactive) | |
2526 (insert last-command-char) | |
2527 (save-excursion | |
2528 (if (progn | |
2529 (beginning-of-line) | |
2530 (looking-at verilog-directive-re-1)) | |
2531 (verilog-indent-line)))) | |
2532 | |
2533 (defun electric-verilog-tab () | |
2534 "Function called when TAB is pressed in Verilog mode." | |
2535 (interactive) | |
2536 ;; If verilog-tab-always-indent, indent the beginning of the line. | |
2537 (if (or verilog-tab-always-indent | |
2538 (save-excursion | |
2539 (skip-chars-backward " \t") | |
2540 (bolp))) | |
2541 (let* ((oldpnt (point)) | |
2542 (boi-point | |
2543 (save-excursion | |
2544 (beginning-of-line) | |
2545 (skip-chars-forward " \t") | |
2546 (verilog-indent-line) | |
2547 (back-to-indentation) | |
2548 (point)))) | |
2549 (if (< (point) boi-point) | |
2550 (back-to-indentation) | |
2551 (cond ((not verilog-tab-to-comment)) | |
2552 ((not (eolp)) | |
2553 (end-of-line)) | |
2554 (t | |
2555 (indent-for-comment) | |
2556 (when (and (eolp) (= oldpnt (point))) | |
2557 ; kill existing comment | |
2558 (beginning-of-line) | |
2559 (re-search-forward comment-start-skip oldpnt 'move) | |
2560 (goto-char (match-beginning 0)) | |
2561 (skip-chars-backward " \t") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2562 (kill-region (point) oldpnt)))))) |
79545 | 2563 (progn (insert "\t")))) |
2564 | |
2565 | |
2566 | |
2567 ;; | |
2568 ;; Interactive functions | |
2569 ;; | |
2570 | |
2571 (defun verilog-indent-buffer () | |
2572 "Indent-region the entire buffer as Verilog code. | |
2573 To call this from the command line, see \\[verilog-batch-indent]." | |
2574 (interactive) | |
2575 (verilog-mode) | |
2576 (indent-region (point-min) (point-max) nil)) | |
2577 | |
2578 (defun verilog-insert-block () | |
2579 "Insert Verilog begin ... end; block in the code with right indentation." | |
2580 (interactive) | |
2581 (verilog-indent-line) | |
2582 (insert "begin") | |
2583 (electric-verilog-terminate-line) | |
2584 (save-excursion | |
2585 (electric-verilog-terminate-line) | |
2586 (insert "end") | |
2587 (beginning-of-line) | |
2588 (verilog-indent-line))) | |
2589 | |
2590 (defun verilog-star-comment () | |
2591 "Insert Verilog star comment at point." | |
2592 (interactive) | |
2593 (verilog-indent-line) | |
2594 (insert "/*") | |
2595 (save-excursion | |
2596 (newline) | |
2597 (insert " */")) | |
2598 (newline) | |
2599 (insert " * ")) | |
2600 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2601 (defun verilog-insert-1 (fmt max) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2602 "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
|
2603 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
|
2604 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
|
2605 (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
|
2606 (n 0)) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2607 (save-excursion |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2608 (while (< n max) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2609 (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
|
2610 (forward-line 1) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2611 ;; 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
|
2612 ;; shorter than col. |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2613 (if (eobp) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2614 (setq n max) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2615 (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
|
2616 (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
|
2617 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2618 (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
|
2619 "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
|
2620 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
|
2621 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
|
2622 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
|
2623 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
|
2624 located after the first 'a' gives: |
79545 | 2625 |
2626 a = b a[ 0] = b | |
2627 a = b a[ 1] = b | |
2628 a = b a[ 2] = b | |
2629 a = b a[ 3] = b | |
2630 a = b ==> insert-indices ==> a[ 4] = b | |
2631 a = b a[ 5] = b | |
2632 a = b a[ 6] = b | |
2633 a = b a[ 7] = b | |
2634 a = b a[ 8] = b" | |
2635 | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2636 (interactive "NMAX: ") |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2637 (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
|
2638 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2639 (defun verilog-generate-numbers (max) |
79545 | 2640 "Insert a set of generated numbers into a rectangle. |
2641 The upper left corner is defined by point. The numbers are padded to three | |
2642 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
|
2643 is supplied, then the user is prompted for the MAX number. Consider the |
79545 | 2644 following code fragment: |
2645 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2646 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
|
2647 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
|
2648 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
|
2649 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
|
2650 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
|
2651 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
|
2652 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
|
2653 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
|
2654 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
|
2655 |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2656 (interactive "NMAX: ") |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
2657 (verilog-insert-1 "%3.3d" max)) |
79545 | 2658 |
2659 (defun verilog-mark-defun () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
2660 "Mark the current Verilog function (or procedure). |
79545 | 2661 This puts the mark at the end, and point at the beginning." |
2662 (interactive) | |
80172
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
2663 (if (featurep 'xemacs) |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
2664 (progn |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
2665 (push-mark (point)) |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
2666 (verilog-end-of-defun) |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
2667 (push-mark (point)) |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
2668 (verilog-beg-of-defun) |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
2669 (if (fboundp 'zmacs-activate-region) |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
2670 (zmacs-activate-region))) |
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
2671 (mark-defun))) |
79545 | 2672 |
2673 (defun verilog-comment-region (start end) | |
2674 ; checkdoc-params: (start end) | |
2675 "Put the region into a Verilog comment. | |
2676 The comments that are in this area are \"deformed\": | |
2677 `*)' becomes `!(*' and `}' becomes `!{'. | |
2678 These deformed comments are returned to normal if you use | |
2679 \\[verilog-uncomment-region] to undo the commenting. | |
2680 | |
2681 The commented area starts with `verilog-exclude-str-start', and ends with | |
2682 `verilog-exclude-str-end'. But if you change these variables, | |
2683 \\[verilog-uncomment-region] won't recognize the comments." | |
2684 (interactive "r") | |
2685 (save-excursion | |
2686 ;; Insert start and endcomments | |
2687 (goto-char end) | |
2688 (if (and (save-excursion (skip-chars-forward " \t") (eolp)) | |
2689 (not (save-excursion (skip-chars-backward " \t") (bolp)))) | |
2690 (forward-line 1) | |
2691 (beginning-of-line)) | |
2692 (insert verilog-exclude-str-end) | |
2693 (setq end (point)) | |
2694 (newline) | |
2695 (goto-char start) | |
2696 (beginning-of-line) | |
2697 (insert verilog-exclude-str-start) | |
2698 (newline) | |
2699 ;; Replace end-comments within commented area | |
2700 (goto-char end) | |
2701 (save-excursion | |
2702 (while (re-search-backward "\\*/" start t) | |
2703 (replace-match "*-/" t t))) | |
2704 (save-excursion | |
2705 (let ((s+1 (1+ start))) | |
2706 (while (re-search-backward "/\\*" s+1 t) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2707 (replace-match "/-*" t t)))))) |
79545 | 2708 |
2709 (defun verilog-uncomment-region () | |
2710 "Uncomment a commented area; change deformed comments back to normal. | |
2711 This command does nothing if the pointer is not in a commented | |
2712 area. See also `verilog-comment-region'." | |
2713 (interactive) | |
2714 (save-excursion | |
2715 (let ((start (point)) | |
2716 (end (point))) | |
2717 ;; Find the boundaries of the comment | |
2718 (save-excursion | |
2719 (setq start (progn (search-backward verilog-exclude-str-start nil t) | |
2720 (point))) | |
2721 (setq end (progn (search-forward verilog-exclude-str-end nil t) | |
2722 (point)))) | |
2723 ;; Check if we're really inside a comment | |
2724 (if (or (equal start (point)) (<= end (point))) | |
2725 (message "Not standing within commented area.") | |
2726 (progn | |
2727 ;; Remove endcomment | |
2728 (goto-char end) | |
2729 (beginning-of-line) | |
2730 (let ((pos (point))) | |
2731 (end-of-line) | |
2732 (delete-region pos (1+ (point)))) | |
2733 ;; Change comments back to normal | |
2734 (save-excursion | |
2735 (while (re-search-backward "\\*-/" start t) | |
2736 (replace-match "*/" t t))) | |
2737 (save-excursion | |
2738 (while (re-search-backward "/-\\*" start t) | |
2739 (replace-match "/*" t t))) | |
2740 ;; Remove start comment | |
2741 (goto-char start) | |
2742 (beginning-of-line) | |
2743 (let ((pos (point))) | |
2744 (end-of-line) | |
2745 (delete-region pos (1+ (point))))))))) | |
2746 | |
2747 (defun verilog-beg-of-defun () | |
2748 "Move backward to the beginning of the current function or procedure." | |
2749 (interactive) | |
2750 (verilog-re-search-backward verilog-defun-re nil 'move)) | |
2751 | |
2752 (defun verilog-end-of-defun () | |
2753 "Move forward to the end of the current function or procedure." | |
2754 (interactive) | |
2755 (verilog-re-search-forward verilog-end-defun-re nil 'move)) | |
2756 | |
2757 (defun verilog-get-beg-of-defun (&optional warn) | |
2758 (save-excursion | |
2759 (cond ((verilog-re-search-forward-quick verilog-defun-re nil t) | |
2760 (point)) | |
2761 (t | |
2762 (error "%s: Can't find module beginning" (verilog-point-text)) | |
2763 (point-max))))) | |
2764 (defun verilog-get-end-of-defun (&optional warn) | |
2765 (save-excursion | |
2766 (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t) | |
2767 (point)) | |
2768 (t | |
2769 (error "%s: Can't find endmodule" (verilog-point-text)) | |
2770 (point-max))))) | |
2771 | |
2772 (defun verilog-label-be (&optional arg) | |
2773 "Label matching begin ... end, fork ... join and case ... endcase statements. | |
2774 With ARG, first kill any existing labels." | |
2775 (interactive) | |
2776 (let ((cnt 0) | |
2777 (oldpos (point)) | |
2778 (b (progn | |
2779 (verilog-beg-of-defun) | |
2780 (point-marker))) | |
2781 (e (progn | |
2782 (verilog-end-of-defun) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2783 (point-marker)))) |
79545 | 2784 (goto-char (marker-position b)) |
2785 (if (> (- e b) 200) | |
2786 (message "Relabeling module...")) | |
2787 (while (and | |
2788 (> (marker-position e) (point)) | |
2789 (verilog-re-search-forward | |
2790 (concat | |
2791 "\\<end\\(\\(function\\)\\|\\(task\\)\\|\\(module\\)\\|\\(primitive\\)\\|\\(interface\\)\\|\\(package\\)\\|\\(case\\)\\)?\\>" | |
2792 "\\|\\(`endif\\)\\|\\(`else\\)") | |
2793 nil 'move)) | |
2794 (goto-char (match-beginning 0)) | |
2795 (let ((indent-str (verilog-indent-line))) | |
2796 (verilog-set-auto-endcomments indent-str 't) | |
2797 (end-of-line) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2798 (delete-horizontal-space)) |
79545 | 2799 (setq cnt (1+ cnt)) |
2800 (if (= 9 (% cnt 10)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2801 (message "%d..." cnt))) |
79545 | 2802 (goto-char oldpos) |
2803 (if (or | |
2804 (> (- e b) 200) | |
2805 (> cnt 20)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2806 (message "%d lines auto commented" cnt)))) |
79545 | 2807 |
2808 (defun verilog-beg-of-statement () | |
2809 "Move backward to beginning of statement." | |
2810 (interactive) | |
2811 ;; Move back token by token until we see the end | |
2812 ;; of some ealier line. | |
2813 (while | |
2814 ;; If the current point does not begin a new | |
2815 ;; statement, as in the character ahead of us is a ';', or SOF | |
2816 ;; or the string after us unambiguosly starts a statement, | |
2817 ;; or the token before us unambiguously ends a statement, | |
2818 ;; then move back a token and test again. | |
2819 (not (or | |
2820 (bolp) | |
2821 (= (preceding-char) ?\;) | |
2822 (not (or | |
2823 (looking-at "\\<") | |
2824 (forward-word -1))) | |
2825 (and | |
2826 (looking-at verilog-extended-complete-re) | |
2827 (not (save-excursion | |
2828 (verilog-backward-token) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2829 (looking-at verilog-extended-complete-re)))) |
79545 | 2830 (looking-at verilog-basic-complete-re) |
2831 (save-excursion | |
2832 (verilog-backward-token) | |
2833 (or | |
2834 (looking-at verilog-end-block-re) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2835 (looking-at verilog-preprocessor-re))))) |
79545 | 2836 (verilog-backward-syntactic-ws) |
2837 (verilog-backward-token)) | |
2838 ;; Now point is where the previous line ended. | |
2839 (verilog-forward-syntactic-ws)) | |
2840 | |
2841 (defun verilog-beg-of-statement-1 () | |
2842 "Move backward to beginning of statement." | |
2843 (interactive) | |
2844 (let ((pt (point))) | |
2845 | |
2846 (while (and (not (looking-at verilog-complete-reg)) | |
2847 (setq pt (point)) | |
2848 (verilog-backward-token) | |
2849 (not (looking-at verilog-complete-reg)) | |
2850 (verilog-backward-syntactic-ws) | |
2851 (setq pt (point)) | |
2852 (not (bolp)) | |
2853 (not (= (preceding-char) ?\;)))) | |
2854 (goto-char pt) | |
2855 (verilog-forward-ws&directives))) | |
2856 | |
2857 (defun verilog-end-of-statement () | |
2858 "Move forward to end of current statement." | |
2859 (interactive) | |
2860 (let ((nest 0) pos) | |
2861 (or (looking-at verilog-beg-block-re) | |
2862 ;; Skip to end of statement | |
2863 (setq pos (catch 'found | |
2864 (while t | |
2865 (forward-sexp 1) | |
2866 (verilog-skip-forward-comment-or-string) | |
2867 (cond ((looking-at "[ \t]*;") | |
2868 (skip-chars-forward "^;") | |
2869 (forward-char 1) | |
2870 (throw 'found (point))) | |
2871 ((save-excursion | |
2872 (forward-sexp -1) | |
2873 (looking-at verilog-beg-block-re)) | |
2874 (goto-char (match-beginning 0)) | |
2875 (throw 'found nil)) | |
2876 ((looking-at "[ \t]*)") | |
79546 | 2877 (throw 'found (point))) |
79545 | 2878 ((eobp) |
2879 (throw 'found (point)))))))) | |
2880 (if (not pos) | |
2881 ;; Skip a whole block | |
2882 (catch 'found | |
2883 (while t | |
2884 (verilog-re-search-forward verilog-end-statement-re nil 'move) | |
2885 (setq nest (if (match-end 1) | |
2886 (1+ nest) | |
2887 (1- nest))) | |
2888 (cond ((eobp) | |
2889 (throw 'found (point))) | |
2890 ((= 0 nest) | |
2891 (throw 'found (verilog-end-of-statement)))))) | |
2892 pos))) | |
2893 | |
2894 (defun verilog-in-case-region-p () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
2895 "Return true if in a case region. |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
2896 More specifically, point @ in the line foo : @ begin" |
79545 | 2897 (interactive) |
2898 (save-excursion | |
2899 (if (and | |
2900 (progn (verilog-forward-syntactic-ws) | |
2901 (looking-at "\\<begin\\>")) | |
2902 (progn (verilog-backward-syntactic-ws) | |
2903 (= (preceding-char) ?\:))) | |
2904 (catch 'found | |
2905 (let ((nest 1)) | |
2906 (while t | |
2907 (verilog-re-search-backward | |
2908 (concat "\\(\\<module\\>\\)\\|\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|" | |
2909 "\\(\\<endcase\\>\\)\\>") | |
2910 nil 'move) | |
2911 (cond | |
2912 ((match-end 3) | |
2913 (setq nest (1+ nest))) | |
2914 ((match-end 2) | |
2915 (if (= nest 1) | |
2916 (throw 'found 1)) | |
2917 (setq nest (1- nest))) | |
2918 (t | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2919 (throw 'found (= nest 0))))))) |
79545 | 2920 nil))) |
2921 (defun verilog-in-struct-region-p () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
2922 "Return true if in a struct region. |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
2923 More specifically, in a list after a struct|union keyword." |
79545 | 2924 (interactive) |
2925 (save-excursion | |
2926 (let* ((state (parse-partial-sexp (point-min) (point))) | |
2927 (depth (nth 0 state))) | |
2928 (if depth | |
2929 (progn (backward-up-list depth) | |
2930 (verilog-beg-of-statement) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2931 (looking-at "\\<typedef\\>?\\s-*\\<struct\\|union\\>")))))) |
79545 | 2932 |
2933 (defun verilog-in-generate-region-p () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
2934 "Return true if in a generate region. |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
2935 More specifically, after a generate and before an endgenerate." |
79545 | 2936 (interactive) |
2937 (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
|
2938 (nest 1)) |
79545 | 2939 (save-excursion |
2940 (while (and | |
2941 (/= nest 0) | |
2942 (verilog-re-search-backward "\\<\\(generate\\)\\|\\(endgenerate\\)\\>" lim 'move) | |
2943 (cond | |
2944 ((match-end 1) ; generate | |
2945 (setq nest (1- nest))) | |
2946 ((match-end 2) ; endgenerate | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2947 (setq nest (1+ nest))))))) |
79545 | 2948 (= nest 0) )) ; return nest |
2949 | |
2950 (defun verilog-in-fork-region-p () | |
2951 "Return true if between a fork and join." | |
2952 (interactive) | |
2953 (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
|
2954 (nest 1)) |
79545 | 2955 (save-excursion |
2956 (while (and | |
2957 (/= nest 0) | |
2958 (verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\(_any\\|_none\\)?\\)\\>" lim 'move) | |
2959 (cond | |
2960 ((match-end 1) ; fork | |
2961 (setq nest (1- nest))) | |
2962 ((match-end 2) ; join | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2963 (setq nest (1+ nest))))))) |
79545 | 2964 (= nest 0) )) ; return nest |
2965 | |
2966 (defun verilog-backward-case-item (lim) | |
2967 "Skip backward to nearest enclosing case item. | |
2968 Limit search to point LIM." | |
2969 (interactive) | |
2970 (let ((str 'nil) | |
2971 (lim1 | |
2972 (progn | |
2973 (save-excursion | |
2974 (verilog-re-search-backward verilog-endcomment-reason-re | |
2975 lim 'move) | |
2976 (point))))) | |
2977 ;; Try to find the real : | |
2978 (if (save-excursion (search-backward ":" lim1 t)) | |
2979 (let ((colon 0) | |
2980 b e ) | |
2981 (while | |
2982 (and | |
2983 (< colon 1) | |
2984 (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)" | |
2985 lim1 'move)) | |
2986 (cond | |
2987 ((match-end 1) ;; [ | |
2988 (setq colon (1+ colon)) | |
2989 (if (>= colon 0) | |
2990 (error "%s: unbalanced [" (verilog-point-text)))) | |
2991 ((match-end 2) ;; ] | |
2992 (setq colon (1- colon))) | |
2993 | |
2994 ((match-end 3) ;; : | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
2995 (setq colon (1+ colon))))) |
79545 | 2996 ;; Skip back to beginning of case item |
2997 (skip-chars-backward "\t ") | |
2998 (verilog-skip-backward-comment-or-string) | |
2999 (setq e (point)) | |
3000 (setq b | |
3001 (progn | |
3002 (if | |
3003 (verilog-re-search-backward | |
3004 "\\<\\(case[zx]?\\)\\>\\|;\\|\\<end\\>" nil 'move) | |
3005 (progn | |
3006 (cond | |
3007 ((match-end 1) | |
3008 (goto-char (match-end 1)) | |
3009 (verilog-forward-ws&directives) | |
3010 (if (looking-at "(") | |
3011 (progn | |
3012 (forward-sexp) | |
3013 (verilog-forward-ws&directives))) | |
3014 (point)) | |
3015 (t | |
3016 (goto-char (match-end 0)) | |
3017 (verilog-forward-ws&directives) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3018 (point)))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3019 (error "Malformed case item")))) |
79545 | 3020 (setq str (buffer-substring b e)) |
3021 (if | |
3022 (setq e | |
3023 (string-match | |
3024 "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str)) | |
3025 (setq str (concat (substring str 0 e) "..."))) | |
3026 str) | |
3027 'nil))) | |
3028 | |
3029 | |
3030 ;; | |
3031 ;; Other functions | |
3032 ;; | |
3033 | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3034 (defun verilog-kill-existing-comment () |
79545 | 3035 "Kill auto comment on this line." |
3036 (save-excursion | |
3037 (let* ( | |
3038 (e (progn | |
3039 (end-of-line) | |
3040 (point))) | |
3041 (b (progn | |
3042 (beginning-of-line) | |
3043 (search-forward "//" e t)))) | |
3044 (if b | |
3045 (delete-region (- b 2) e))))) | |
3046 | |
3047 (defconst verilog-directive-nest-re | |
3048 (concat "\\(`else\\>\\)\\|" | |
3049 "\\(`endif\\>\\)\\|" | |
3050 "\\(`if\\>\\)\\|" | |
3051 "\\(`ifdef\\>\\)\\|" | |
3052 "\\(`ifndef\\>\\)")) | |
3053 (defun verilog-set-auto-endcomments (indent-str kill-existing-comment) | |
3054 "Add ending comment with given INDENT-STR. | |
3055 With KILL-EXISTING-COMMENT, remove what was there before. | |
3056 Insert `// case: 7 ' or `// NAME ' on this line if appropriate. | |
3057 Insert `// case expr ' if this line ends a case block. | |
3058 Insert `// ifdef FOO ' if this line ends code conditional on FOO. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
3059 Insert `// NAME ' if this line ends a function, task, module, |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
3060 primitive or interface named NAME." |
79545 | 3061 (save-excursion |
3062 (cond | |
3063 (; Comment close preprocessor directives | |
3064 (and | |
3065 (looking-at "\\(`endif\\)\\|\\(`else\\)") | |
3066 (or kill-existing-comment | |
3067 (not (save-excursion | |
3068 (end-of-line) | |
3069 (search-backward "//" (verilog-get-beg-of-line) t))))) | |
3070 (let ((nest 1) b e | |
3071 m | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3072 (else (if (match-end 2) "!" " "))) |
79545 | 3073 (end-of-line) |
3074 (if kill-existing-comment | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3075 (verilog-kill-existing-comment)) |
79545 | 3076 (delete-horizontal-space) |
3077 (save-excursion | |
3078 (backward-sexp 1) | |
3079 (while (and (/= nest 0) | |
3080 (verilog-re-search-backward verilog-directive-nest-re nil 'move)) | |
3081 (cond | |
3082 ((match-end 1) ; `else | |
3083 (if (= nest 1) | |
3084 (setq else "!"))) | |
3085 ((match-end 2) ; `endif | |
3086 (setq nest (1+ nest))) | |
3087 ((match-end 3) ; `if | |
3088 (setq nest (1- nest))) | |
3089 ((match-end 4) ; `ifdef | |
3090 (setq nest (1- nest))) | |
3091 ((match-end 5) ; `ifndef | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3092 (setq nest (1- nest))))) |
79545 | 3093 (if (match-end 0) |
3094 (setq | |
3095 m (buffer-substring | |
3096 (match-beginning 0) | |
3097 (match-end 0)) | |
3098 b (progn | |
3099 (skip-chars-forward "^ \t") | |
3100 (verilog-forward-syntactic-ws) | |
3101 (point)) | |
3102 e (progn | |
3103 (skip-chars-forward "a-zA-Z0-9_") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3104 (point))))) |
79545 | 3105 (if b |
3106 (if (> (count-lines (point) b) verilog-minimum-comment-distance) | |
3107 (insert (concat " // " else m " " (buffer-substring b e)))) | |
3108 (progn | |
3109 (insert " // unmatched `else or `endif") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3110 (ding 't))))) |
79545 | 3111 |
3112 (; Comment close case/class/function/task/module and named block | |
3113 (and (looking-at "\\<end") | |
3114 (or kill-existing-comment | |
3115 (not (save-excursion | |
3116 (end-of-line) | |
3117 (search-backward "//" (verilog-get-beg-of-line) t))))) | |
3118 (let ((type (car indent-str))) | |
3119 (unless (eq type 'declaration) | |
3120 (unless (looking-at (concat "\\(" verilog-end-block-ordered-re "\\)[ \t]*:")) ;; ignore named ends | |
3121 (if (looking-at verilog-end-block-ordered-re) | |
3122 (cond | |
3123 (;- This is a case block; search back for the start of this case | |
3124 (match-end 1) ;; of verilog-end-block-ordered-re | |
3125 | |
3126 (let ((err 't) | |
3127 (str "UNMATCHED!!")) | |
3128 (save-excursion | |
3129 (verilog-leap-to-head) | |
3130 (cond | |
3131 ((looking-at "\\<randcase\\>") | |
3132 (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
|
3133 (setq err nil)) |
79545 | 3134 ((match-end 0) |
3135 (goto-char (match-end 1)) | |
3136 (if nil | |
3137 (let (s f) | |
3138 (setq s (match-beginning 1)) | |
3139 (setq f (progn (end-of-line) | |
3140 (point))) | |
3141 (setq str (buffer-substring s f))) | |
3142 (setq err nil)) | |
3143 (setq str (concat (buffer-substring (match-beginning 1) (match-end 1)) | |
3144 " " | |
3145 (verilog-get-expr)))))) | |
3146 (end-of-line) | |
3147 (if kill-existing-comment | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3148 (verilog-kill-existing-comment)) |
79545 | 3149 (delete-horizontal-space) |
3150 (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
|
3151 (if err (ding 't)))) |
79545 | 3152 |
3153 (;- This is a begin..end block | |
3154 (match-end 2) ;; of verilog-end-block-ordered-re | |
3155 (let ((str " // UNMATCHED !!") | |
3156 (err 't) | |
3157 (here (point)) | |
3158 there | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3159 cntx) |
79545 | 3160 (save-excursion |
3161 (verilog-leap-to-head) | |
3162 (setq there (point)) | |
3163 (if (not (match-end 0)) | |
3164 (progn | |
3165 (goto-char here) | |
3166 (end-of-line) | |
3167 (if kill-existing-comment | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3168 (verilog-kill-existing-comment)) |
79545 | 3169 (delete-horizontal-space) |
3170 (insert str) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3171 (ding 't)) |
79545 | 3172 (let ((lim |
3173 (save-excursion (verilog-beg-of-defun) (point))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3174 (here (point))) |
79545 | 3175 (cond |
3176 (;-- handle named block differently | |
3177 (looking-at verilog-named-block-re) | |
3178 (search-forward ":") | |
3179 (setq there (point)) | |
3180 (setq str (verilog-get-expr)) | |
3181 (setq err nil) | |
3182 (setq str (concat " // block: " str ))) | |
3183 | |
3184 ((verilog-in-case-region-p) ;-- handle case item differently | |
3185 (goto-char here) | |
3186 (setq str (verilog-backward-case-item lim)) | |
3187 (setq there (point)) | |
3188 (setq err nil) | |
3189 (setq str (concat " // case: " str ))) | |
3190 | |
3191 (;- try to find "reason" for this begin | |
3192 (cond | |
3193 (; | |
3194 (eq here (progn | |
3195 (verilog-backward-token) | |
3196 (verilog-beg-of-statement-1) | |
3197 (point))) | |
3198 (setq err nil) | |
3199 (setq str "")) | |
3200 ((looking-at verilog-endcomment-reason-re) | |
3201 (setq there (match-end 0)) | |
3202 (setq cntx (concat | |
3203 (buffer-substring (match-beginning 0) (match-end 0)) " ")) | |
3204 (cond | |
3205 (;- begin | |
3206 (match-end 2) | |
3207 (setq err nil) | |
3208 (save-excursion | |
3209 (if (and (verilog-continued-line) | |
3210 (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>")) | |
3211 (progn | |
3212 (goto-char (match-end 0)) | |
3213 (setq there (point)) | |
3214 (setq str | |
3215 (concat " // " | |
3216 (buffer-substring (match-beginning 0) (match-end 0)) " " | |
3217 (verilog-get-expr)))) | |
3218 (setq str "")))) | |
3219 | |
3220 (;- else | |
3221 (match-end 4) | |
3222 (let ((nest 0) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3223 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)")) |
79545 | 3224 (catch 'skip |
3225 (while (verilog-re-search-backward reg nil 'move) | |
3226 (cond | |
3227 ((match-end 1) ; begin | |
3228 (setq nest (1- nest))) | |
3229 ((match-end 2) ; end | |
3230 (setq nest (1+ nest))) | |
3231 ((match-end 3) | |
3232 (if (= 0 nest) | |
3233 (progn | |
3234 (goto-char (match-end 0)) | |
3235 (setq there (point)) | |
3236 (setq err nil) | |
3237 (setq str (verilog-get-expr)) | |
3238 (setq str (concat " // else: !if" str )) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3239 (throw 'skip 1))))))))) |
79545 | 3240 |
3241 (;- end else | |
3242 (match-end 5) | |
3243 (goto-char there) | |
3244 (let ((nest 0) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3245 (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)")) |
79545 | 3246 (catch 'skip |
3247 (while (verilog-re-search-backward reg nil 'move) | |
3248 (cond | |
3249 ((match-end 1) ; begin | |
3250 (setq nest (1- nest))) | |
3251 ((match-end 2) ; end | |
3252 (setq nest (1+ nest))) | |
3253 ((match-end 3) | |
3254 (if (= 0 nest) | |
3255 (progn | |
3256 (goto-char (match-end 0)) | |
3257 (setq there (point)) | |
3258 (setq err nil) | |
3259 (setq str (verilog-get-expr)) | |
3260 (setq str (concat " // else: !if" str )) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3261 (throw 'skip 1))))))))) |
79545 | 3262 |
3263 (;- task/function/initial et cetera | |
3264 t | |
3265 (match-end 0) | |
3266 (goto-char (match-end 0)) | |
3267 (setq there (point)) | |
3268 (setq err nil) | |
3269 (setq str (verilog-get-expr)) | |
3270 (setq str (concat " // " cntx str ))) | |
3271 | |
3272 (;-- otherwise... | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3273 (setq str " // auto-endcomment confused ")))) |
79545 | 3274 |
3275 ((and | |
3276 (verilog-in-case-region-p) ;-- handle case item differently | |
3277 (progn | |
3278 (setq there (point)) | |
3279 (goto-char here) | |
3280 (setq str (verilog-backward-case-item lim)))) | |
3281 (setq err nil) | |
3282 (setq str (concat " // case: " str ))) | |
3283 | |
3284 ((verilog-in-fork-region-p) | |
3285 (setq err nil) | |
3286 (setq str " // fork branch" )) | |
3287 | |
3288 ((looking-at "\\<end\\>") | |
3289 ;; HERE | |
3290 (forward-word 1) | |
3291 (verilog-forward-syntactic-ws) | |
3292 (setq err nil) | |
3293 (setq str (verilog-get-expr)) | |
3294 (setq str (concat " // " cntx str ))) | |
3295 | |
3296 )))) | |
3297 (goto-char here) | |
3298 (end-of-line) | |
3299 (if kill-existing-comment | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3300 (verilog-kill-existing-comment)) |
79545 | 3301 (delete-horizontal-space) |
3302 (if (or err | |
3303 (> (count-lines here there) verilog-minimum-comment-distance)) | |
3304 (insert str)) | |
3305 (if err (ding 't)) | |
3306 )))) | |
3307 (;- this is endclass, which can be nested | |
3308 (match-end 11) ;; of verilog-end-block-ordered-re | |
3309 ;;(goto-char there) | |
3310 (let ((nest 0) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3311 (reg "\\<\\(class\\)\\|\\(endclass\\)\\|\\(package\\|primitive\\|\\(macro\\)?module\\)\\>") |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3312 string) |
79545 | 3313 (save-excursion |
3314 (catch 'skip | |
3315 (while (verilog-re-search-backward reg nil 'move) | |
3316 (cond | |
3317 ((match-end 3) ; endclass | |
3318 (ding 't) | |
3319 (setq string "unmatched endclass") | |
3320 (throw 'skip 1)) | |
3321 | |
3322 ((match-end 2) ; endclass | |
3323 (setq nest (1+ nest))) | |
3324 | |
3325 ((match-end 1) ; class | |
3326 (setq nest (1- nest)) | |
3327 (if (< nest 0) | |
3328 (progn | |
3329 (goto-char (match-end 0)) | |
3330 (let (b e) | |
3331 (setq b (progn | |
3332 (skip-chars-forward "^ \t") | |
3333 (verilog-forward-ws&directives) | |
3334 (point)) | |
3335 e (progn | |
3336 (skip-chars-forward "a-zA-Z0-9_") | |
3337 (point))) | |
3338 (setq string (buffer-substring b e))) | |
3339 (throw 'skip 1)))) | |
3340 )))) | |
3341 (end-of-line) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3342 (insert (concat " // " string )))) |
79545 | 3343 |
3344 (;- this is end{function,generate,task,module,primitive,table,generate} | |
3345 ;- which can not be nested. | |
3346 t | |
3347 (let (string reg (width nil)) | |
3348 (end-of-line) | |
3349 (if kill-existing-comment | |
3350 (save-match-data | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
3351 (verilog-kill-existing-comment))) |
79545 | 3352 (delete-horizontal-space) |
3353 (backward-sexp) | |
3354 (cond | |
3355 ((match-end 5) ;; of verilog-end-block-ordered-re | |
3356 (setq reg "\\(\\<function\\>\\)\\|\\(\\<\\(endfunction\\|task\\|\\(macro\\)?module\\|primitive\\)\\>\\)") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3357 (setq width "\\(\\s-*\\(\\[[^]]*\\]\\)\\|\\(real\\(time\\)?\\)\\|\\(integer\\)\\|\\(time\\)\\)?")) |
79545 | 3358 ((match-end 6) ;; of verilog-end-block-ordered-re |
3359 (setq reg "\\(\\<task\\>\\)\\|\\(\\<\\(endtask\\|function\\|\\(macro\\)?module\\|primitive\\)\\>\\)")) | |
3360 ((match-end 7) ;; of verilog-end-block-ordered-re | |
3361 (setq reg "\\(\\<\\(macro\\)?module\\>\\)\\|\\<endmodule\\>")) | |
3362 ((match-end 8) ;; of verilog-end-block-ordered-re | |
3363 (setq reg "\\(\\<primitive\\>\\)\\|\\(\\<\\(endprimitive\\|package\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3364 ((match-end 9) ;; of verilog-end-block-ordered-re | |
3365 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<\\(endinterface\\|package\\|primitive\\|\\(macro\\)?module\\)\\>\\)")) | |
3366 ((match-end 10) ;; of verilog-end-block-ordered-re | |
3367 (setq reg "\\(\\<package\\>\\)\\|\\(\\<\\(endpackage\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3368 ((match-end 11) ;; of verilog-end-block-ordered-re | |
3369 (setq reg "\\(\\<class\\>\\)\\|\\(\\<\\(endclass\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3370 ((match-end 12) ;; of verilog-end-block-ordered-re | |
3371 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<\\(endcovergroup\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3372 ((match-end 13) ;; of verilog-end-block-ordered-re | |
3373 (setq reg "\\(\\<program\\>\\)\\|\\(\\<\\(endprogram\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3374 ((match-end 14) ;; of verilog-end-block-ordered-re | |
3375 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<\\(endsequence\\|primitive\\|interface\\|\\(macro\\)?module\\)\\>\\)")) | |
3376 ((match-end 15) ;; of verilog-end-block-ordered-re | |
3377 (setq reg "\\(\\<clocking\\>\\)\\|\\<endclocking\\>")) | |
3378 | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3379 (t (error "Problem in verilog-set-auto-endcomments"))) |
79545 | 3380 (let (b e) |
3381 (save-excursion | |
3382 (verilog-re-search-backward reg nil 'move) | |
3383 (cond | |
3384 ((match-end 1) | |
3385 (setq b (progn | |
3386 (skip-chars-forward "^ \t") | |
3387 (verilog-forward-ws&directives) | |
3388 (if (and width (looking-at width)) | |
3389 (progn | |
3390 (goto-char (match-end 0)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3391 (verilog-forward-ws&directives))) |
79545 | 3392 (point)) |
3393 e (progn | |
3394 (skip-chars-forward "a-zA-Z0-9_") | |
3395 (point))) | |
3396 (setq string (buffer-substring b e))) | |
3397 (t | |
3398 (ding 't) | |
3399 (setq string "unmatched end(function|task|module|primitive|interface|package|class|clocking)"))))) | |
3400 (end-of-line) | |
3401 (insert (concat " // " string ))) | |
3402 )))))))))) | |
3403 | |
3404 (defun verilog-get-expr() | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
3405 "Grab expression at point, e.g, case ( a | b & (c ^d))." |
79545 | 3406 (let* ((b (progn |
3407 (verilog-forward-syntactic-ws) | |
3408 (skip-chars-forward " \t") | |
3409 (point))) | |
3410 (e (let ((par 1)) | |
3411 (cond | |
3412 ((looking-at "@") | |
3413 (forward-char 1) | |
3414 (verilog-forward-syntactic-ws) | |
3415 (if (looking-at "(") | |
3416 (progn | |
3417 (forward-char 1) | |
3418 (while (and (/= par 0) | |
3419 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move)) | |
3420 (cond | |
3421 ((match-end 1) | |
3422 (setq par (1+ par))) | |
3423 ((match-end 2) | |
3424 (setq par (1- par))))))) | |
3425 (point)) | |
3426 ((looking-at "(") | |
3427 (forward-char 1) | |
3428 (while (and (/= par 0) | |
3429 (verilog-re-search-forward "\\((\\)\\|\\()\\)" nil 'move)) | |
3430 (cond | |
3431 ((match-end 1) | |
3432 (setq par (1+ par))) | |
3433 ((match-end 2) | |
3434 (setq par (1- par))))) | |
3435 (point)) | |
3436 ((looking-at "\\[") | |
3437 (forward-char 1) | |
3438 (while (and (/= par 0) | |
3439 (verilog-re-search-forward "\\(\\[\\)\\|\\(\\]\\)" nil 'move)) | |
3440 (cond | |
3441 ((match-end 1) | |
3442 (setq par (1+ par))) | |
3443 ((match-end 2) | |
3444 (setq par (1- par))))) | |
3445 (verilog-forward-syntactic-ws) | |
3446 (skip-chars-forward "^ \t\n\f") | |
3447 (point)) | |
3448 ((looking-at "/[/\\*]") | |
3449 b) | |
3450 ('t | |
3451 (skip-chars-forward "^: \t\n\f") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3452 (point))))) |
79545 | 3453 (str (buffer-substring b e))) |
3454 (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str)) | |
3455 (setq str (concat (substring str 0 e) "..."))) | |
3456 str)) | |
3457 | |
3458 (defun verilog-expand-vector () | |
3459 "Take a signal vector on the current line and expand it to multiple lines. | |
3460 Useful for creating tri's and other expanded fields." | |
3461 (interactive) | |
3462 (verilog-expand-vector-internal "[" "]")) | |
3463 | |
3464 (defun verilog-expand-vector-internal (bra ket) | |
3465 "Given BRA, the start brace and KET, the end brace, expand one line into many lines." | |
3466 (save-excursion | |
3467 (forward-line 0) | |
3468 (let ((signal-string (buffer-substring (point) | |
3469 (progn | |
3470 (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
|
3471 (if (string-match |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3472 (concat "\\(.*\\)" |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3473 (regexp-quote bra) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3474 "\\([0-9]*\\)\\(:[0-9]*\\|\\)\\(::[0-9---]*\\|\\)" |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3475 (regexp-quote ket) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3476 "\\(.*\\)$") signal-string) |
79545 | 3477 (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
|
3478 (vec-start (string-to-number (match-string 2 signal-string))) |
79545 | 3479 (vec-end (if (= (match-beginning 3) (match-end 3)) |
3480 vec-start | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3481 (string-to-number |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3482 (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
|
3483 (match-end 3))))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3484 (vec-range |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3485 (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
|
3486 1 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3487 (string-to-number |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3488 (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
|
3489 (match-end 4))))) |
79545 | 3490 (sig-tail (match-string 5 signal-string)) |
3491 vec) | |
3492 ;; Decode vectors | |
3493 (setq vec nil) | |
3494 (if (< vec-range 0) | |
3495 (let ((tmp vec-start)) | |
3496 (setq vec-start vec-end | |
3497 vec-end tmp | |
3498 vec-range (- vec-range)))) | |
3499 (if (< vec-end vec-start) | |
3500 (while (<= vec-end vec-start) | |
3501 (setq vec (append vec (list vec-start))) | |
3502 (setq vec-start (- vec-start vec-range))) | |
3503 (while (<= vec-start vec-end) | |
3504 (setq vec (append vec (list vec-start))) | |
3505 (setq vec-start (+ vec-start vec-range)))) | |
3506 ;; | |
3507 ;; Delete current line | |
3508 (delete-region (point) (progn (forward-line 0) (point))) | |
3509 ;; | |
3510 ;; Expand vector | |
3511 (while vec | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3512 (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
|
3513 (int-to-string (car vec)) ket sig-tail "\n")) |
79545 | 3514 (setq vec (cdr vec))) |
3515 (delete-char -1) | |
3516 ;; | |
3517 ))))) | |
3518 | |
3519 (defun verilog-strip-comments () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
3520 "Strip all comments from the Verilog code." |
79545 | 3521 (interactive) |
3522 (goto-char (point-min)) | |
3523 (while (re-search-forward "//" nil t) | |
3524 (if (verilog-within-string) | |
3525 (re-search-forward "\"" nil t) | |
3526 (if (verilog-in-star-comment-p) | |
3527 (re-search-forward "\*/" nil t) | |
3528 (let ((bpt (- (point) 2))) | |
3529 (end-of-line) | |
3530 (delete-region bpt (point)))))) | |
3531 ;; | |
3532 (goto-char (point-min)) | |
3533 (while (re-search-forward "/\\*" nil t) | |
3534 (if (verilog-within-string) | |
3535 (re-search-forward "\"" nil t) | |
3536 (let ((bpt (- (point) 2))) | |
3537 (re-search-forward "\\*/") | |
3538 (delete-region bpt (point)))))) | |
3539 | |
3540 (defun verilog-one-line () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
3541 "Convert structural Verilog instances to occupy one line." |
79545 | 3542 (interactive) |
3543 (goto-char (point-min)) | |
3544 (while (re-search-forward "\\([^;]\\)[ \t]*\n[ \t]*" nil t) | |
3545 (replace-match "\\1 " nil nil))) | |
3546 | |
3547 (defun verilog-linter-name () | |
3548 "Return name of linter, either surelint or verilint." | |
3549 (let ((compile-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil | |
3550 compile-command)) | |
3551 (lint-word1 (verilog-string-replace-matches "\\s .*$" "" nil nil | |
3552 verilog-linter))) | |
3553 (cond ((equal compile-word1 "surelint") `surelint) | |
3554 ((equal compile-word1 "verilint") `verilint) | |
3555 ((equal lint-word1 "surelint") `surelint) | |
3556 ((equal lint-word1 "verilint") `verilint) | |
3557 (t `surelint)))) ;; back compatibility | |
3558 | |
3559 (defun verilog-lint-off () | |
3560 "Convert a Verilog linter warning line into a disable statement. | |
3561 For example: | |
3562 pci_bfm_null.v, line 46: Unused input: pci_rst_ | |
3563 becomes a comment for the appropriate tool. | |
3564 | |
3565 The first word of the `compile-command' or `verilog-linter' | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
3566 variables is used to determine which product is being used. |
79545 | 3567 |
3568 See \\[verilog-surelint-off] and \\[verilog-verilint-off]." | |
3569 (interactive) | |
3570 (let ((linter (verilog-linter-name))) | |
3571 (cond ((equal linter `surelint) | |
3572 (verilog-surelint-off)) | |
3573 ((equal linter `verilint) | |
3574 (verilog-verilint-off)) | |
3575 (t (error "Linter name not set"))))) | |
3576 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3577 (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
|
3578 |
79545 | 3579 (defun verilog-surelint-off () |
3580 "Convert a SureLint warning line into a disable statement. | |
3581 Run from Verilog source window; assumes there is a *compile* buffer | |
3582 with point set appropriately. | |
3583 | |
3584 For example: | |
3585 WARNING [STD-UDDONX]: xx.v, line 8: output out is never assigned. | |
3586 becomes: | |
3587 // surefire lint_line_off UDDONX" | |
3588 (interactive) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3589 (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
|
3590 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
|
3591 compilation-last-buffer))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3592 (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
|
3593 ;; 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
|
3594 (save-excursion |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3595 (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
|
3596 (beginning-of-line) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3597 (when |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3598 (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
|
3599 (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
|
3600 (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
|
3601 (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
|
3602 (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
|
3603 dir filename) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3604 (unless buffer |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3605 (progn |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3606 (setq buffer |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3607 (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
|
3608 (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
|
3609 (or buffer |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3610 (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
|
3611 (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
|
3612 (read-file-name |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3613 (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
|
3614 file) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3615 dir file t)))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3616 (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
|
3617 (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
|
3618 (setq buffer |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3619 (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
|
3620 (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
|
3621 (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
|
3622 (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
|
3623 (end-of-line) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3624 (catch 'already |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3625 (cond |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3626 ((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
|
3627 (re-search-backward "//") |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3628 (cond |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3629 ((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
|
3630 (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
|
3631 (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
|
3632 (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
|
3633 (throw 'already t) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3634 (insert (concat " " code))))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3635 (t |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3636 ))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3637 ((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
|
3638 (re-search-backward "/\*") |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3639 (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
|
3640 (t |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3641 (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
|
3642 ))))))))) |
79545 | 3643 |
3644 (defun verilog-verilint-off () | |
3645 "Convert a Verilint warning line into a disable statement. | |
3646 | |
3647 For example: | |
3648 (W240) pci_bfm_null.v, line 46: Unused input: pci_rst_ | |
3649 becomes: | |
3650 //Verilint 240 off // WARNING: Unused input" | |
3651 (interactive) | |
3652 (save-excursion | |
3653 (beginning-of-line) | |
3654 (when (looking-at "\\(.*\\)([WE]\\([0-9A-Z]+\\)).*,\\s +line\\s +[0-9]+:\\s +\\([^:\n]+\\):?.*$") | |
3655 (replace-match (format | |
3656 ;; %3s makes numbers 1-999 line up nicely | |
3657 "\\1//Verilint %3s off // WARNING: \\3" | |
3658 (match-string 2))) | |
3659 (beginning-of-line) | |
3660 (verilog-indent-line)))) | |
3661 | |
3662 (defun verilog-auto-save-compile () | |
3663 "Update automatics with \\[verilog-auto], save the buffer, and compile." | |
3664 (interactive) | |
3665 (verilog-auto) ; Always do it for safety | |
3666 (save-buffer) | |
3667 (compile compile-command)) | |
3668 | |
3669 | |
3670 | |
3671 ;; | |
3672 ;; Batch | |
3673 ;; | |
3674 | |
3675 (defmacro verilog-batch-error-wrapper (&rest body) | |
3676 "Execute BODY and add error prefix to any errors found. | |
3677 This lets programs calling batch mode to easily extract error messages." | |
79546 | 3678 `(condition-case err |
3679 (progn ,@body) | |
3680 (error | |
3681 (error "%%Error: %s%s" (error-message-string err) | |
3682 (if (featurep 'xemacs) "\n" ""))))) ;; xemacs forgets to add a newline | |
79545 | 3683 |
3684 (defun verilog-batch-execute-func (funref) | |
3685 "Internal processing of a batch command, running FUNREF on all command arguments." | |
3686 (verilog-batch-error-wrapper | |
3687 ;; General globals needed | |
3688 (setq make-backup-files nil) | |
3689 (setq-default make-backup-files nil) | |
3690 (setq enable-local-variables t) | |
3691 (setq enable-local-eval t) | |
3692 ;; Make sure any sub-files we read get proper mode | |
3693 (setq default-major-mode `verilog-mode) | |
3694 ;; 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
|
3695 (mapc (lambda (buf) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3696 (when (buffer-file-name buf) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3697 (save-excursion |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3698 (set-buffer buf) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3699 (verilog-mode)))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3700 (buffer-list)) |
79545 | 3701 ;; Process the files |
3702 (mapcar '(lambda (buf) | |
3703 (when (buffer-file-name buf) | |
3704 (save-excursion | |
3705 (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
|
3706 (error |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
3707 (concat "File not found: " (buffer-file-name buf)))) |
79545 | 3708 (message (concat "Processing " (buffer-file-name buf))) |
3709 (set-buffer buf) | |
3710 (funcall funref) | |
3711 (save-buffer)))) | |
3712 (buffer-list)))) | |
3713 | |
3714 (defun verilog-batch-auto () | |
3715 "For use with --batch, perform automatic expansions as a stand-alone tool. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
3716 This sets up the appropriate Verilog mode environment, updates automatics |
79545 | 3717 with \\[verilog-auto] on all command-line files, and saves the buffers. |
3718 For proper results, multiple filenames need to be passed on the command | |
3719 line in bottom-up order." | |
3720 (unless noninteractive | |
3721 (error "Use verilog-batch-auto only with --batch")) ;; Otherwise we'd mess up buffer modes | |
3722 (verilog-batch-execute-func `verilog-auto)) | |
3723 | |
3724 (defun verilog-batch-delete-auto () | |
3725 "For use with --batch, perform automatic deletion as a stand-alone tool. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
3726 This sets up the appropriate Verilog mode environment, deletes automatics |
79545 | 3727 with \\[verilog-delete-auto] on all command-line files, and saves the buffers." |
3728 (unless noninteractive | |
3729 (error "Use verilog-batch-delete-auto only with --batch")) ;; Otherwise we'd mess up buffer modes | |
3730 (verilog-batch-execute-func `verilog-delete-auto)) | |
3731 | |
3732 (defun verilog-batch-inject-auto () | |
3733 "For use with --batch, perform automatic injection as a stand-alone tool. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
3734 This sets up the appropriate Verilog mode environment, injects new automatics |
79545 | 3735 with \\[verilog-inject-auto] on all command-line files, and saves the buffers. |
3736 For proper results, multiple filenames need to be passed on the command | |
3737 line in bottom-up order." | |
3738 (unless noninteractive | |
3739 (error "Use verilog-batch-inject-auto only with --batch")) ;; Otherwise we'd mess up buffer modes | |
3740 (verilog-batch-execute-func `verilog-inject-auto)) | |
3741 | |
3742 (defun verilog-batch-indent () | |
3743 "For use with --batch, reindent an a entire file as a stand-alone tool. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
3744 This sets up the appropriate Verilog mode environment, calls |
79545 | 3745 \\[verilog-indent-buffer] on all command-line files, and saves the buffers." |
3746 (unless noninteractive | |
3747 (error "Use verilog-batch-indent only with --batch")) ;; Otherwise we'd mess up buffer modes | |
3748 (verilog-batch-execute-func `verilog-indent-buffer)) | |
3749 | |
3750 | |
3751 ;; | |
3752 ;; Indentation | |
3753 ;; | |
3754 (defconst verilog-indent-alist | |
3755 '((block . (+ ind verilog-indent-level)) | |
3756 (case . (+ ind verilog-case-indent)) | |
3757 (cparenexp . (+ ind verilog-indent-level)) | |
3758 (cexp . (+ ind verilog-cexp-indent)) | |
3759 (defun . verilog-indent-level-module) | |
3760 (declaration . verilog-indent-level-declaration) | |
3761 (directive . (verilog-calculate-indent-directive)) | |
3762 (tf . verilog-indent-level) | |
3763 (behavioral . (+ verilog-indent-level-behavioral verilog-indent-level-module)) | |
3764 (statement . ind) | |
3765 (cpp . 0) | |
3766 (comment . (verilog-comment-indent)) | |
3767 (unknown . 3) | |
3768 (string . 0))) | |
3769 | |
3770 (defun verilog-continued-line-1 (lim) | |
3771 "Return true if this is a continued line. | |
3772 Set point to where line starts. Limit search to point LIM." | |
3773 (let ((continued 't)) | |
3774 (if (eq 0 (forward-line -1)) | |
3775 (progn | |
3776 (end-of-line) | |
3777 (verilog-backward-ws&directives lim) | |
3778 (if (bobp) | |
3779 (setq continued nil) | |
3780 (setq continued (verilog-backward-token)))) | |
3781 (setq continued nil)) | |
3782 continued)) | |
3783 | |
3784 (defun verilog-calculate-indent () | |
3785 "Calculate the indent of the current Verilog line. | |
3786 Examine previous lines. Once a line is found that is definitive as to the | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
3787 type of the current line, return that lines' indent level and its type. |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
3788 Return a list of two elements: (INDENT-TYPE INDENT-LEVEL)." |
79545 | 3789 (save-excursion |
3790 (let* ((starting_position (point)) | |
3791 (par 0) | |
3792 (begin (looking-at "[ \t]*begin\\>")) | |
3793 (lim (save-excursion (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)" nil t))) | |
3794 (type (catch 'nesting | |
3795 ;; Keep working backwards until we can figure out | |
3796 ;; what type of statement this is. | |
3797 ;; Basically we need to figure out | |
3798 ;; 1) if this is a continuation of the previous line; | |
3799 ;; 2) are we in a block scope (begin..end) | |
3800 | |
3801 ;; if we are in a comment, done. | |
3802 (if (verilog-in-star-comment-p) | |
3803 (throw 'nesting 'comment)) | |
3804 | |
3805 ;; if we have a directive, done. | |
3806 (if (save-excursion (beginning-of-line) (looking-at verilog-directive-re-1)) | |
3807 (throw 'nesting 'directive)) | |
3808 | |
3809 ;; unless we are in the newfangled coverpoint or constraint blocks | |
3810 ;; if we are in a parenthesized list, and the user likes to indent these, return. | |
3811 (if (and | |
3812 verilog-indent-lists | |
3813 (not (verilog-in-coverage)) | |
3814 (verilog-in-paren)) | |
3815 (progn (setq par 1) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3816 (throw 'nesting 'block))) |
79545 | 3817 |
3818 ;; See if we are continuing a previous line | |
3819 (while t | |
3820 ;; trap out if we crawl off the top of the buffer | |
3821 (if (bobp) (throw 'nesting 'cpp)) | |
3822 | |
3823 (if (verilog-continued-line-1 lim) | |
3824 (let ((sp (point))) | |
3825 (if (and | |
3826 (not (looking-at verilog-complete-reg)) | |
3827 (verilog-continued-line-1 lim)) | |
3828 (progn (goto-char sp) | |
3829 (throw 'nesting 'cexp)) | |
3830 | |
3831 (goto-char sp)) | |
3832 | |
3833 (if (and begin | |
3834 (not verilog-indent-begin-after-if) | |
3835 (looking-at verilog-no-indent-begin-re)) | |
3836 (progn | |
3837 (beginning-of-line) | |
3838 (skip-chars-forward " \t") | |
3839 (throw 'nesting 'statement)) | |
3840 (progn | |
3841 (throw 'nesting 'cexp)))) | |
3842 ;; not a continued line | |
3843 (goto-char starting_position)) | |
3844 | |
3845 (if (looking-at "\\<else\\>") | |
3846 ;; search back for governing if, striding across begin..end pairs | |
3847 ;; appropriately | |
3848 (let ((elsec 1)) | |
3849 (while (verilog-re-search-backward verilog-ends-re nil 'move) | |
3850 (cond | |
3851 ((match-end 1) ; else, we're in deep | |
3852 (setq elsec (1+ elsec))) | |
3853 ((match-end 2) ; if | |
3854 (setq elsec (1- elsec)) | |
3855 (if (= 0 elsec) | |
3856 (if verilog-align-ifelse | |
3857 (throw 'nesting 'statement) | |
3858 (progn ;; back up to first word on this line | |
3859 (beginning-of-line) | |
3860 (verilog-forward-syntactic-ws) | |
3861 (throw 'nesting 'statement))))) | |
3862 (t ; endblock | |
3863 ; try to leap back to matching outward block by striding across | |
3864 ; indent level changing tokens then immediately | |
3865 ; previous line governs indentation. | |
3866 (let (( reg) (nest 1)) | |
3867 ;; verilog-ends => else|if|end|join(_any|_none|)|endcase|endclass|endtable|endspecify|endfunction|endtask|endgenerate|endgroup | |
3868 (cond | |
3869 ((match-end 3) ; end | |
3870 ;; Search back for matching begin | |
3871 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" )) | |
3872 ((match-end 4) ; endcase | |
3873 ;; Search back for matching case | |
3874 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )) | |
3875 ((match-end 5) ; endfunction | |
3876 ;; Search back for matching function | |
3877 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )) | |
3878 ((match-end 6) ; endtask | |
3879 ;; Search back for matching task | |
3880 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" )) | |
3881 ((match-end 7) ; endspecify | |
3882 ;; Search back for matching specify | |
3883 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )) | |
3884 ((match-end 8) ; endtable | |
3885 ;; Search back for matching table | |
3886 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )) | |
3887 ((match-end 9) ; endgenerate | |
3888 ;; Search back for matching generate | |
3889 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" )) | |
3890 ((match-end 10) ; joins | |
3891 ;; Search back for matching fork | |
3892 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|none\\)?\\>\\)" )) | |
3893 ((match-end 11) ; class | |
3894 ;; Search back for matching class | |
3895 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" )) | |
3896 ((match-end 12) ; covergroup | |
3897 ;; Search back for matching covergroup | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3898 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))) |
79545 | 3899 (catch 'skip |
3900 (while (verilog-re-search-backward reg nil 'move) | |
3901 (cond | |
3902 ((match-end 1) ; begin | |
3903 (setq nest (1- nest)) | |
3904 (if (= 0 nest) | |
3905 (throw 'skip 1))) | |
3906 ((match-end 2) ; end | |
3907 (setq nest (1+ nest))))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3908 ))))))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3909 (throw 'nesting (verilog-calc-1))) |
79545 | 3910 );; catch nesting |
3911 );; type | |
3912 ) | |
3913 ;; Return type of block and indent level. | |
3914 (if (not type) | |
3915 (setq type 'cpp)) | |
3916 (if (> par 0) ; Unclosed Parenthesis | |
3917 (list 'cparenexp par) | |
3918 (cond | |
3919 ((eq type 'case) | |
3920 (list type (verilog-case-indent-level))) | |
3921 ((eq type 'statement) | |
3922 (list type (current-column))) | |
3923 ((eq type 'defun) | |
3924 (list type 0)) | |
3925 (t | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3926 (list type (verilog-current-indent-level)))))))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3927 |
79545 | 3928 (defun verilog-wai () |
3929 "Show matching nesting block for debugging." | |
3930 (interactive) | |
3931 (save-excursion | |
3932 (let ((nesting (verilog-calc-1))) | |
3933 (message "You are at nesting %s" nesting)))) | |
3934 | |
3935 (defun verilog-calc-1 () | |
3936 (catch 'nesting | |
3937 (while (verilog-re-search-backward (concat "\\({\\|}\\|" verilog-indent-re "\\)") nil 'move) | |
3938 (cond | |
3939 ((equal (char-after) ?\{) | |
3940 (if (verilog-at-constraint-p) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
3941 (throw 'nesting 'block))) |
79545 | 3942 ((equal (char-after) ?\}) |
3943 | |
3944 (let ((there (verilog-at-close-constraint-p))) | |
3945 (if there (goto-char there)))) | |
3946 | |
3947 ((looking-at verilog-beg-block-re-ordered) | |
3948 (cond | |
3949 ((match-end 2) ; *sigh* could be "unique case" or "priority casex" | |
3950 (let ((here (point))) | |
3951 (verilog-beg-of-statement) | |
3952 (if (looking-at verilog-extended-case-re) | |
3953 (throw 'nesting 'case) | |
3954 (goto-char here))) | |
3955 (throw 'nesting 'case)) | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
3956 |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
3957 ((match-end 4) ; *sigh* could be "disable fork" |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
3958 (let ((here (point))) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
3959 (verilog-beg-of-statement) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
3960 (if (looking-at verilog-disable-fork-re) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
3961 t ; is disable fork, this is a normal statement |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
3962 (progn ; or is fork, starts a new block |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
3963 (goto-char here) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
3964 (throw 'nesting 'block))))) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
3965 |
79545 | 3966 |
3967 ;; need to consider typedef struct here... | |
3968 ((looking-at "\\<class\\|struct\\|function\\|task\\|property\\>") | |
3969 ; *sigh* These words have an optional prefix: | |
3970 ; extern {virtual|protected}? function a(); | |
3971 ; assert property (p_1); | |
3972 ; typedef class foo; | |
3973 ; and we don't want to confuse this with | |
3974 ; function a(); | |
3975 ; property | |
3976 ; ... | |
3977 ; endfunction | |
3978 (let ((here (point))) | |
3979 (save-excursion | |
3980 (verilog-beg-of-statement) | |
3981 (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
|
3982 (throw 'nesting 'block))))) |
79545 | 3983 (t (throw 'nesting 'block)))) |
3984 | |
3985 ((looking-at verilog-end-block-re) | |
3986 (verilog-leap-to-head) | |
3987 (if (verilog-in-case-region-p) | |
3988 (progn | |
3989 (verilog-leap-to-case-head) | |
3990 (if (looking-at verilog-case-re) | |
3991 (throw 'nesting 'case))))) | |
3992 | |
3993 ((looking-at (if (verilog-in-generate-region-p) | |
3994 verilog-defun-level-not-generate-re | |
3995 verilog-defun-level-re)) | |
3996 (throw 'nesting 'defun)) | |
3997 | |
3998 ((looking-at verilog-cpp-level-re) | |
3999 (throw 'nesting 'cpp)) | |
4000 | |
4001 ((bobp) | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4002 (throw 'nesting 'cpp)))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4003 (throw 'nesting 'cpp))) |
79545 | 4004 |
4005 (defun verilog-calculate-indent-directive () | |
4006 "Return indentation level for directive. | |
4007 For speed, the searcher looks at the last directive, not the indent | |
4008 of the appropriate enclosing block." | |
4009 (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
|
4010 (ind 0)) ;; Relative offset caused by other directives (like `endif on same line as `else) |
79545 | 4011 ;; Start at current location, scan back for another directive |
4012 | |
4013 (save-excursion | |
4014 (beginning-of-line) | |
4015 (while (and (< base 0) | |
4016 (verilog-re-search-backward verilog-directive-re nil t)) | |
4017 (cond ((save-excursion (skip-chars-backward " \t") (bolp)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4018 (setq base (current-indentation)))) |
79545 | 4019 (cond ((and (looking-at verilog-directive-end) (< base 0)) ;; Only matters when not at BOL |
4020 (setq ind (- ind verilog-indent-level-directive))) | |
4021 ((and (looking-at verilog-directive-middle) (>= base 0)) ;; Only matters when at BOL | |
4022 (setq ind (+ ind verilog-indent-level-directive))) | |
4023 ((looking-at verilog-directive-begin) | |
4024 (setq ind (+ ind verilog-indent-level-directive))))) | |
4025 ;; Adjust indent to starting indent of critical line | |
4026 (setq ind (max 0 (+ ind base)))) | |
4027 | |
4028 (save-excursion | |
4029 (beginning-of-line) | |
4030 (skip-chars-forward " \t") | |
4031 (cond ((or (looking-at verilog-directive-middle) | |
4032 (looking-at verilog-directive-end)) | |
4033 (setq ind (max 0 (- ind verilog-indent-level-directive)))))) | |
4034 ind)) | |
4035 | |
4036 (defun verilog-leap-to-case-head () | |
4037 (let ((nest 1)) | |
4038 (while (/= 0 nest) | |
4039 (verilog-re-search-backward "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" nil 'move) | |
4040 (cond | |
4041 ((match-end 1) | |
4042 (setq nest (1- nest))) | |
4043 ((match-end 2) | |
4044 (setq nest (1+ nest))) | |
4045 ((bobp) | |
4046 (ding 't) | |
4047 (setq nest 0)))))) | |
4048 | |
4049 (defun verilog-leap-to-head () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
4050 "Move point to the head of this block. |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
4051 Jump from end to matching begin, from endcase to matching case, and so on." |
79545 | 4052 (let ((reg nil) |
4053 snest | |
4054 (nest 1)) | |
4055 (cond | |
4056 ((looking-at "\\<end\\>") | |
4057 ;; 1: Search back for matching begin | |
4058 (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|" | |
4059 "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))) | |
4060 ((looking-at "\\<endcase\\>") | |
4061 ;; 2: Search back for matching case | |
4062 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)" )) | |
4063 ((looking-at "\\<join\\(_any\\|_none\\)?\\>") | |
4064 ;; 3: Search back for matching fork | |
4065 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )) | |
4066 ((looking-at "\\<endclass\\>") | |
4067 ;; 4: Search back for matching class | |
4068 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" )) | |
4069 ((looking-at "\\<endtable\\>") | |
4070 ;; 5: Search back for matching table | |
4071 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )) | |
4072 ((looking-at "\\<endspecify\\>") | |
4073 ;; 6: Search back for matching specify | |
4074 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )) | |
4075 ((looking-at "\\<endfunction\\>") | |
4076 ;; 7: Search back for matching function | |
4077 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )) | |
4078 ((looking-at "\\<endgenerate\\>") | |
4079 ;; 8: Search back for matching generate | |
4080 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" )) | |
4081 ((looking-at "\\<endtask\\>") | |
4082 ;; 9: Search back for matching task | |
4083 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" )) | |
4084 ((looking-at "\\<endgroup\\>") | |
4085 ;; 10: Search back for matching covergroup | |
4086 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )) | |
4087 ((looking-at "\\<endproperty\\>") | |
4088 ;; 11: Search back for matching property | |
4089 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" )) | |
4090 ((looking-at "\\<endinterface\\>") | |
4091 ;; 12: Search back for matching interface | |
4092 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" )) | |
4093 ((looking-at "\\<endsequence\\>") | |
4094 ;; 12: Search back for matching sequence | |
4095 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )) | |
4096 ((looking-at "\\<endclocking\\>") | |
4097 ;; 12: Search back for matching clocking | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4098 (setq reg "\\(\\<clocking\\)\\|\\(\\<endclocking\\>\\)" ))) |
79545 | 4099 (if reg |
4100 (catch 'skip | |
4101 (let (sreg) | |
4102 (while (verilog-re-search-backward reg nil 'move) | |
4103 (cond | |
4104 ((match-end 1) ; begin | |
4105 (setq nest (1- nest)) | |
4106 (if (= 0 nest) | |
4107 ;; Now previous line describes syntax | |
4108 (throw 'skip 1)) | |
4109 (if (and snest | |
4110 (= snest nest)) | |
4111 (setq reg sreg))) | |
4112 ((match-end 2) ; end | |
4113 (setq nest (1+ nest))) | |
4114 ((match-end 3) | |
4115 ;; endcase, jump to case | |
4116 (setq snest nest) | |
4117 (setq nest (1+ nest)) | |
4118 (setq sreg reg) | |
4119 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )) | |
4120 ((match-end 4) | |
4121 ;; join, jump to fork | |
4122 (setq snest nest) | |
4123 (setq nest (1+ nest)) | |
4124 (setq sreg reg) | |
4125 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )) | |
4126 ))))))) | |
4127 | |
4128 (defun verilog-continued-line () | |
4129 "Return true if this is a continued line. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
4130 Set point to where line starts." |
79545 | 4131 (let ((continued 't)) |
4132 (if (eq 0 (forward-line -1)) | |
4133 (progn | |
4134 (end-of-line) | |
4135 (verilog-backward-ws&directives) | |
4136 (if (bobp) | |
4137 (setq continued nil) | |
4138 (while (and continued | |
4139 (save-excursion | |
4140 (skip-chars-backward " \t") | |
4141 (not (bolp)))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4142 (setq continued (verilog-backward-token))))) |
79545 | 4143 (setq continued nil)) |
4144 continued)) | |
4145 | |
4146 (defun verilog-backward-token () | |
4147 "Step backward token, returning true if we are now at an end of line token." | |
4148 (interactive) | |
4149 (verilog-backward-syntactic-ws) | |
4150 (cond | |
4151 ((bolp) | |
4152 nil) | |
4153 (;-- Anything ending in a ; is complete | |
4154 (= (preceding-char) ?\;) | |
4155 nil) | |
4156 (; If a "}" is prefixed by a ";", then this is a complete statement | |
4157 ; i.e.: constraint foo { a = b; } | |
4158 (= (preceding-char) ?\}) | |
4159 (progn | |
4160 (backward-char) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4161 (verilog-at-close-constraint-p))) |
79545 | 4162 (;-- constraint foo { a = b } |
4163 ; is a complete statement. *sigh* | |
4164 (= (preceding-char) ?\{) | |
4165 (progn | |
4166 (backward-char) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4167 (not (verilog-at-constraint-p)))) |
79545 | 4168 (;-- Could be 'case (foo)' or 'always @(bar)' which is complete |
4169 ; also could be simply '@(foo)' | |
4170 ; or foo u1 #(a=8) | |
4171 ; (b, ... which ISN'T complete | |
4172 ;;;; Do we need this??? | |
4173 (= (preceding-char) ?\)) | |
4174 (progn | |
4175 (backward-char) | |
4176 (backward-up-list 1) | |
4177 (verilog-backward-syntactic-ws) | |
4178 (let ((back (point))) | |
4179 (forward-word -1) | |
4180 (cond | |
4181 ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>") | |
4182 (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]"))) | |
4183 (t | |
4184 (goto-char back) | |
4185 (cond | |
4186 ((= (preceding-char) ?\@) | |
4187 (backward-char) | |
4188 (save-excursion | |
4189 (verilog-backward-token) | |
4190 (not (looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|initial\\|while\\)\\>")))) | |
4191 ((= (preceding-char) ?\#) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4192 (backward-char)) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4193 (t t))))))) |
79545 | 4194 |
4195 (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete | |
4196 t | |
4197 (forward-word -1) | |
4198 (cond | |
4199 ((looking-at "\\<else\\>") | |
4200 t) | |
80171
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
4201 ((looking-at verilog-behavioral-block-beg-re) |
97019d686b43
* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80165
diff
changeset
|
4202 t) |
79545 | 4203 ((looking-at verilog-indent-re) |
4204 nil) | |
4205 (t | |
4206 (let | |
4207 ((back (point))) | |
4208 (verilog-backward-syntactic-ws) | |
4209 (cond | |
4210 ((= (preceding-char) ?\:) | |
4211 (backward-char) | |
4212 (verilog-backward-syntactic-ws) | |
4213 (backward-sexp) | |
4214 (if (looking-at verilog-nameable-item-re ) | |
4215 nil | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4216 t)) |
79545 | 4217 ((= (preceding-char) ?\#) |
4218 (backward-char) | |
4219 t) | |
4220 ((= (preceding-char) ?\`) | |
4221 (backward-char) | |
4222 t) | |
4223 | |
4224 (t | |
4225 (goto-char back) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4226 t)))))))) |
79545 | 4227 |
4228 (defun verilog-backward-syntactic-ws (&optional bound) | |
4229 "Backward skip over syntactic whitespace for Emacs 19. | |
4230 Optional BOUND limits search." | |
4231 (save-restriction | |
4232 (let* ((bound (or bound (point-min))) (here bound) ) | |
4233 (if (< bound (point)) | |
4234 (progn | |
4235 (narrow-to-region bound (point)) | |
4236 (while (/= here (point)) | |
4237 (setq here (point)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4238 (verilog-skip-backward-comments)))))) |
79545 | 4239 t) |
4240 | |
4241 (defun verilog-forward-syntactic-ws (&optional bound) | |
4242 "Forward skip over syntactic whitespace for Emacs 19. | |
4243 Optional BOUND limits search." | |
4244 (save-restriction | |
4245 (let* ((bound (or bound (point-max))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4246 (here bound)) |
79545 | 4247 (if (> bound (point)) |
4248 (progn | |
4249 (narrow-to-region (point) bound) | |
4250 (while (/= here (point)) | |
4251 (setq here (point)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4252 (forward-comment (buffer-size)))))))) |
79545 | 4253 |
4254 (defun verilog-backward-ws&directives (&optional bound) | |
4255 "Backward skip over syntactic whitespace and compiler directives for Emacs 19. | |
4256 Optional BOUND limits search." | |
4257 (save-restriction | |
4258 (let* ((bound (or bound (point-min))) | |
4259 (here bound) | |
4260 (p nil) ) | |
4261 (if (< bound (point)) | |
4262 (progn | |
4263 (let ((state | |
4264 (save-excursion | |
4265 (parse-partial-sexp (point-min) (point))))) | |
4266 (cond | |
4267 ((nth 7 state) ;; in // comment | |
4268 (verilog-re-search-backward "//" nil 'move) | |
4269 (skip-chars-backward "/")) | |
4270 ((nth 4 state) ;; in /* */ comment | |
4271 (verilog-re-search-backward "/\*" nil 'move)))) | |
4272 (narrow-to-region bound (point)) | |
4273 (while (/= here (point)) | |
4274 (setq here (point)) | |
4275 (verilog-skip-backward-comments) | |
4276 (setq p | |
4277 (save-excursion | |
4278 (beginning-of-line) | |
4279 (cond | |
4280 ((verilog-within-translate-off) | |
4281 (verilog-back-to-start-translate-off (point-min))) | |
4282 ((looking-at verilog-directive-re-1) | |
4283 (point)) | |
4284 (t | |
4285 nil)))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4286 (if p (goto-char p)))))))) |
79545 | 4287 |
4288 (defun verilog-forward-ws&directives (&optional bound) | |
4289 "Forward skip over syntactic whitespace and compiler directives for Emacs 19. | |
4290 Optional BOUND limits search." | |
4291 (save-restriction | |
4292 (let* ((bound (or bound (point-max))) | |
4293 (here bound) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4294 jump) |
79545 | 4295 (if (> bound (point)) |
4296 (progn | |
4297 (let ((state | |
4298 (save-excursion | |
4299 (parse-partial-sexp (point-min) (point))))) | |
4300 (cond | |
4301 ((nth 7 state) ;; in // comment | |
4302 (verilog-re-search-forward "//" nil 'move)) | |
4303 ((nth 4 state) ;; in /* */ comment | |
4304 (verilog-re-search-forward "/\*" nil 'move)))) | |
4305 (narrow-to-region (point) bound) | |
4306 (while (/= here (point)) | |
4307 (setq here (point) | |
4308 jump nil) | |
4309 (forward-comment (buffer-size)) | |
4310 (save-excursion | |
4311 (beginning-of-line) | |
4312 (if (looking-at verilog-directive-re-1) | |
4313 (setq jump t))) | |
4314 (if jump | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4315 (beginning-of-line 2)))))))) |
79545 | 4316 |
4317 (defun verilog-in-comment-p () | |
4318 "Return true if in a star or // comment." | |
4319 (let ((state | |
4320 (save-excursion | |
4321 (parse-partial-sexp (point-min) (point))))) | |
4322 (or (nth 4 state) (nth 7 state)))) | |
4323 | |
4324 (defun verilog-in-star-comment-p () | |
4325 "Return true if in a star comment." | |
4326 (let ((state | |
4327 (save-excursion | |
4328 (parse-partial-sexp (point-min) (point))))) | |
4329 (and | |
4330 (nth 4 state) ; t if in a comment of style a // or b /**/ | |
4331 (not | |
4332 (nth 7 state) ; t if in a comment of style b /**/ | |
4333 )))) | |
4334 | |
4335 (defun verilog-in-slash-comment-p () | |
4336 "Return true if in a slash comment." | |
4337 (let ((state | |
4338 (save-excursion | |
4339 (parse-partial-sexp (point-min) (point))))) | |
4340 (nth 7 state))) | |
4341 | |
4342 (defun verilog-in-comment-or-string-p () | |
4343 "Return true if in a string or comment." | |
4344 (let ((state | |
4345 (save-excursion | |
4346 (parse-partial-sexp (point-min) (point))))) | |
4347 (or (nth 3 state) (nth 4 state) (nth 7 state)))) ; Inside string or comment) | |
4348 | |
4349 (defun verilog-in-escaped-name-p () | |
4350 "Return true if in an escaped name." | |
4351 (save-excursion | |
4352 (backward-char) | |
4353 (skip-chars-backward "^ \t\n\f") | |
4354 (if (equal (char-after (point) ) ?\\ ) | |
4355 t | |
4356 nil))) | |
4357 | |
4358 (defun verilog-in-paren () | |
4359 "Return true if in a parenthetical expression." | |
4360 (let ((state | |
4361 (save-excursion | |
4362 (parse-partial-sexp (point-min) (point))))) | |
4363 (> (nth 0 state) 0 ))) | |
4364 | |
4365 (defun verilog-in-coverage () | |
4366 "Return true if in a constraint or coverpoint expression." | |
4367 (interactive) | |
4368 (save-excursion | |
4369 (if (verilog-in-paren) | |
4370 (progn | |
4371 (backward-up-list 1) | |
4372 (verilog-at-constraint-p) | |
4373 ) | |
4374 nil))) | |
4375 (defun verilog-at-close-constraint-p () | |
4376 "If at the } that closes a constraint or covergroup, return true." | |
4377 (if (and | |
4378 (equal (char-after) ?\}) | |
4379 (verilog-in-paren)) | |
4380 | |
4381 (save-excursion | |
4382 (verilog-backward-ws&directives) | |
4383 (if (equal (char-before) ?\;) | |
4384 (point) | |
4385 nil)))) | |
4386 | |
4387 (defun verilog-at-constraint-p () | |
4388 "If at the { of a constraint or coverpoint definition, return true, moving point to constraint." | |
4389 (if (save-excursion | |
4390 (and | |
4391 (equal (char-after) ?\{) | |
4392 (forward-list) | |
4393 (progn (backward-char 1) | |
4394 (verilog-backward-ws&directives) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4395 (equal (char-before) ?\;)))) |
79545 | 4396 ;; maybe |
4397 (verilog-re-search-backward "\\<constraint\\|coverpoint\\|cross\\>" nil 'move) | |
4398 ;; not | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4399 nil)) |
79545 | 4400 |
4401 (defun verilog-parenthesis-depth () | |
4402 "Return non zero if in parenthetical-expression." | |
4403 (save-excursion | |
4404 (nth 1 (parse-partial-sexp (point-min) (point))))) | |
4405 | |
4406 | |
4407 (defun verilog-skip-forward-comment-or-string () | |
4408 "Return true if in a string or comment." | |
4409 (let ((state | |
4410 (save-excursion | |
4411 (parse-partial-sexp (point-min) (point))))) | |
4412 (cond | |
4413 ((nth 3 state) ;Inside string | |
4414 (goto-char (nth 3 state)) | |
4415 t) | |
4416 ((nth 7 state) ;Inside // comment | |
4417 (forward-line 1) | |
4418 t) | |
4419 ((nth 4 state) ;Inside any comment (hence /**/) | |
4420 (search-forward "*/")) | |
4421 (t | |
4422 nil)))) | |
4423 | |
4424 (defun verilog-skip-backward-comment-or-string () | |
4425 "Return true if in a string or comment." | |
4426 (let ((state | |
4427 (save-excursion | |
4428 (parse-partial-sexp (point-min) (point))))) | |
4429 (cond | |
4430 ((nth 3 state) ;Inside string | |
4431 (search-backward "\"") | |
4432 t) | |
4433 ((nth 7 state) ;Inside // comment | |
4434 (search-backward "//") | |
4435 (skip-chars-backward "/") | |
4436 t) | |
4437 ((nth 4 state) ;Inside /* */ comment | |
4438 (search-backward "/*") | |
4439 t) | |
4440 (t | |
4441 nil)))) | |
4442 | |
4443 (defun verilog-skip-backward-comments () | |
4444 "Return true if a comment was skipped." | |
4445 (let ((more t)) | |
4446 (while more | |
4447 (setq more | |
4448 (let ((state | |
4449 (save-excursion | |
4450 (parse-partial-sexp (point-min) (point))))) | |
4451 (cond | |
4452 ((nth 7 state) ;Inside // comment | |
4453 (search-backward "//") | |
4454 (skip-chars-backward "/") | |
4455 (skip-chars-backward " \t\n\f") | |
4456 t) | |
4457 ((nth 4 state) ;Inside /* */ comment | |
4458 (search-backward "/*") | |
4459 (skip-chars-backward " \t\n\f") | |
4460 t) | |
4461 ((and (not (bobp)) | |
4462 (= (char-before) ?\/) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4463 (= (char-before (1- (point))) ?\*)) |
79545 | 4464 (goto-char (- (point) 2)) |
4465 t) | |
4466 (t | |
4467 (skip-chars-backward " \t\n\f") | |
4468 nil))))))) | |
4469 | |
4470 (defun verilog-skip-forward-comment-p () | |
4471 "If in comment, move to end and return true." | |
4472 (let (state) | |
4473 (progn | |
4474 (setq state | |
4475 (save-excursion | |
4476 (parse-partial-sexp (point-min) (point)))) | |
4477 (cond | |
4478 ((nth 3 state) | |
4479 t) | |
4480 ((nth 7 state) ;Inside // comment | |
4481 (end-of-line) | |
4482 (forward-char 1) | |
4483 t) | |
4484 ((nth 4 state) ;Inside any comment | |
4485 t) | |
4486 (t | |
4487 nil))))) | |
4488 | |
4489 (defun verilog-indent-line-relative () | |
4490 "Cheap version of indent line. | |
4491 Only look at a few lines to determine indent level." | |
4492 (interactive) | |
4493 (let ((indent-str) | |
4494 (sp (point))) | |
4495 (if (looking-at "^[ \t]*$") | |
4496 (cond ;- A blank line; No need to be too smart. | |
4497 ((bobp) | |
4498 (setq indent-str (list 'cpp 0))) | |
4499 ((verilog-continued-line) | |
4500 (let ((sp1 (point))) | |
4501 (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
|
4502 (progn |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4503 (goto-char sp) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4504 (setq indent-str |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4505 (list 'statement (verilog-current-indent-level)))) |
79545 | 4506 (goto-char sp1) |
4507 (setq indent-str (list 'block (verilog-current-indent-level))))) | |
4508 (goto-char sp)) | |
4509 ((goto-char sp) | |
4510 (setq indent-str (verilog-calculate-indent)))) | |
4511 (progn (skip-chars-forward " \t") | |
4512 (setq indent-str (verilog-calculate-indent)))) | |
4513 (verilog-do-indent indent-str))) | |
4514 | |
4515 (defun verilog-indent-line () | |
4516 "Indent for special part of code." | |
4517 (verilog-do-indent (verilog-calculate-indent))) | |
4518 | |
4519 (defun verilog-do-indent (indent-str) | |
4520 (let ((type (car indent-str)) | |
4521 (ind (car (cdr indent-str)))) | |
4522 (cond | |
4523 (; handle continued exp | |
4524 (eq type 'cexp) | |
4525 (let ((here (point))) | |
4526 (verilog-backward-syntactic-ws) | |
4527 (cond | |
4528 ((or | |
4529 (= (preceding-char) ?\,) | |
4530 (= (preceding-char) ?\]) | |
4531 (save-excursion | |
4532 (verilog-beg-of-statement-1) | |
4533 (looking-at verilog-declaration-re))) | |
4534 (let* ( fst | |
4535 (val | |
4536 (save-excursion | |
4537 (backward-char 1) | |
4538 (verilog-beg-of-statement-1) | |
4539 (setq fst (point)) | |
4540 (if (looking-at verilog-declaration-re) | |
4541 (progn ;; we have multiple words | |
4542 (goto-char (match-end 0)) | |
4543 (skip-chars-forward " \t") | |
4544 (cond | |
4545 ((and verilog-indent-declaration-macros | |
4546 (= (following-char) ?\`)) | |
4547 (progn | |
4548 (forward-char 1) | |
4549 (forward-word 1) | |
4550 (skip-chars-forward " \t"))) | |
4551 ((= (following-char) ?\[) | |
4552 (progn | |
4553 (forward-char 1) | |
4554 (backward-up-list -1) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4555 (skip-chars-forward " \t")))) |
79545 | 4556 (current-column)) |
4557 (progn | |
4558 (goto-char fst) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4559 (+ (current-column) verilog-cexp-indent)))))) |
79545 | 4560 (goto-char here) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4561 (indent-line-to val))) |
79545 | 4562 ((= (preceding-char) ?\) ) |
4563 (goto-char here) | |
4564 (let ((val (eval (cdr (assoc type verilog-indent-alist))))) | |
4565 (indent-line-to val))) | |
4566 (t | |
4567 (goto-char here) | |
4568 (let ((val)) | |
4569 (verilog-beg-of-statement-1) | |
4570 (if (and (< (point) here) | |
4571 (verilog-re-search-forward "=[ \\t]*" here 'move)) | |
4572 (setq val (current-column)) | |
4573 (setq val (eval (cdr (assoc type verilog-indent-alist))))) | |
4574 (goto-char here) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4575 (indent-line-to val)))))) |
79545 | 4576 |
4577 (; handle inside parenthetical expressions | |
4578 (eq type 'cparenexp) | |
4579 (let ((val (save-excursion | |
4580 (backward-up-list 1) | |
4581 (forward-char 1) | |
4582 (skip-chars-forward " \t") | |
4583 (current-column)))) | |
4584 (indent-line-to val) | |
4585 (if (and (not (verilog-in-struct-region-p)) | |
4586 (looking-at verilog-declaration-re)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4587 (verilog-indent-declaration ind)))) |
79545 | 4588 |
4589 (;-- Handle the ends | |
4590 (or | |
4591 (looking-at verilog-end-block-re ) | |
4592 (verilog-at-close-constraint-p)) | |
4593 (let ((val (if (eq type 'statement) | |
4594 (- ind verilog-indent-level) | |
4595 ind))) | |
4596 (indent-line-to val))) | |
4597 | |
4598 (;-- Case -- maybe line 'em up | |
4599 (and (eq type 'case) (not (looking-at "^[ \t]*$"))) | |
4600 (progn | |
4601 (cond | |
4602 ((looking-at "\\<endcase\\>") | |
4603 (indent-line-to ind)) | |
4604 (t | |
4605 (let ((val (eval (cdr (assoc type verilog-indent-alist))))) | |
4606 (indent-line-to val)))))) | |
4607 | |
4608 (;-- defun | |
4609 (and (eq type 'defun) | |
4610 (looking-at verilog-zero-indent-re)) | |
4611 (indent-line-to 0)) | |
4612 | |
4613 (;-- declaration | |
4614 (and (or | |
4615 (eq type 'defun) | |
4616 (eq type 'block)) | |
4617 (looking-at verilog-declaration-re)) | |
4618 (verilog-indent-declaration ind)) | |
4619 | |
4620 (;-- Everything else | |
4621 t | |
4622 (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
|
4623 (indent-line-to val)))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4624 |
79545 | 4625 (if (looking-at "[ \t]+$") |
4626 (skip-chars-forward " \t")) | |
4627 indent-str ; Return indent data | |
4628 )) | |
4629 | |
4630 (defun verilog-current-indent-level () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
4631 "Return the indent-level of the current statement." |
79545 | 4632 (save-excursion |
4633 (let (par-pos) | |
4634 (beginning-of-line) | |
4635 (setq par-pos (verilog-parenthesis-depth)) | |
4636 (while par-pos | |
4637 (goto-char par-pos) | |
4638 (beginning-of-line) | |
4639 (setq par-pos (verilog-parenthesis-depth))) | |
4640 (skip-chars-forward " \t") | |
4641 (current-column)))) | |
4642 | |
4643 (defun verilog-case-indent-level () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
4644 "Return the indent-level of the current statement. |
79545 | 4645 Do not count named blocks or case-statements." |
4646 (save-excursion | |
4647 (skip-chars-forward " \t") | |
4648 (cond | |
4649 ((looking-at verilog-named-block-re) | |
4650 (current-column)) | |
4651 ((and (not (looking-at verilog-case-re)) | |
4652 (looking-at "^[^:;]+[ \t]*:")) | |
4653 (verilog-re-search-forward ":" nil t) | |
4654 (skip-chars-forward " \t") | |
4655 (current-column)) | |
4656 (t | |
4657 (current-column))))) | |
4658 | |
4659 (defun verilog-indent-comment () | |
4660 "Indent current line as comment." | |
4661 (let* ((stcol | |
4662 (cond | |
4663 ((verilog-in-star-comment-p) | |
4664 (save-excursion | |
4665 (re-search-backward "/\\*" nil t) | |
4666 (1+(current-column)))) | |
4667 (comment-column | |
4668 comment-column ) | |
4669 (t | |
4670 (save-excursion | |
4671 (re-search-backward "//" nil t) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4672 (current-column)))))) |
79545 | 4673 (indent-line-to stcol) |
4674 stcol)) | |
4675 | |
4676 (defun verilog-more-comment () | |
4677 "Make more comment lines like the previous." | |
4678 (let* ((star 0) | |
4679 (stcol | |
4680 (cond | |
4681 ((verilog-in-star-comment-p) | |
4682 (save-excursion | |
4683 (setq star 1) | |
4684 (re-search-backward "/\\*" nil t) | |
4685 (1+(current-column)))) | |
4686 (comment-column | |
4687 comment-column ) | |
4688 (t | |
4689 (save-excursion | |
4690 (re-search-backward "//" nil t) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4691 (current-column)))))) |
79545 | 4692 (progn |
4693 (indent-to stcol) | |
4694 (if (and star | |
4695 (save-excursion | |
4696 (forward-line -1) | |
4697 (skip-chars-forward " \t") | |
4698 (looking-at "\*"))) | |
4699 (insert "* "))))) | |
4700 | |
4701 (defun verilog-comment-indent (&optional arg) | |
4702 "Return the column number the line should be indented to. | |
4703 ARG is ignored, for `comment-indent-function' compatibility." | |
4704 (cond | |
4705 ((verilog-in-star-comment-p) | |
4706 (save-excursion | |
4707 (re-search-backward "/\\*" nil t) | |
4708 (1+(current-column)))) | |
4709 ( comment-column | |
4710 comment-column ) | |
4711 (t | |
4712 (save-excursion | |
4713 (re-search-backward "//" nil t) | |
4714 (current-column))))) | |
4715 | |
4716 ;; | |
4717 | |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4718 (defun verilog-pretty-declarations (&optional quiet) |
79545 | 4719 "Line up declarations around point." |
4720 (interactive) | |
4721 (save-excursion | |
4722 (if (progn | |
4723 (verilog-beg-of-statement-1) | |
4724 (looking-at verilog-declaration-re)) | |
4725 (let* ((m1 (make-marker)) | |
4726 (e) (r) | |
4727 (here (point)) | |
4728 ;; Start of declaration range | |
4729 (start | |
4730 (progn | |
4731 (verilog-beg-of-statement-1) | |
4732 (while (looking-at verilog-declaration-re) | |
4733 (beginning-of-line) | |
4734 (setq e (point)) | |
4735 (verilog-backward-syntactic-ws) | |
4736 (backward-char) | |
4737 (verilog-beg-of-statement-1)) ;Ack, need to grok `define | |
4738 e)) | |
4739 ;; End of declaration range | |
4740 (end | |
4741 (progn | |
4742 (goto-char here) | |
4743 (verilog-end-of-statement) | |
4744 (setq e (point)) ;Might be on last line | |
4745 (verilog-forward-syntactic-ws) | |
4746 (while (looking-at verilog-declaration-re) | |
4747 (beginning-of-line) | |
4748 (verilog-end-of-statement) | |
4749 (setq e (point)) | |
4750 (verilog-forward-syntactic-ws)) | |
4751 e)) | |
4752 (edpos (set-marker (make-marker) end)) | |
4753 (ind) | |
4754 (base-ind | |
4755 (progn | |
4756 (goto-char start) | |
4757 (verilog-do-indent (verilog-calculate-indent)) | |
4758 (verilog-forward-ws&directives) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4759 (current-column)))) |
79545 | 4760 (goto-char end) |
4761 (goto-char start) | |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4762 (if (and (not quiet) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4763 (> (- end start) 100)) |
79545 | 4764 (message "Lining up declarations..(please stand by)")) |
4765 ;; Get the beginning of line indent first | |
4766 (while (progn (setq e (marker-position edpos)) | |
4767 (< (point) e)) | |
4768 (cond | |
4769 ( (save-excursion (skip-chars-backward " \t") | |
4770 (bolp)) | |
4771 (verilog-forward-ws&directives) | |
4772 (indent-line-to base-ind) | |
4773 (verilog-forward-ws&directives) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4774 (verilog-re-search-forward "[ \t\n\f]" e 'move)) |
79545 | 4775 (t |
4776 (just-one-space) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4777 (verilog-re-search-forward "[ \t\n\f]" e 'move))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4778 ;;(forward-line) |
79545 | 4779 ) |
4780 ;; Now find biggest prefix | |
4781 (setq ind (verilog-get-lineup-indent start edpos)) | |
4782 ;; Now indent each line. | |
4783 (goto-char start) | |
4784 (while (progn (setq e (marker-position edpos)) | |
4785 (setq r (- e (point))) | |
4786 (> r 0)) | |
4787 (setq e (point)) | |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4788 (unless quiet (message "%d" r)) |
79545 | 4789 (cond |
4790 ((or (and verilog-indent-declaration-macros | |
4791 (looking-at verilog-declaration-re-1-macro)) | |
4792 (looking-at verilog-declaration-re-1-no-macro)) | |
4793 (let ((p (match-end 0))) | |
4794 (set-marker m1 p) | |
4795 (if (verilog-re-search-forward "[[#`]" p 'move) | |
4796 (progn | |
4797 (forward-char -1) | |
4798 (just-one-space) | |
4799 (goto-char (marker-position m1)) | |
4800 (just-one-space) | |
4801 (indent-to ind)) | |
4802 (progn | |
4803 (just-one-space) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4804 (indent-to ind))))) |
79545 | 4805 ((verilog-continued-line-1 start) |
4806 (goto-char e) | |
4807 (indent-line-to ind)) | |
4808 (t ; Must be comment or white space | |
4809 (goto-char e) | |
4810 (verilog-forward-ws&directives) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4811 (forward-line -1))) |
79545 | 4812 (forward-line 1)) |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4813 (unless quiet (message "")))))) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4814 |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4815 (defun verilog-pretty-expr (&optional quiet myre) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4816 "Line up expressions around point, or optional regexp MYRE." |
79545 | 4817 (interactive "sRegular Expression: ((<|:)?=) ") |
4818 (save-excursion | |
4819 (if (or (eq myre nil) | |
4820 (string-equal myre "")) | |
4821 (setq myre "\\(<\\|:\\)?=")) | |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4822 (setq myre (concat "\\(^[^;#:<=>]*\\)\\(" myre "\\)")) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4823 (let ((rexp(concat "^\\s-*" verilog-complete-reg))) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4824 (beginning-of-line) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4825 (if (and (not (looking-at rexp )) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4826 (looking-at myre)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4827 (let* ((here (point)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4828 (e) (r) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4829 (start |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4830 (progn |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4831 (beginning-of-line) |
79545 | 4832 (setq e (point)) |
4833 (verilog-backward-syntactic-ws) | |
4834 (beginning-of-line) | |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4835 (while (and (not (looking-at rexp )) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4836 (looking-at myre) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4837 (not (bobp)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4838 ) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4839 (setq e (point)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4840 (verilog-backward-syntactic-ws) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4841 (beginning-of-line) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4842 ) ;Ack, need to grok `define |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4843 e)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4844 (end |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4845 (progn |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4846 (goto-char here) |
79545 | 4847 (end-of-line) |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4848 (setq e (point)) ;Might be on last line |
79545 | 4849 (verilog-forward-syntactic-ws) |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4850 (beginning-of-line) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4851 (while (and (not (looking-at rexp )) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4852 (looking-at myre)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4853 (end-of-line) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4854 (setq e (point)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4855 (verilog-forward-syntactic-ws) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4856 (beginning-of-line) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4857 ) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4858 e)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4859 (edpos (set-marker (make-marker) end)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4860 (ind) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4861 ) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4862 (goto-char start) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4863 (verilog-do-indent (verilog-calculate-indent)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4864 (if (and (not quiet) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4865 (> (- end start) 100)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4866 (message "Lining up expressions..(please stand by)")) |
80141
00b853b0f933
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
80024
diff
changeset
|
4867 |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4868 ;; Set indent to minimum throughout region |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4869 (while (< (point) (marker-position edpos)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4870 (beginning-of-line) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4871 (verilog-just-one-space myre) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4872 (end-of-line) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4873 (verilog-forward-syntactic-ws) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4874 ) |
80141
00b853b0f933
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
80024
diff
changeset
|
4875 |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4876 ;; Now find biggest prefix |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4877 (setq ind (verilog-get-lineup-indent-2 myre start edpos)) |
80141
00b853b0f933
(customize): Fix typo in error message.
Juanma Barranquero <lekktu@gmail.com>
parents:
80024
diff
changeset
|
4878 |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4879 ;; Now indent each line. |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4880 (goto-char start) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4881 (while (progn (setq e (marker-position edpos)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4882 (setq r (- e (point))) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4883 (> r 0)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4884 (setq e (point)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4885 (if (not quiet) (message "%d" r)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4886 (cond |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4887 ((looking-at myre) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4888 (goto-char (match-end 1)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4889 (if (not (verilog-parenthesis-depth)) ;; ignore parenthsized exprs |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4890 (if (eq (char-after) ?=) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4891 (indent-to (1+ ind)) ; line up the = of the <= with surrounding = |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4892 (indent-to ind) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4893 ))) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4894 ((verilog-continued-line-1 start) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4895 (goto-char e) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4896 (indent-line-to ind)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4897 (t ; Must be comment or white space |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4898 (goto-char e) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4899 (verilog-forward-ws&directives) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4900 (forward-line -1)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4901 ) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4902 (forward-line 1)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4903 (unless quiet (message "")) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4904 ))))) |
79545 | 4905 |
4906 (defun verilog-just-one-space (myre) | |
4907 "Remove extra spaces around regular expression MYRE." | |
4908 (interactive) | |
4909 (if (and (not(looking-at verilog-complete-reg)) | |
4910 (looking-at myre)) | |
4911 (let ((p1 (match-end 1)) | |
4912 (p2 (match-end 2))) | |
4913 (progn | |
4914 (goto-char p2) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4915 (if (looking-at "\\s-") (just-one-space)) |
79545 | 4916 (goto-char p1) |
4917 (forward-char -1) | |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4918 (if (looking-at "\\s-") (just-one-space)) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
4919 )))) |
79545 | 4920 |
4921 (defun verilog-indent-declaration (baseind) | |
4922 "Indent current lines as declaration. | |
4923 Line up the variable names based on previous declaration's indentation. | |
4924 BASEIND is the base indent to offset everything." | |
4925 (interactive) | |
4926 (let ((pos (point-marker)) | |
4927 (lim (save-excursion | |
4928 ;; (verilog-re-search-backward verilog-declaration-opener nil 'move) | |
4929 (verilog-re-search-backward "\\(\\<begin\\>\\)\\|\\(\\<module\\>\\)\\|\\(\\<task\\>\\)" nil 'move) | |
4930 (point))) | |
4931 (ind) | |
4932 (val) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4933 (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
|
4934 (setq val |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4935 (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist))))) |
79545 | 4936 (indent-line-to val) |
4937 | |
4938 ;; Use previous declaration (in this module) as template. | |
4939 (if (or (memq 'all verilog-auto-lineup) | |
4940 (memq 'declaration verilog-auto-lineup)) | |
79546 | 4941 (if (verilog-re-search-backward |
79545 | 4942 (or (and verilog-indent-declaration-macros |
4943 verilog-declaration-re-1-macro) | |
4944 verilog-declaration-re-1-no-macro) lim t) | |
4945 (progn | |
4946 (goto-char (match-end 0)) | |
4947 (skip-chars-forward " \t") | |
4948 (setq ind (current-column)) | |
4949 (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
|
4950 (setq val |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4951 (+ baseind |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4952 (eval (cdr (assoc 'declaration verilog-indent-alist))))) |
79545 | 4953 (indent-line-to val) |
4954 (if (and verilog-indent-declaration-macros | |
4955 (looking-at verilog-declaration-re-2-macro)) | |
4956 (let ((p (match-end 0))) | |
4957 (set-marker m1 p) | |
4958 (if (verilog-re-search-forward "[[#`]" p 'move) | |
4959 (progn | |
4960 (forward-char -1) | |
4961 (just-one-space) | |
4962 (goto-char (marker-position m1)) | |
4963 (just-one-space) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4964 (indent-to ind)) |
79545 | 4965 (if (/= (current-column) ind) |
4966 (progn | |
4967 (just-one-space) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
4968 (indent-to ind))))) |
79545 | 4969 (if (looking-at verilog-declaration-re-2-no-macro) |
4970 (let ((p (match-end 0))) | |
4971 (set-marker m1 p) | |
4972 (if (verilog-re-search-forward "[[`#]" p 'move) | |
4973 (progn | |
4974 (forward-char -1) | |
4975 (just-one-space) | |
4976 (goto-char (marker-position m1)) | |
4977 (just-one-space) | |
4978 (indent-to ind)) | |
4979 (if (/= (current-column) ind) | |
4980 (progn | |
4981 (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
|
4982 (indent-to ind)))))))))) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
4983 (goto-char pos))) |
79545 | 4984 |
4985 (defun verilog-get-lineup-indent (b edpos) | |
4986 "Return the indent level that will line up several lines within the region. | |
4987 Region is defined by B and EDPOS." | |
4988 (save-excursion | |
4989 (let ((ind 0) e) | |
4990 (goto-char b) | |
4991 ;; Get rightmost position | |
4992 (while (progn (setq e (marker-position edpos)) | |
4993 (< (point) e)) | |
79546 | 4994 (if (verilog-re-search-forward |
79545 | 4995 (or (and verilog-indent-declaration-macros |
4996 verilog-declaration-re-1-macro) | |
4997 verilog-declaration-re-1-no-macro) e 'move) | |
4998 (progn | |
4999 (goto-char (match-end 0)) | |
5000 (verilog-backward-syntactic-ws) | |
5001 (if (> (current-column) ind) | |
5002 (setq ind (current-column))) | |
5003 (goto-char (match-end 0))))) | |
5004 (if (> ind 0) | |
5005 (1+ ind) | |
5006 ;; No lineup-string found | |
5007 (goto-char b) | |
5008 (end-of-line) | |
5009 (skip-chars-backward " \t") | |
5010 (1+ (current-column)))))) | |
5011 | |
5012 (defun verilog-get-lineup-indent-2 (myre b edpos) | |
5013 "Return the indent level that will line up several lines within the region." | |
5014 (save-excursion | |
5015 (let ((ind 0) e) | |
5016 (goto-char b) | |
5017 ;; Get rightmost position | |
5018 (while (progn (setq e (marker-position edpos)) | |
5019 (< (point) e)) | |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
5020 (if (and (verilog-re-search-forward myre e 'move) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
5021 (not (verilog-parenthesis-depth))) ;; skip parenthsized exprs |
79545 | 5022 (progn |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
5023 (goto-char (match-beginning 2)) |
79545 | 5024 (verilog-backward-syntactic-ws) |
5025 (if (> (current-column) ind) | |
5026 (setq ind (current-column))) | |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
5027 (goto-char (match-end 0))) |
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
5028 )) |
79545 | 5029 (if (> ind 0) |
5030 (1+ ind) | |
5031 ;; No lineup-string found | |
5032 (goto-char b) | |
5033 (end-of-line) | |
5034 (skip-chars-backward " \t") | |
5035 (1+ (current-column)))))) | |
5036 | |
5037 (defun verilog-comment-depth (type val) | |
5038 "A useful mode debugging aide. TYPE and VAL are comments for insertion." | |
5039 (save-excursion | |
5040 (let | |
5041 ((b (prog2 | |
5042 (beginning-of-line) | |
5043 (point-marker) | |
5044 (end-of-line))) | |
5045 (e (point-marker))) | |
5046 (if (re-search-backward " /\\* \[#-\]# \[a-zA-Z\]+ \[0-9\]+ ## \\*/" b t) | |
5047 (progn | |
5048 (replace-match " /* -# ## */") | |
5049 (end-of-line)) | |
5050 (progn | |
5051 (end-of-line) | |
5052 (insert " /* ## ## */")))) | |
5053 (backward-char 6) | |
5054 (insert | |
5055 (format "%s %d" type val)))) | |
5056 | |
5057 ;; | |
5058 ;; | |
5059 ;; Completion | |
5060 ;; | |
5061 (defvar verilog-str nil) | |
5062 (defvar verilog-all nil) | |
5063 (defvar verilog-pred nil) | |
5064 (defvar verilog-buffer-to-use nil) | |
5065 (defvar verilog-flag nil) | |
5066 (defvar verilog-toggle-completions nil | |
5067 "*True means \\<verilog-mode-map>\\[verilog-complete-word] should try all possible completions one by one. | |
5068 Repeated use of \\[verilog-complete-word] will show you all of them. | |
5069 Normally, when there is more than one possible completion, | |
5070 it displays a list of all possible completions.") | |
5071 | |
5072 | |
5073 (defvar verilog-type-keywords | |
5074 '( | |
5075 "and" "buf" "bufif0" "bufif1" "cmos" "defparam" "inout" "input" | |
5076 "integer" "localparam" "logic" "mailbox" "nand" "nmos" "nor" "not" "notif0" | |
5077 "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pullup" | |
5078 "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0" | |
5079 "rtranif1" "semaphore" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1" | |
5080 "triand" "trior" "trireg" "wand" "wire" "wor" "xnor" "xor" | |
5081 ) | |
5082 "*Keywords for types used when completing a word in a declaration or parmlist. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5083 \(Eg. integer, real, reg...)") |
79545 | 5084 |
5085 (defvar verilog-cpp-keywords | |
5086 '("module" "macromodule" "primitive" "timescale" "define" "ifdef" "ifndef" "else" | |
5087 "endif") | |
5088 "*Keywords to complete when at first word of a line in declarative scope. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5089 \(Eg. initial, always, begin, assign.) |
79545 | 5090 The procedures and variables defined within the Verilog program |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5091 will be completed at runtime and should not be added to this list.") |
79545 | 5092 |
5093 (defvar verilog-defun-keywords | |
5094 (append | |
5095 '( | |
5096 "always" "always_comb" "always_ff" "always_latch" "assign" | |
5097 "begin" "end" "generate" "endgenerate" "module" "endmodule" | |
5098 "specify" "endspecify" "function" "endfunction" "initial" "final" | |
5099 "task" "endtask" "primitive" "endprimitive" | |
5100 ) | |
5101 verilog-type-keywords) | |
5102 "*Keywords to complete when at first word of a line in declarative scope. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5103 \(Eg. initial, always, begin, assign.) |
79545 | 5104 The procedures and variables defined within the Verilog program |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5105 will be completed at runtime and should not be added to this list.") |
79545 | 5106 |
5107 (defvar verilog-block-keywords | |
5108 '( | |
5109 "begin" "break" "case" "continue" "else" "end" "endfunction" | |
5110 "endgenerate" "endinterface" "endpackage" "endspecify" "endtask" | |
5111 "for" "fork" "if" "join" "join_any" "join_none" "repeat" "return" | |
5112 "while") | |
5113 "*Keywords to complete when at first word of a line in behavioral scope. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5114 \(Eg. begin, if, then, else, for, fork.) |
79545 | 5115 The procedures and variables defined within the Verilog program |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5116 will be completed at runtime and should not be added to this list.") |
79545 | 5117 |
5118 (defvar verilog-tf-keywords | |
5119 '("begin" "break" "fork" "join" "join_any" "join_none" "case" "end" "endtask" "endfunction" "if" "else" "for" "while" "repeat") | |
5120 "*Keywords to complete when at first word of a line in a task or function. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5121 \(Eg. begin, if, then, else, for, fork.) |
79545 | 5122 The procedures and variables defined within the Verilog program |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5123 will be completed at runtime and should not be added to this list.") |
79545 | 5124 |
5125 (defvar verilog-case-keywords | |
5126 '("begin" "fork" "join" "join_any" "join_none" "case" "end" "endcase" "if" "else" "for" "repeat") | |
5127 "*Keywords to complete when at first word of a line in case scope. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5128 \(Eg. begin, if, then, else, for, fork.) |
79545 | 5129 The procedures and variables defined within the Verilog program |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5130 will be completed at runtime and should not be added to this list.") |
79545 | 5131 |
5132 (defvar verilog-separator-keywords | |
5133 '("else" "then" "begin") | |
5134 "*Keywords to complete when NOT standing at the first word of a statement. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5135 \(Eg. else, then.) |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5136 Variables and function names defined within the Verilog program |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5137 will be completed at runtime and should not be added to this list.") |
79545 | 5138 |
5139 (defun verilog-string-diff (str1 str2) | |
5140 "Return index of first letter where STR1 and STR2 differs." | |
5141 (catch 'done | |
5142 (let ((diff 0)) | |
5143 (while t | |
5144 (if (or (> (1+ diff) (length str1)) | |
5145 (> (1+ diff) (length str2))) | |
5146 (throw 'done diff)) | |
5147 (or (equal (aref str1 diff) (aref str2 diff)) | |
5148 (throw 'done diff)) | |
5149 (setq diff (1+ diff)))))) | |
5150 | |
5151 ;; Calculate all possible completions for functions if argument is `function', | |
5152 ;; completions for procedures if argument is `procedure' or both functions and | |
5153 ;; procedures otherwise. | |
5154 | |
5155 (defun verilog-func-completion (type) | |
5156 "Build regular expression for module/task/function names. | |
5157 TYPE is 'module, 'tf for task or function, or t if unknown." | |
5158 (if (string= verilog-str "") | |
5159 (setq verilog-str "[a-zA-Z_]")) | |
5160 (let ((verilog-str (concat (cond | |
5161 ((eq type 'module) "\\<\\(module\\)\\s +") | |
5162 ((eq type 'tf) "\\<\\(task\\|function\\)\\s +") | |
5163 (t "\\<\\(task\\|function\\|module\\)\\s +")) | |
5164 "\\<\\(" verilog-str "[a-zA-Z0-9_.]*\\)\\>")) | |
5165 match) | |
5166 | |
5167 (if (not (looking-at verilog-defun-re)) | |
5168 (verilog-re-search-backward verilog-defun-re nil t)) | |
5169 (forward-char 1) | |
5170 | |
5171 ;; Search through all reachable functions | |
5172 (goto-char (point-min)) | |
5173 (while (verilog-re-search-forward verilog-str (point-max) t) | |
5174 (progn (setq match (buffer-substring (match-beginning 2) | |
5175 (match-end 2))) | |
5176 (if (or (null verilog-pred) | |
5177 (funcall verilog-pred match)) | |
5178 (setq verilog-all (cons match verilog-all))))) | |
5179 (if (match-beginning 0) | |
5180 (goto-char (match-beginning 0))))) | |
5181 | |
5182 (defun verilog-get-completion-decl (end) | |
5183 "Macro for searching through current declaration (var, type or const) | |
5184 for matches of `str' and adding the occurrence tp `all' through point END." | |
5185 (let ((re (or (and verilog-indent-declaration-macros | |
5186 verilog-declaration-re-2-macro) | |
5187 verilog-declaration-re-2-no-macro)) | |
5188 decl-end match) | |
5189 ;; Traverse lines | |
5190 (while (and (< (point) end) | |
5191 (verilog-re-search-forward re end t)) | |
5192 ;; Traverse current line | |
5193 (setq decl-end (save-excursion (verilog-declaration-end))) | |
5194 (while (and (verilog-re-search-forward verilog-symbol-re decl-end t) | |
5195 (not (match-end 1))) | |
5196 (setq match (buffer-substring (match-beginning 0) (match-end 0))) | |
5197 (if (string-match (concat "\\<" verilog-str) match) | |
5198 (if (or (null verilog-pred) | |
5199 (funcall verilog-pred match)) | |
5200 (setq verilog-all (cons match verilog-all))))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5201 (forward-line 1))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5202 verilog-all) |
79545 | 5203 |
5204 (defun verilog-type-completion () | |
5205 "Calculate all possible completions for types." | |
5206 (let ((start (point)) | |
5207 goon) | |
5208 ;; Search for all reachable type declarations | |
5209 (while (or (verilog-beg-of-defun) | |
5210 (setq goon (not goon))) | |
5211 (save-excursion | |
5212 (if (and (< start (prog1 (save-excursion (verilog-end-of-defun) | |
5213 (point)) | |
5214 (forward-char 1))) | |
5215 (verilog-re-search-forward | |
5216 "\\<type\\>\\|\\<\\(begin\\|function\\|procedure\\)\\>" | |
5217 start t) | |
5218 (not (match-end 1))) | |
5219 ;; Check current type declaration | |
5220 (verilog-get-completion-decl start)))))) | |
5221 | |
5222 (defun verilog-var-completion () | |
5223 "Calculate all possible completions for variables (or constants)." | |
5224 (let ((start (point))) | |
5225 ;; Search for all reachable var declarations | |
5226 (verilog-beg-of-defun) | |
5227 (save-excursion | |
5228 ;; Check var declarations | |
5229 (verilog-get-completion-decl start)))) | |
5230 | |
5231 (defun verilog-keyword-completion (keyword-list) | |
5232 "Give list of all possible completions of keywords in KEYWORD-LIST." | |
5233 (mapcar '(lambda (s) | |
5234 (if (string-match (concat "\\<" verilog-str) s) | |
5235 (if (or (null verilog-pred) | |
5236 (funcall verilog-pred s)) | |
5237 (setq verilog-all (cons s verilog-all))))) | |
5238 keyword-list)) | |
5239 | |
5240 | |
5241 (defun verilog-completion (verilog-str verilog-pred verilog-flag) | |
5242 "Function passed to `completing-read', `try-completion' or `all-completions'. | |
5243 Called to get completion on VERILOG-STR. If VERILOG-PRED is non-nil, it | |
5244 must be a function to be called for every match to check if this should | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5245 really be a match. If VERILOG-FLAG is t, the function returns a list of |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5246 all possible completions. If VERILOG-FLAG is nil it returns a string, |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5247 the longest possible completion, or t if VERILOG-STR is an exact match. |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5248 If VERILOG-FLAG is 'lambda, the function returns t if VERILOG-STR is an |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5249 exact match, nil otherwise." |
79545 | 5250 (save-excursion |
5251 (let ((verilog-all nil)) | |
5252 ;; Set buffer to use for searching labels. This should be set | |
5253 ;; within functions which use verilog-completions | |
5254 (set-buffer verilog-buffer-to-use) | |
5255 | |
5256 ;; Determine what should be completed | |
5257 (let ((state (car (verilog-calculate-indent)))) | |
5258 (cond ((eq state 'defun) | |
5259 (save-excursion (verilog-var-completion)) | |
5260 (verilog-func-completion 'module) | |
5261 (verilog-keyword-completion verilog-defun-keywords)) | |
5262 | |
5263 ((eq state 'behavioral) | |
5264 (save-excursion (verilog-var-completion)) | |
5265 (verilog-func-completion 'module) | |
5266 (verilog-keyword-completion verilog-defun-keywords)) | |
5267 | |
5268 ((eq state 'block) | |
5269 (save-excursion (verilog-var-completion)) | |
5270 (verilog-func-completion 'tf) | |
5271 (verilog-keyword-completion verilog-block-keywords)) | |
5272 | |
5273 ((eq state 'case) | |
5274 (save-excursion (verilog-var-completion)) | |
5275 (verilog-func-completion 'tf) | |
5276 (verilog-keyword-completion verilog-case-keywords)) | |
5277 | |
5278 ((eq state 'tf) | |
5279 (save-excursion (verilog-var-completion)) | |
5280 (verilog-func-completion 'tf) | |
5281 (verilog-keyword-completion verilog-tf-keywords)) | |
5282 | |
5283 ((eq state 'cpp) | |
5284 (save-excursion (verilog-var-completion)) | |
5285 (verilog-keyword-completion verilog-cpp-keywords)) | |
5286 | |
5287 ((eq state 'cparenexp) | |
5288 (save-excursion (verilog-var-completion))) | |
5289 | |
5290 (t;--Anywhere else | |
5291 (save-excursion (verilog-var-completion)) | |
5292 (verilog-func-completion 'both) | |
5293 (verilog-keyword-completion verilog-separator-keywords)))) | |
5294 | |
5295 ;; Now we have built a list of all matches. Give response to caller | |
5296 (verilog-completion-response)))) | |
5297 | |
5298 (defun verilog-completion-response () | |
5299 (cond ((or (equal verilog-flag 'lambda) (null verilog-flag)) | |
5300 ;; This was not called by all-completions | |
5301 (if (null verilog-all) | |
5302 ;; Return nil if there was no matching label | |
5303 nil | |
5304 ;; Get longest string common in the labels | |
5305 (let* ((elm (cdr verilog-all)) | |
5306 (match (car verilog-all)) | |
5307 (min (length match)) | |
5308 tmp) | |
5309 (if (string= match verilog-str) | |
5310 ;; Return t if first match was an exact match | |
5311 (setq match t) | |
5312 (while (not (null elm)) | |
5313 ;; Find longest common string | |
5314 (if (< (setq tmp (verilog-string-diff match (car elm))) min) | |
5315 (progn | |
5316 (setq min tmp) | |
5317 (setq match (substring match 0 min)))) | |
5318 ;; Terminate with match=t if this is an exact match | |
5319 (if (string= (car elm) verilog-str) | |
5320 (progn | |
5321 (setq match t) | |
5322 (setq elm nil)) | |
5323 (setq elm (cdr elm))))) | |
5324 ;; If this is a test just for exact match, return nil ot t | |
5325 (if (and (equal verilog-flag 'lambda) (not (equal match 't))) | |
5326 nil | |
5327 match)))) | |
5328 ;; If flag is t, this was called by all-completions. Return | |
5329 ;; list of all possible completions | |
5330 (verilog-flag | |
5331 verilog-all))) | |
5332 | |
5333 (defvar verilog-last-word-numb 0) | |
5334 (defvar verilog-last-word-shown nil) | |
5335 (defvar verilog-last-completions nil) | |
5336 | |
5337 (defun verilog-complete-word () | |
5338 "Complete word at current point. | |
5339 \(See also `verilog-toggle-completions', `verilog-type-keywords', | |
5340 and `verilog-separator-keywords'.)" | |
5341 (interactive) | |
5342 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point))) | |
5343 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))) | |
5344 (verilog-str (buffer-substring b e)) | |
5345 ;; The following variable is used in verilog-completion | |
5346 (verilog-buffer-to-use (current-buffer)) | |
5347 (allcomp (if (and verilog-toggle-completions | |
5348 (string= verilog-last-word-shown verilog-str)) | |
5349 verilog-last-completions | |
5350 (all-completions verilog-str 'verilog-completion))) | |
5351 (match (if verilog-toggle-completions | |
5352 "" (try-completion | |
5353 verilog-str (mapcar '(lambda (elm) | |
5354 (cons elm 0)) allcomp))))) | |
5355 ;; Delete old string | |
5356 (delete-region b e) | |
5357 | |
5358 ;; Toggle-completions inserts whole labels | |
5359 (if verilog-toggle-completions | |
5360 (progn | |
5361 ;; Update entry number in list | |
5362 (setq verilog-last-completions allcomp | |
5363 verilog-last-word-numb | |
5364 (if (>= verilog-last-word-numb (1- (length allcomp))) | |
5365 0 | |
5366 (1+ verilog-last-word-numb))) | |
5367 (setq verilog-last-word-shown (elt allcomp verilog-last-word-numb)) | |
5368 ;; Display next match or same string if no match was found | |
5369 (if (not (null allcomp)) | |
5370 (insert "" verilog-last-word-shown) | |
5371 (insert "" verilog-str) | |
5372 (message "(No match)"))) | |
5373 ;; The other form of completion does not necessarily do that. | |
5374 | |
5375 ;; Insert match if found, or the original string if no match | |
5376 (if (or (null match) (equal match 't)) | |
5377 (progn (insert "" verilog-str) | |
5378 (message "(No match)")) | |
5379 (insert "" match)) | |
5380 ;; Give message about current status of completion | |
5381 (cond ((equal match 't) | |
5382 (if (not (null (cdr allcomp))) | |
5383 (message "(Complete but not unique)") | |
5384 (message "(Sole completion)"))) | |
5385 ;; Display buffer if the current completion didn't help | |
5386 ;; on completing the label. | |
5387 ((and (not (null (cdr allcomp))) (= (length verilog-str) | |
5388 (length match))) | |
5389 (with-output-to-temp-buffer "*Completions*" | |
5390 (display-completion-list allcomp)) | |
5391 ;; Wait for a key press. Then delete *Completion* window | |
5392 (momentary-string-display "" (point)) | |
5393 (delete-window (get-buffer-window (get-buffer "*Completions*"))) | |
5394 ))))) | |
5395 | |
5396 (defun verilog-show-completions () | |
5397 "Show all possible completions at current point." | |
5398 (interactive) | |
5399 (let* ((b (save-excursion (skip-chars-backward "a-zA-Z0-9_") (point))) | |
5400 (e (save-excursion (skip-chars-forward "a-zA-Z0-9_") (point))) | |
5401 (verilog-str (buffer-substring b e)) | |
5402 ;; The following variable is used in verilog-completion | |
5403 (verilog-buffer-to-use (current-buffer)) | |
5404 (allcomp (if (and verilog-toggle-completions | |
5405 (string= verilog-last-word-shown verilog-str)) | |
5406 verilog-last-completions | |
5407 (all-completions verilog-str 'verilog-completion)))) | |
5408 ;; Show possible completions in a temporary buffer. | |
5409 (with-output-to-temp-buffer "*Completions*" | |
5410 (display-completion-list allcomp)) | |
5411 ;; Wait for a key press. Then delete *Completion* window | |
5412 (momentary-string-display "" (point)) | |
5413 (delete-window (get-buffer-window (get-buffer "*Completions*"))))) | |
5414 | |
5415 | |
5416 (defun verilog-get-default-symbol () | |
5417 "Return symbol around current point as a string." | |
5418 (save-excursion | |
5419 (buffer-substring (progn | |
5420 (skip-chars-backward " \t") | |
5421 (skip-chars-backward "a-zA-Z0-9_") | |
5422 (point)) | |
5423 (progn | |
5424 (skip-chars-forward "a-zA-Z0-9_") | |
5425 (point))))) | |
5426 | |
5427 (defun verilog-build-defun-re (str &optional arg) | |
5428 "Return function/task/module starting with STR as regular expression. | |
5429 With optional second ARG non-nil, STR is the complete name of the instruction." | |
5430 (if arg | |
5431 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "\\)\\>") | |
5432 (concat "^\\(function\\|task\\|module\\)[ \t]+\\(" str "[a-zA-Z0-9_]*\\)\\>"))) | |
5433 | |
5434 (defun verilog-comp-defun (verilog-str verilog-pred verilog-flag) | |
5435 "Function passed to `completing-read', `try-completion' or `all-completions'. | |
5436 Returns a completion on any function name based on VERILOG-STR prefix. If | |
5437 VERILOG-PRED is non-nil, it must be a function to be called for every match | |
5438 to check if this should really be a match. If VERILOG-FLAG is t, the | |
5439 function returns a list of all possible completions. If it is nil it | |
5440 returns a string, the longest possible completion, or t if VERILOG-STR is | |
5441 an exact match. If VERILOG-FLAG is 'lambda, the function returns t if | |
5442 VERILOG-STR is an exact match, nil otherwise." | |
5443 (save-excursion | |
5444 (let ((verilog-all nil) | |
5445 match) | |
5446 | |
5447 ;; Set buffer to use for searching labels. This should be set | |
5448 ;; within functions which use verilog-completions | |
5449 (set-buffer verilog-buffer-to-use) | |
5450 | |
5451 (let ((verilog-str verilog-str)) | |
5452 ;; Build regular expression for functions | |
5453 (if (string= verilog-str "") | |
5454 (setq verilog-str (verilog-build-defun-re "[a-zA-Z_]")) | |
5455 (setq verilog-str (verilog-build-defun-re verilog-str))) | |
5456 (goto-char (point-min)) | |
5457 | |
5458 ;; Build a list of all possible completions | |
5459 (while (verilog-re-search-forward verilog-str nil t) | |
5460 (setq match (buffer-substring (match-beginning 2) (match-end 2))) | |
5461 (if (or (null verilog-pred) | |
5462 (funcall verilog-pred match)) | |
5463 (setq verilog-all (cons match verilog-all))))) | |
5464 | |
5465 ;; Now we have built a list of all matches. Give response to caller | |
5466 (verilog-completion-response)))) | |
5467 | |
5468 (defun verilog-goto-defun () | |
5469 "Move to specified Verilog module/task/function. | |
5470 The default is a name found in the buffer around point. | |
5471 If search fails, other files are checked based on | |
5472 `verilog-library-flags'." | |
5473 (interactive) | |
5474 (let* ((default (verilog-get-default-symbol)) | |
5475 ;; The following variable is used in verilog-comp-function | |
5476 (verilog-buffer-to-use (current-buffer)) | |
5477 (label (if (not (string= default "")) | |
5478 ;; Do completion with default | |
5479 (completing-read (concat "Label: (default " default ") ") | |
5480 'verilog-comp-defun nil nil "") | |
5481 ;; There is no default value. Complete without it | |
5482 (completing-read "Label: " | |
5483 'verilog-comp-defun nil nil ""))) | |
5484 pt) | |
5485 ;; If there was no response on prompt, use default value | |
5486 (if (string= label "") | |
5487 (setq label default)) | |
5488 ;; Goto right place in buffer if label is not an empty string | |
5489 (or (string= label "") | |
5490 (progn | |
5491 (save-excursion | |
5492 (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
|
5493 (setq pt |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5494 (re-search-forward (verilog-build-defun-re label t) nil t))) |
79545 | 5495 (when pt |
5496 (goto-char pt) | |
5497 (beginning-of-line)) | |
5498 pt) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5499 (verilog-goto-defun-file label)))) |
79545 | 5500 |
5501 ;; Eliminate compile warning | |
80172
7d8f87158250
(eval-when-compile): Don't define
Dan Nicolaescu <dann@ics.uci.edu>
parents:
80171
diff
changeset
|
5502 (defvar occur-pos-list) |
79545 | 5503 |
5504 (defun verilog-showscopes () | |
5505 "List all scopes in this module." | |
5506 (interactive) | |
5507 (let ((buffer (current-buffer)) | |
5508 (linenum 1) | |
5509 (nlines 0) | |
5510 (first 1) | |
5511 (prevpos (point-min)) | |
5512 (final-context-start (make-marker)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5513 (regexp "\\(module\\s-+\\w+\\s-*(\\)\\|\\(\\w+\\s-+\\w+\\s-*(\\)")) |
79545 | 5514 (with-output-to-temp-buffer "*Occur*" |
5515 (save-excursion | |
5516 (message (format "Searching for %s ..." regexp)) | |
5517 ;; Find next match, but give up if prev match was at end of buffer. | |
5518 (while (and (not (= prevpos (point-max))) | |
5519 (verilog-re-search-forward regexp nil t)) | |
5520 (goto-char (match-beginning 0)) | |
5521 (beginning-of-line) | |
5522 (save-match-data | |
5523 (setq linenum (+ linenum (count-lines prevpos (point))))) | |
5524 (setq prevpos (point)) | |
5525 (goto-char (match-end 0)) | |
5526 (let* ((start (save-excursion | |
5527 (goto-char (match-beginning 0)) | |
5528 (forward-line (if (< nlines 0) nlines (- nlines))) | |
5529 (point))) | |
5530 (end (save-excursion | |
5531 (goto-char (match-end 0)) | |
5532 (if (> nlines 0) | |
5533 (forward-line (1+ nlines)) | |
5534 (forward-line 1)) | |
5535 (point))) | |
5536 (tag (format "%3d" linenum)) | |
5537 (empty (make-string (length tag) ?\ )) | |
5538 tem) | |
5539 (save-excursion | |
5540 (setq tem (make-marker)) | |
5541 (set-marker tem (point)) | |
5542 (set-buffer standard-output) | |
5543 (setq occur-pos-list (cons tem occur-pos-list)) | |
5544 (or first (zerop nlines) | |
5545 (insert "--------\n")) | |
5546 (setq first nil) | |
5547 (insert-buffer-substring buffer start end) | |
5548 (backward-char (- end start)) | |
5549 (setq tem (if (< nlines 0) (- nlines) nlines)) | |
5550 (while (> tem 0) | |
5551 (insert empty ?:) | |
5552 (forward-line 1) | |
5553 (setq tem (1- tem))) | |
5554 (let ((this-linenum linenum)) | |
5555 (set-marker final-context-start | |
5556 (+ (point) (- (match-end 0) (match-beginning 0)))) | |
5557 (while (< (point) final-context-start) | |
5558 (if (null tag) | |
5559 (setq tag (format "%3d" this-linenum))) | |
5560 (insert tag ?:))))))) | |
5561 (set-buffer-modified-p nil)))) | |
5562 | |
5563 | |
5564 ;; Highlight helper functions | |
5565 (defconst verilog-directive-regexp "\\(translate\\|coverage\\|lint\\)_") | |
5566 (defun verilog-within-translate-off () | |
5567 "Return point if within translate-off region, else nil." | |
5568 (and (save-excursion | |
5569 (re-search-backward | |
5570 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>") | |
5571 nil t)) | |
5572 (equal "off" (match-string 2)) | |
5573 (point))) | |
5574 | |
5575 (defun verilog-start-translate-off (limit) | |
5576 "Return point before translate-off directive if before LIMIT, else nil." | |
5577 (when (re-search-forward | |
5578 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>") | |
5579 limit t) | |
5580 (match-beginning 0))) | |
5581 | |
5582 (defun verilog-back-to-start-translate-off (limit) | |
5583 "Return point before translate-off directive if before LIMIT, else nil." | |
5584 (when (re-search-backward | |
5585 (concat "//\\s-*.*\\s-*" verilog-directive-regexp "off\\>") | |
5586 limit t) | |
5587 (match-beginning 0))) | |
5588 | |
5589 (defun verilog-end-translate-off (limit) | |
5590 "Return point after translate-on directive if before LIMIT, else nil." | |
5591 | |
5592 (re-search-forward (concat | |
5593 "//\\s-*.*\\s-*" verilog-directive-regexp "on\\>") limit t)) | |
5594 | |
5595 (defun verilog-match-translate-off (limit) | |
5596 "Match a translate-off block, setting `match-data' and returning t, else nil. | |
5597 Bound search by LIMIT." | |
5598 (when (< (point) limit) | |
5599 (let ((start (or (verilog-within-translate-off) | |
5600 (verilog-start-translate-off limit))) | |
5601 (case-fold-search t)) | |
5602 (when start | |
5603 (let ((end (or (verilog-end-translate-off limit) limit))) | |
5604 (set-match-data (list start end)) | |
5605 (goto-char end)))))) | |
5606 | |
5607 (defun verilog-font-lock-match-item (limit) | |
5608 "Match, and move over, any declaration item after point. | |
5609 Bound search by LIMIT. Adapted from | |
5610 `font-lock-match-c-style-declaration-item-and-skip-to-next'." | |
5611 (condition-case nil | |
5612 (save-restriction | |
5613 (narrow-to-region (point-min) limit) | |
5614 ;; match item | |
5615 (when (looking-at "\\s-*\\([a-zA-Z]\\w*\\)") | |
5616 (save-match-data | |
5617 (goto-char (match-end 1)) | |
5618 ;; move to next item | |
5619 (if (looking-at "\\(\\s-*,\\)") | |
5620 (goto-char (match-end 1)) | |
5621 (end-of-line) t)))) | |
5622 (error nil))) | |
5623 | |
5624 | |
5625 ;; Added by Subbu Meiyappan for Header | |
5626 | |
5627 (defun verilog-header () | |
5628 "Insert a standard Verilog file header." | |
5629 (interactive) | |
5630 (let ((start (point))) | |
5631 (insert "\ | |
5632 //----------------------------------------------------------------------------- | |
5633 // Title : <title> | |
5634 // Project : <project> | |
5635 //----------------------------------------------------------------------------- | |
5636 // File : <filename> | |
5637 // Author : <author> | |
5638 // Created : <credate> | |
5639 // Last modified : <moddate> | |
5640 //----------------------------------------------------------------------------- | |
5641 // Description : | |
5642 // <description> | |
5643 //----------------------------------------------------------------------------- | |
5644 // Copyright (c) <copydate> by <company> This model is the confidential and | |
5645 // proprietary property of <company> and the possession or use of this | |
5646 // file requires a written license from <company>. | |
5647 //------------------------------------------------------------------------------ | |
5648 // Modification history : | |
5649 // <modhist> | |
5650 //----------------------------------------------------------------------------- | |
5651 | |
5652 ") | |
5653 (goto-char start) | |
5654 (search-forward "<filename>") | |
5655 (replace-match (buffer-name) t t) | |
5656 (search-forward "<author>") (replace-match "" t t) | |
5657 (insert (user-full-name)) | |
5658 (insert " <" (user-login-name) "@" (system-name) ">") | |
5659 (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
|
5660 (verilog-insert-date) |
79545 | 5661 (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
|
5662 (verilog-insert-date) |
79545 | 5663 (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
|
5664 (verilog-insert-year) |
79545 | 5665 (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
|
5666 (verilog-insert-date) |
79545 | 5667 (insert " : created") |
5668 (goto-char start) | |
5669 (let (string) | |
5670 (setq string (read-string "title: ")) | |
5671 (search-forward "<title>") | |
5672 (replace-match string t t) | |
5673 (setq string (read-string "project: " verilog-project)) | |
5674 (setq verilog-project string) | |
5675 (search-forward "<project>") | |
5676 (replace-match string t t) | |
5677 (setq string (read-string "Company: " verilog-company)) | |
5678 (setq verilog-company string) | |
5679 (search-forward "<company>") | |
5680 (replace-match string t t) | |
5681 (search-forward "<company>") | |
5682 (replace-match string t t) | |
5683 (search-forward "<company>") | |
5684 (replace-match string t t) | |
5685 (search-backward "<description>") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5686 (replace-match "" t t)))) |
79545 | 5687 |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
5688 ;; 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
|
5689 |
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
5690 (defun verilog-insert-date () |
79545 | 5691 "Insert date from the system." |
5692 (interactive) | |
5693 (let ((timpos)) | |
5694 (setq timpos (point)) | |
5695 (if verilog-date-scientific-format | |
5696 (shell-command "date \"+@%Y/%m/%d\"" t) | |
5697 (shell-command "date \"+@%d.%m.%Y\"" t)) | |
5698 (search-forward "@") | |
5699 (delete-region timpos (point)) | |
5700 (end-of-line)) | |
5701 (delete-char 1)) | |
5702 | |
79554
bc59ec18d036
(verilog-kill-existing-comment, verilog-insert-date)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79552
diff
changeset
|
5703 (defun verilog-insert-year () |
79545 | 5704 "Insert year from the system." |
5705 (interactive) | |
5706 (let ((timpos)) | |
5707 (setq timpos (point)) | |
5708 (shell-command "date \"+@%Y\"" t) | |
5709 (search-forward "@") | |
5710 (delete-region timpos (point)) | |
5711 (end-of-line)) | |
5712 (delete-char 1)) | |
5713 | |
5714 | |
5715 ;; | |
5716 ;; Signal list parsing | |
5717 ;; | |
5718 | |
5719 ;; Elements of a signal list | |
5720 (defsubst verilog-sig-name (sig) | |
5721 (car sig)) | |
5722 (defsubst verilog-sig-bits (sig) | |
5723 (nth 1 sig)) | |
5724 (defsubst verilog-sig-comment (sig) | |
5725 (nth 2 sig)) | |
5726 (defsubst verilog-sig-memory (sig) | |
5727 (nth 3 sig)) | |
5728 (defsubst verilog-sig-enum (sig) | |
5729 (nth 4 sig)) | |
5730 (defsubst verilog-sig-signed (sig) | |
5731 (nth 5 sig)) | |
5732 (defsubst verilog-sig-type (sig) | |
5733 (nth 6 sig)) | |
5734 (defsubst verilog-sig-multidim (sig) | |
5735 (nth 7 sig)) | |
5736 (defsubst verilog-sig-multidim-string (sig) | |
5737 (if (verilog-sig-multidim sig) | |
5738 (let ((str "") (args (verilog-sig-multidim sig))) | |
5739 (while args | |
5740 (setq str (concat str (car args))) | |
5741 (setq args (cdr args))) | |
5742 str))) | |
5743 (defsubst verilog-sig-width (sig) | |
5744 (verilog-make-width-expression (verilog-sig-bits sig))) | |
5745 | |
5746 (defsubst verilog-alw-get-inputs (sigs) | |
5747 (nth 2 sigs)) | |
5748 (defsubst verilog-alw-get-outputs (sigs) | |
5749 (nth 0 sigs)) | |
5750 (defsubst verilog-alw-get-uses-delayed (sigs) | |
5751 (nth 3 sigs)) | |
5752 | |
5753 (defun verilog-signals-not-in (in-list not-list) | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5754 "Return list of signals in IN-LIST that aren't also in NOT-LIST. |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
5755 Also remove any duplicates in IN-LIST. |
79545 | 5756 Signals must be in standard (base vector) form." |
5757 (let (out-list) | |
5758 (while in-list | |
5759 (if (not (or (assoc (car (car in-list)) not-list) | |
5760 (assoc (car (car in-list)) out-list))) | |
5761 (setq out-list (cons (car in-list) out-list))) | |
5762 (setq in-list (cdr in-list))) | |
5763 (nreverse out-list))) | |
5764 ;;(verilog-signals-not-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" ""))) | |
5765 | |
5766 (defun verilog-signals-in (in-list other-list) | |
5767 "Return list of signals in IN-LIST that are also in OTHER-LIST. | |
5768 Signals must be in standard (base vector) form." | |
5769 (let (out-list) | |
5770 (while in-list | |
5771 (if (assoc (car (car in-list)) other-list) | |
5772 (setq out-list (cons (car in-list) out-list))) | |
5773 (setq in-list (cdr in-list))) | |
5774 (nreverse out-list))) | |
5775 ;;(verilog-signals-in '(("A" "") ("B" "") ("DEL" "[2:3]")) '(("DEL" "") ("EXT" ""))) | |
5776 | |
5777 (defun verilog-signals-memory (in-list) | |
5778 "Return list of signals in IN-LIST that are memoried (multidimensional)." | |
5779 (let (out-list) | |
5780 (while in-list | |
5781 (if (nth 3 (car in-list)) | |
5782 (setq out-list (cons (car in-list) out-list))) | |
5783 (setq in-list (cdr in-list))) | |
5784 out-list)) | |
5785 ;;(verilog-signals-memory '(("A" nil nil "[3:0]")) '(("B" nil nil nil))) | |
5786 | |
5787 (defun verilog-signals-sort-compare (a b) | |
5788 "Compare signal A and B for sorting." | |
5789 (string< (car a) (car b))) | |
5790 | |
5791 (defun verilog-signals-not-params (in-list) | |
5792 "Return list of signals in IN-LIST that aren't parameters or numeric constants." | |
5793 (let (out-list) | |
5794 (while in-list | |
5795 (unless (boundp (intern (concat "vh-" (car (car in-list))))) | |
5796 (setq out-list (cons (car in-list) out-list))) | |
5797 (setq in-list (cdr in-list))) | |
5798 (nreverse out-list))) | |
5799 | |
5800 (defun verilog-signals-combine-bus (in-list) | |
5801 "Return a list of signals in IN-LIST, with busses combined. | |
5802 Duplicate signals are also removed. For example A[2] and A[1] become A[2:1]." | |
5803 (let (combo buswarn | |
5804 out-list | |
5805 sig highbit lowbit ; Temp information about current signal | |
5806 sv-name sv-highbit sv-lowbit ; Details about signal we are forming | |
5807 sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring | |
5808 bus) | |
5809 ;; Shove signals so duplicated signals will be adjacent | |
5810 (setq in-list (sort in-list `verilog-signals-sort-compare)) | |
5811 (while in-list | |
5812 (setq sig (car in-list)) | |
5813 ;; No current signal; form from existing details | |
5814 (unless sv-name | |
5815 (setq sv-name (verilog-sig-name sig) | |
5816 sv-highbit nil | |
5817 sv-busstring nil | |
5818 sv-comment (verilog-sig-comment sig) | |
5819 sv-memory (verilog-sig-memory sig) | |
5820 sv-enum (verilog-sig-enum sig) | |
5821 sv-signed (verilog-sig-signed sig) | |
5822 sv-type (verilog-sig-type sig) | |
5823 sv-multidim (verilog-sig-multidim sig) | |
5824 combo "" | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5825 buswarn "")) |
79545 | 5826 ;; Extract bus details |
5827 (setq bus (verilog-sig-bits sig)) | |
5828 (cond ((and bus | |
5829 (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
|
5830 (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
|
5831 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
|
5832 (match-string 2 bus)))) |
79545 | 5833 (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
|
5834 (setq highbit (string-to-number (match-string 1 bus)) |
79545 | 5835 lowbit highbit)))) |
5836 ;; Combine bits in bus | |
5837 (if sv-highbit | |
5838 (setq sv-highbit (max highbit sv-highbit) | |
5839 sv-lowbit (min lowbit sv-lowbit)) | |
5840 (setq sv-highbit highbit | |
5841 sv-lowbit lowbit))) | |
5842 (bus | |
5843 ;; String, probably something like `preproc:0 | |
5844 (setq sv-busstring bus))) | |
5845 ;; Peek ahead to next signal | |
5846 (setq in-list (cdr in-list)) | |
5847 (setq sig (car in-list)) | |
5848 (cond ((and sig (equal sv-name (verilog-sig-name sig))) | |
5849 ;; 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
|
5850 (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
|
5851 (not (equal sv-busstring (verilog-sig-bits sig)))) |
79545 | 5852 (when nil ;; Debugging |
5853 (message (concat "Warning, can't merge into single bus " | |
5854 sv-name bus | |
5855 ", the AUTOs may be wrong"))) | |
5856 (setq buswarn ", Couldn't Merge")) | |
5857 (if (verilog-sig-comment sig) (setq combo ", ...")) | |
5858 (setq sv-memory (or sv-memory (verilog-sig-memory sig)) | |
5859 sv-enum (or sv-enum (verilog-sig-enum sig)) | |
5860 sv-signed (or sv-signed (verilog-sig-signed sig)) | |
5861 sv-type (or sv-type (verilog-sig-type sig)) | |
5862 sv-multidim (or sv-multidim (verilog-sig-multidim sig)))) | |
5863 ;; Doesn't match next signal, add to queue, zero in prep for next | |
5864 ;; Note sig may also be nil for the last signal in the list | |
5865 (t | |
5866 (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
|
5867 (cons |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5868 (list sv-name |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5869 (or sv-busstring |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5870 (if sv-highbit |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
5871 (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
|
5872 (int-to-string sv-lowbit) "]"))) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5873 (concat sv-comment combo buswarn) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5874 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
|
5875 out-list) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5876 sv-name nil)))) |
79545 | 5877 ;; |
5878 out-list)) | |
5879 | |
5880 (defun verilog-sig-tieoff (sig &optional no-width) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
5881 "Return tieoff expression for given SIG, with appropriate width. |
79545 | 5882 Ignore width if optional NO-WIDTH is set." |
5883 (let* ((width (if no-width nil (verilog-sig-width sig)))) | |
5884 (concat | |
5885 (if (and verilog-active-low-regexp | |
5886 (string-match verilog-active-low-regexp (verilog-sig-name sig))) | |
5887 "~" "") | |
5888 (cond ((not width) | |
5889 "0") | |
5890 ((string-match "^[0-9]+$" width) | |
5891 (concat width (if (verilog-sig-signed sig) "'sh0" "'h0"))) | |
5892 (t | |
5893 (concat "{" width "{1'b0}}")))))) | |
5894 | |
5895 ;; | |
5896 ;; Port/Wire/Etc Reading | |
5897 ;; | |
5898 | |
5899 (defun verilog-read-inst-backward-name () | |
5900 "Internal. Move point back to beginning of inst-name." | |
5901 (verilog-backward-open-paren) | |
5902 (let (done) | |
5903 (while (not done) | |
5904 (verilog-re-search-backward-quick "\\()\\|\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil) ; ] isn't word boundary | |
5905 (cond ((looking-at ")") | |
5906 (verilog-backward-open-paren)) | |
5907 (t (setq done t))))) | |
5908 (while (looking-at "\\]") | |
5909 (verilog-backward-open-bracket) | |
5910 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|\\]\\)" nil nil)) | |
5911 (skip-chars-backward "a-zA-Z0-9`_$")) | |
5912 | |
5913 (defun verilog-read-inst-module () | |
5914 "Return module_name when point is inside instantiation." | |
5915 (save-excursion | |
5916 (verilog-read-inst-backward-name) | |
5917 ;; Skip over instantiation name | |
5918 (verilog-re-search-backward-quick "\\(\\b[a-zA-Z0-9`_\$]\\|)\\)" nil nil) ; ) isn't word boundary | |
5919 ;; Check for parameterized instantiations | |
5920 (when (looking-at ")") | |
5921 (verilog-backward-open-paren) | |
5922 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil)) | |
5923 (skip-chars-backward "a-zA-Z0-9'_$") | |
5924 (looking-at "[a-zA-Z0-9`_\$]+") | |
5925 ;; Important: don't use match string, this must work with emacs 19 font-lock on | |
5926 (buffer-substring-no-properties (match-beginning 0) (match-end 0)))) | |
5927 | |
5928 (defun verilog-read-inst-name () | |
5929 "Return instance_name when point is inside instantiation." | |
5930 (save-excursion | |
5931 (verilog-read-inst-backward-name) | |
5932 (looking-at "[a-zA-Z0-9`_\$]+") | |
5933 ;; Important: don't use match string, this must work with emacs 19 font-lock on | |
5934 (buffer-substring-no-properties (match-beginning 0) (match-end 0)))) | |
5935 | |
5936 (defun verilog-read-module-name () | |
5937 "Return module name when after its ( or ;." | |
5938 (save-excursion | |
5939 (re-search-backward "[(;]") | |
5940 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil) | |
5941 (skip-chars-backward "a-zA-Z0-9`_$") | |
5942 (looking-at "[a-zA-Z0-9`_\$]+") | |
5943 ;; Important: don't use match string, this must work with emacs 19 font-lock on | |
5944 (buffer-substring-no-properties (match-beginning 0) (match-end 0)))) | |
5945 | |
5946 (defun verilog-read-auto-params (num-param &optional max-param) | |
5947 "Return parameter list inside auto. | |
5948 Optional NUM-PARAM and MAX-PARAM check for a specific number of parameters." | |
5949 (let ((olist)) | |
5950 (save-excursion | |
5951 ;; /*AUTOPUNT("parameter", "parameter")*/ | |
5952 (search-backward "(") | |
5953 (while (looking-at "(?\\s *\"\\([^\"]*\\)\"\\s *,?") | |
5954 (setq olist (cons (match-string 1) olist)) | |
5955 (goto-char (match-end 0)))) | |
5956 (or (eq nil num-param) | |
5957 (<= num-param (length olist)) | |
5958 (error "%s: Expected %d parameters" (verilog-point-text) num-param)) | |
5959 (if (eq max-param nil) (setq max-param num-param)) | |
5960 (or (eq nil max-param) | |
5961 (>= max-param (length olist)) | |
5962 (error "%s: Expected <= %d parameters" (verilog-point-text) max-param)) | |
5963 (nreverse olist))) | |
5964 | |
5965 (defun verilog-read-decls () | |
5966 "Compute signal declaration information for the current module at point. | |
5967 Return a array of [outputs inouts inputs wire reg assign const]." | |
5968 (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max))) | |
5969 (functask 0) (paren 0) (sig-paren 0) | |
5970 sigs-in sigs-out sigs-inout sigs-wire sigs-reg sigs-assign sigs-const sigs-gparam | |
5971 vec expect-signal keywd newsig rvalue enum io signed typedefed multidim) | |
5972 (save-excursion | |
5973 (verilog-beg-of-defun) | |
5974 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point)) | |
5975 (while (< (point) end-mod-point) | |
5976 ;;(if dbg (setq dbg (cons (format "Pt %s Vec %s Kwd'%s'\n" (point) vec keywd) dbg))) | |
5977 (cond | |
5978 ((looking-at "//") | |
5979 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") | |
5980 (setq enum (match-string 1))) | |
5981 (search-forward "\n")) | |
5982 ((looking-at "/\\*") | |
5983 (forward-char 2) | |
5984 (if (looking-at "[^*]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") | |
5985 (setq enum (match-string 1))) | |
5986 (or (search-forward "*/") | |
5987 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point)))) | |
5988 ((looking-at "(\\*") | |
5989 (forward-char 2) | |
5990 (or (looking-at "\\s-*)") ; It's a "always @ (*)" | |
5991 (search-forward "*)") | |
5992 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point)))) | |
5993 ((eq ?\" (following-char)) | |
5994 (or (re-search-forward "[^\\]\"" nil t) ;; don't forward-char first, since we look for a non backslash first | |
5995 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point)))) | |
5996 ((eq ?\; (following-char)) | |
5997 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil) | |
5998 (forward-char 1)) | |
5999 ((eq ?= (following-char)) | |
6000 (setq rvalue t newsig nil) | |
6001 (forward-char 1)) | |
6002 ((and (or rvalue sig-paren) | |
6003 (cond ((and (eq ?, (following-char)) | |
6004 (eq paren sig-paren)) | |
6005 (setq rvalue nil) | |
6006 (forward-char 1) | |
6007 t) | |
6008 ;; ,'s can occur inside {} & funcs | |
6009 ((looking-at "[{(]") | |
6010 (setq paren (1+ paren)) | |
6011 (forward-char 1) | |
6012 t) | |
6013 ((looking-at "[})]") | |
6014 (setq paren (1- paren)) | |
6015 (forward-char 1) | |
6016 (when (< paren sig-paren) | |
6017 (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
|
6018 t)))) |
79545 | 6019 ((looking-at "\\s-*\\(\\[[^]]+\\]\\)") |
6020 (goto-char (match-end 0)) | |
6021 (cond (newsig ; Memory, not just width. Patch last signal added's memory (nth 3) | |
6022 (setcar (cdr (cdr (cdr newsig))) (match-string 1))) | |
6023 (vec ;; Multidimensional | |
6024 (setq multidim (cons vec multidim)) | |
6025 (setq vec (verilog-string-replace-matches | |
6026 "\\s-+" "" nil nil (match-string 1)))) | |
6027 (t ;; Bit width | |
6028 (setq vec (verilog-string-replace-matches | |
6029 "\\s-+" "" nil nil (match-string 1)))))) | |
6030 ;; Normal or escaped identifier -- note we remember the \ if escaped | |
6031 ((looking-at "\\s-*\\([a-zA-Z0-9`_$]+\\|\\\\[^ \t\n\f]+\\)") | |
6032 (goto-char (match-end 0)) | |
6033 (setq keywd (match-string 1)) | |
6034 (when (string-match "^\\\\" keywd) | |
6035 (setq keywd (concat keywd " "))) ;; Escaped ID needs space at end | |
6036 (cond ((equal keywd "input") | |
6037 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren | |
6038 expect-signal 'sigs-in io t)) | |
6039 ((equal keywd "output") | |
6040 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren | |
6041 expect-signal 'sigs-out io t)) | |
6042 ((equal keywd "inout") | |
6043 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren | |
6044 expect-signal 'sigs-inout io t)) | |
6045 ((or (equal keywd "wire") | |
6046 (equal keywd "tri") | |
6047 (equal keywd "tri0") | |
6048 (equal keywd "tri1")) | |
6049 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren | |
6050 expect-signal 'sigs-wire))) | |
6051 ((or (equal keywd "reg") | |
6052 (equal keywd "trireg")) | |
6053 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren | |
6054 expect-signal 'sigs-reg))) | |
6055 ((equal keywd "assign") | |
6056 (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren | |
6057 expect-signal 'sigs-assign)) | |
6058 ((or (equal keywd "supply0") | |
6059 (equal keywd "supply1") | |
6060 (equal keywd "supply") | |
6061 (equal keywd "localparam")) | |
6062 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren | |
6063 expect-signal 'sigs-const))) | |
6064 ((or (equal keywd "parameter")) | |
6065 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren | |
6066 expect-signal 'sigs-gparam))) | |
6067 ((equal keywd "signed") | |
6068 (setq signed "signed")) | |
6069 ((or (equal keywd "function") | |
6070 (equal keywd "task")) | |
6071 (setq functask (1+ functask))) | |
6072 ((or (equal keywd "endfunction") | |
6073 (equal keywd "endtask")) | |
6074 (setq functask (1- functask))) | |
6075 ((or (equal keywd "`ifdef") | |
6076 (equal keywd "`ifndef")) | |
6077 (setq rvalue t)) | |
6078 ((verilog-typedef-name-p keywd) | |
6079 (setq typedefed keywd)) | |
6080 ((and expect-signal | |
6081 (eq functask 0) | |
6082 (not rvalue) | |
6083 (eq paren sig-paren) | |
6084 (not (member keywd verilog-keywords))) | |
6085 ;; Add new signal to expect-signal's variable | |
6086 (setq newsig (list keywd vec nil nil enum signed typedefed multidim)) | |
6087 (set expect-signal (cons newsig | |
6088 (symbol-value expect-signal)))))) | |
6089 (t | |
6090 (forward-char 1))) | |
6091 (skip-syntax-forward " ")) | |
6092 ;; Return arguments | |
6093 (vector (nreverse sigs-out) | |
6094 (nreverse sigs-inout) | |
6095 (nreverse sigs-in) | |
6096 (nreverse sigs-wire) | |
6097 (nreverse sigs-reg) | |
6098 (nreverse sigs-assign) | |
6099 (nreverse sigs-const) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6100 (nreverse sigs-gparam))))) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6101 |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6102 (eval-when-compile |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6103 ;; Prevent compile warnings; these are let's, not globals |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6104 ;; Do not remove the eval-when-compile |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6105 ;; - 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
|
6106 (defvar sigs-in) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6107 (defvar sigs-inout) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6108 (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
|
6109 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6110 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6111 (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
|
6112 (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
|
6113 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6114 (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
|
6115 (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
|
6116 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6117 |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6118 ;; 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
|
6119 ;; 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
|
6120 ;; 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
|
6121 (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
|
6122 (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
|
6123 (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
|
6124 (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
|
6125 (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
|
6126 (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
|
6127 (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
|
6128 (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
|
6129 (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
|
6130 (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
|
6131 (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
|
6132 (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
|
6133 (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
|
6134 (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
|
6135 (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
|
6136 (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
|
6137 (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
|
6138 (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
|
6139 (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
|
6140 (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
|
6141 (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
|
6142 (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
|
6143 |
79545 | 6144 |
6145 (defun verilog-read-sub-decls-sig (submodi comment port sig vec multidim) | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
6146 "For `verilog-read-sub-decls-line', add a signal." |
79545 | 6147 (let (portdata) |
6148 (when sig | |
6149 (setq port (verilog-symbol-detick-denumber port)) | |
6150 (setq sig (verilog-symbol-detick-denumber sig)) | |
6151 (if sig (setq sig (verilog-string-replace-matches "^[---+~!|&]+" "" nil nil sig))) | |
6152 (if vec (setq vec (verilog-symbol-detick-denumber vec))) | |
6153 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim))) | |
6154 (unless (or (not sig) | |
6155 (equal sig "")) ;; Ignore .foo(1'b1) assignments | |
6156 (cond ((setq portdata (assoc port (verilog-modi-get-inouts submodi))) | |
6157 (setq sigs-inout (cons (list sig vec (concat "To/From " comment) nil nil | |
6158 (verilog-sig-signed portdata) | |
6159 (verilog-sig-type portdata) | |
6160 multidim) | |
6161 sigs-inout))) | |
6162 ((setq portdata (assoc port (verilog-modi-get-outputs submodi))) | |
6163 (setq sigs-out (cons (list sig vec (concat "From " comment) nil nil | |
6164 (verilog-sig-signed portdata) | |
6165 (verilog-sig-type portdata) | |
6166 multidim) | |
6167 sigs-out))) | |
6168 ((setq portdata (assoc port (verilog-modi-get-inputs submodi))) | |
6169 (setq sigs-in (cons (list sig vec (concat "To " comment) nil nil | |
6170 (verilog-sig-signed portdata) | |
6171 (verilog-sig-type portdata) | |
6172 multidim) | |
6173 sigs-in))) | |
6174 ;; (t -- warning pin isn't defined.) ; Leave for lint tool | |
6175 ))))) | |
6176 | |
6177 (defun verilog-read-sub-decls-line (submodi comment) | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
6178 "For `verilog-read-sub-decls', read lines of port defs until none match anymore. |
79545 | 6179 Return the list of signals found, using submodi to look up each port." |
6180 (let (done port sig vec multidim) | |
6181 (save-excursion | |
6182 (forward-line 1) | |
6183 (while (not done) | |
6184 ;; Get port name | |
6185 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*") | |
6186 (setq port (match-string 1)) | |
6187 (goto-char (match-end 0))) | |
6188 ((looking-at "\\s-*\\.\\s-*\\(\\\\[^ \t\n\f]*\\)\\s-*(\\s-*") | |
6189 (setq port (concat (match-string 1) " ")) ;; escaped id's need trailing space | |
6190 (goto-char (match-end 0))) | |
6191 ((looking-at "\\s-*\\.[^(]*(") | |
6192 (setq port nil) ;; skip this line | |
6193 (goto-char (match-end 0))) | |
6194 (t | |
6195 (setq port nil done t))) ;; Unknown, ignore rest of line | |
6196 ;; Get signal name | |
6197 (when port | |
6198 (setq multidim nil) | |
6199 (cond ((looking-at "\\(\\\\[^ \t\n\f]*\\)\\s-*)") | |
6200 (setq sig (concat (match-string 1) " ") ;; escaped id's need trailing space | |
6201 vec nil)) | |
6202 ; We intentionally ignore (non-escaped) signals with .s in them | |
6203 ; this prevents AUTOWIRE etc from noticing hierarchical sigs. | |
6204 ((looking-at "\\([^[({).]*\\)\\s-*)") | |
6205 (setq sig (verilog-string-remove-spaces (match-string 1)) | |
6206 vec nil)) | |
6207 ((looking-at "\\([^[({).]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)") | |
6208 (setq sig (verilog-string-remove-spaces (match-string 1)) | |
6209 vec (match-string 2))) | |
6210 ((looking-at "\\([^[({).]*\\)\\s-*/\\*\\(\\[[^*]+\\]\\)\\*/\\s-*)") | |
6211 (setq sig (verilog-string-remove-spaces (match-string 1)) | |
6212 vec nil) | |
6213 (let ((parse (match-string 2))) | |
6214 (while (string-match "^\\(\\[[^]]+\\]\\)\\(.*\\)$" parse) | |
6215 (when vec (setq multidim (cons vec multidim))) | |
6216 (setq vec (match-string 1 parse)) | |
6217 (setq parse (match-string 2 parse))))) | |
6218 ((looking-at "{\\(.*\\)}.*\\s-*)") | |
6219 (let ((mlst (split-string (match-string 1) ",")) | |
6220 mstr) | |
6221 (while (setq mstr (pop mlst)) | |
6222 ;;(unless noninteractive (message "sig: %s " mstr)) | |
6223 (cond | |
6224 ((string-match "\\(['`a-zA-Z0-9_$]+\\)\\s-*$" mstr) | |
6225 (setq sig (verilog-string-remove-spaces (match-string 1 mstr)) | |
6226 vec nil) | |
6227 ;;(unless noninteractive (message "concat sig1: %s %s" mstr (match-string 1 mstr))) | |
6228 ) | |
6229 ((string-match "\\([^[({).]+\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*" mstr) | |
6230 (setq sig (verilog-string-remove-spaces (match-string 1 mstr)) | |
6231 vec (match-string 2 mstr)) | |
6232 ;;(unless noninteractive (message "concat sig2: '%s' '%s' '%s'" mstr (match-string 1 mstr) (match-string 2 mstr))) | |
6233 ) | |
6234 (t | |
6235 (setq sig nil))) | |
6236 ;; Process signals | |
6237 (verilog-read-sub-decls-sig submodi comment port sig vec multidim)))) | |
6238 (t | |
6239 (setq sig nil))) | |
6240 ;; Process signals | |
6241 (verilog-read-sub-decls-sig submodi comment port sig vec multidim)) | |
6242 ;; | |
6243 (forward-line 1))))) | |
6244 | |
6245 (defun verilog-read-sub-decls () | |
6246 "Internally parse signals going to modules under this module. | |
6247 Return a array of [ outputs inouts inputs ] signals for modules that are | |
6248 instantiated in this module. For example if declare A A (.B(SIG)) and SIG | |
6249 is a output, then SIG will be included in the list. | |
6250 | |
6251 This only works on instantiations created with /*AUTOINST*/ converted by | |
6252 \\[verilog-auto-inst]. Otherwise, it would have to read in the whole | |
6253 component library to determine connectivity of the design. | |
6254 | |
6255 One work around for this problem is to manually create // Inputs and // | |
6256 Outputs comments above subcell signals, for example: | |
6257 | |
6258 module1 instance1x ( | |
6259 // Outputs | |
6260 .out (out), | |
6261 // Inputs | |
6262 .in (in));" | |
6263 (save-excursion | |
6264 (let ((end-mod-point (verilog-get-end-of-defun t)) | |
6265 st-point end-inst-point | |
6266 ;; below 3 modified by verilog-read-sub-decls-line | |
6267 sigs-out sigs-inout sigs-in) | |
6268 (verilog-beg-of-defun) | |
6269 (while (re-search-forward "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t) | |
6270 (save-excursion | |
6271 (goto-char (match-beginning 0)) | |
6272 (unless (verilog-inside-comment-p) | |
6273 ;; Attempt to snarf a comment | |
6274 (let* ((submod (verilog-read-inst-module)) | |
6275 (inst (verilog-read-inst-name)) | |
6276 (comment (concat inst " of " submod ".v")) submodi) | |
6277 (when (setq submodi (verilog-modi-lookup submod t)) | |
6278 ;; This could have used a list created by verilog-auto-inst | |
6279 ;; However I want it to be runnable even on user's manually added signals | |
6280 (verilog-backward-open-paren) | |
6281 (setq end-inst-point (save-excursion (forward-sexp 1) (point)) | |
6282 st-point (point)) | |
6283 (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t) | |
6284 (verilog-read-sub-decls-line submodi comment)) ;; Modifies sigs-out | |
6285 (goto-char st-point) | |
6286 (while (re-search-forward "\\s *// Inouts" end-inst-point t) | |
6287 (verilog-read-sub-decls-line submodi comment)) ;; Modifies sigs-inout | |
6288 (goto-char st-point) | |
6289 (while (re-search-forward "\\s *// Inputs" end-inst-point t) | |
6290 (verilog-read-sub-decls-line submodi comment)) ;; Modifies sigs-in | |
6291 ))))) | |
6292 ;; Combine duplicate bits | |
6293 ;;(setq rr (vector sigs-out sigs-inout sigs-in)) | |
6294 (vector (verilog-signals-combine-bus (nreverse sigs-out)) | |
6295 (verilog-signals-combine-bus (nreverse sigs-inout)) | |
6296 (verilog-signals-combine-bus (nreverse sigs-in)))))) | |
6297 | |
6298 (defun verilog-read-inst-pins () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
6299 "Return an array of [ pins ] for the current instantiation at point. |
79545 | 6300 For example if declare A A (.B(SIG)) then B will be included in the list." |
6301 (save-excursion | |
6302 (let ((end-mod-point (point)) ;; presume at /*AUTOINST*/ point | |
6303 pins pin) | |
6304 (verilog-backward-open-paren) | |
6305 (while (re-search-forward "\\.\\([^(,) \t\n\f]*\\)\\s-*" end-mod-point t) | |
6306 (setq pin (match-string 1)) | |
6307 (unless (verilog-inside-comment-p) | |
6308 (setq pins (cons (list pin) pins)) | |
6309 (when (looking-at "(") | |
6310 (forward-sexp 1)))) | |
6311 (vector pins)))) | |
6312 | |
6313 (defun verilog-read-arg-pins () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
6314 "Return an array of [ pins ] for the current argument declaration at point." |
79545 | 6315 (save-excursion |
6316 (let ((end-mod-point (point)) ;; presume at /*AUTOARG*/ point | |
6317 pins pin) | |
6318 (verilog-backward-open-paren) | |
6319 (while (re-search-forward "\\([a-zA-Z0-9$_.%`]+\\)" end-mod-point t) | |
6320 (setq pin (match-string 1)) | |
6321 (unless (verilog-inside-comment-p) | |
6322 (setq pins (cons (list pin) pins)))) | |
6323 (vector pins)))) | |
6324 | |
6325 (defun verilog-read-auto-constants (beg end-mod-point) | |
6326 "Return a list of AUTO_CONSTANTs used in the region from BEG to END-MOD-POINT." | |
6327 ;; Insert new | |
6328 (save-excursion | |
6329 (let (sig-list tpl-end-pt) | |
6330 (goto-char beg) | |
6331 (while (re-search-forward "\\<AUTO_CONSTANT" end-mod-point t) | |
6332 (if (not (looking-at "\\s *(")) | |
6333 (error "%s: Missing () after AUTO_CONSTANT" (verilog-point-text))) | |
6334 (search-forward "(" end-mod-point) | |
6335 (setq tpl-end-pt (save-excursion | |
6336 (backward-char 1) | |
6337 (forward-sexp 1) ;; Moves to paren that closes argdecl's | |
6338 (backward-char 1) | |
6339 (point))) | |
6340 (while (re-search-forward "\\s-*\\([\"a-zA-Z0-9$_.%`]+\\)\\s-*,*" tpl-end-pt t) | |
6341 (setq sig-list (cons (list (match-string 1) nil nil) sig-list)))) | |
6342 sig-list))) | |
6343 | |
6344 (defun verilog-read-auto-lisp (start end) | |
6345 "Look for and evaluate a AUTO_LISP between START and END." | |
6346 (save-excursion | |
6347 (goto-char start) | |
6348 (while (re-search-forward "\\<AUTO_LISP(" end t) | |
6349 (backward-char) | |
6350 (let* ((beg-pt (prog1 (point) | |
6351 (forward-sexp 1))) ;; Closing paren | |
6352 (end-pt (point))) | |
6353 (eval-region beg-pt end-pt nil))))) | |
6354 | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6355 (eval-when-compile |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6356 ;; Prevent compile warnings; these are let's, not globals |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6357 ;; Do not remove the eval-when-compile |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6358 ;; - 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
|
6359 (defvar sigs-in) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6360 (defvar sigs-out) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6361 (defvar got-sig) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6362 (defvar got-rvalue) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6363 (defvar uses-delayed) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6364 (defvar vector-skip-list)) |
79545 | 6365 |
6366 (defun verilog-read-always-signals-recurse | |
6367 (exit-keywd rvalue ignore-next) | |
6368 "Recursive routine for parentheses/bracket matching. | |
6369 EXIT-KEYWD is expression to stop at, nil if top level. | |
6370 RVALUE is true if at right hand side of equal. | |
6371 IGNORE-NEXT is true to ignore next token, fake from inside case statement." | |
6372 (let* ((semi-rvalue (equal "endcase" exit-keywd)) ;; true if after a ; we are looking for rvalue | |
6373 keywd last-keywd sig-tolk sig-last-tolk gotend got-sig got-rvalue end-else-check) | |
6374 ;;(if dbg (setq dbg (concat dbg (format "Recursion %S %S %S\n" exit-keywd rvalue ignore-next)))) | |
6375 (while (not (or (eobp) gotend)) | |
6376 (cond | |
6377 ((looking-at "//") | |
6378 (search-forward "\n")) | |
6379 ((looking-at "/\\*") | |
6380 (or (search-forward "*/") | |
6381 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point)))) | |
6382 ((looking-at "(\\*") | |
6383 (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)" | |
6384 (search-forward "*)") | |
6385 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point)))) | |
6386 (t (setq keywd (buffer-substring-no-properties | |
6387 (point) | |
6388 (save-excursion (when (eq 0 (skip-chars-forward "a-zA-Z0-9$_.%`")) | |
6389 (forward-char 1)) | |
6390 (point))) | |
6391 sig-last-tolk sig-tolk | |
6392 sig-tolk nil) | |
6393 ;;(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)))) | |
6394 (cond | |
6395 ((equal keywd "\"") | |
6396 (or (re-search-forward "[^\\]\"" nil t) | |
6397 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point)))) | |
6398 ;; else at top level loop, keep parsing | |
6399 ((and end-else-check (equal keywd "else")) | |
6400 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else %s\n" keywd)))) | |
6401 ;; no forward movement, want to see else in lower loop | |
6402 (setq end-else-check nil)) | |
6403 ;; End at top level loop | |
6404 ((and end-else-check (looking-at "[^ \t\n\f]")) | |
6405 ;;(if dbg (setq dbg (concat dbg (format "\tif-check-else-other %s\n" keywd)))) | |
6406 (setq gotend t)) | |
6407 ;; Final statement? | |
6408 ((and exit-keywd (equal keywd exit-keywd)) | |
6409 (setq gotend t) | |
6410 (forward-char (length keywd))) | |
6411 ;; Standard tokens... | |
6412 ((equal keywd ";") | |
6413 (setq ignore-next nil rvalue semi-rvalue) | |
6414 ;; Final statement at top level loop? | |
6415 (when (not exit-keywd) | |
6416 ;;(if dbg (setq dbg (concat dbg (format "\ttop-end-check %s\n" keywd)))) | |
6417 (setq end-else-check t)) | |
6418 (forward-char 1)) | |
6419 ((equal keywd "'") | |
6420 (if (looking-at "'s?[hdxbo][0-9a-fA-F_xz? \t]*") | |
6421 (goto-char (match-end 0)) | |
6422 (forward-char 1))) | |
6423 ((equal keywd ":") ;; Case statement, begin/end label, x?y:z | |
6424 (cond ((equal "endcase" exit-keywd) ;; case x: y=z; statement next | |
6425 (setq ignore-next nil rvalue nil)) | |
6426 ((equal "?" exit-keywd) ;; x?y:z rvalue | |
6427 ) ;; NOP | |
6428 (got-sig ;; label: statement | |
6429 (setq ignore-next nil rvalue semi-rvalue got-sig nil)) | |
6430 ((not rvalue) ;; begin label | |
6431 (setq ignore-next t rvalue nil))) | |
6432 (forward-char 1)) | |
6433 ((equal keywd "=") | |
6434 (if (eq (char-before) ?< ) | |
6435 (setq uses-delayed 1)) | |
6436 (setq ignore-next nil rvalue t) | |
6437 (forward-char 1)) | |
6438 ((equal keywd "?") | |
6439 (forward-char 1) | |
6440 (verilog-read-always-signals-recurse ":" rvalue nil)) | |
6441 ((equal keywd "[") | |
6442 (forward-char 1) | |
6443 (verilog-read-always-signals-recurse "]" t nil)) | |
6444 ((equal keywd "(") | |
6445 (forward-char 1) | |
6446 (cond (sig-last-tolk ;; Function call; zap last signal | |
6447 (setq got-sig nil))) | |
6448 (cond ((equal last-keywd "for") | |
6449 (verilog-read-always-signals-recurse ";" nil nil) | |
6450 (verilog-read-always-signals-recurse ";" t nil) | |
6451 (verilog-read-always-signals-recurse ")" nil nil)) | |
6452 (t (verilog-read-always-signals-recurse ")" t nil)))) | |
6453 ((equal keywd "begin") | |
6454 (skip-syntax-forward "w_") | |
6455 (verilog-read-always-signals-recurse "end" nil nil) | |
6456 ;;(if dbg (setq dbg (concat dbg (format "\tgot-end %s\n" exit-keywd)))) | |
6457 (setq ignore-next nil rvalue semi-rvalue) | |
6458 (if (not exit-keywd) (setq end-else-check t))) | |
6459 ((or (equal keywd "case") | |
6460 (equal keywd "casex") | |
6461 (equal keywd "casez")) | |
6462 (skip-syntax-forward "w_") | |
6463 (verilog-read-always-signals-recurse "endcase" t nil) | |
6464 (setq ignore-next nil rvalue semi-rvalue) | |
6465 (if (not exit-keywd) (setq gotend t))) ;; top level begin/end | |
6466 ((string-match "^[$`a-zA-Z_]" keywd) ;; not exactly word constituent | |
6467 (cond ((or (equal keywd "`ifdef") | |
6468 (equal keywd "`ifndef")) | |
6469 (setq ignore-next t)) | |
6470 ((or ignore-next | |
6471 (member keywd verilog-keywords) | |
6472 (string-match "^\\$" keywd)) ;; PLI task | |
6473 (setq ignore-next nil)) | |
6474 (t | |
6475 (setq keywd (verilog-symbol-detick-denumber keywd)) | |
6476 (when got-sig | |
6477 (if got-rvalue (setq sigs-in (cons got-sig sigs-in)) | |
6478 (setq sigs-out (cons got-sig sigs-out))) | |
6479 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S rv=%S\n" got-sig got-rvalue)))) | |
6480 ) | |
6481 (setq got-rvalue rvalue | |
6482 got-sig (if (or (not keywd) | |
6483 (assoc keywd (if got-rvalue sigs-in sigs-out))) | |
6484 nil (list keywd nil nil)) | |
6485 sig-tolk t))) | |
6486 (skip-chars-forward "a-zA-Z0-9$_.%`")) | |
6487 (t | |
6488 (forward-char 1))) | |
6489 ;; End of non-comment token | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6490 (setq last-keywd keywd))) |
79545 | 6491 (skip-syntax-forward " ")) |
6492 ;; Append the final pending signal | |
6493 (when got-sig | |
6494 (if got-rvalue (setq sigs-in (cons got-sig sigs-in)) | |
6495 (setq sigs-out (cons got-sig sigs-out))) | |
6496 ;;(if dbg (setq dbg (concat dbg (format "\t\tgot-sig=%S rv=%S\n" got-sig got-rvalue)))) | |
6497 (setq got-sig nil)) | |
6498 ;;(if dbg (setq dbg (concat dbg (format "ENDRecursion %s\n" exit-keywd)))) | |
6499 )) | |
6500 | |
6501 (defun verilog-read-always-signals () | |
6502 "Parse always block at point and return list of (outputs inout inputs)." | |
6503 ;; Insert new | |
6504 (save-excursion | |
6505 (let* (;;(dbg "") | |
6506 sigs-in sigs-out | |
6507 uses-delayed) ;; Found signal/rvalue; push if not function | |
6508 (search-forward ")") | |
6509 (verilog-read-always-signals-recurse nil nil nil) | |
6510 ;;(if dbg (save-excursion (set-buffer (get-buffer-create "*vl-dbg*")) (delete-region (point-min) (point-max)) (insert dbg) (setq dbg ""))) | |
6511 ;; Return what was found | |
6512 (list sigs-out nil sigs-in uses-delayed)))) | |
6513 | |
6514 (defun verilog-read-instants () | |
6515 "Parse module at point and return list of ( ( file instance ) ... )." | |
6516 (verilog-beg-of-defun) | |
6517 (let* ((end-mod-point (verilog-get-end-of-defun t)) | |
6518 (state nil) | |
6519 (instants-list nil)) | |
6520 (save-excursion | |
6521 (while (< (point) end-mod-point) | |
6522 ;; Stay at level 0, no comments | |
6523 (while (progn | |
6524 (setq state (parse-partial-sexp (point) end-mod-point 0 t nil)) | |
6525 (or (> (car state) 0) ; in parens | |
6526 (nth 5 state) ; comment | |
6527 )) | |
6528 (forward-line 1)) | |
6529 (beginning-of-line) | |
6530 (if (looking-at "^\\s-*\\([a-zA-Z0-9`_$]+\\)\\s-+\\([a-zA-Z0-9`_$]+\\)\\s-*(") | |
6531 ;;(if (looking-at "^\\(.+\\)$") | |
6532 (let ((module (match-string 1)) | |
6533 (instant (match-string 2))) | |
6534 (if (not (member module verilog-keywords)) | |
6535 (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
|
6536 (forward-line 1))) |
79545 | 6537 instants-list)) |
6538 | |
6539 | |
6540 (defun verilog-read-auto-template (module) | |
6541 "Look for a auto_template for the instantiation of the given MODULE. | |
6542 If found returns the signal name connections. Return REGEXP and | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
6543 list of ( (signal_name connection_name)... )." |
79545 | 6544 (save-excursion |
6545 ;; Find beginning | |
6546 (let ((tpl-regexp "\\([0-9]+\\)") | |
6547 (lineno 0) | |
6548 (templateno 0) | |
6549 tpl-sig-list tpl-wild-list tpl-end-pt rep) | |
6550 (cond ((or | |
6551 (re-search-backward (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t) | |
6552 (progn | |
6553 (goto-char (point-min)) | |
6554 (re-search-forward (concat "^\\s-*/?\\*?\\s-*" module "\\s-+AUTO_TEMPLATE") nil t))) | |
6555 (goto-char (match-end 0)) | |
6556 ;; Parse "REGEXP" | |
6557 ;; We reserve @"..." for future lisp expressions that evaluate once-per-AUTOINST | |
6558 (when (looking-at "\\s-*\"\\([^\"]*)\\)\"") | |
6559 (setq tpl-regexp (match-string 1)) | |
6560 (goto-char (match-end 0))) | |
6561 (search-forward "(") | |
6562 ;; Parse lines in the template | |
6563 (when verilog-auto-inst-template-numbers | |
6564 (save-excursion | |
6565 (goto-char (point-min)) | |
6566 (while (search-forward "AUTO_TEMPLATE" nil t) | |
6567 (setq templateno (1+ templateno))))) | |
6568 (setq tpl-end-pt (save-excursion | |
6569 (backward-char 1) | |
6570 (forward-sexp 1) ;; Moves to paren that closes argdecl's | |
6571 (backward-char 1) | |
6572 (point))) | |
6573 ;; | |
6574 (while (< (point) tpl-end-pt) | |
6575 (cond ((looking-at "\\s-*\\.\\([a-zA-Z0-9`_$]+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)") | |
6576 (setq tpl-sig-list (cons (list | |
6577 (match-string-no-properties 1) | |
6578 (match-string-no-properties 2) | |
6579 templateno lineno) | |
6580 tpl-sig-list)) | |
6581 (goto-char (match-end 0))) | |
6582 ;; Regexp form?? | |
6583 ((looking-at | |
6584 ;; Regexp bug in xemacs disallows ][ inside [], and wants + last | |
6585 "\\s-*\\.\\(\\([a-zA-Z0-9`_$+@^.*?|---]+\\|[][]\\|\\\\[()|]\\)+\\)\\s-*(\\(.*\\))\\s-*\\(,\\|)\\s-*;\\)") | |
6586 (setq rep (match-string-no-properties 3)) | |
6587 (goto-char (match-end 0)) | |
6588 (setq tpl-wild-list | |
6589 (cons (list | |
6590 (concat "^" | |
6591 (verilog-string-replace-matches "@" "\\\\([0-9]+\\\\)" nil nil | |
6592 (match-string 1)) | |
6593 "$") | |
6594 rep | |
6595 templateno lineno) | |
6596 tpl-wild-list))) | |
6597 ((looking-at "[ \t\f]+") | |
6598 (goto-char (match-end 0))) | |
6599 ((looking-at "\n") | |
6600 (setq lineno (1+ lineno)) | |
6601 (goto-char (match-end 0))) | |
6602 ((looking-at "//") | |
6603 (search-forward "\n")) | |
6604 ((looking-at "/\\*") | |
6605 (forward-char 2) | |
6606 (or (search-forward "*/") | |
6607 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point)))) | |
6608 (t | |
6609 (error "%s: AUTO_TEMPLATE parsing error: %s" | |
6610 (verilog-point-text) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6611 (progn (looking-at ".*$") (match-string 0)))))) |
79545 | 6612 ;; Return |
6613 (vector tpl-regexp | |
6614 (list tpl-sig-list tpl-wild-list))) | |
6615 ;; If no template found | |
6616 (t (vector tpl-regexp nil)))))) | |
6617 ;;(progn (find-file "auto-template.v") (verilog-read-auto-template "ptl_entry")) | |
6618 | |
6619 (defun verilog-set-define (defname defvalue &optional buffer enumname) | |
6620 "Set the definition DEFNAME to the DEFVALUE in the given BUFFER. | |
6621 Optionally associate it with the specified enumeration ENUMNAME." | |
6622 (save-excursion | |
6623 (set-buffer (or buffer (current-buffer))) | |
6624 (let ((mac (intern (concat "vh-" defname)))) | |
6625 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1) | |
6626 ;; Need to define to a constant if no value given | |
6627 (set (make-variable-buffer-local mac) | |
6628 (if (equal defvalue "") "1" defvalue))) | |
6629 (if enumname | |
6630 (let ((enumvar (intern (concat "venum-" enumname)))) | |
6631 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1) | |
6632 (make-variable-buffer-local enumvar) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6633 (add-to-list enumvar defname))))) |
79545 | 6634 |
6635 (defun verilog-read-defines (&optional filename recurse subcall) | |
6636 "Read `defines and parameters for the current file, or optional FILENAME. | |
6637 If the filename is provided, `verilog-library-flags' will be used to | |
6638 resolve it. If optional RECURSE is non-nil, recurse through `includes. | |
6639 | |
6640 Parameters must be simple assignments to constants, or have their own | |
6641 \"parameter\" label rather than a list of parameters. Thus: | |
6642 | |
6643 parameter X = 5, Y = 10; // Ok | |
6644 parameter X = {1'b1, 2'h2}; // Ok | |
6645 parameter X = {1'b1, 2'h2}, Y = 10; // Bad, make into 2 parameter lines | |
6646 | |
6647 Defines must be simple text substitutions, one on a line, starting | |
6648 at the beginning of the line. Any ifdefs or multiline comments around the | |
6649 define are ignored. | |
6650 | |
6651 Defines are stored inside Emacs variables using the name vh-{definename}. | |
6652 | |
6653 This function is useful for setting vh-* variables. The file variables | |
6654 feature can be used to set defines that `verilog-mode' can see; put at the | |
6655 *END* of your file something like: | |
6656 | |
6657 // Local Variables: | |
6658 // vh-macro:\"macro_definition\" | |
6659 // End: | |
6660 | |
6661 If macros are defined earlier in the same file and you want their values, | |
6662 you can read them automatically (provided `enable-local-eval' is on): | |
6663 | |
6664 // Local Variables: | |
6665 // eval:(verilog-read-defines) | |
6666 // eval:(verilog-read-defines \"group_standard_includes.v\") | |
6667 // End: | |
6668 | |
6669 Note these are only read when the file is first visited, you must use | |
6670 \\[find-alternate-file] RET to have these take effect after editing them! | |
6671 | |
6672 If you want to disable the \"Process `eval' or hook local variables\" | |
6673 warning message, you need to add to your .emacs file: | |
6674 | |
6675 (setq enable-local-eval t)" | |
6676 (let ((origbuf (current-buffer))) | |
6677 (save-excursion | |
6678 (unless subcall (verilog-getopt-flags)) | |
6679 (when filename | |
6680 (let ((fns (verilog-library-filenames filename (buffer-file-name)))) | |
6681 (if fns | |
6682 (set-buffer (find-file-noselect (car fns))) | |
6683 (error (concat (verilog-point-text) | |
6684 ": Can't find verilog-read-defines file: " filename))))) | |
6685 (when recurse | |
6686 (goto-char (point-min)) | |
6687 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t) | |
6688 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string-no-properties 1)))) | |
6689 (unless (verilog-inside-comment-p) | |
6690 (verilog-read-defines inc recurse t))))) | |
6691 ;; Read `defines | |
6692 ;; note we don't use verilog-re... it's faster this way, and that | |
6693 ;; function has problems when comments are at the end of the define | |
6694 (goto-char (point-min)) | |
6695 (while (re-search-forward "^\\s-*`define\\s-+\\([a-zA-Z0-9_$]+\\)\\s-+\\(.*\\)$" nil t) | |
6696 (let ((defname (match-string-no-properties 1)) | |
6697 (defvalue (match-string-no-properties 2))) | |
6698 (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue)) | |
6699 (verilog-set-define defname defvalue origbuf))) | |
6700 ;; Hack: Read parameters | |
6701 (goto-char (point-min)) | |
6702 (while (re-search-forward | |
6703 "^\\s-*\\(parameter\\|localparam\\)\\(\\(\\s-*\\[[^]]*\\]\\|\\)\\s-+\\([a-zA-Z0-9_$]+\\)\\s-*=\\s-*\\([^;,]*\\),?\\|\\)\\s-*" nil t) | |
6704 (let ((var (match-string-no-properties 4)) | |
6705 (val (match-string-no-properties 5)) | |
6706 enumname) | |
6707 ;; The primary way of getting defines is verilog-read-decls | |
6708 ;; However, that isn't called yet for included files, so we'll add another scheme | |
6709 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") | |
6710 (setq enumname (match-string-no-properties 1))) | |
6711 (if var | |
6712 (verilog-set-define var val origbuf enumname)) | |
6713 (forward-comment 999) | |
6714 (while (looking-at "\\s-*,?\\s-*\\([a-zA-Z0-9_$]+\\)\\s-*=\\s-*\\([^;,]*\\),?\\s-*") | |
6715 (verilog-set-define (match-string-no-properties 1) (match-string-no-properties 2) origbuf enumname) | |
6716 (goto-char (match-end 0)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6717 (forward-comment 999))))))) |
79545 | 6718 |
6719 (defun verilog-read-includes () | |
6720 "Read `includes for the current file. | |
6721 This will find all of the `includes which are at the beginning of lines, | |
6722 ignoring any ifdefs or multiline comments around them. | |
6723 `verilog-read-defines' is then performed on the current and each included | |
6724 file. | |
6725 | |
6726 It is often useful put at the *END* of your file something like: | |
6727 | |
6728 // Local Variables: | |
6729 // eval:(verilog-read-defines) | |
6730 // eval:(verilog-read-includes) | |
6731 // End: | |
6732 | |
6733 Note includes are only read when the file is first visited, you must use | |
6734 \\[find-alternate-file] RET to have these take effect after editing them! | |
6735 | |
6736 It is good to get in the habit of including all needed files in each .v | |
6737 file that needs it, rather than waiting for compile time. This will aid | |
6738 this process, Verilint, and readability. To prevent defining the same | |
6739 variable over and over when many modules are compiled together, put a test | |
6740 around the inside each include file: | |
6741 | |
6742 foo.v (a include): | |
6743 `ifdef _FOO_V // include if not already included | |
6744 `else | |
6745 `define _FOO_V | |
6746 ... contents of file | |
6747 `endif // _FOO_V" | |
6748 ;;slow: (verilog-read-defines nil t)) | |
6749 (save-excursion | |
6750 (verilog-getopt-flags) | |
6751 (goto-char (point-min)) | |
6752 (while (re-search-forward "^\\s-*`include\\s-+\\([^ \t\n\f]+\\)" nil t) | |
6753 (let ((inc (verilog-string-replace-matches "\"" "" nil nil (match-string 1)))) | |
6754 (verilog-read-defines inc nil t))))) | |
6755 | |
6756 (defun verilog-read-signals (&optional start end) | |
6757 "Return a simple list of all possible signals in the file. | |
6758 Bounded by optional region from START to END. Overly aggressive but fast. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
6759 Some macros and such are also found and included. For dinotrace.el." |
79545 | 6760 (let (sigs-all keywd) |
6761 (progn;save-excursion | |
6762 (goto-char (or start (point-min))) | |
6763 (setq end (or end (point-max))) | |
6764 (while (re-search-forward "[\"/a-zA-Z_.%`]" end t) | |
6765 (forward-char -1) | |
6766 (cond | |
6767 ((looking-at "//") | |
6768 (search-forward "\n")) | |
6769 ((looking-at "/\\*") | |
6770 (search-forward "*/")) | |
6771 ((looking-at "(\\*") | |
6772 (or (looking-at "(\\*\\s-*)") ; It's a "always @ (*)" | |
6773 (search-forward "*)"))) | |
6774 ((eq ?\" (following-char)) | |
6775 (re-search-forward "[^\\]\"")) ;; don't forward-char first, since we look for a non backslash first | |
6776 ((looking-at "\\s-*\\([a-zA-Z0-9$_.%`]+\\)") | |
6777 (goto-char (match-end 0)) | |
6778 (setq keywd (match-string-no-properties 1)) | |
6779 (or (member keywd verilog-keywords) | |
6780 (member keywd sigs-all) | |
6781 (setq sigs-all (cons keywd sigs-all)))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6782 (t (forward-char 1)))) |
79545 | 6783 ;; Return list |
6784 sigs-all))) | |
6785 | |
6786 ;; | |
6787 ;; Argument file parsing | |
6788 ;; | |
6789 | |
6790 (defun verilog-getopt (arglist) | |
6791 "Parse -f, -v etc arguments in ARGLIST list or string." | |
6792 (unless (listp arglist) (setq arglist (list arglist))) | |
6793 (let ((space-args '()) | |
6794 arg next-param) | |
6795 ;; Split on spaces, so users can pass whole command lines | |
6796 (while arglist | |
6797 (setq arg (car arglist) | |
6798 arglist (cdr arglist)) | |
6799 (while (string-match "^\\([^ \t\n\f]+\\)[ \t\n\f]*\\(.*$\\)" arg) | |
6800 (setq space-args (append space-args | |
6801 (list (match-string-no-properties 1 arg)))) | |
6802 (setq arg (match-string 2 arg)))) | |
6803 ;; Parse arguments | |
6804 (while space-args | |
6805 (setq arg (car space-args) | |
6806 space-args (cdr space-args)) | |
6807 (cond | |
6808 ;; Need another arg | |
6809 ((equal arg "-f") | |
6810 (setq next-param arg)) | |
6811 ((equal arg "-v") | |
6812 (setq next-param arg)) | |
6813 ((equal arg "-y") | |
6814 (setq next-param arg)) | |
6815 ;; +libext+(ext1)+(ext2)... | |
6816 ((string-match "^\\+libext\\+\\(.*\\)" arg) | |
6817 (setq arg (match-string 1 arg)) | |
6818 (while (string-match "\\([^+]+\\)\\+?\\(.*\\)" arg) | |
6819 (verilog-add-list-unique `verilog-library-extensions | |
6820 (match-string 1 arg)) | |
6821 (setq arg (match-string 2 arg)))) | |
6822 ;; | |
6823 ((or (string-match "^-D\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; -Ddefine=val | |
6824 (string-match "^-D\\([^+=]*\\)\\(\\)" arg) ;; -Ddefine | |
6825 (string-match "^\\+define\\([^+=]*\\)[+=]\\(.*\\)" arg) ;; +define+val | |
6826 (string-match "^\\+define\\([^+=]*\\)\\(\\)" arg)) ;; +define+define | |
6827 (verilog-set-define (match-string 1 arg) (match-string 2 arg))) | |
6828 ;; | |
6829 ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ;; +incdir+dir | |
6830 (string-match "^-I\\(.*\\)" arg)) ;; -Idir | |
6831 (verilog-add-list-unique `verilog-library-directories | |
6832 (match-string 1 arg))) | |
6833 ;; Ignore | |
6834 ((equal "+librescan" arg)) | |
6835 ((string-match "^-U\\(.*\\)" arg)) ;; -Udefine | |
6836 ;; Second parameters | |
6837 ((equal next-param "-f") | |
6838 (setq next-param nil) | |
6839 (verilog-getopt-file arg)) | |
6840 ((equal next-param "-v") | |
6841 (setq next-param nil) | |
6842 (verilog-add-list-unique `verilog-library-files arg)) | |
6843 ((equal next-param "-y") | |
6844 (setq next-param nil) | |
6845 (verilog-add-list-unique `verilog-library-directories arg)) | |
6846 ;; Filename | |
6847 ((string-match "^[^-+]" arg) | |
6848 (verilog-add-list-unique `verilog-library-files arg)) | |
6849 ;; Default - ignore; no warning | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6850 )))) |
79545 | 6851 ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir")) |
6852 | |
6853 (defun verilog-getopt-file (filename) | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
6854 "Read Verilog options from the specified FILENAME." |
79545 | 6855 (save-excursion |
6856 (let ((fns (verilog-library-filenames filename (buffer-file-name))) | |
6857 (orig-buffer (current-buffer)) | |
6858 line) | |
6859 (if fns | |
6860 (set-buffer (find-file-noselect (car fns))) | |
6861 (error (concat (verilog-point-text) | |
6862 "Can't find verilog-getopt-file -f file: " filename))) | |
6863 (goto-char (point-min)) | |
6864 (while (not (eobp)) | |
6865 (setq line (buffer-substring (point) | |
6866 (save-excursion (end-of-line) (point)))) | |
6867 (forward-line 1) | |
6868 (when (string-match "//" line) | |
6869 (setq line (substring line 0 (match-beginning 0)))) | |
6870 (save-excursion | |
6871 (set-buffer orig-buffer) ; Variables are buffer-local, so need right context. | |
6872 (verilog-getopt line)))))) | |
6873 | |
6874 (defun verilog-getopt-flags () | |
6875 "Convert `verilog-library-flags' into standard library variables." | |
6876 ;; If the flags are local, then all the outputs should be local also | |
6877 (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
|
6878 (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
|
6879 verilog-library-directories |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6880 verilog-library-files |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
6881 verilog-library-flags))) |
79545 | 6882 ;; Allow user to customize |
6883 (run-hooks 'verilog-before-getopt-flags-hook) | |
6884 ;; Process arguments | |
6885 (verilog-getopt verilog-library-flags) | |
6886 ;; Allow user to customize | |
6887 (run-hooks 'verilog-getopt-flags-hook)) | |
6888 | |
6889 (defun verilog-add-list-unique (varref object) | |
6890 "Append to VARREF list the given OBJECT, | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
6891 unless it is already a member of the variable's list." |
79545 | 6892 (unless (member object (symbol-value varref)) |
6893 (set varref (append (symbol-value varref) (list object)))) | |
6894 varref) | |
6895 ;;(progn (setq l '()) (verilog-add-list-unique `l "a") (verilog-add-list-unique `l "a") l) | |
6896 | |
6897 | |
6898 ;; | |
6899 ;; Module name lookup | |
6900 ;; | |
6901 | |
6902 (defun verilog-module-inside-filename-p (module filename) | |
6903 "Return point if MODULE is specified inside FILENAME, else nil. | |
6904 Allows version control to check out the file if need be." | |
6905 (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
|
6906 (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
|
6907 (vc-backend filename))) |
79545 | 6908 (let (pt) |
6909 (save-excursion | |
6910 (set-buffer (find-file-noselect filename)) | |
6911 (goto-char (point-min)) | |
6912 (while (and | |
6913 ;; It may be tempting to look for verilog-defun-re, don't, it slows things down a lot! | |
6914 (verilog-re-search-forward-quick "\\<module\\>" nil t) | |
6915 (verilog-re-search-forward-quick "[(;]" nil t)) | |
6916 (if (equal module (verilog-read-module-name)) | |
6917 (setq pt (point)))) | |
6918 pt)))) | |
6919 | |
6920 (defun verilog-is-number (symbol) | |
6921 "Return true if SYMBOL is number-like." | |
6922 (or (string-match "^[0-9 \t:]+$" symbol) | |
6923 (string-match "^[---]*[0-9]+$" symbol) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
6924 (string-match "^[0-9 \t]+'s?[hdxbo][0-9a-fA-F_xz? \t]*$" symbol))) |
79545 | 6925 |
6926 (defun verilog-symbol-detick (symbol wing-it) | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
6927 "Return an expanded SYMBOL name without any defines. |
79545 | 6928 If the variable vh-{symbol} is defined, return that value. |
6929 If undefined, and WING-IT, return just SYMBOL without the tick, else nil." | |
6930 (while (and symbol (string-match "^`" symbol)) | |
6931 (setq symbol (substring symbol 1)) | |
6932 (setq symbol | |
6933 (if (boundp (intern (concat "vh-" symbol))) | |
6934 ;; Emacs has a bug where boundp on a buffer-local | |
6935 ;; variable in only one buffer returns t in another. | |
6936 ;; This can confuse, so check for nil. | |
6937 (let ((val (eval (intern (concat "vh-" symbol))))) | |
6938 (if (eq val nil) | |
6939 (if wing-it symbol nil) | |
6940 val)) | |
6941 (if wing-it symbol nil)))) | |
6942 symbol) | |
6943 ;;(verilog-symbol-detick "`mod" nil) | |
6944 | |
6945 (defun verilog-symbol-detick-denumber (symbol) | |
6946 "Return SYMBOL with defines converted and any numbers dropped to nil." | |
6947 (when (string-match "^`" symbol) | |
6948 ;; This only will work if the define is a simple signal, not | |
6949 ;; something like a[b]. Sorry, it should be substituted into the parser | |
6950 (setq symbol | |
6951 (verilog-string-replace-matches | |
6952 "\[[^0-9: \t]+\]" "" nil nil | |
6953 (or (verilog-symbol-detick symbol nil) | |
6954 (if verilog-auto-sense-defines-constant | |
6955 "0" | |
6956 symbol))))) | |
6957 (if (verilog-is-number symbol) | |
6958 nil | |
6959 symbol)) | |
6960 | |
6961 (defun verilog-symbol-detick-text (text) | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
6962 "Return TEXT without any known defines. |
79545 | 6963 If the variable vh-{symbol} is defined, substitute that value." |
6964 (let ((ok t) symbol val) | |
6965 (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text)) | |
6966 (setq symbol (match-string 1 text)) | |
6967 (message symbol) | |
6968 (cond ((and | |
6969 (boundp (intern (concat "vh-" symbol))) | |
6970 ;; Emacs has a bug where boundp on a buffer-local | |
6971 ;; variable in only one buffer returns t in another. | |
6972 ;; This can confuse, so check for nil. | |
6973 (setq val (eval (intern (concat "vh-" symbol))))) | |
6974 (setq text (replace-match val nil nil text))) | |
6975 (t (setq ok nil))))) | |
6976 text) | |
6977 ;;(progn (setq vh-mod "`foo" vh-foo "bar") (verilog-symbol-detick-text "bar `mod `undefed")) | |
6978 | |
6979 (defun verilog-expand-dirnames (&optional dirnames) | |
6980 "Return a list of existing directories given a list of wildcarded DIRNAMES. | |
6981 Or, just the existing dirnames themselves if there are no wildcards." | |
6982 (interactive) | |
6983 (unless dirnames (error "`verilog-library-directories' should include at least '.'")) | |
6984 (setq dirnames (reverse dirnames)) ; not nreverse | |
6985 (let ((dirlist nil) | |
6986 pattern dirfile dirfiles dirname root filename rest) | |
6987 (while dirnames | |
6988 (setq dirname (substitute-in-file-name (car dirnames)) | |
6989 dirnames (cdr dirnames)) | |
6990 (cond ((string-match (concat "^\\(\\|[/\\]*[^*?]*[/\\]\\)" ;; root | |
6991 "\\([^/\\]*[*?][^/\\]*\\)" ;; filename with *? | |
6992 "\\(.*\\)") ;; rest | |
6993 dirname) | |
6994 (setq root (match-string 1 dirname) | |
6995 filename (match-string 2 dirname) | |
6996 rest (match-string 3 dirname) | |
6997 pattern filename) | |
6998 ;; now replace those * and ? with .+ and . | |
6999 ;; use ^ and /> to get only whole file names | |
7000 ;;verilog-string-replace-matches | |
7001 (setq pattern (verilog-string-replace-matches "[*]" ".+" nil nil pattern) | |
7002 pattern (verilog-string-replace-matches "[?]" "." nil nil pattern) | |
7003 | |
7004 ;; Unfortunately allows abc/*/rtl to match abc/rtl | |
7005 ;; because abc/.. shows up in dirfiles. Solutions welcome. | |
7006 dirfiles (if (file-directory-p root) ; Ignore version control external | |
7007 (directory-files root t pattern nil))) | |
7008 (while dirfiles | |
7009 (setq dirfile (expand-file-name (concat (car dirfiles) rest)) | |
7010 dirfiles (cdr dirfiles)) | |
7011 (if (file-directory-p dirfile) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7012 (setq dirlist (cons dirfile dirlist))))) |
79545 | 7013 ;; Defaults |
7014 (t | |
7015 (if (file-directory-p dirname) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7016 (setq dirlist (cons dirname dirlist)))))) |
79545 | 7017 dirlist)) |
7018 ;;(verilog-expand-dirnames (list "." ".." "nonexist" "../*" "/home/wsnyder/*/v")) | |
7019 | |
7020 (defun verilog-library-filenames (filename current &optional check-ext) | |
7021 "Return a search path to find the given FILENAME name. | |
7022 Uses the CURRENT filename, `verilog-library-directories' and | |
7023 `verilog-library-extensions' variables to build the path. | |
7024 With optional CHECK-EXT also check `verilog-library-extensions'." | |
7025 (let ((ckdir (verilog-expand-dirnames verilog-library-directories)) | |
7026 fn outlist) | |
7027 (while ckdir | |
7028 (let ((ckext (if check-ext verilog-library-extensions `("")))) | |
7029 (while ckext | |
7030 (setq fn (expand-file-name | |
7031 (concat filename (car ckext)) | |
7032 (expand-file-name (car ckdir) (file-name-directory current)))) | |
7033 (if (file-exists-p fn) | |
7034 (setq outlist (cons fn outlist))) | |
7035 (setq ckext (cdr ckext)))) | |
7036 (setq ckdir (cdr ckdir))) | |
7037 (nreverse outlist))) | |
7038 | |
7039 (defun verilog-module-filenames (module current) | |
7040 "Return a search path to find the given MODULE name. | |
7041 Uses the CURRENT filename, `verilog-library-extensions', | |
7042 `verilog-library-directories' and `verilog-library-files' | |
7043 variables to build the path." | |
7044 ;; Return search locations for it | |
7045 (append (list current) ; first, current buffer | |
7046 (verilog-library-filenames module current t) | |
7047 verilog-library-files)) ; finally, any libraries | |
7048 | |
7049 ;; | |
7050 ;; Module Information | |
7051 ;; | |
7052 ;; Many of these functions work on "modi" a module information structure | |
7053 ;; A modi is: [module-name-string file-name begin-point] | |
7054 | |
7055 (defvar verilog-cache-enabled t | |
7056 "If true, enable caching of signals, etc. Set to nil for debugging to make things SLOW!") | |
7057 | |
7058 (defvar verilog-modi-cache-list nil | |
7059 "Cache of ((Module Function) Buf-Tick Buf-Modtime Func-Returns)... | |
7060 For speeding up verilog-modi-get-* commands. | |
7061 Buffer-local.") | |
7062 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
7063 (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
|
7064 |
79545 | 7065 (defvar verilog-modi-cache-preserve-tick nil |
7066 "Modification tick after which the cache is still considered valid. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7067 Use `verilog-preserve-cache' to set it.") |
79545 | 7068 (defvar verilog-modi-cache-preserve-buffer nil |
7069 "Modification tick after which the cache is still considered valid. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7070 Use `verilog-preserve-cache' to set it.") |
79545 | 7071 |
7072 (defun verilog-modi-current () | |
7073 "Return the modi structure for the module currently at point." | |
7074 (let* (name pt) | |
7075 ;; read current module's name | |
7076 (save-excursion | |
7077 (verilog-re-search-backward-quick verilog-defun-re nil nil) | |
7078 (verilog-re-search-forward-quick "(" nil nil) | |
7079 (setq name (verilog-read-module-name)) | |
7080 (setq pt (point))) | |
7081 ;; return | |
7082 (vector name (or (buffer-file-name) (current-buffer)) pt))) | |
7083 | |
7084 (defvar verilog-modi-lookup-last-mod nil "Cache of last module looked up.") | |
7085 (defvar verilog-modi-lookup-last-modi nil "Cache of last modi returned.") | |
7086 (defvar verilog-modi-lookup-last-current nil "Cache of last `current-buffer' looked up.") | |
7087 (defvar verilog-modi-lookup-last-tick nil "Cache of last `buffer-modified-tick' looked up.") | |
7088 | |
7089 (defun verilog-modi-lookup (module allow-cache &optional ignore-error) | |
7090 "Find the file and point at which MODULE is defined. | |
7091 If ALLOW-CACHE is set, check and remember cache of previous lookups. | |
7092 Return modi if successful, else print message unless IGNORE-ERROR is true." | |
7093 (let* ((current (or (buffer-file-name) (current-buffer)))) | |
7094 (cond ((and verilog-modi-lookup-last-modi | |
7095 verilog-cache-enabled | |
7096 allow-cache | |
7097 (equal verilog-modi-lookup-last-mod module) | |
7098 (equal verilog-modi-lookup-last-current current) | |
7099 (equal verilog-modi-lookup-last-tick (buffer-modified-tick))) | |
7100 ;; ok as is | |
7101 ) | |
7102 (t (let* ((realmod (verilog-symbol-detick module t)) | |
7103 (orig-filenames (verilog-module-filenames realmod current)) | |
7104 (filenames orig-filenames) | |
7105 pt) | |
7106 (while (and filenames (not pt)) | |
7107 (if (not (setq pt (verilog-module-inside-filename-p realmod (car filenames)))) | |
7108 (setq filenames (cdr filenames)))) | |
7109 (cond (pt (setq verilog-modi-lookup-last-modi | |
7110 (vector realmod (car filenames) pt))) | |
7111 (t (setq verilog-modi-lookup-last-modi nil) | |
7112 (or ignore-error | |
7113 (error (concat (verilog-point-text) | |
7114 ": Can't locate " module " module definition" | |
7115 (if (not (equal module realmod)) | |
7116 (concat " (Expanded macro to " realmod ")") | |
7117 "") | |
7118 "\n Check the verilog-library-directories variable." | |
7119 "\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
|
7120 (mapconcat 'concat orig-filenames "\n\t")))))) |
79545 | 7121 (setq verilog-modi-lookup-last-mod module |
7122 verilog-modi-lookup-last-current current | |
7123 verilog-modi-lookup-last-tick (buffer-modified-tick))))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7124 verilog-modi-lookup-last-modi)) |
79545 | 7125 |
7126 (defsubst verilog-modi-name (modi) | |
7127 (aref modi 0)) | |
7128 (defsubst verilog-modi-file-or-buffer (modi) | |
7129 (aref modi 1)) | |
7130 (defsubst verilog-modi-point (modi) | |
7131 (aref modi 2)) | |
7132 | |
7133 (defun verilog-modi-filename (modi) | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7134 "Filename of MODI, or name of buffer if it's never been saved." |
79545 | 7135 (if (bufferp (verilog-modi-file-or-buffer modi)) |
7136 (or (buffer-file-name (verilog-modi-file-or-buffer modi)) | |
7137 (buffer-name (verilog-modi-file-or-buffer modi))) | |
7138 (verilog-modi-file-or-buffer modi))) | |
7139 | |
7140 (defun verilog-modi-goto (modi) | |
7141 "Move point/buffer to specified MODI." | |
7142 (or modi (error "Passed unfound modi to goto, check earlier")) | |
7143 (set-buffer (if (bufferp (verilog-modi-file-or-buffer modi)) | |
7144 (verilog-modi-file-or-buffer modi) | |
7145 (find-file-noselect (verilog-modi-file-or-buffer modi)))) | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7146 (or (equal major-mode `verilog-mode) ;; Put into Verilog mode to get syntax |
79545 | 7147 (verilog-mode)) |
7148 (goto-char (verilog-modi-point modi))) | |
7149 | |
7150 (defun verilog-goto-defun-file (module) | |
7151 "Move point to the file at which a given MODULE is defined." | |
7152 (interactive "sGoto File for Module: ") | |
7153 (let* ((modi (verilog-modi-lookup module nil))) | |
7154 (when modi | |
7155 (verilog-modi-goto modi) | |
7156 (switch-to-buffer (current-buffer))))) | |
7157 | |
7158 (defun verilog-modi-cache-results (modi function) | |
7159 "Run on MODI the given FUNCTION. Locate the module in a file. | |
7160 Cache the output of function so next call may have faster access." | |
7161 (let (func-returns fass) | |
7162 (save-excursion | |
7163 (verilog-modi-goto modi) | |
7164 (if (and (setq fass (assoc (list (verilog-modi-name modi) function) | |
7165 verilog-modi-cache-list)) | |
7166 ;; Destroy caching when incorrect; Modified or file changed | |
7167 (not (and verilog-cache-enabled | |
7168 (or (equal (buffer-modified-tick) (nth 1 fass)) | |
7169 (and verilog-modi-cache-preserve-tick | |
7170 (<= verilog-modi-cache-preserve-tick (nth 1 fass)) | |
7171 (equal verilog-modi-cache-preserve-buffer (current-buffer)))) | |
7172 (equal (visited-file-modtime) (nth 2 fass))))) | |
7173 (setq verilog-modi-cache-list nil | |
7174 fass nil)) | |
7175 (cond (fass | |
7176 ;; Found | |
7177 (setq func-returns (nth 3 fass))) | |
7178 (t | |
7179 ;; Read from file | |
7180 ;; Clear then restore any hilighting to make emacs19 happy | |
7181 (let ((fontlocked (when (and (boundp 'font-lock-mode) | |
7182 font-lock-mode) | |
7183 (font-lock-mode nil) | |
7184 t))) | |
7185 (setq func-returns (funcall function)) | |
7186 (when fontlocked (font-lock-mode t))) | |
7187 ;; Cache for next time | |
7188 (setq verilog-modi-cache-list | |
7189 (cons (list (list (verilog-modi-name modi) function) | |
7190 (buffer-modified-tick) | |
7191 (visited-file-modtime) | |
7192 func-returns) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7193 verilog-modi-cache-list))))) |
79545 | 7194 ;; |
7195 func-returns)) | |
7196 | |
7197 (defun verilog-modi-cache-add (modi function element sig-list) | |
7198 "Add function return results to the module cache. | |
7199 Update MODI's cache for given FUNCTION so that the return ELEMENT of that | |
7200 function now contains the additional SIG-LIST parameters." | |
7201 (let (fass) | |
7202 (save-excursion | |
7203 (verilog-modi-goto modi) | |
7204 (if (setq fass (assoc (list (verilog-modi-name modi) function) | |
7205 verilog-modi-cache-list)) | |
7206 (let ((func-returns (nth 3 fass))) | |
7207 (aset func-returns element | |
7208 (append sig-list (aref func-returns element)))))))) | |
7209 | |
7210 (defmacro verilog-preserve-cache (&rest body) | |
7211 "Execute the BODY forms, allowing cache preservation within BODY. | |
7212 This means that changes to the buffer will not result in the cache being | |
7213 flushed. If the changes affect the modsig state, they must call the | |
7214 modsig-cache-add-* function, else the results of later calls may be | |
7215 incorrect. Without this, changes are assumed to be adding/removing signals | |
7216 and invalidating the cache." | |
7217 `(let ((verilog-modi-cache-preserve-tick (buffer-modified-tick)) | |
7218 (verilog-modi-cache-preserve-buffer (current-buffer))) | |
7219 (progn ,@body))) | |
7220 | |
7221 | |
7222 (defun verilog-signals-matching-enum (in-list enum) | |
7223 "Return all signals in IN-LIST matching the given ENUM." | |
7224 (let (out-list) | |
7225 (while in-list | |
7226 (if (equal (verilog-sig-enum (car in-list)) enum) | |
7227 (setq out-list (cons (car in-list) out-list))) | |
7228 (setq in-list (cdr in-list))) | |
7229 ;; New scheme | |
7230 (let* ((enumvar (intern (concat "venum-" enum))) | |
7231 (enumlist (and (boundp enumvar) (eval enumvar)))) | |
7232 (while enumlist | |
7233 (add-to-list 'out-list (list (car enumlist))) | |
7234 (setq enumlist (cdr enumlist)))) | |
7235 (nreverse out-list))) | |
7236 | |
7237 (defun verilog-signals-not-matching-regexp (in-list regexp) | |
7238 "Return all signals in IN-LIST not matching the given REGEXP, if non-nil." | |
7239 (if (not regexp) | |
7240 in-list | |
7241 (let (out-list) | |
7242 (while in-list | |
7243 (if (not (string-match regexp (verilog-sig-name (car in-list)))) | |
7244 (setq out-list (cons (car in-list) out-list))) | |
7245 (setq in-list (cdr in-list))) | |
7246 (nreverse out-list)))) | |
7247 | |
7248 ;; Combined | |
7249 (defun verilog-modi-get-signals (modi) | |
7250 (append | |
7251 (verilog-modi-get-outputs modi) | |
7252 (verilog-modi-get-inouts modi) | |
7253 (verilog-modi-get-inputs modi) | |
7254 (verilog-modi-get-wires modi) | |
7255 (verilog-modi-get-regs modi) | |
7256 (verilog-modi-get-assigns modi) | |
7257 (verilog-modi-get-consts modi) | |
7258 (verilog-modi-get-gparams modi))) | |
7259 | |
7260 (defun verilog-modi-get-ports (modi) | |
7261 (append | |
7262 (verilog-modi-get-outputs modi) | |
7263 (verilog-modi-get-inouts modi) | |
7264 (verilog-modi-get-inputs modi))) | |
7265 | |
7266 (defsubst verilog-modi-cache-add-outputs (modi sig-list) | |
7267 (verilog-modi-cache-add modi 'verilog-read-decls 0 sig-list)) | |
7268 (defsubst verilog-modi-cache-add-inouts (modi sig-list) | |
7269 (verilog-modi-cache-add modi 'verilog-read-decls 1 sig-list)) | |
7270 (defsubst verilog-modi-cache-add-inputs (modi sig-list) | |
7271 (verilog-modi-cache-add modi 'verilog-read-decls 2 sig-list)) | |
7272 (defsubst verilog-modi-cache-add-wires (modi sig-list) | |
7273 (verilog-modi-cache-add modi 'verilog-read-decls 3 sig-list)) | |
7274 (defsubst verilog-modi-cache-add-regs (modi sig-list) | |
7275 (verilog-modi-cache-add modi 'verilog-read-decls 4 sig-list)) | |
7276 | |
7277 (defun verilog-signals-from-signame (signame-list) | |
7278 "Return signals in standard form from SIGNAME-LIST, a simple list of signal names." | |
7279 (mapcar (function (lambda (name) (list name nil nil))) | |
7280 signame-list)) | |
7281 | |
7282 ;; | |
7283 ;; Auto creation utilities | |
7284 ;; | |
7285 | |
7286 (defun verilog-auto-search-do (search-for func) | |
7287 "Search for the given auto text SEARCH-FOR, and perform FUNC where it occurs." | |
7288 (goto-char (point-min)) | |
7289 (while (search-forward search-for nil t) | |
7290 (if (not (save-excursion | |
7291 (goto-char (match-beginning 0)) | |
7292 (verilog-inside-comment-p))) | |
7293 (funcall func)))) | |
7294 | |
7295 (defun verilog-auto-re-search-do (search-for func) | |
7296 "Search for the given auto text SEARCH-FOR, and perform FUNC where it occurs." | |
7297 (goto-char (point-min)) | |
7298 (while (re-search-forward search-for nil t) | |
7299 (if (not (save-excursion | |
7300 (goto-char (match-beginning 0)) | |
7301 (verilog-inside-comment-p))) | |
7302 (funcall func)))) | |
7303 | |
7304 (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
|
7305 "Print out a definition for SIG of the given TYPE, |
79545 | 7306 with appropriate INDENT-PT indentation." |
7307 (indent-to indent-pt) | |
7308 (insert type) | |
7309 (when (verilog-sig-signed sig) | |
7310 (insert " " (verilog-sig-signed sig))) | |
7311 (when (verilog-sig-multidim sig) | |
7312 (insert " " (verilog-sig-multidim-string sig))) | |
7313 (when (verilog-sig-bits sig) | |
7314 (insert " " (verilog-sig-bits sig))) | |
7315 (indent-to (max 24 (+ indent-pt 16))) | |
7316 (unless (= (char-syntax (preceding-char)) ?\ ) | |
7317 (insert " ")) ; Need space between "]name" if indent-to did nothing | |
7318 (insert (verilog-sig-name sig))) | |
7319 | |
7320 (defun verilog-insert-definition (sigs direction indent-pt v2k &optional dont-sort) | |
7321 "Print out a definition for a list of SIGS of the given DIRECTION, | |
7322 with appropriate INDENT-PT indentation. If V2K, use Verilog 2001 I/O | |
7323 format. Sort unless DONT-SORT. DIRECTION is normally wire/reg/output." | |
7324 (or dont-sort | |
7325 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare))) | |
7326 (while sigs | |
7327 (let ((sig (car sigs))) | |
7328 (verilog-insert-one-definition | |
7329 sig | |
7330 ;; Want "type x" or "output type x", not "wire type x" | |
7331 (cond ((verilog-sig-type sig) | |
7332 (concat | |
7333 (if (not (equal direction "wire")) | |
7334 (concat direction " ")) | |
7335 (verilog-sig-type sig))) | |
7336 (t direction)) | |
7337 indent-pt) | |
7338 (insert (if v2k "," ";")) | |
7339 (if (or (not (verilog-sig-comment sig)) | |
7340 (equal "" (verilog-sig-comment sig))) | |
7341 (insert "\n") | |
7342 (indent-to (max 48 (+ indent-pt 40))) | |
7343 (insert (concat "// " (verilog-sig-comment sig) "\n"))) | |
7344 (setq sigs (cdr sigs))))) | |
7345 | |
7346 (eval-when-compile | |
7347 (if (not (boundp 'indent-pt)) | |
7348 (defvar indent-pt nil "Local used by insert-indent"))) | |
7349 | |
7350 (defun verilog-insert-indent (&rest stuff) | |
7351 "Indent to position stored in local `indent-pt' variable, then insert STUFF. | |
7352 Presumes that any newlines end a list element." | |
7353 (let ((need-indent t)) | |
7354 (while stuff | |
7355 (if need-indent (indent-to indent-pt)) | |
7356 (setq need-indent nil) | |
7357 (insert (car stuff)) | |
7358 (setq need-indent (string-match "\n$" (car stuff)) | |
7359 stuff (cdr stuff))))) | |
7360 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n")) | |
7361 | |
7362 (defun verilog-repair-open-comma () | |
7363 "If backwards-from-point is other than a open parenthesis insert comma." | |
7364 (save-excursion | |
7365 (verilog-backward-syntactic-ws) | |
7366 (when (save-excursion | |
7367 (backward-char 1) | |
7368 (and (not (looking-at "[(,]")) | |
7369 (progn | |
7370 (verilog-re-search-backward "[(`]" nil t) | |
7371 (looking-at "(")))) | |
7372 (insert ",")))) | |
7373 | |
7374 (defun verilog-repair-close-comma () | |
7375 "If point is at a comma followed by a close parenthesis, fix it. | |
7376 This repairs those mis-inserted by a AUTOARG." | |
7377 ;; It would be much nicer if Verilog allowed extra commas like Perl does! | |
7378 (save-excursion | |
7379 (verilog-forward-close-paren) | |
7380 (backward-char 1) | |
7381 (verilog-backward-syntactic-ws) | |
7382 (backward-char 1) | |
7383 (when (looking-at ",") | |
7384 (delete-char 1)))) | |
7385 | |
7386 (defun verilog-get-list (start end) | |
7387 "Return the elements of a comma separated list between START and END." | |
7388 (interactive) | |
7389 (let ((my-list (list)) | |
7390 my-string) | |
7391 (save-excursion | |
7392 (while (< (point) end) | |
7393 (when (re-search-forward "\\([^,{]+\\)" end t) | |
7394 (setq my-string (verilog-string-remove-spaces (match-string 1))) | |
7395 (setq my-list (nconc my-list (list my-string) )) | |
7396 (goto-char (match-end 0)))) | |
7397 my-list))) | |
7398 | |
7399 (defun verilog-make-width-expression (range-exp) | |
7400 "Return an expression calculating the length of a range [x:y] in RANGE-EXP." | |
7401 ;; strip off the [] | |
7402 (cond ((not range-exp) | |
7403 "1") | |
7404 (t | |
7405 (if (string-match "^\\[\\(.*\\)\\]$" range-exp) | |
7406 (setq range-exp (match-string 1 range-exp))) | |
7407 (cond ((not range-exp) | |
7408 "1") | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
7409 ((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
|
7410 range-exp) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
7411 (int-to-string |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
7412 (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
|
7413 (string-to-number (match-string 2 range-exp))))))) |
79545 | 7414 ((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
|
7415 (concat "(1+(" (match-string 1 range-exp) ")" |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7416 (if (equal "0" (match-string 2 range-exp)) |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7417 "" ;; Don't bother with -(0) |
79545 | 7418 (concat "-(" (match-string 2 range-exp) ")")) |
7419 ")")) | |
7420 (t nil))))) | |
7421 ;;(verilog-make-width-expression "`A:`B") | |
7422 | |
7423 (defun verilog-typedef-name-p (variable-name) | |
7424 "Return true if the VARIABLE-NAME is a type definition." | |
7425 (when verilog-typedef-regexp | |
7426 (string-match verilog-typedef-regexp variable-name))) | |
7427 | |
7428 ;; | |
7429 ;; Auto deletion | |
7430 ;; | |
7431 | |
7432 (defun verilog-delete-autos-lined () | |
7433 "Delete autos that occupy multiple lines, between begin and end comments." | |
7434 (let ((pt (point))) | |
7435 (forward-line 1) | |
7436 (when (and | |
7437 (looking-at "\\s-*// Beginning") | |
7438 (search-forward "// End of automatic" nil t)) | |
7439 ;; End exists | |
7440 (end-of-line) | |
7441 (delete-region pt (point)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7442 (forward-line 1)))) |
79545 | 7443 |
7444 (defun verilog-forward-close-paren () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7445 "Find the close parenthesis that match the current point. |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7446 Ignore other close parenthesis with matching open parens." |
79545 | 7447 (let ((parens 1)) |
7448 (while (> parens 0) | |
7449 (unless (verilog-re-search-forward-quick "[()]" nil t) | |
7450 (error "%s: Mismatching ()" (verilog-point-text))) | |
7451 (cond ((= (preceding-char) ?\( ) | |
7452 (setq parens (1+ parens))) | |
7453 ((= (preceding-char) ?\) ) | |
7454 (setq parens (1- parens))))))) | |
7455 | |
7456 (defun verilog-backward-open-paren () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7457 "Find the open parenthesis that match the current point. |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7458 Ignore other open parenthesis with matching close parens." |
79545 | 7459 (let ((parens 1)) |
7460 (while (> parens 0) | |
7461 (unless (verilog-re-search-backward-quick "[()]" nil t) | |
7462 (error "%s: Mismatching ()" (verilog-point-text))) | |
7463 (cond ((= (following-char) ?\) ) | |
7464 (setq parens (1+ parens))) | |
7465 ((= (following-char) ?\( ) | |
7466 (setq parens (1- parens))))))) | |
7467 | |
7468 (defun verilog-backward-open-bracket () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7469 "Find the open bracket that match the current point. |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7470 Ignore other open bracket with matching close bracket." |
79545 | 7471 (let ((parens 1)) |
7472 (while (> parens 0) | |
7473 (unless (verilog-re-search-backward-quick "[][]" nil t) | |
7474 (error "%s: Mismatching []" (verilog-point-text))) | |
7475 (cond ((= (following-char) ?\] ) | |
7476 (setq parens (1+ parens))) | |
7477 ((= (following-char) ?\[ ) | |
7478 (setq parens (1- parens))))))) | |
7479 | |
7480 (defun verilog-delete-to-paren () | |
7481 "Delete the automatic inst/sense/arg created by autos. | |
7482 Deletion stops at the matching end parenthesis." | |
7483 (delete-region (point) | |
7484 (save-excursion | |
7485 (verilog-backward-open-paren) | |
7486 (forward-sexp 1) ;; Moves to paren that closes argdecl's | |
7487 (backward-char 1) | |
7488 (point)))) | |
7489 | |
7490 (defun verilog-auto-star-safe () | |
7491 "Return if a .* AUTOINST is safe to delete or expand. | |
7492 It was created by the AUTOS themselves, or by the user." | |
7493 (and verilog-auto-star-expand | |
7494 (looking-at "[ \t\n\f,]*\\([)]\\|// \\(Outputs\\|Inouts\\|Inputs\\)\\)"))) | |
7495 | |
7496 (defun verilog-delete-auto-star-all () | |
7497 "Delete a .* AUTOINST, if it is safe." | |
7498 (when (verilog-auto-star-safe) | |
7499 (verilog-delete-to-paren))) | |
7500 | |
7501 (defun verilog-delete-auto-star-implicit () | |
7502 "Delete all .* implicit connections created by `verilog-auto-star'. | |
7503 This function will be called automatically at save unless | |
7504 `verilog-auto-star-save' is set, any non-templated expanded pins will be | |
7505 removed." | |
7506 (interactive) | |
7507 (let (paren-pt indent have-close-paren) | |
7508 (save-excursion | |
7509 (goto-char (point-min)) | |
7510 ;; We need to match these even outside of comments. | |
7511 ;; For reasonable performance, we don't check if inside comments, sorry. | |
7512 (while (re-search-forward "// Implicit \\.\\*" nil t) | |
7513 (setq paren-pt (point)) | |
7514 (beginning-of-line) | |
7515 (setq have-close-paren | |
7516 (save-excursion | |
7517 (when (search-forward ");" paren-pt t) | |
7518 (setq indent (current-indentation)) | |
7519 t))) | |
7520 (delete-region (point) (+ 1 paren-pt)) ; Nuke line incl CR | |
7521 (when have-close-paren | |
7522 ;; Delete extra commentary | |
7523 (save-excursion | |
7524 (while (progn | |
7525 (forward-line -1) | |
7526 (looking-at "\\s *//\\s *\\(Outputs\\|Inouts\\|Inputs\\)\n")) | |
7527 (delete-region (match-beginning 0) (match-end 0)))) | |
7528 ;; If it is simple, we can put the ); on the same line as the last text | |
7529 (let ((rtn-pt (point))) | |
7530 (save-excursion | |
7531 (while (progn (backward-char 1) | |
7532 (looking-at "[ \t\n\f]"))) | |
7533 (when (looking-at ",") | |
7534 (delete-region (+ 1 (point)) rtn-pt)))) | |
7535 (when (bolp) | |
7536 (indent-to indent)) | |
7537 (insert ");\n") | |
7538 ;; Still need to kill final comma - always is one as we put one after the .* | |
7539 (re-search-backward ",") | |
7540 (delete-char 1)))))) | |
7541 | |
7542 (defun verilog-delete-auto () | |
7543 "Delete the automatic outputs, regs, and wires created by \\[verilog-auto]. | |
7544 Use \\[verilog-auto] to re-insert the updated AUTOs. | |
7545 | |
7546 The hooks `verilog-before-delete-auto-hook' and `verilog-delete-auto-hook' are | |
7547 called before and after this function, respectively." | |
7548 (interactive) | |
7549 (save-excursion | |
7550 (if (buffer-file-name) | |
7551 (find-file-noselect (buffer-file-name))) ;; To check we have latest version | |
7552 ;; Allow user to customize | |
7553 (run-hooks 'verilog-before-delete-auto-hook) | |
7554 | |
7555 ;; Remove those that have multi-line insertions | |
7556 (verilog-auto-re-search-do "/\\*AUTO\\(OUTPUTEVERY\\|CONCATCOMMENT\\|WIRE\\|REG\\|DEFINEVALUE\\|REGINPUT\\|INPUT\\|OUTPUT\\|INOUT\\|RESET\\|TIEOFF\\|UNUSED\\)\\*/" | |
7557 'verilog-delete-autos-lined) | |
7558 ;; Remove those that have multi-line insertions with parameters | |
7559 (verilog-auto-re-search-do "/\\*AUTO\\(INOUTMODULE\\|ASCIIENUM\\)([^)]*)\\*/" | |
7560 'verilog-delete-autos-lined) | |
7561 ;; Remove those that are in parenthesis | |
7562 (verilog-auto-re-search-do "/\\*\\(AS\\|AUTO\\(ARG\\|CONCATWIDTH\\|INST\\|INSTPARAM\\|SENSE\\)\\)\\*/" | |
7563 'verilog-delete-to-paren) | |
7564 ;; Do .* instantiations, but avoid removing any user pins by looking for our magic comments | |
7565 (verilog-auto-re-search-do "\\.\\*" | |
7566 'verilog-delete-auto-star-all) | |
7567 ;; Remove template comments ... anywhere in case was pasted after AUTOINST removed | |
7568 (goto-char (point-min)) | |
7569 (while (re-search-forward "\\s-*// \\(Templated\\|Implicit \\.\\*\\)[ \tLT0-9]*$" nil t) | |
7570 (replace-match "")) | |
7571 | |
7572 ;; Final customize | |
7573 (run-hooks 'verilog-delete-auto-hook))) | |
7574 | |
7575 ;; | |
7576 ;; Auto inject | |
7577 ;; | |
7578 | |
7579 (defun verilog-inject-auto () | |
7580 "Examine legacy non-AUTO code and insert AUTOs in appropriate places. | |
7581 | |
7582 Any always @ blocks with sensitivity lists that match computed lists will | |
7583 be replaced with /*AS*/ comments. | |
7584 | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7585 Any cells will get /*AUTOINST*/ added to the end of the pin list. |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7586 Pins with have identical names will be deleted. |
79545 | 7587 |
7588 Argument lists will not be deleted, /*AUTOARG*/ will only be inserted to | |
7589 support adding new ports. You may wish to delete older ports yourself. | |
7590 | |
7591 For example: | |
7592 | |
7593 module ex_inject (i, o); | |
7594 input i; | |
7595 input j; | |
7596 output o; | |
7597 always @ (i or j) | |
7598 o = i | j; | |
7599 cell cell (.foobar(baz), | |
7600 .j(j)); | |
7601 endmodule | |
7602 | |
7603 Typing \\[verilog-inject-auto] will make this into: | |
7604 | |
7605 module ex_inject (i, o/*AUTOARG*/ | |
7606 // Inputs | |
7607 j); | |
7608 input i; | |
7609 output o; | |
7610 always @ (/*AS*/i or j) | |
7611 o = i | j; | |
7612 cell cell (.foobar(baz), | |
7613 /*AUTOINST*/ | |
7614 // Outputs | |
7615 .j(j)); | |
7616 endmodule" | |
7617 (interactive) | |
7618 (verilog-auto t)) | |
7619 | |
7620 (defun verilog-inject-arg () | |
7621 "Inject AUTOARG into new code. See `verilog-inject-auto'." | |
7622 ;; Presume one module per file. | |
7623 (save-excursion | |
7624 (goto-char (point-min)) | |
7625 (while (verilog-re-search-forward-quick "\\<module\\>" nil t) | |
7626 (let ((endmodp (save-excursion | |
7627 (verilog-re-search-forward-quick "\\<endmodule\\>" nil t) | |
7628 (point)))) | |
7629 ;; See if there's already a comment .. inside a comment so not verilog-re-search | |
7630 (when (not (re-search-forward "/\\*AUTOARG\\*/" endmodp t)) | |
7631 (verilog-re-search-forward-quick ";" nil t) | |
7632 (backward-char 1) | |
7633 (verilog-backward-syntactic-ws) | |
7634 (backward-char 1) ; Moves to paren that closes argdecl's | |
7635 (when (looking-at ")") | |
7636 (insert "/*AUTOARG*/"))))))) | |
7637 | |
7638 (defun verilog-inject-sense () | |
7639 "Inject AUTOSENSE into new code. See `verilog-inject-auto'." | |
7640 (save-excursion | |
7641 (goto-char (point-min)) | |
7642 (while (verilog-re-search-forward-quick "\\<always\\s *@\\s *(" nil t) | |
7643 (let ((start-pt (point)) | |
7644 (modi (verilog-modi-current)) | |
7645 pre-sigs | |
7646 got-sigs) | |
7647 (backward-char 1) | |
7648 (forward-sexp 1) | |
7649 (backward-char 1) ;; End ) | |
7650 (when (not (verilog-re-search-backward "/\\*\\(AUTOSENSE\\|AS\\)\\*/" start-pt t)) | |
7651 (setq pre-sigs (verilog-signals-from-signame | |
7652 (verilog-read-signals start-pt (point))) | |
7653 got-sigs (verilog-auto-sense-sigs modi nil)) | |
7654 (when (not (or (verilog-signals-not-in pre-sigs got-sigs) ; Both are equal? | |
7655 (verilog-signals-not-in got-sigs pre-sigs))) | |
7656 (delete-region start-pt (point)) | |
7657 (insert "/*AS*/"))))))) | |
7658 | |
7659 (defun verilog-inject-inst () | |
7660 "Inject AUTOINST into new code. See `verilog-inject-auto'." | |
7661 (save-excursion | |
7662 (goto-char (point-min)) | |
7663 ;; It's hard to distinguish modules; we'll instead search for pins. | |
7664 (while (verilog-re-search-forward-quick "\\.\\s *[a-zA-Z0-9`_\$]+\\s *(\\s *[a-zA-Z0-9`_\$]+\\s *)" nil t) | |
7665 (verilog-backward-open-paren) ;; Inst start | |
7666 (cond | |
7667 ((= (preceding-char) ?\#) ;; #(...) parameter section, not pin. Skip. | |
7668 (forward-char 1) | |
7669 (verilog-forward-close-paren)) ;; Parameters done | |
7670 (t | |
7671 (forward-char 1) | |
7672 (let ((indent-pt (+ (current-column))) | |
7673 (end-pt (save-excursion (verilog-forward-close-paren) (point)))) | |
7674 (cond ((verilog-re-search-forward "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-pt t) | |
7675 (goto-char end-pt)) ;; Already there, continue search with next instance | |
7676 (t | |
7677 ;; Delete identical interconnect | |
7678 (let ((case-fold-search nil)) ;; So we don't convert upper-to-lower, etc | |
7679 (while (verilog-re-search-forward "\\.\\s *\\([a-zA-Z0-9`_\$]+\\)*\\s *(\\s *\\1\\s *)\\s *" end-pt t) | |
7680 (delete-region (match-beginning 0) (match-end 0)) | |
7681 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0)))) ;; Keep it correct | |
7682 (while (or (looking-at "[ \t\n\f,]+") | |
7683 (looking-at "//[^\n]*")) | |
7684 (delete-region (match-beginning 0) (match-end 0)) | |
7685 (setq end-pt (- end-pt (- (match-end 0) (match-beginning 0))))))) | |
7686 (verilog-forward-close-paren) | |
7687 (backward-char 1) | |
7688 ;; Not verilog-re-search, as we don't want to strip comments | |
7689 (while (re-search-backward "[ \t\n\f]+" (- (point) 1) t) | |
7690 (delete-region (match-beginning 0) (match-end 0))) | |
7691 (insert "\n") | |
7692 (indent-to indent-pt) | |
7693 (insert "/*AUTOINST*/"))))))))) | |
7694 | |
7695 ;; | |
7696 ;; Auto save | |
7697 ;; | |
7698 | |
7699 (defun verilog-auto-save-check () | |
7700 "On saving see if we need auto update." | |
7701 (cond ((not verilog-auto-save-policy)) ; disabled | |
7702 ((not (save-excursion | |
7703 (save-match-data | |
7704 (let ((case-fold-search nil)) | |
7705 (goto-char (point-min)) | |
7706 (re-search-forward "AUTO" nil t)))))) | |
7707 ((eq verilog-auto-save-policy 'force) | |
7708 (verilog-auto)) | |
7709 ((not (buffer-modified-p))) | |
7710 ((eq verilog-auto-update-tick (buffer-modified-tick))) ; up-to-date | |
7711 ((eq verilog-auto-save-policy 'detect) | |
7712 (verilog-auto)) | |
7713 (t | |
7714 (when (yes-or-no-p "AUTO statements not recomputed, do it now? ") | |
7715 (verilog-auto)) | |
7716 ;; Don't ask again if didn't update | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7717 (set (make-local-variable 'verilog-auto-update-tick) (buffer-modified-tick)))) |
79545 | 7718 (when (not verilog-auto-star-save) |
7719 (verilog-delete-auto-star-implicit)) | |
7720 nil) ;; Always return nil -- we don't write the file ourselves | |
7721 | |
7722 (defun verilog-auto-read-locals () | |
7723 "Return file local variable segment at bottom of file." | |
7724 (save-excursion | |
7725 (goto-char (point-max)) | |
7726 (if (re-search-backward "Local Variables:" nil t) | |
7727 (buffer-substring-no-properties (point) (point-max)) | |
7728 ""))) | |
7729 | |
7730 (defun verilog-auto-reeval-locals (&optional force) | |
7731 "Read file local variable segment at bottom of file if it has changed. | |
7732 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
|
7733 (make-local-variable 'verilog-auto-last-file-locals) |
79545 | 7734 (let ((curlocal (verilog-auto-read-locals))) |
7735 (when (or force (not (equal verilog-auto-last-file-locals curlocal))) | |
7736 (setq verilog-auto-last-file-locals curlocal) | |
7737 ;; Note this may cause this function to be recursively invoked. | |
7738 ;; The above when statement will prevent it from recursing forever. | |
7739 (hack-local-variables) | |
7740 t))) | |
7741 | |
7742 ;; | |
7743 ;; Auto creation | |
7744 ;; | |
7745 | |
7746 (defun verilog-auto-arg-ports (sigs message indent-pt) | |
7747 "Print a list of ports for a AUTOINST. | |
7748 Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT." | |
7749 (when sigs | |
7750 (insert "\n") | |
7751 (indent-to indent-pt) | |
7752 (insert message) | |
7753 (insert "\n") | |
7754 (let ((space "")) | |
7755 (indent-to indent-pt) | |
7756 (while sigs | |
7757 (cond ((> (+ 2 (current-column) (length (verilog-sig-name (car sigs)))) fill-column) | |
7758 (insert "\n") | |
7759 (indent-to indent-pt)) | |
7760 (t (insert space))) | |
7761 (insert (verilog-sig-name (car sigs)) ",") | |
7762 (setq sigs (cdr sigs) | |
7763 space " "))))) | |
7764 | |
7765 (defun verilog-auto-arg () | |
7766 "Expand AUTOARG statements. | |
7767 Replace the argument declarations at the beginning of the | |
7768 module with ones automatically derived from input and output | |
7769 statements. This can be dangerous if the module is instantiated | |
7770 using position-based connections, so use only name-based when | |
7771 instantiating the resulting module. Long lines are split based | |
7772 on the `fill-column', see \\[set-fill-column]. | |
7773 | |
7774 Limitations: | |
7775 Concatenation and outputting partial busses is not supported. | |
7776 | |
7777 Typedefs must match `verilog-typedef-regexp', which is disabled by default. | |
7778 | |
7779 For example: | |
7780 | |
7781 module ex_arg (/*AUTOARG*/); | |
7782 input i; | |
7783 output o; | |
7784 endmodule | |
7785 | |
7786 Typing \\[verilog-auto] will make this into: | |
7787 | |
7788 module ex_arg (/*AUTOARG*/ | |
7789 // Outputs | |
7790 o, | |
7791 // Inputs | |
7792 i | |
7793 ); | |
7794 input i; | |
7795 output o; | |
7796 endmodule | |
7797 | |
7798 Any ports declared between the ( and /*AUTOARG*/ are presumed to be | |
7799 predeclared and are not redeclared by AUTOARG. AUTOARG will make a | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7800 conservative guess on adding a comma for the first signal, if you have |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7801 any ifdefs or complicated expressions before the AUTOARG you will need |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7802 to choose the comma yourself. |
79545 | 7803 |
7804 Avoid declaring ports manually, as it makes code harder to maintain." | |
7805 (save-excursion | |
7806 (let ((modi (verilog-modi-current)) | |
7807 (skip-pins (aref (verilog-read-arg-pins) 0))) | |
7808 (verilog-repair-open-comma) | |
7809 (verilog-auto-arg-ports (verilog-signals-not-in | |
7810 (verilog-modi-get-outputs modi) | |
7811 skip-pins) | |
7812 "// Outputs" | |
7813 verilog-indent-level-declaration) | |
7814 (verilog-auto-arg-ports (verilog-signals-not-in | |
7815 (verilog-modi-get-inouts modi) | |
7816 skip-pins) | |
7817 "// Inouts" | |
7818 verilog-indent-level-declaration) | |
7819 (verilog-auto-arg-ports (verilog-signals-not-in | |
7820 (verilog-modi-get-inputs modi) | |
7821 skip-pins) | |
7822 "// Inputs" | |
7823 verilog-indent-level-declaration) | |
7824 (verilog-repair-close-comma) | |
7825 (unless (eq (char-before) ?/ ) | |
7826 (insert "\n")) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7827 (indent-to verilog-indent-level-declaration)))) |
79545 | 7828 |
7829 (defun verilog-auto-inst-port-map (port-st) | |
7830 nil) | |
7831 | |
7832 (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning | |
7833 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning | |
7834 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning | |
7835 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning | |
7836 (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning | |
7837 | |
7838 (defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star) | |
7839 "Print out a instantiation connection for this PORT-ST. | |
7840 Insert to INDENT-PT, use template TPL-LIST. | |
7841 @ are instantiation numbers, replaced with TPL-NUM. | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7842 @\"(expression @)\" are evaluated, with @ as a variable. |
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
7843 If FOR-STAR add comment it is a .* expansion." |
79545 | 7844 (let* ((port (verilog-sig-name port-st)) |
7845 (tpl-ass (or (assoc port (car tpl-list)) | |
7846 (verilog-auto-inst-port-map port-st))) | |
7847 ;; vl-* are documented for user use | |
7848 (vl-name (verilog-sig-name port-st)) | |
7849 (vl-width (verilog-sig-width port-st)) | |
7850 (vl-bits (if (or verilog-auto-inst-vector | |
7851 (not (assoc port vector-skip-list)) | |
7852 (not (equal (verilog-sig-bits port-st) | |
7853 (verilog-sig-bits (assoc port vector-skip-list))))) | |
7854 (or (verilog-sig-bits port-st) "") | |
7855 "")) | |
7856 ;; Default if not found | |
7857 (tpl-net (if (verilog-sig-multidim port-st) | |
7858 (concat port "/*" (verilog-sig-multidim-string port-st) | |
7859 vl-bits "*/") | |
7860 (concat port vl-bits))) | |
7861 (case-fold-search nil)) | |
7862 ;; Find template | |
7863 (cond (tpl-ass ; Template of exact port name | |
7864 (setq tpl-net (nth 1 tpl-ass))) | |
7865 ((nth 1 tpl-list) ; Wildcards in template, search them | |
7866 (let ((wildcards (nth 1 tpl-list))) | |
7867 (while wildcards | |
7868 (when (string-match (nth 0 (car wildcards)) port) | |
7869 (setq tpl-ass (car wildcards) ; so allow @ parsing | |
7870 tpl-net (replace-match (nth 1 (car wildcards)) | |
7871 t nil port))) | |
7872 (setq wildcards (cdr wildcards)))))) | |
7873 ;; Parse Templated variable | |
7874 (when tpl-ass | |
7875 ;; Evaluate @"(lispcode)" | |
7876 (when (string-match "@\".*[^\\]\"" tpl-net) | |
7877 (while (string-match "@\"\\(\\([^\\\"]*\\(\\\\.\\)*\\)*\\)\"" tpl-net) | |
7878 (setq tpl-net | |
7879 (concat | |
7880 (substring tpl-net 0 (match-beginning 0)) | |
7881 (save-match-data | |
7882 (let* ((expr (match-string 1 tpl-net)) | |
7883 (value | |
7884 (progn | |
7885 (setq expr (verilog-string-replace-matches "\\\\\"" "\"" nil nil expr)) | |
7886 (setq expr (verilog-string-replace-matches "@" tpl-num nil nil expr)) | |
7887 (prin1 (eval (car (read-from-string expr))) | |
7888 (lambda (ch) ()))))) | |
7889 (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
|
7890 value)) |
79545 | 7891 (substring tpl-net (match-end 0)))))) |
7892 ;; Replace @ and [] magic variables in final output | |
7893 (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
|
7894 (setq tpl-net (verilog-string-replace-matches "\\[\\]" vl-bits nil nil tpl-net))) |
79545 | 7895 (indent-to indent-pt) |
7896 (insert "." port) | |
7897 (indent-to verilog-auto-inst-column) | |
7898 (insert "(" tpl-net "),") | |
7899 (cond (tpl-ass | |
7900 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16) | |
7901 verilog-auto-inst-column)) | |
7902 (insert " // Templated") | |
7903 (when verilog-auto-inst-template-numbers | |
7904 (insert " T" (int-to-string (nth 2 tpl-ass)) | |
7905 " L" (int-to-string (nth 3 tpl-ass))))) | |
7906 (for-star | |
7907 (indent-to (+ (if (< verilog-auto-inst-column 48) 24 16) | |
7908 verilog-auto-inst-column)) | |
7909 (insert " // Implicit .\*"))) ;For some reason the . or * must be escaped... | |
7910 (insert "\n"))) | |
7911 ;;(verilog-auto-inst-port (list "foo" "[5:0]") 10 (list (list "foo" "a@\"(% (+ @ 1) 4)\"a")) "3") | |
7912 ;;(x "incom[@\"(+ (* 8 @) 7)\":@\"(* 8 @)\"]") | |
7913 ;;(x ".out (outgo[@\"(concat (+ (* 8 @) 7) \\\":\\\" ( * 8 @))\"]));") | |
7914 | |
7915 (defun verilog-auto-inst-first () | |
7916 "Insert , etc before first ever port in this instant, as part of \\[verilog-auto-inst]." | |
7917 ;; Do we need a trailing comma? | |
7918 ;; There maybe a ifdef or something similar before us. What a mess. Thus | |
7919 ;; to avoid trouble we only insert on preceeding ) or *. | |
7920 ;; Insert first port on new line | |
7921 (insert "\n") ;; Must insert before search, so point will move forward if insert comma | |
7922 (save-excursion | |
7923 (verilog-re-search-backward "[^ \t\n\f]" nil nil) | |
7924 (when (looking-at ")\\|\\*") ;; Generally don't insert, unless we are fairly sure | |
7925 (forward-char 1) | |
7926 (insert ",")))) | |
7927 | |
7928 (defun verilog-auto-star () | |
7929 "Expand SystemVerilog .* pins, as part of \\[verilog-auto]. | |
7930 | |
7931 If `verilog-auto-star-expand' is set, .* pins are treated if they were | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7932 AUTOINST statements, otherwise they are ignored. For safety, Verilog mode |
79545 | 7933 will also ignore any .* that are not last in your pin list (this prevents |
7934 it from deleting pins following the .* when it expands the AUTOINST.) | |
7935 | |
7936 On writing your file, unless `verilog-auto-star-save' is set, any | |
7937 non-templated expanded pins will be removed. You may do this at any time | |
7938 with \\[verilog-delete-auto-star-implicit]. | |
7939 | |
7940 If you are converting a module to use .* for the first time, you may wish | |
7941 to use \\[verilog-inject-auto] and then replace the created AUTOINST with .*. | |
7942 | |
7943 See `verilog-auto-inst' for examples, templates, and more information." | |
7944 (when (verilog-auto-star-safe) | |
7945 (verilog-auto-inst))) | |
7946 | |
7947 (defun verilog-auto-inst () | |
7948 "Expand AUTOINST statements, as part of \\[verilog-auto]. | |
7949 Replace the pin connections to an instantiation with ones | |
7950 automatically derived from the module header of the instantiated netlist. | |
7951 | |
7952 If `verilog-auto-star-expand' is set, also expand SystemVerilog .* ports, | |
7953 and delete them before saving unless `verilog-auto-star-save' is set. | |
7954 See `verilog-auto-star' for more information. | |
7955 | |
7956 Limitations: | |
7957 Module names must be resolvable to filenames by adding a | |
7958 `verilog-library-extensions', and being found in the same directory, or | |
7959 by changing the variable `verilog-library-flags' or | |
7960 `verilog-library-directories'. Macros `modname are translated through the | |
7961 vh-{name} Emacs variable, if that is not found, it just ignores the `. | |
7962 | |
7963 In templates you must have one signal per line, ending in a ), or ));, | |
7964 and have proper () nesting, including a final ); to end the template. | |
7965 | |
7966 Typedefs must match `verilog-typedef-regexp', which is disabled by default. | |
7967 | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
7968 SystemVerilog multidimensional input/output has only experimental support. |
79545 | 7969 |
7970 For example, first take the submodule inst.v: | |
7971 | |
7972 module inst (o,i) | |
7973 output [31:0] o; | |
7974 input i; | |
7975 wire [31:0] o = {32{i}}; | |
7976 endmodule | |
7977 | |
7978 This is then used in a upper level module: | |
7979 | |
7980 module ex_inst (o,i) | |
7981 output o; | |
7982 input i; | |
7983 inst inst (/*AUTOINST*/); | |
7984 endmodule | |
7985 | |
7986 Typing \\[verilog-auto] will make this into: | |
7987 | |
7988 module ex_inst (o,i) | |
7989 output o; | |
7990 input i; | |
7991 inst inst (/*AUTOINST*/ | |
7992 // Outputs | |
7993 .ov (ov[31:0]), | |
7994 // Inputs | |
7995 .i (i)); | |
7996 endmodule | |
7997 | |
7998 Where the list of inputs and outputs came from the inst module. | |
7999 | |
8000 Exceptions: | |
8001 | |
8002 Unless you are instantiating a module multiple times, or the module is | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8003 something trivial like an adder, DO NOT CHANGE SIGNAL NAMES ACROSS HIERARCHY. |
79545 | 8004 It just makes for unmaintainable code. To sanitize signal names, try |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8005 vrename from http://www.veripool.com. |
79545 | 8006 |
8007 When you need to violate this suggestion there are two ways to list | |
8008 exceptions, placing them before the AUTOINST, or using templates. | |
8009 | |
8010 Any ports defined before the /*AUTOINST*/ are not included in the list of | |
8011 automatics. This is similar to making a template as described below, but | |
8012 is restricted to simple connections just like you normally make. Also note | |
8013 that any signals before the AUTOINST will only be picked up by AUTOWIRE if | |
8014 you have the appropriate // Input or // Output comment, and exactly the | |
8015 same line formatting as AUTOINST itself uses. | |
8016 | |
8017 inst inst (// Inputs | |
8018 .i (my_i_dont_mess_with_it), | |
8019 /*AUTOINST*/ | |
8020 // Outputs | |
8021 .ov (ov[31:0])); | |
8022 | |
8023 | |
8024 Templates: | |
8025 | |
8026 For multiple instantiations based upon a single template, create a | |
8027 commented out template: | |
8028 | |
8029 /* instantiating_module_name AUTO_TEMPLATE ( | |
8030 .sig3 (sigz[]), | |
8031 ); | |
8032 */ | |
8033 | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8034 Templates go ABOVE the instantiation(s). When an instantiation is |
79545 | 8035 expanded `verilog-mode' simply searches up for the closest template. |
8036 Thus you can have multiple templates for the same module, just alternate | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8037 between the template for an instantiation and the instantiation itself. |
79545 | 8038 |
8039 The module name must be the same as the name of the module in the | |
8040 instantiation name, and the code \"AUTO_TEMPLATE\" must be in these exact | |
8041 words and capitalized. Only signals that must be different for each | |
8042 instantiation need to be listed. | |
8043 | |
8044 Inside a template, a [] in a connection name (with nothing else inside | |
8045 the brackets) will be replaced by the same bus subscript as it is being | |
8046 connected to, or the [] will be removed if it is a single bit signal. | |
8047 Generally it is a good idea to do this for all connections in a template, | |
8048 as then they will work for any width signal, and with AUTOWIRE. See | |
8049 PTL_BUS becoming PTL_BUSNEW below. | |
8050 | |
8051 If you have a complicated template, set `verilog-auto-inst-template-numbers' | |
8052 to see which regexps are matching. Don't leave that mode set after | |
8053 debugging is completed though, it will result in lots of extra differences | |
8054 and merge conflicts. | |
8055 | |
8056 For example: | |
8057 | |
8058 /* psm_mas AUTO_TEMPLATE ( | |
8059 .ptl_bus (ptl_busnew[]), | |
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 .NotInTemplate (NotInTemplate), | |
8069 .ptl_bus (ptl_busnew[3:0]), // Templated | |
8070 .... | |
8071 | |
8072 @ Templates: | |
8073 | |
8074 It is common to instantiate a cell multiple times, so templates make it | |
8075 trivial to substitute part of the cell name into the connection name. | |
8076 | |
8077 /* cell_type AUTO_TEMPLATE <optional \"REGEXP\"> ( | |
8078 .sig1 (sigx[@]), | |
8079 .sig2 (sigy[@\"(% (+ 1 @) 4)\"]), | |
8080 ); | |
8081 */ | |
8082 | |
8083 If no regular expression is provided immediately after the AUTO_TEMPLATE | |
8084 keyword, then the @ character in any connection names will be replaced | |
8085 with the instantiation number; the first digits found in the cell's | |
8086 instantiation name. | |
8087 | |
8088 If a regular expression is provided, the @ character will be replaced | |
8089 with the first \(\) grouping that matches against the cell name. Using a | |
8090 regexp of \"\\([0-9]+\\)\" provides identical values for @ as when no | |
8091 regexp is provided. If you use multiple layers of parenthesis, | |
8092 \"test\\([^0-9]+\\)_\\([0-9]+\\)\" would replace @ with non-number | |
8093 characters after test and before _, whereas | |
8094 \"\\(test\\([a-z]+\\)_\\([0-9]+\\)\\)\" would replace @ with the entire | |
8095 match. | |
8096 | |
8097 For example: | |
8098 | |
8099 /* psm_mas AUTO_TEMPLATE ( | |
8100 .ptl_mapvalidx (ptl_mapvalid[@]), | |
8101 .ptl_mapvalidp1x (ptl_mapvalid[@\"(% (+ 1 @) 4)\"]), | |
8102 ); | |
8103 */ | |
8104 psm_mas ms2m (/*AUTOINST*/); | |
8105 | |
8106 Typing \\[verilog-auto] will make this into: | |
8107 | |
8108 psm_mas ms2m (/*AUTOINST*/ | |
8109 // Outputs | |
8110 .ptl_mapvalidx (ptl_mapvalid[2]), | |
8111 .ptl_mapvalidp1x (ptl_mapvalid[3])); | |
8112 | |
8113 Note the @ character was replaced with the 2 from \"ms2m\". | |
8114 | |
8115 Alternatively, using a regular expression for @: | |
8116 | |
8117 /* psm_mas AUTO_TEMPLATE \"_\\([a-z]+\\)\" ( | |
8118 .ptl_mapvalidx (@_ptl_mapvalid), | |
8119 .ptl_mapvalidp1x (ptl_mapvalid_@), | |
8120 ); | |
8121 */ | |
8122 psm_mas ms2_FOO (/*AUTOINST*/); | |
8123 psm_mas ms2_BAR (/*AUTOINST*/); | |
8124 | |
8125 Typing \\[verilog-auto] will make this into: | |
8126 | |
8127 psm_mas ms2_FOO (/*AUTOINST*/ | |
8128 // Outputs | |
8129 .ptl_mapvalidx (FOO_ptl_mapvalid), | |
8130 .ptl_mapvalidp1x (ptl_mapvalid_FOO)); | |
8131 psm_mas ms2_BAR (/*AUTOINST*/ | |
8132 // Outputs | |
8133 .ptl_mapvalidx (BAR_ptl_mapvalid), | |
8134 .ptl_mapvalidp1x (ptl_mapvalid_BAR)); | |
8135 | |
8136 | |
8137 Regexp Templates: | |
8138 | |
8139 A template entry of the form | |
8140 | |
8141 .pci_req\\([0-9]+\\)_l (pci_req_jtag_[\\1]), | |
8142 | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8143 will apply an Emacs style regular expression search for any port beginning |
79545 | 8144 in pci_req followed by numbers and ending in _l and connecting that to |
8145 the pci_req_jtag_[] net, with the bus subscript coming from what matches | |
8146 inside the first set of \\( \\). Thus pci_req2_l becomes pci_req_jtag_[2]. | |
8147 | |
8148 Since \\([0-9]+\\) is so common and ugly to read, a @ in the port name | |
8149 does the same thing. (Note a @ in the connection/replacement text is | |
8150 completely different -- still use \\1 there!) Thus this is the same as | |
8151 the above template: | |
8152 | |
8153 .pci_req@_l (pci_req_jtag_[\\1]), | |
8154 | |
8155 Here's another example to remove the _l, useful when naming conventions | |
8156 specify _ alone to mean active low. Note the use of [] to keep the bus | |
8157 subscript: | |
8158 | |
8159 .\\(.*\\)_l (\\1_[]), | |
8160 | |
8161 Lisp Templates: | |
8162 | |
8163 First any regular expression template is expanded. | |
8164 | |
8165 If the syntax @\"( ... )\" is found in a connection, the expression in | |
8166 quotes will be evaluated as a Lisp expression, with @ replaced by the | |
8167 instantiation number. The MAPVALIDP1X example above would put @+1 modulo | |
8168 4 into the brackets. Quote all double-quotes inside the expression with | |
8169 a leading backslash (\\\"). There are special variables defined that are | |
8170 useful in these Lisp functions: | |
8171 | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8172 vl-name Name portion of the input/output port. |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8173 vl-bits Bus bits portion of the input/output port ('[2:0]'). |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8174 vl-width Width of the input/output port ('3' for [2:0]). |
79545 | 8175 May be a (...) expression if bits isn't a constant. |
8176 vl-dir Direction of the pin input/output/inout. | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8177 vl-cell-type Module name/type of the cell ('psm_mas'). |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8178 vl-cell-name Instance name of the cell ('ms2m'). |
79545 | 8179 |
8180 Normal Lisp variables may be used in expressions. See | |
8181 `verilog-read-defines' which can set vh-{definename} variables for use | |
8182 here. Also, any comments of the form: | |
8183 | |
8184 /*AUTO_LISP(setq foo 1)*/ | |
8185 | |
8186 will evaluate any Lisp expression inside the parenthesis between the | |
8187 beginning of the buffer and the point of the AUTOINST. This allows | |
8188 functions to be defined or variables to be changed between instantiations. | |
8189 | |
8190 Note that when using lisp expressions errors may occur when @ is not a | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8191 number; you may need to use the standard Emacs Lisp functions |
79545 | 8192 `number-to-string' and `string-to-number'. |
8193 | |
8194 After the evaluation is completed, @ substitution and [] substitution | |
8195 occur." | |
8196 (save-excursion | |
8197 ;; Find beginning | |
8198 (let* ((pt (point)) | |
8199 (for-star (save-excursion (backward-char 2) (looking-at "\\.\\*"))) | |
8200 (indent-pt (save-excursion (verilog-backward-open-paren) | |
8201 (1+ (current-column)))) | |
8202 (verilog-auto-inst-column (max verilog-auto-inst-column | |
8203 (+ 16 (* 8 (/ (+ indent-pt 7) 8))))) | |
8204 (modi (verilog-modi-current)) | |
8205 (vector-skip-list (unless verilog-auto-inst-vector | |
8206 (verilog-modi-get-signals modi))) | |
8207 submod submodi inst skip-pins tpl-list tpl-num did-first) | |
8208 ;; Find module name that is instantiated | |
8209 (setq submod (verilog-read-inst-module) | |
8210 inst (verilog-read-inst-name) | |
8211 vl-cell-type submod | |
8212 vl-cell-name inst | |
8213 skip-pins (aref (verilog-read-inst-pins) 0)) | |
8214 | |
8215 ;; Parse any AUTO_LISP() before here | |
8216 (verilog-read-auto-lisp (point-min) pt) | |
8217 | |
8218 ;; Lookup position, etc of submodule | |
8219 ;; Note this may raise an error | |
8220 (when (setq submodi (verilog-modi-lookup submod t)) | |
8221 ;; If there's a number in the instantiation, it may be a argument to the | |
8222 ;; automatic variable instantiation program. | |
8223 (let* ((tpl-info (verilog-read-auto-template submod)) | |
8224 (tpl-regexp (aref tpl-info 0))) | |
8225 (setq tpl-num (if (string-match tpl-regexp inst) | |
8226 (match-string 1 inst) | |
8227 "") | |
8228 tpl-list (aref tpl-info 1))) | |
8229 ;; Find submodule's signals and dump | |
8230 (let ((sig-list (verilog-signals-not-in | |
8231 (verilog-modi-get-outputs submodi) | |
8232 skip-pins)) | |
8233 (vl-dir "output")) | |
8234 (when sig-list | |
8235 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) | |
8236 (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
|
8237 ;; 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
|
8238 (insert "// Outputs\n") |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8239 (mapc (lambda (port) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8240 (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
|
8241 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
|
8242 sig-list))) |
79545 | 8243 (let ((sig-list (verilog-signals-not-in |
8244 (verilog-modi-get-inouts submodi) | |
8245 skip-pins)) | |
8246 (vl-dir "inout")) | |
8247 (when sig-list | |
8248 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) | |
8249 (indent-to indent-pt) | |
8250 (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
|
8251 (mapc (lambda (port) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8252 (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
|
8253 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
|
8254 sig-list))) |
79545 | 8255 (let ((sig-list (verilog-signals-not-in |
8256 (verilog-modi-get-inputs submodi) | |
8257 skip-pins)) | |
8258 (vl-dir "input")) | |
8259 (when sig-list | |
8260 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) | |
8261 (indent-to indent-pt) | |
8262 (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
|
8263 (mapc (lambda (port) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8264 (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
|
8265 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
|
8266 sig-list))) |
79545 | 8267 ;; Kill extra semi |
8268 (save-excursion | |
8269 (cond (did-first | |
8270 (re-search-backward "," pt t) | |
8271 (delete-char 1) | |
8272 (insert ");") | |
8273 (search-forward "\n") ;; Added by inst-port | |
8274 (delete-backward-char 1) | |
8275 (if (search-forward ")" nil t) ;; From user, moved up a line | |
8276 (delete-backward-char 1)) | |
8277 (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
|
8278 (delete-backward-char 1))))))))) |
79545 | 8279 |
8280 (defun verilog-auto-inst-param () | |
8281 "Expand AUTOINSTPARAM statements, as part of \\[verilog-auto]. | |
8282 Replace the parameter connections to an instantiation with ones | |
8283 automatically derived from the module header of the instantiated netlist. | |
8284 | |
8285 See \\[verilog-auto-inst] for limitations, and templates to customize the | |
8286 output. | |
8287 | |
8288 For example, first take the submodule inst.v: | |
8289 | |
8290 module inst (o,i) | |
8291 parameter PAR; | |
8292 endmodule | |
8293 | |
8294 This is then used in a upper level module: | |
8295 | |
8296 module ex_inst (o,i) | |
8297 parameter PAR; | |
8298 inst #(/*AUTOINSTPARAM*/) | |
8299 inst (/*AUTOINST*/); | |
8300 endmodule | |
8301 | |
8302 Typing \\[verilog-auto] will make this into: | |
8303 | |
8304 module ex_inst (o,i) | |
8305 output o; | |
8306 input i; | |
8307 inst (/*AUTOINSTPARAM*/ | |
8308 // Parameters | |
8309 .PAR (PAR)); | |
8310 inst (/*AUTOINST*/); | |
8311 endmodule | |
8312 | |
8313 Where the list of parameter connections come from the inst module. | |
8314 | |
8315 Templates: | |
8316 | |
8317 You can customize the parameter connections using AUTO_TEMPLATEs, | |
8318 just as you would with \\[verilog-auto-inst]." | |
8319 (save-excursion | |
8320 ;; Find beginning | |
8321 (let* ((pt (point)) | |
8322 (indent-pt (save-excursion (verilog-backward-open-paren) | |
8323 (1+ (current-column)))) | |
8324 (verilog-auto-inst-column (max verilog-auto-inst-column | |
8325 (+ 16 (* 8 (/ (+ indent-pt 7) 8))))) | |
8326 (modi (verilog-modi-current)) | |
8327 (vector-skip-list (unless verilog-auto-inst-vector | |
8328 (verilog-modi-get-signals modi))) | |
8329 submod submodi inst skip-pins tpl-list tpl-num did-first) | |
8330 ;; Find module name that is instantiated | |
8331 (setq submod (save-excursion | |
8332 ;; Get to the point where AUTOINST normally is to read the module | |
8333 (verilog-re-search-forward-quick "[(;]" nil nil) | |
8334 (verilog-read-inst-module)) | |
8335 inst (save-excursion | |
8336 ;; Get to the point where AUTOINST normally is to read the module | |
8337 (verilog-re-search-forward-quick "[(;]" nil nil) | |
8338 (verilog-read-inst-name)) | |
8339 vl-cell-type submod | |
8340 vl-cell-name inst | |
8341 skip-pins (aref (verilog-read-inst-pins) 0)) | |
8342 | |
8343 ;; Parse any AUTO_LISP() before here | |
8344 (verilog-read-auto-lisp (point-min) pt) | |
8345 | |
8346 ;; Lookup position, etc of submodule | |
8347 ;; Note this may raise an error | |
8348 (when (setq submodi (verilog-modi-lookup submod t)) | |
8349 ;; If there's a number in the instantiation, it may be a argument to the | |
8350 ;; automatic variable instantiation program. | |
8351 (let* ((tpl-info (verilog-read-auto-template submod)) | |
8352 (tpl-regexp (aref tpl-info 0))) | |
8353 (setq tpl-num (if (string-match tpl-regexp inst) | |
8354 (match-string 1 inst) | |
8355 "") | |
8356 tpl-list (aref tpl-info 1))) | |
8357 ;; Find submodule's signals and dump | |
8358 (let ((sig-list (verilog-signals-not-in | |
8359 (verilog-modi-get-gparams submodi) | |
8360 skip-pins)) | |
8361 (vl-dir "parameter")) | |
8362 (when sig-list | |
8363 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) | |
8364 (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
|
8365 ;; 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
|
8366 (insert "// Parameters\n") |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8367 (mapc (lambda (port) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
8368 (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
|
8369 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
|
8370 sig-list))) |
79545 | 8371 ;; Kill extra semi |
8372 (save-excursion | |
8373 (cond (did-first | |
8374 (re-search-backward "," pt t) | |
8375 (delete-char 1) | |
8376 (insert ")") | |
8377 (search-forward "\n") ;; Added by inst-port | |
8378 (delete-backward-char 1) | |
8379 (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
|
8380 (delete-backward-char 1))))))))) |
79545 | 8381 |
8382 (defun verilog-auto-reg () | |
8383 "Expand AUTOREG statements, as part of \\[verilog-auto]. | |
8384 Make reg statements for any output that isn't already declared, | |
8385 and isn't a wire output from a block. | |
8386 | |
8387 Limitations: | |
8388 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'). | |
8389 | |
8390 This does NOT work on memories, declare those yourself. | |
8391 | |
8392 An example: | |
8393 | |
8394 module ex_reg (o,i) | |
8395 output o; | |
8396 input i; | |
8397 /*AUTOREG*/ | |
8398 always o = i; | |
8399 endmodule | |
8400 | |
8401 Typing \\[verilog-auto] will make this into: | |
8402 | |
8403 module ex_reg (o,i) | |
8404 output o; | |
8405 input i; | |
8406 /*AUTOREG*/ | |
8407 // Beginning of automatic regs (for this module's undeclared outputs) | |
8408 reg o; | |
8409 // End of automatics | |
8410 always o = i; | |
8411 endmodule" | |
8412 (save-excursion | |
8413 ;; Point must be at insertion point. | |
8414 (let* ((indent-pt (current-indentation)) | |
8415 (modi (verilog-modi-current)) | |
8416 (sig-list (verilog-signals-not-in | |
8417 (verilog-modi-get-outputs modi) | |
8418 (append (verilog-modi-get-wires modi) | |
8419 (verilog-modi-get-regs modi) | |
8420 (verilog-modi-get-assigns modi) | |
8421 (verilog-modi-get-consts modi) | |
8422 (verilog-modi-get-gparams modi) | |
8423 (verilog-modi-get-sub-outputs modi) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8424 (verilog-modi-get-sub-inouts modi))))) |
79545 | 8425 (forward-line 1) |
8426 (when sig-list | |
8427 (verilog-insert-indent "// Beginning of automatic regs (for this module's undeclared outputs)\n") | |
8428 (verilog-insert-definition sig-list "reg" indent-pt nil) | |
8429 (verilog-modi-cache-add-regs modi sig-list) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8430 (verilog-insert-indent "// End of automatics\n"))))) |
79545 | 8431 |
8432 (defun verilog-auto-reg-input () | |
8433 "Expand AUTOREGINPUT statements, as part of \\[verilog-auto]. | |
8434 Make reg statements instantiation inputs that aren't already declared. | |
8435 This is useful for making a top level shell for testing the module that is | |
8436 to be instantiated. | |
8437 | |
8438 Limitations: | |
8439 This ONLY detects inputs of AUTOINSTants (see `verilog-read-sub-decls'). | |
8440 | |
8441 This does NOT work on memories, declare those yourself. | |
8442 | |
8443 An example (see `verilog-auto-inst' for what else is going on here): | |
8444 | |
8445 module ex_reg_input (o,i) | |
8446 output o; | |
8447 input i; | |
8448 /*AUTOREGINPUT*/ | |
8449 inst inst (/*AUTOINST*/); | |
8450 endmodule | |
8451 | |
8452 Typing \\[verilog-auto] will make this into: | |
8453 | |
8454 module ex_reg_input (o,i) | |
8455 output o; | |
8456 input i; | |
8457 /*AUTOREGINPUT*/ | |
8458 // Beginning of automatic reg inputs (for undeclared ... | |
8459 reg [31:0] iv; // From inst of inst.v | |
8460 // End of automatics | |
8461 inst inst (/*AUTOINST*/ | |
8462 // Outputs | |
8463 .o (o[31:0]), | |
8464 // Inputs | |
8465 .iv (iv)); | |
8466 endmodule" | |
8467 (save-excursion | |
8468 ;; Point must be at insertion point. | |
8469 (let* ((indent-pt (current-indentation)) | |
8470 (modi (verilog-modi-current)) | |
8471 (sig-list (verilog-signals-combine-bus | |
8472 (verilog-signals-not-in | |
8473 (append (verilog-modi-get-sub-inputs modi) | |
8474 (verilog-modi-get-sub-inouts modi)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8475 (verilog-modi-get-signals modi))))) |
79545 | 8476 (forward-line 1) |
8477 (when sig-list | |
8478 (verilog-insert-indent "// Beginning of automatic reg inputs (for undeclared instantiated-module inputs)\n") | |
8479 (verilog-insert-definition sig-list "reg" indent-pt nil) | |
8480 (verilog-modi-cache-add-regs modi sig-list) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8481 (verilog-insert-indent "// End of automatics\n"))))) |
79545 | 8482 |
8483 (defun verilog-auto-wire () | |
8484 "Expand AUTOWIRE statements, as part of \\[verilog-auto]. | |
8485 Make wire statements for instantiations outputs that aren't | |
8486 already declared. | |
8487 | |
8488 Limitations: | |
8489 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'), | |
8490 and all busses must have widths, such as those from AUTOINST, or using [] | |
8491 in AUTO_TEMPLATEs. | |
8492 | |
8493 This does NOT work on memories or SystemVerilog .name connections, | |
8494 declare those yourself. | |
8495 | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8496 Verilog mode will add \"Couldn't Merge\" comments to signals it cannot |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8497 determine how to bus together. This occurs when you have ports with |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8498 non-numeric or non-sequential bus subscripts. If Verilog mode |
79545 | 8499 mis-guessed, you'll have to declare them yourself. |
8500 | |
8501 An example (see `verilog-auto-inst' for what else is going on here): | |
8502 | |
8503 module ex_wire (o,i) | |
8504 output o; | |
8505 input i; | |
8506 /*AUTOWIRE*/ | |
8507 inst inst (/*AUTOINST*/); | |
8508 endmodule | |
8509 | |
8510 Typing \\[verilog-auto] will make this into: | |
8511 | |
8512 module ex_wire (o,i) | |
8513 output o; | |
8514 input i; | |
8515 /*AUTOWIRE*/ | |
8516 // Beginning of automatic wires | |
8517 wire [31:0] ov; // From inst of inst.v | |
8518 // End of automatics | |
8519 inst inst (/*AUTOINST*/ | |
8520 // Outputs | |
8521 .ov (ov[31:0]), | |
8522 // Inputs | |
8523 .i (i)); | |
8524 wire o = | ov; | |
8525 endmodule" | |
8526 (save-excursion | |
8527 ;; Point must be at insertion point. | |
8528 (let* ((indent-pt (current-indentation)) | |
8529 (modi (verilog-modi-current)) | |
8530 (sig-list (verilog-signals-combine-bus | |
8531 (verilog-signals-not-in | |
8532 (append (verilog-modi-get-sub-outputs modi) | |
8533 (verilog-modi-get-sub-inouts modi)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8534 (verilog-modi-get-signals modi))))) |
79545 | 8535 (forward-line 1) |
8536 (when sig-list | |
8537 (verilog-insert-indent "// Beginning of automatic wires (for undeclared instantiated-module outputs)\n") | |
8538 (verilog-insert-definition sig-list "wire" indent-pt nil) | |
8539 (verilog-modi-cache-add-wires modi sig-list) | |
8540 (verilog-insert-indent "// End of automatics\n") | |
8541 (when nil ;; Too slow on huge modules, plus makes everyone's module change | |
8542 (beginning-of-line) | |
8543 (setq pnt (point)) | |
80024
9231505e5076
* progmodes/verilog-mode.el (verilog-declaration-core-re):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79986
diff
changeset
|
8544 (verilog-pretty-declarations quiet) |
79545 | 8545 (goto-char pnt) |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8546 (verilog-pretty-expr "//")))))) |
79545 | 8547 |
8548 (defun verilog-auto-output () | |
8549 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto]. | |
8550 Make output statements for any output signal from an /*AUTOINST*/ that | |
8551 isn't a input to another AUTOINST. This is useful for modules which | |
8552 only instantiate other modules. | |
8553 | |
8554 Limitations: | |
8555 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'). | |
8556 | |
8557 If placed inside the parenthesis of a module declaration, it creates | |
8558 Verilog 2001 style, else uses Verilog 1995 style. | |
8559 | |
8560 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's | |
8561 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE). | |
8562 | |
8563 Typedefs must match `verilog-typedef-regexp', which is disabled by default. | |
8564 | |
8565 Signals matching `verilog-auto-output-ignore-regexp' are not included. | |
8566 | |
8567 An example (see `verilog-auto-inst' for what else is going on here): | |
8568 | |
8569 module ex_output (ov,i) | |
8570 input i; | |
8571 /*AUTOOUTPUT*/ | |
8572 inst inst (/*AUTOINST*/); | |
8573 endmodule | |
8574 | |
8575 Typing \\[verilog-auto] will make this into: | |
8576 | |
8577 module ex_output (ov,i) | |
8578 input i; | |
8579 /*AUTOOUTPUT*/ | |
8580 // Beginning of automatic outputs (from unused autoinst outputs) | |
8581 output [31:0] ov; // From inst of inst.v | |
8582 // End of automatics | |
8583 inst inst (/*AUTOINST*/ | |
8584 // Outputs | |
8585 .ov (ov[31:0]), | |
8586 // Inputs | |
8587 .i (i)); | |
8588 endmodule" | |
8589 (save-excursion | |
8590 ;; Point must be at insertion point. | |
8591 (let* ((indent-pt (current-indentation)) | |
8592 (v2k (verilog-in-paren)) | |
8593 (modi (verilog-modi-current)) | |
8594 (sig-list (verilog-signals-not-in | |
8595 (verilog-modi-get-sub-outputs modi) | |
8596 (append (verilog-modi-get-outputs modi) | |
8597 (verilog-modi-get-inouts modi) | |
8598 (verilog-modi-get-sub-inputs modi) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8599 (verilog-modi-get-sub-inouts modi))))) |
79545 | 8600 (setq sig-list (verilog-signals-not-matching-regexp |
8601 sig-list verilog-auto-output-ignore-regexp)) | |
8602 (forward-line 1) | |
8603 (when v2k (verilog-repair-open-comma)) | |
8604 (when sig-list | |
8605 (verilog-insert-indent "// Beginning of automatic outputs (from unused autoinst outputs)\n") | |
8606 (verilog-insert-definition sig-list "output" indent-pt v2k) | |
8607 (verilog-modi-cache-add-outputs modi sig-list) | |
8608 (verilog-insert-indent "// End of automatics\n")) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8609 (when v2k (verilog-repair-close-comma))))) |
79545 | 8610 |
8611 (defun verilog-auto-output-every () | |
8612 "Expand AUTOOUTPUTEVERY statements, as part of \\[verilog-auto]. | |
8613 Make output statements for any signals that aren't primary inputs or | |
8614 outputs already. This makes every signal in the design a output. This is | |
8615 useful to get Synopsys to preserve every signal in the design, since it | |
8616 won't optimize away the outputs. | |
8617 | |
8618 An example: | |
8619 | |
8620 module ex_output_every (o,i,tempa,tempb) | |
8621 output o; | |
8622 input i; | |
8623 /*AUTOOUTPUTEVERY*/ | |
8624 wire tempa = i; | |
8625 wire tempb = tempa; | |
8626 wire o = tempb; | |
8627 endmodule | |
8628 | |
8629 Typing \\[verilog-auto] will make this into: | |
8630 | |
8631 module ex_output_every (o,i,tempa,tempb) | |
8632 output o; | |
8633 input i; | |
8634 /*AUTOOUTPUTEVERY*/ | |
8635 // Beginning of automatic outputs (every signal) | |
8636 output tempb; | |
8637 output tempa; | |
8638 // End of automatics | |
8639 wire tempa = i; | |
8640 wire tempb = tempa; | |
8641 wire o = tempb; | |
8642 endmodule" | |
8643 (save-excursion | |
8644 ;;Point must be at insertion point | |
8645 (let* ((indent-pt (current-indentation)) | |
8646 (v2k (verilog-in-paren)) | |
8647 (modi (verilog-modi-current)) | |
8648 (sig-list (verilog-signals-combine-bus | |
8649 (verilog-signals-not-in | |
8650 (verilog-modi-get-signals modi) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8651 (verilog-modi-get-ports modi))))) |
79545 | 8652 (forward-line 1) |
8653 (when v2k (verilog-repair-open-comma)) | |
8654 (when sig-list | |
8655 (verilog-insert-indent "// Beginning of automatic outputs (every signal)\n") | |
8656 (verilog-insert-definition sig-list "output" indent-pt v2k) | |
8657 (verilog-modi-cache-add-outputs modi sig-list) | |
8658 (verilog-insert-indent "// End of automatics\n")) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8659 (when v2k (verilog-repair-close-comma))))) |
79545 | 8660 |
8661 (defun verilog-auto-input () | |
8662 "Expand AUTOINPUT statements, as part of \\[verilog-auto]. | |
8663 Make input statements for any input signal into an /*AUTOINST*/ that | |
8664 isn't declared elsewhere inside the module. This is useful for modules which | |
8665 only instantiate other modules. | |
8666 | |
8667 Limitations: | |
8668 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'). | |
8669 | |
8670 If placed inside the parenthesis of a module declaration, it creates | |
8671 Verilog 2001 style, else uses Verilog 1995 style. | |
8672 | |
8673 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's | |
8674 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE). | |
8675 | |
8676 Typedefs must match `verilog-typedef-regexp', which is disabled by default. | |
8677 | |
8678 Signals matching `verilog-auto-input-ignore-regexp' are not included. | |
8679 | |
8680 An example (see `verilog-auto-inst' for what else is going on here): | |
8681 | |
8682 module ex_input (ov,i) | |
8683 output [31:0] ov; | |
8684 /*AUTOINPUT*/ | |
8685 inst inst (/*AUTOINST*/); | |
8686 endmodule | |
8687 | |
8688 Typing \\[verilog-auto] will make this into: | |
8689 | |
8690 module ex_input (ov,i) | |
8691 output [31:0] ov; | |
8692 /*AUTOINPUT*/ | |
8693 // Beginning of automatic inputs (from unused autoinst inputs) | |
8694 input i; // From inst of inst.v | |
8695 // End of automatics | |
8696 inst inst (/*AUTOINST*/ | |
8697 // Outputs | |
8698 .ov (ov[31:0]), | |
8699 // Inputs | |
8700 .i (i)); | |
8701 endmodule" | |
8702 (save-excursion | |
8703 (let* ((indent-pt (current-indentation)) | |
8704 (v2k (verilog-in-paren)) | |
8705 (modi (verilog-modi-current)) | |
8706 (sig-list (verilog-signals-not-in | |
8707 (verilog-modi-get-sub-inputs modi) | |
8708 (append (verilog-modi-get-inputs modi) | |
8709 (verilog-modi-get-inouts modi) | |
8710 (verilog-modi-get-wires modi) | |
8711 (verilog-modi-get-regs modi) | |
8712 (verilog-modi-get-consts modi) | |
8713 (verilog-modi-get-gparams modi) | |
8714 (verilog-modi-get-sub-outputs modi) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8715 (verilog-modi-get-sub-inouts modi))))) |
79545 | 8716 (setq sig-list (verilog-signals-not-matching-regexp |
8717 sig-list verilog-auto-input-ignore-regexp)) | |
8718 (forward-line 1) | |
8719 (when v2k (verilog-repair-open-comma)) | |
8720 (when sig-list | |
8721 (verilog-insert-indent "// Beginning of automatic inputs (from unused autoinst inputs)\n") | |
8722 (verilog-insert-definition sig-list "input" indent-pt v2k) | |
8723 (verilog-modi-cache-add-inputs modi sig-list) | |
8724 (verilog-insert-indent "// End of automatics\n")) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8725 (when v2k (verilog-repair-close-comma))))) |
79545 | 8726 |
8727 (defun verilog-auto-inout () | |
8728 "Expand AUTOINOUT statements, as part of \\[verilog-auto]. | |
8729 Make inout statements for any inout signal in an /*AUTOINST*/ that | |
8730 isn't declared elsewhere inside the module. | |
8731 | |
8732 Limitations: | |
8733 This ONLY detects outputs of AUTOINSTants (see `verilog-read-sub-decls'). | |
8734 | |
8735 If placed inside the parenthesis of a module declaration, it creates | |
8736 Verilog 2001 style, else uses Verilog 1995 style. | |
8737 | |
8738 If any concatenation, or bit-subscripts are missing in the AUTOINSTant's | |
8739 instantiation, all bets are off. (For example due to a AUTO_TEMPLATE). | |
8740 | |
8741 Typedefs must match `verilog-typedef-regexp', which is disabled by default. | |
8742 | |
8743 Signals matching `verilog-auto-inout-ignore-regexp' are not included. | |
8744 | |
8745 An example (see `verilog-auto-inst' for what else is going on here): | |
8746 | |
8747 module ex_inout (ov,i) | |
8748 input i; | |
8749 /*AUTOINOUT*/ | |
8750 inst inst (/*AUTOINST*/); | |
8751 endmodule | |
8752 | |
8753 Typing \\[verilog-auto] will make this into: | |
8754 | |
8755 module ex_inout (ov,i) | |
8756 input i; | |
8757 /*AUTOINOUT*/ | |
8758 // Beginning of automatic inouts (from unused autoinst inouts) | |
8759 inout [31:0] ov; // From inst of inst.v | |
8760 // End of automatics | |
8761 inst inst (/*AUTOINST*/ | |
8762 // Inouts | |
8763 .ov (ov[31:0]), | |
8764 // Inputs | |
8765 .i (i)); | |
8766 endmodule" | |
8767 (save-excursion | |
8768 ;; Point must be at insertion point. | |
8769 (let* ((indent-pt (current-indentation)) | |
8770 (v2k (verilog-in-paren)) | |
8771 (modi (verilog-modi-current)) | |
8772 (sig-list (verilog-signals-not-in | |
8773 (verilog-modi-get-sub-inouts modi) | |
8774 (append (verilog-modi-get-outputs modi) | |
8775 (verilog-modi-get-inouts modi) | |
8776 (verilog-modi-get-inputs modi) | |
8777 (verilog-modi-get-sub-inputs modi) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8778 (verilog-modi-get-sub-outputs modi))))) |
79545 | 8779 (setq sig-list (verilog-signals-not-matching-regexp |
8780 sig-list verilog-auto-inout-ignore-regexp)) | |
8781 (forward-line 1) | |
8782 (when v2k (verilog-repair-open-comma)) | |
8783 (when sig-list | |
8784 (verilog-insert-indent "// Beginning of automatic inouts (from unused autoinst inouts)\n") | |
8785 (verilog-insert-definition sig-list "inout" indent-pt v2k) | |
8786 (verilog-modi-cache-add-inouts modi sig-list) | |
8787 (verilog-insert-indent "// End of automatics\n")) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8788 (when v2k (verilog-repair-close-comma))))) |
79545 | 8789 |
8790 (defun verilog-auto-inout-module () | |
8791 "Expand AUTOINOUTMODULE statements, as part of \\[verilog-auto]. | |
8792 Take input/output/inout statements from the specified module and insert | |
8793 into the current module. This is useful for making null templates and | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8794 shell modules which need to have identical I/O with another module. |
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
8795 Any I/O which are already defined in this module will not be redefined. |
79545 | 8796 |
8797 Limitations: | |
8798 If placed inside the parenthesis of a module declaration, it creates | |
8799 Verilog 2001 style, else uses Verilog 1995 style. | |
8800 | |
8801 Concatenation and outputting partial busses is not supported. | |
8802 | |
8803 Module names must be resolvable to filenames. See `verilog-auto-inst'. | |
8804 | |
8805 Signals are not inserted in the same order as in the original module, | |
8806 though they will appear to be in the same order to a AUTOINST | |
8807 instantiating either module. | |
8808 | |
8809 An example: | |
8810 | |
8811 module ex_shell (/*AUTOARG*/) | |
8812 /*AUTOINOUTMODULE(\"ex_main\")*/ | |
8813 endmodule | |
8814 | |
8815 module ex_main (i,o,io) | |
8816 input i; | |
8817 output o; | |
8818 inout io; | |
8819 endmodule | |
8820 | |
8821 Typing \\[verilog-auto] will make this into: | |
8822 | |
8823 module ex_shell (/*AUTOARG*/i,o,io) | |
8824 /*AUTOINOUTMODULE(\"ex_main\")*/ | |
8825 // Beginning of automatic in/out/inouts (from specific module) | |
8826 input i; | |
8827 output o; | |
8828 inout io; | |
8829 // End of automatics | |
8830 endmodule" | |
8831 (save-excursion | |
8832 (let* ((submod (car (verilog-read-auto-params 1))) submodi) | |
8833 ;; Lookup position, etc of co-module | |
8834 ;; Note this may raise an error | |
8835 (when (setq submodi (verilog-modi-lookup submod t)) | |
8836 (let* ((indent-pt (current-indentation)) | |
8837 (v2k (verilog-in-paren)) | |
8838 (modi (verilog-modi-current)) | |
8839 (sig-list-i (verilog-signals-not-in | |
8840 (verilog-modi-get-inputs submodi) | |
8841 (append (verilog-modi-get-inputs modi)))) | |
8842 (sig-list-o (verilog-signals-not-in | |
8843 (verilog-modi-get-outputs submodi) | |
8844 (append (verilog-modi-get-outputs modi)))) | |
8845 (sig-list-io (verilog-signals-not-in | |
8846 (verilog-modi-get-inouts submodi) | |
8847 (append (verilog-modi-get-inouts modi))))) | |
8848 (forward-line 1) | |
8849 (when v2k (verilog-repair-open-comma)) | |
8850 (when (or sig-list-i sig-list-o sig-list-io) | |
8851 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n") | |
8852 ;; Don't sort them so a upper AUTOINST will match the main module | |
8853 (verilog-insert-definition sig-list-o "output" indent-pt v2k t) | |
8854 (verilog-insert-definition sig-list-io "inout" indent-pt v2k t) | |
8855 (verilog-insert-definition sig-list-i "input" indent-pt v2k t) | |
8856 (verilog-modi-cache-add-inputs modi sig-list-i) | |
8857 (verilog-modi-cache-add-outputs modi sig-list-o) | |
8858 (verilog-modi-cache-add-inouts modi sig-list-io) | |
8859 (verilog-insert-indent "// End of automatics\n")) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8860 (when v2k (verilog-repair-close-comma))))))) |
79545 | 8861 |
8862 (defun verilog-auto-sense-sigs (modi presense-sigs) | |
8863 "Return list of signals for current AUTOSENSE block." | |
8864 (let* ((sigss (verilog-read-always-signals)) | |
8865 (sig-list (verilog-signals-not-params | |
8866 (verilog-signals-not-in (verilog-alw-get-inputs sigss) | |
8867 (append (and (not verilog-auto-sense-include-inputs) | |
8868 (verilog-alw-get-outputs sigss)) | |
8869 (verilog-modi-get-consts modi) | |
8870 (verilog-modi-get-gparams modi) | |
8871 presense-sigs))))) | |
8872 sig-list)) | |
8873 | |
8874 (defun verilog-auto-sense () | |
8875 "Expand AUTOSENSE statements, as part of \\[verilog-auto]. | |
8876 Replace the always (/*AUTOSENSE*/) sensitivity list (/*AS*/ for short) | |
8877 with one automatically derived from all inputs declared in the always | |
8878 statement. Signals that are generated within the same always block are NOT | |
8879 placed into the sensitivity list (see `verilog-auto-sense-include-inputs'). | |
8880 Long lines are split based on the `fill-column', see \\[set-fill-column]. | |
8881 | |
8882 Limitations: | |
8883 Verilog does not allow memories (multidimensional arrays) in sensitivity | |
8884 lists. AUTOSENSE will thus exclude them, and add a /*memory or*/ comment. | |
8885 | |
8886 Constant signals: | |
8887 AUTOSENSE cannot always determine if a `define is a constant or a signal | |
8888 (it could be in a include file for example). If a `define or other signal | |
8889 is put into the AUTOSENSE list and is not desired, use the AUTO_CONSTANT | |
8890 declaration anywhere in the module (parenthesis are required): | |
8891 | |
8892 /* AUTO_CONSTANT ( `this_is_really_constant_dont_autosense_it ) */ | |
8893 | |
8894 Better yet, use a parameter, which will be understood to be constant | |
8895 automatically. | |
8896 | |
8897 OOps! | |
8898 If AUTOSENSE makes a mistake, please report it. (First try putting | |
8899 a begin/end after your always!) As a workaround, if a signal that | |
8900 shouldn't be in the sensitivity list was, use the AUTO_CONSTANT above. | |
8901 If a signal should be in the sensitivity list wasn't, placing it before | |
8902 the /*AUTOSENSE*/ comment will prevent it from being deleted when the | |
8903 autos are updated (or added if it occurs there already). | |
8904 | |
8905 An example: | |
8906 | |
8907 always @ (/*AUTOSENSE*/) begin | |
8908 /* AUTO_CONSTANT (`constant) */ | |
8909 outin = ina | inb | `constant; | |
8910 out = outin; | |
8911 end | |
8912 | |
8913 Typing \\[verilog-auto] will make this into: | |
8914 | |
8915 always @ (/*AUTOSENSE*/ina or inb) begin | |
8916 /* AUTO_CONSTANT (`constant) */ | |
8917 outin = ina | inb | `constant; | |
8918 out = outin; | |
8919 end" | |
8920 (save-excursion | |
8921 ;; Find beginning | |
8922 (let* ((start-pt (save-excursion | |
8923 (verilog-re-search-backward "(" nil t) | |
8924 (point))) | |
8925 (indent-pt (save-excursion | |
8926 (or (and (goto-char start-pt) (1+ (current-column))) | |
8927 (current-indentation)))) | |
8928 (modi (verilog-modi-current)) | |
8929 (sig-memories (verilog-signals-memory | |
8930 (append | |
8931 (verilog-modi-get-regs modi) | |
8932 (verilog-modi-get-wires modi)))) | |
8933 sig-list not-first presense-sigs) | |
8934 ;; Read signals in always, eliminate outputs from sense list | |
8935 (setq presense-sigs (verilog-signals-from-signame | |
8936 (save-excursion | |
8937 (verilog-read-signals start-pt (point))))) | |
8938 (setq sig-list (verilog-auto-sense-sigs modi presense-sigs)) | |
8939 (when sig-memories | |
8940 (let ((tlen (length sig-list))) | |
8941 (setq sig-list (verilog-signals-not-in sig-list sig-memories)) | |
8942 (if (not (eq tlen (length sig-list))) (insert " /*memory or*/ ")))) | |
8943 (if (and presense-sigs ;; Add a "or" if not "(.... or /*AUTOSENSE*/" | |
8944 (save-excursion (goto-char (point)) | |
8945 (verilog-re-search-backward "[a-zA-Z0-9$_.%`]+" start-pt t) | |
8946 (verilog-re-search-backward "\\s-" start-pt t) | |
8947 (while (looking-at "\\s-`endif") | |
8948 (verilog-re-search-backward "[a-zA-Z0-9$_.%`]+" start-pt t) | |
8949 (verilog-re-search-backward "\\s-" start-pt t)) | |
8950 (not (looking-at "\\s-or\\b")))) | |
8951 (setq not-first t)) | |
8952 (setq sig-list (sort sig-list `verilog-signals-sort-compare)) | |
8953 (while sig-list | |
8954 (cond ((> (+ 4 (current-column) (length (verilog-sig-name (car sig-list)))) fill-column) ;+4 for width of or | |
8955 (insert "\n") | |
8956 (indent-to indent-pt) | |
8957 (if not-first (insert "or "))) | |
8958 (not-first (insert " or "))) | |
8959 (insert (verilog-sig-name (car sig-list))) | |
8960 (setq sig-list (cdr sig-list) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
8961 not-first t))))) |
79545 | 8962 |
8963 (defun verilog-auto-reset () | |
8964 "Expand AUTORESET statements, as part of \\[verilog-auto]. | |
8965 Replace the /*AUTORESET*/ comment with code to initialize all | |
8966 registers set elsewhere in the always block. | |
8967 | |
8968 Limitations: | |
8969 AUTORESET will not clear memories. | |
8970 | |
8971 AUTORESET uses <= if there are any <= in the block, else it uses =. | |
8972 | |
8973 /*AUTORESET*/ presumes that any signals mentioned between the previous | |
8974 begin/case/if statement and the AUTORESET comment are being reset manually | |
8975 and should not be automatically reset. This includes omitting any signals | |
8976 used on the right hand side of assignments. | |
8977 | |
8978 By default, AUTORESET will include the width of the signal in the autos, | |
8979 this is a recent change. To control this behavior, see | |
8980 `verilog-auto-reset-widths'. | |
8981 | |
8982 AUTORESET ties signals to deasserted, which is presumed to be zero. | |
8983 Signals that match `verilog-active-low-regexp' will be deasserted by tieing | |
8984 them to a one. | |
8985 | |
8986 An example: | |
8987 | |
8988 always @(posedge clk or negedge reset_l) begin | |
8989 if (!reset_l) begin | |
8990 c <= 1; | |
8991 /*AUTORESET*/ | |
8992 end | |
8993 else begin | |
8994 a <= in_a; | |
8995 b <= in_b; | |
8996 c <= in_c; | |
8997 end | |
8998 end | |
8999 | |
9000 Typing \\[verilog-auto] will make this into: | |
9001 | |
9002 always @(posedge core_clk or negedge reset_l) begin | |
9003 if (!reset_l) begin | |
9004 c <= 1; | |
9005 /*AUTORESET*/ | |
9006 // Beginning of autoreset for uninitialized flops | |
9007 a <= 0; | |
9008 b <= 0; | |
9009 // End of automatics | |
9010 end | |
9011 else begin | |
9012 a <= in_a; | |
9013 b <= in_b; | |
9014 c <= in_c; | |
9015 end | |
9016 end" | |
9017 | |
9018 (interactive) | |
9019 (save-excursion | |
9020 ;; Find beginning | |
9021 (let* ((indent-pt (current-indentation)) | |
9022 (modi (verilog-modi-current)) | |
9023 (all-list (verilog-modi-get-signals modi)) | |
9024 sigss sig-list prereset-sigs assignment-str) | |
9025 ;; Read signals in always, eliminate outputs from reset list | |
9026 (setq prereset-sigs (verilog-signals-from-signame | |
9027 (save-excursion | |
9028 (verilog-read-signals | |
9029 (save-excursion | |
9030 (verilog-re-search-backward "\\(@\\|\\<begin\\>\\|\\<if\\>\\|\\<case\\>\\)" nil t) | |
9031 (point)) | |
9032 (point))))) | |
9033 (save-excursion | |
9034 (verilog-re-search-backward "@" nil t) | |
9035 (setq sigss (verilog-read-always-signals))) | |
9036 (setq assignment-str (if (verilog-alw-get-uses-delayed sigss) | |
9037 (concat " <= " verilog-assignment-delay) | |
9038 " = ")) | |
9039 (setq sig-list (verilog-signals-not-in (verilog-alw-get-outputs sigss) | |
9040 prereset-sigs)) | |
9041 (setq sig-list (sort sig-list `verilog-signals-sort-compare)) | |
9042 (when sig-list | |
9043 (insert "\n"); | |
9044 (indent-to indent-pt) | |
9045 (insert "// Beginning of autoreset for uninitialized flops\n"); | |
9046 (indent-to indent-pt) | |
9047 (while sig-list | |
9048 (let ((sig (or (assoc (verilog-sig-name (car sig-list)) all-list) ;; As sig-list has no widths | |
9049 (car sig-list)))) | |
9050 (insert (verilog-sig-name sig) | |
9051 assignment-str | |
9052 (verilog-sig-tieoff sig (not verilog-auto-reset-widths)) | |
9053 ";\n") | |
9054 (indent-to indent-pt) | |
9055 (setq sig-list (cdr sig-list)))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9056 (insert "// End of automatics"))))) |
79545 | 9057 |
9058 (defun verilog-auto-tieoff () | |
9059 "Expand AUTOTIEOFF statements, as part of \\[verilog-auto]. | |
9060 Replace the /*AUTOTIEOFF*/ comment with code to wire-tie all unused output | |
9061 signals to deasserted. | |
9062 | |
9063 /*AUTOTIEOFF*/ is used to make stub modules; modules that have the same | |
9064 input/output list as another module, but no internals. Specifically, it | |
9065 finds all outputs in the module, and if that input is not otherwise declared | |
9066 as a register or wire, creates a tieoff. | |
9067 | |
9068 AUTORESET ties signals to deasserted, which is presumed to be zero. | |
9069 Signals that match `verilog-active-low-regexp' will be deasserted by tieing | |
9070 them to a one. | |
9071 | |
9072 An example of making a stub for another module: | |
9073 | |
9074 module FooStub (/*AUTOINST*/); | |
9075 /*AUTOINOUTMODULE(\"Foo\")*/ | |
9076 /*AUTOTIEOFF*/ | |
9077 // verilator lint_off UNUSED | |
9078 wire _unused_ok = &{1'b0, | |
9079 /*AUTOUNUSED*/ | |
9080 1'b0}; | |
9081 // verilator lint_on UNUSED | |
9082 endmodule | |
9083 | |
9084 Typing \\[verilog-auto] will make this into: | |
9085 | |
9086 module FooStub (/*AUTOINST*/...); | |
9087 /*AUTOINOUTMODULE(\"Foo\")*/ | |
9088 // Beginning of autotieoff | |
9089 output [2:0] foo; | |
9090 // End of automatics | |
9091 | |
9092 /*AUTOTIEOFF*/ | |
9093 // Beginning of autotieoff | |
9094 wire [2:0] foo = 3'b0; | |
9095 // End of automatics | |
9096 ... | |
9097 endmodule" | |
9098 (interactive) | |
9099 (save-excursion | |
9100 ;; Find beginning | |
9101 (let* ((indent-pt (current-indentation)) | |
9102 (modi (verilog-modi-current)) | |
9103 (sig-list (verilog-signals-not-in | |
9104 (verilog-modi-get-outputs modi) | |
9105 (append (verilog-modi-get-wires modi) | |
9106 (verilog-modi-get-regs modi) | |
9107 (verilog-modi-get-assigns modi) | |
9108 (verilog-modi-get-consts modi) | |
9109 (verilog-modi-get-gparams modi) | |
9110 (verilog-modi-get-sub-outputs modi) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9111 (verilog-modi-get-sub-inouts modi))))) |
79545 | 9112 (when sig-list |
9113 (forward-line 1) | |
9114 (verilog-insert-indent "// Beginning of automatic tieoffs (for this module's unterminated outputs)\n") | |
9115 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)) | |
9116 (verilog-modi-cache-add-wires modi sig-list) ; Before we trash list | |
9117 (while sig-list | |
9118 (let ((sig (car sig-list))) | |
9119 (verilog-insert-one-definition sig "wire" indent-pt) | |
9120 (indent-to (max 48 (+ indent-pt 40))) | |
9121 (insert "= " (verilog-sig-tieoff sig) | |
9122 ";\n") | |
9123 (setq sig-list (cdr sig-list)))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9124 (verilog-insert-indent "// End of automatics\n"))))) |
79545 | 9125 |
9126 (defun verilog-auto-unused () | |
9127 "Expand AUTOUNUSED statements, as part of \\[verilog-auto]. | |
9128 Replace the /*AUTOUNUSED*/ comment with a comma separated list of all unused | |
9129 input and inout signals. | |
9130 | |
9131 /*AUTOUNUSED*/ is used to make stub modules; modules that have the same | |
9132 input/output list as another module, but no internals. Specifically, it | |
9133 finds all inputs and inouts in the module, and if that input is not otherwise | |
9134 used, adds it to a comma separated list. | |
9135 | |
9136 The comma separated list is intended to be used to create a _unused_ok | |
9137 signal. Using the exact name \"_unused_ok\" for name of the temporary | |
9138 signal is recommended as it will insure maximum forward compatibility, it | |
9139 also makes lint warnings easy to understand; ignore any unused warnings | |
9140 with \"unused\" in the signal name. | |
9141 | |
9142 To reduce simulation time, the _unused_ok signal should be forced to a | |
9143 constant to prevent wiggling. The easiest thing to do is use a | |
9144 reduction-and with 1'b0 as shown. | |
9145 | |
9146 This way all unused signals are in one place, making it convenient to add | |
9147 your tool's specific pragmas around the assignment to disable any unused | |
9148 warnings. | |
9149 | |
9150 You can add signals you do not want included in AUTOUNUSED with | |
9151 `verilog-auto-unused-ignore-regexp'. | |
9152 | |
9153 An example of making a stub for another module: | |
9154 | |
9155 module FooStub (/*AUTOINST*/); | |
9156 /*AUTOINOUTMODULE(\"Foo\")*/ | |
9157 /*AUTOTIEOFF*/ | |
9158 // verilator lint_off UNUSED | |
9159 wire _unused_ok = &{1'b0, | |
9160 /*AUTOUNUSED*/ | |
9161 1'b0}; | |
9162 // verilator lint_on UNUSED | |
9163 endmodule | |
9164 | |
9165 Typing \\[verilog-auto] will make this into: | |
9166 | |
9167 ... | |
9168 // verilator lint_off UNUSED | |
9169 wire _unused_ok = &{1'b0, | |
9170 /*AUTOUNUSED*/ | |
9171 // Beginning of automatics | |
9172 unused_input_a, | |
9173 unused_input_b, | |
9174 unused_input_c, | |
9175 // End of automatics | |
9176 1'b0}; | |
9177 // verilator lint_on UNUSED | |
9178 endmodule" | |
9179 (interactive) | |
9180 (save-excursion | |
9181 ;; Find beginning | |
9182 (let* ((indent-pt (progn (search-backward "/*") (current-column))) | |
9183 (modi (verilog-modi-current)) | |
9184 (sig-list (verilog-signals-not-in | |
9185 (append (verilog-modi-get-inputs modi) | |
9186 (verilog-modi-get-inouts modi)) | |
9187 (append (verilog-modi-get-sub-inputs modi) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9188 (verilog-modi-get-sub-inouts modi))))) |
79545 | 9189 (setq sig-list (verilog-signals-not-matching-regexp |
9190 sig-list verilog-auto-unused-ignore-regexp)) | |
9191 (when sig-list | |
9192 (forward-line 1) | |
9193 (verilog-insert-indent "// Beginning of automatic unused inputs\n") | |
9194 (setq sig-list (sort (copy-alist sig-list) `verilog-signals-sort-compare)) | |
9195 (while sig-list | |
9196 (let ((sig (car sig-list))) | |
9197 (indent-to indent-pt) | |
9198 (insert (verilog-sig-name sig) ",\n") | |
9199 (setq sig-list (cdr sig-list)))) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9200 (verilog-insert-indent "// End of automatics\n"))))) |
79545 | 9201 |
9202 (defun verilog-enum-ascii (signm elim-regexp) | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
9203 "Convert an enum name SIGNM to an ascii string for insertion. |
79545 | 9204 Remove user provided prefix ELIM-REGEXP." |
9205 (or elim-regexp (setq elim-regexp "_ DONT MATCH IT_")) | |
9206 (let ((case-fold-search t)) | |
9207 ;; All upper becomes all lower for readability | |
9208 (downcase (verilog-string-replace-matches elim-regexp "" nil nil signm)))) | |
9209 | |
9210 (defun verilog-auto-ascii-enum () | |
9211 "Expand AUTOASCIIENUM statements, as part of \\[verilog-auto]. | |
9212 Create a register to contain the ASCII decode of a enumerated signal type. | |
9213 This will allow trace viewers to show the ASCII name of states. | |
9214 | |
9215 First, parameters are built into a enumeration using the synopsys enum | |
9216 comment. The comment must be between the keyword and the symbol. | |
79546 | 9217 \(Annoying, but that's what Synopsys's dc_shell FSM reader requires.) |
79545 | 9218 |
9219 Next, registers which that enum applies to are also tagged with the same | |
9220 enum. Synopsys also suggests labeling state vectors, but `verilog-mode' | |
9221 doesn't care. | |
9222 | |
9223 Finally, a AUTOASCIIENUM command is used. | |
9224 | |
9225 The first parameter is the name of the signal to be decoded. | |
9226 | |
9227 The second parameter is the name to store the ASCII code into. For the | |
9228 signal foo, I suggest the name _foo__ascii, where the leading _ indicates | |
9229 a signal that is just for simulation, and the magic characters _ascii | |
9230 tell viewers like Dinotrace to display in ASCII format. | |
9231 | |
9232 The final optional parameter is a string which will be removed from the | |
9233 state names. | |
9234 | |
9235 An example: | |
9236 | |
9237 //== State enumeration | |
9238 parameter [2:0] // synopsys enum state_info | |
9239 SM_IDLE = 3'b000, | |
9240 SM_SEND = 3'b001, | |
9241 SM_WAIT1 = 3'b010; | |
9242 //== State variables | |
9243 reg [2:0] /* synopsys enum state_info */ | |
9244 state_r; /* synopsys state_vector state_r */ | |
9245 reg [2:0] /* synopsys enum state_info */ | |
9246 state_e1; | |
9247 | |
9248 //== ASCII state decoding | |
9249 | |
9250 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/ | |
9251 | |
9252 Typing \\[verilog-auto] will make this into: | |
9253 | |
9254 ... same front matter ... | |
9255 | |
9256 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/ | |
9257 // Beginning of automatic ASCII enum decoding | |
9258 reg [39:0] state_ascii_r; // Decode of state_r | |
9259 always @(state_r) begin | |
9260 case ({state_r}) | |
9261 SM_IDLE: state_ascii_r = \"idle \"; | |
9262 SM_SEND: state_ascii_r = \"send \"; | |
9263 SM_WAIT1: state_ascii_r = \"wait1\"; | |
9264 default: state_ascii_r = \"%Erro\"; | |
9265 endcase | |
9266 end | |
9267 // End of automatics" | |
9268 (save-excursion | |
9269 (let* ((params (verilog-read-auto-params 2 3)) | |
9270 (undecode-name (nth 0 params)) | |
9271 (ascii-name (nth 1 params)) | |
9272 (elim-regexp (nth 2 params)) | |
9273 ;; | |
9274 (indent-pt (current-indentation)) | |
9275 (modi (verilog-modi-current)) | |
9276 ;; | |
9277 (sig-list-consts (append (verilog-modi-get-consts modi) | |
9278 (verilog-modi-get-gparams modi))) | |
9279 (sig-list-all (append (verilog-modi-get-regs modi) | |
9280 (verilog-modi-get-outputs modi) | |
9281 (verilog-modi-get-inouts modi) | |
9282 (verilog-modi-get-inputs modi) | |
9283 (verilog-modi-get-wires modi))) | |
9284 ;; | |
9285 (undecode-sig (or (assoc undecode-name sig-list-all) | |
9286 (error "%s: Signal %s not found in design" (verilog-point-text) undecode-name))) | |
9287 (undecode-enum (or (verilog-sig-enum undecode-sig) | |
9288 (error "%s: Signal %s does not have a enum tag" (verilog-point-text) undecode-name))) | |
9289 ;; | |
9290 (enum-sigs (or (verilog-signals-matching-enum sig-list-consts undecode-enum) | |
9291 (error "%s: No state definitions for %s" (verilog-point-text) undecode-enum))) | |
9292 ;; | |
9293 (enum-chars 0) | |
9294 (ascii-chars 0)) | |
9295 ;; | |
9296 ;; Find number of ascii chars needed | |
9297 (let ((tmp-sigs enum-sigs)) | |
9298 (while tmp-sigs | |
9299 (setq enum-chars (max enum-chars (length (verilog-sig-name (car tmp-sigs)))) | |
9300 ascii-chars (max ascii-chars (length (verilog-enum-ascii | |
9301 (verilog-sig-name (car tmp-sigs)) | |
9302 elim-regexp))) | |
9303 tmp-sigs (cdr tmp-sigs)))) | |
9304 ;; | |
9305 (forward-line 1) | |
9306 (verilog-insert-indent "// Beginning of automatic ASCII enum decoding\n") | |
9307 (let ((decode-sig-list (list (list ascii-name (format "[%d:0]" (- (* ascii-chars 8) 1)) | |
9308 (concat "Decode of " undecode-name) nil nil)))) | |
9309 (verilog-insert-definition decode-sig-list "reg" indent-pt nil) | |
9310 (verilog-modi-cache-add-regs modi decode-sig-list)) | |
9311 ;; | |
9312 (verilog-insert-indent "always @(" undecode-name ") begin\n") | |
9313 (setq indent-pt (+ indent-pt verilog-indent-level)) | |
9314 (indent-to indent-pt) | |
9315 (insert "case ({" undecode-name "})\n") | |
9316 (setq indent-pt (+ indent-pt verilog-case-indent)) | |
9317 ;; | |
9318 (let ((tmp-sigs enum-sigs) | |
9319 (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n" (1+ (max 8 enum-chars)) | |
9320 ascii-name ascii-chars)) | |
9321 (errname (substring "%Error" 0 (min 6 ascii-chars)))) | |
9322 (while tmp-sigs | |
9323 (verilog-insert-indent | |
9324 (format chrfmt (concat (verilog-sig-name (car tmp-sigs)) ":") | |
9325 (verilog-enum-ascii (verilog-sig-name (car tmp-sigs)) | |
9326 elim-regexp))) | |
9327 (setq tmp-sigs (cdr tmp-sigs))) | |
9328 (verilog-insert-indent (format chrfmt "default:" errname))) | |
9329 ;; | |
9330 (setq indent-pt (- indent-pt verilog-case-indent)) | |
9331 (verilog-insert-indent "endcase\n") | |
9332 (setq indent-pt (- indent-pt verilog-indent-level)) | |
9333 (verilog-insert-indent "end\n" | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9334 "// End of automatics\n")))) |
79545 | 9335 |
9336 (defun verilog-auto-templated-rel () | |
9337 "Replace Templated relative line numbers with absolute line numbers. | |
9338 Internal use only. This hacks around the line numbers in AUTOINST Templates | |
9339 being different from the final output's line numbering." | |
9340 (let ((templateno 0) (template-line (list 0))) | |
9341 ;; Find line number each template is on | |
9342 (goto-char (point-min)) | |
9343 (while (search-forward "AUTO_TEMPLATE" nil t) | |
9344 (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
|
9345 (setq template-line |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9346 (cons (count-lines (point-min) (point)) template-line))) |
79545 | 9347 (setq template-line (nreverse template-line)) |
9348 ;; Replace T# L# with absolute line number | |
9349 (goto-char (point-min)) | |
9350 (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
|
9351 (replace-match |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9352 (concat " Templated " |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9353 (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
|
9354 template-line) |
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9355 (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
|
9356 t t)))) |
79545 | 9357 |
9358 | |
9359 ;; | |
9360 ;; Auto top level | |
9361 ;; | |
9362 | |
9363 (defun verilog-auto (&optional inject) ; Use verilog-inject-auto instead of passing a arg | |
9364 "Expand AUTO statements. | |
9365 Look for any /*AUTO...*/ commands in the code, as used in | |
9366 instantiations or argument headers. Update the list of signals | |
9367 following the /*AUTO...*/ command. | |
9368 | |
9369 Use \\[verilog-delete-auto] to remove the AUTOs. | |
9370 | |
9371 Use \\[verilog-inject-auto] to insert AUTOs for the first time. | |
9372 | |
9373 Use \\[verilog-faq] for a pointer to frequently asked questions. | |
9374 | |
9375 The hooks `verilog-before-auto-hook' and `verilog-auto-hook' are | |
9376 called before and after this function, respectively. | |
9377 | |
9378 For example: | |
9379 module (/*AUTOARG*/) | |
9380 /*AUTOINPUT*/ | |
9381 /*AUTOOUTPUT*/ | |
9382 /*AUTOWIRE*/ | |
9383 /*AUTOREG*/ | |
9384 somesub sub #(/*AUTOINSTPARAM*/) (/*AUTOINST*/); | |
9385 | |
9386 You can also update the AUTOs from the shell using: | |
9387 emacs --batch <filenames.v> -f verilog-batch-auto | |
9388 Or fix indentation with: | |
9389 emacs --batch <filenames.v> -f verilog-batch-indent | |
9390 Likewise, you can delete or inject AUTOs with: | |
9391 emacs --batch <filenames.v> -f verilog-batch-delete-auto | |
9392 emacs --batch <filenames.v> -f verilog-batch-inject-auto | |
9393 | |
9394 Using \\[describe-function], see also: | |
9395 `verilog-auto-arg' for AUTOARG module instantiations | |
9396 `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding | |
9397 `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere | |
9398 `verilog-auto-inout' for AUTOINOUT making hierarchy inouts | |
9399 `verilog-auto-input' for AUTOINPUT making hierarchy inputs | |
9400 `verilog-auto-inst' for AUTOINST instantiation pins | |
9401 `verilog-auto-star' for AUTOINST .* SystemVerilog pins | |
9402 `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params | |
9403 `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs | |
9404 `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs | |
9405 `verilog-auto-reg' for AUTOREG registers | |
9406 `verilog-auto-reg-input' for AUTOREGINPUT instantiation registers | |
9407 `verilog-auto-reset' for AUTORESET flop resets | |
9408 `verilog-auto-sense' for AUTOSENSE always sensitivity lists | |
9409 `verilog-auto-tieoff' for AUTOTIEOFF output tieoffs | |
9410 `verilog-auto-unused' for AUTOUNUSED unused inputs/inouts | |
9411 `verilog-auto-wire' for AUTOWIRE instantiation wires | |
9412 | |
9413 `verilog-read-defines' for reading `define values | |
9414 `verilog-read-includes' for reading `includes | |
9415 | |
9416 If you have bugs with these autos, try contacting the AUTOAUTHOR | |
9417 Wilson Snyder (wsnyder@wsnyder.org), and/or see http://www.veripool.com." | |
9418 (interactive) | |
9419 (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
|
9420 (if (fboundp 'dinotrace-unannotate-all) |
79545 | 9421 (dinotrace-unannotate-all)) |
9422 (let ((oldbuf (if (not (buffer-modified-p)) | |
9423 (buffer-string))) | |
9424 ;; Before version 20, match-string with font-lock returns a | |
9425 ;; vector that is not equal to the string. IE if on "input" | |
9426 ;; nil==(equal "input" (progn (looking-at "input") (match-string 0))) | |
9427 (fontlocked (when (and (boundp 'font-lock-mode) | |
9428 font-lock-mode) | |
9429 (font-lock-mode nil) | |
9430 t))) | |
9431 (unwind-protect | |
9432 (save-excursion | |
9433 ;; If we're not in verilog-mode, change syntax table so parsing works right | |
9434 (unless (eq major-mode `verilog-mode) (verilog-mode)) | |
9435 ;; Allow user to customize | |
9436 (run-hooks 'verilog-before-auto-hook) | |
9437 ;; Try to save the user from needing to revert-file to reread file local-variables | |
9438 (verilog-auto-reeval-locals) | |
9439 (verilog-read-auto-lisp (point-min) (point-max)) | |
9440 (verilog-getopt-flags) | |
9441 ;; These two may seem obvious to do always, but on large includes it can be way too slow | |
9442 (when verilog-auto-read-includes | |
9443 (verilog-read-includes) | |
9444 (verilog-read-defines nil nil t)) | |
9445 ;; This particular ordering is important | |
9446 ;; INST: Lower modules correct, no internal dependencies, FIRST | |
9447 (verilog-preserve-cache | |
9448 ;; Clear existing autos else we'll be screwed by existing ones | |
9449 (verilog-delete-auto) | |
9450 ;; Injection if appropriate | |
9451 (when inject | |
9452 (verilog-inject-inst) | |
9453 (verilog-inject-sense) | |
9454 (verilog-inject-arg)) | |
9455 ;; | |
9456 (verilog-auto-search-do "/*AUTOINSTPARAM*/" 'verilog-auto-inst-param) | |
9457 (verilog-auto-search-do "/*AUTOINST*/" 'verilog-auto-inst) | |
9458 (verilog-auto-search-do ".*" 'verilog-auto-star) | |
9459 ;; Doesn't matter when done, but combine it with a common changer | |
9460 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense) | |
9461 (verilog-auto-re-search-do "/\\*AUTORESET\\*/" 'verilog-auto-reset) | |
9462 ;; Must be done before autoin/out as creates a reg | |
9463 (verilog-auto-re-search-do "/\\*AUTOASCIIENUM([^)]*)\\*/" 'verilog-auto-ascii-enum) | |
9464 ;; | |
9465 ;; first in/outs from other files | |
9466 (verilog-auto-re-search-do "/\\*AUTOINOUTMODULE([^)]*)\\*/" 'verilog-auto-inout-module) | |
9467 ;; next in/outs which need previous sucked inputs first | |
9468 (verilog-auto-search-do "/*AUTOOUTPUT*/" 'verilog-auto-output) | |
9469 (verilog-auto-search-do "/*AUTOINPUT*/" 'verilog-auto-input) | |
9470 (verilog-auto-search-do "/*AUTOINOUT*/" 'verilog-auto-inout) | |
9471 ;; Then tie off those in/outs | |
9472 (verilog-auto-search-do "/*AUTOTIEOFF*/" 'verilog-auto-tieoff) | |
9473 ;; Wires/regs must be after inputs/outputs | |
9474 (verilog-auto-search-do "/*AUTOWIRE*/" 'verilog-auto-wire) | |
9475 (verilog-auto-search-do "/*AUTOREG*/" 'verilog-auto-reg) | |
9476 (verilog-auto-search-do "/*AUTOREGINPUT*/" 'verilog-auto-reg-input) | |
9477 ;; outputevery needs AUTOOUTPUTs done first | |
9478 (verilog-auto-search-do "/*AUTOOUTPUTEVERY*/" 'verilog-auto-output-every) | |
9479 ;; After we've created all new variables | |
9480 (verilog-auto-search-do "/*AUTOUNUSED*/" 'verilog-auto-unused) | |
9481 ;; Must be after all inputs outputs are generated | |
9482 (verilog-auto-search-do "/*AUTOARG*/" 'verilog-auto-arg) | |
9483 ;; Fix line numbers (comments only) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9484 (verilog-auto-templated-rel)) |
79545 | 9485 ;; |
9486 (run-hooks 'verilog-auto-hook) | |
9487 ;; | |
9488 (set (make-local-variable 'verilog-auto-update-tick) (buffer-modified-tick)) | |
9489 ;; | |
9490 ;; If end result is same as when started, clear modified flag | |
9491 (cond ((and oldbuf (equal oldbuf (buffer-string))) | |
9492 (set-buffer-modified-p nil) | |
9493 (unless noninteractive (message "Updating AUTOs...done (no changes)"))) | |
9494 (t (unless noninteractive (message "Updating AUTOs...done"))))) | |
9495 ;; Unwind forms | |
9496 (progn | |
9497 ;; Restore font-lock | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9498 (when fontlocked (font-lock-mode t)))))) |
79545 | 9499 |
9500 | |
9501 ;; | |
9502 ;; Skeleton based code insertion | |
9503 ;; | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9504 (defvar verilog-template-map |
79546 | 9505 (let ((map (make-sparse-keymap))) |
9506 (define-key map "a" 'verilog-sk-always) | |
9507 (define-key map "b" 'verilog-sk-begin) | |
9508 (define-key map "c" 'verilog-sk-case) | |
9509 (define-key map "f" 'verilog-sk-for) | |
9510 (define-key map "g" 'verilog-sk-generate) | |
9511 (define-key map "h" 'verilog-sk-header) | |
9512 (define-key map "i" 'verilog-sk-initial) | |
9513 (define-key map "j" 'verilog-sk-fork) | |
9514 (define-key map "m" 'verilog-sk-module) | |
9515 (define-key map "p" 'verilog-sk-primitive) | |
9516 (define-key map "r" 'verilog-sk-repeat) | |
9517 (define-key map "s" 'verilog-sk-specify) | |
9518 (define-key map "t" 'verilog-sk-task) | |
9519 (define-key map "w" 'verilog-sk-while) | |
9520 (define-key map "x" 'verilog-sk-casex) | |
9521 (define-key map "z" 'verilog-sk-casez) | |
9522 (define-key map "?" 'verilog-sk-if) | |
9523 (define-key map ":" 'verilog-sk-else-if) | |
9524 (define-key map "/" 'verilog-sk-comment) | |
9525 (define-key map "A" 'verilog-sk-assign) | |
9526 (define-key map "F" 'verilog-sk-function) | |
9527 (define-key map "I" 'verilog-sk-input) | |
9528 (define-key map "O" 'verilog-sk-output) | |
9529 (define-key map "S" 'verilog-sk-state-machine) | |
9530 (define-key map "=" 'verilog-sk-inout) | |
9531 (define-key map "W" 'verilog-sk-wire) | |
9532 (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
|
9533 (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
|
9534 map) |
79545 | 9535 "Keymap used in Verilog mode for smart template operations.") |
9536 | |
9537 | |
9538 ;; | |
9539 ;; Place the templates into Verilog Mode. They may be inserted under any key. | |
9540 ;; C-c C-t will be the default. If you use templates a lot, you | |
9541 ;; may want to consider moving the binding to another key in your .emacs | |
9542 ;; file. | |
9543 ;; | |
9544 ;(define-key verilog-mode-map "\C-ct" verilog-template-map) | |
9545 (define-key verilog-mode-map "\C-c\C-t" verilog-template-map) | |
9546 | |
9547 ;;; ---- statement skeletons ------------------------------------------ | |
9548 | |
9549 (define-skeleton verilog-sk-prompt-condition | |
9550 "Prompt for the loop condition." | |
9551 "[condition]: " str ) | |
9552 | |
9553 (define-skeleton verilog-sk-prompt-init | |
9554 "Prompt for the loop init statement." | |
9555 "[initial statement]: " str ) | |
9556 | |
9557 (define-skeleton verilog-sk-prompt-inc | |
9558 "Prompt for the loop increment statement." | |
9559 "[increment statement]: " str ) | |
9560 | |
9561 (define-skeleton verilog-sk-prompt-name | |
9562 "Prompt for the name of something." | |
9563 "[name]: " str) | |
9564 | |
9565 (define-skeleton verilog-sk-prompt-clock | |
9566 "Prompt for the name of something." | |
9567 "name and edge of clock(s): " str) | |
9568 | |
9569 (defvar verilog-sk-reset nil) | |
9570 (defun verilog-sk-prompt-reset () | |
9571 "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
|
9572 (setq verilog-sk-reset (read-string "name of reset: " "rst"))) |
79545 | 9573 |
9574 | |
9575 (define-skeleton verilog-sk-prompt-state-selector | |
9576 "Prompt for the name of a state machine selector." | |
9577 "name of selector (eg {a,b,c,d}): " str ) | |
9578 | |
9579 (define-skeleton verilog-sk-prompt-output | |
9580 "Prompt for the name of something." | |
9581 "output: " str) | |
9582 | |
9583 (define-skeleton verilog-sk-prompt-msb | |
9584 "Prompt for least significant bit specification." | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9585 "msb:" str & ?: & '(verilog-sk-prompt-lsb) | -1 ) |
79545 | 9586 |
9587 (define-skeleton verilog-sk-prompt-lsb | |
9588 "Prompt for least significant bit specification." | |
9589 "lsb:" str ) | |
9590 | |
9591 (defvar verilog-sk-p nil) | |
9592 (define-skeleton verilog-sk-prompt-width | |
9593 "Prompt for a width specification." | |
9594 () | |
9595 (progn | |
9596 (setq verilog-sk-p (point)) | |
9597 (verilog-sk-prompt-msb) | |
9598 (if (> (point) verilog-sk-p) "] " " "))) | |
9599 | |
9600 (defun verilog-sk-header () | |
9601 "Insert a descriptive header at the top of the file." | |
9602 (interactive "*") | |
9603 (save-excursion | |
9604 (goto-char (point-min)) | |
9605 (verilog-sk-header-tmpl))) | |
9606 | |
9607 (define-skeleton verilog-sk-header-tmpl | |
9608 "Insert a comment block containing the module title, author, etc." | |
9609 "[Description]: " | |
9610 "// -*- Mode: Verilog -*-" | |
9611 "\n// Filename : " (buffer-name) | |
9612 "\n// Description : " str | |
9613 "\n// Author : " (user-full-name) | |
9614 "\n// Created On : " (current-time-string) | |
9615 "\n// Last Modified By: ." | |
9616 "\n// Last Modified On: ." | |
9617 "\n// Update Count : 0" | |
9618 "\n// Status : Unknown, Use with caution!" | |
9619 "\n") | |
9620 | |
9621 (define-skeleton verilog-sk-module | |
9622 "Insert a module definition." | |
9623 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9624 > "module " '(verilog-sk-prompt-name) " (/*AUTOARG*/ ) ;" \n |
79545 | 9625 > _ \n |
9626 > (- verilog-indent-level-behavioral) "endmodule" (progn (electric-verilog-terminate-line) nil)) | |
9627 | |
9628 (define-skeleton verilog-sk-primitive | |
9629 "Insert a task definition." | |
9630 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9631 > "primitive " '(verilog-sk-prompt-name) " ( " '(verilog-sk-prompt-output) ("input:" ", " str ) " );"\n |
79545 | 9632 > _ \n |
9633 > (- verilog-indent-level-behavioral) "endprimitive" (progn (electric-verilog-terminate-line) nil)) | |
9634 | |
9635 (define-skeleton verilog-sk-task | |
9636 "Insert a task definition." | |
9637 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9638 > "task " '(verilog-sk-prompt-name) & ?; \n |
79545 | 9639 > _ \n |
9640 > "begin" \n | |
9641 > \n | |
9642 > (- verilog-indent-level-behavioral) "end" \n | |
9643 > (- verilog-indent-level-behavioral) "endtask" (progn (electric-verilog-terminate-line) nil)) | |
9644 | |
9645 (define-skeleton verilog-sk-function | |
9646 "Insert a function definition." | |
9647 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9648 > "function [" '(verilog-sk-prompt-width) | -1 '(verilog-sk-prompt-name) ?; \n |
79545 | 9649 > _ \n |
9650 > "begin" \n | |
9651 > \n | |
9652 > (- verilog-indent-level-behavioral) "end" \n | |
9653 > (- verilog-indent-level-behavioral) "endfunction" (progn (electric-verilog-terminate-line) nil)) | |
9654 | |
9655 (define-skeleton verilog-sk-always | |
9656 "Insert always block. Uses the minibuffer to prompt | |
9657 for sensitivity list." | |
9658 () | |
9659 > "always @ ( /*AUTOSENSE*/ ) begin\n" | |
9660 > _ \n | |
9661 > (- verilog-indent-level-behavioral) "end" \n > | |
9662 ) | |
9663 | |
9664 (define-skeleton verilog-sk-initial | |
9665 "Insert an initial block." | |
9666 () | |
9667 > "initial begin\n" | |
9668 > _ \n | |
9669 > (- verilog-indent-level-behavioral) "end" \n > ) | |
9670 | |
9671 (define-skeleton verilog-sk-specify | |
9672 "Insert specify block. " | |
9673 () | |
9674 > "specify\n" | |
9675 > _ \n | |
9676 > (- verilog-indent-level-behavioral) "endspecify" \n > ) | |
9677 | |
9678 (define-skeleton verilog-sk-generate | |
9679 "Insert generate block. " | |
9680 () | |
9681 > "generate\n" | |
9682 > _ \n | |
9683 > (- verilog-indent-level-behavioral) "endgenerate" \n > ) | |
9684 | |
9685 (define-skeleton verilog-sk-begin | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
9686 "Insert begin end block. Uses the minibuffer to prompt for name." |
79545 | 9687 () |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9688 > "begin" '(verilog-sk-prompt-name) \n |
79545 | 9689 > _ \n |
9690 > (- verilog-indent-level-behavioral) "end" | |
9691 ) | |
9692 | |
9693 (define-skeleton verilog-sk-fork | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
9694 "Insert a fork join block." |
79545 | 9695 () |
9696 > "fork\n" | |
9697 > "begin" \n | |
9698 > _ \n | |
9699 > (- verilog-indent-level-behavioral) "end" \n | |
9700 > "begin" \n | |
9701 > \n | |
9702 > (- verilog-indent-level-behavioral) "end" \n | |
9703 > (- verilog-indent-level-behavioral) "join" \n | |
9704 > ) | |
9705 | |
9706 | |
9707 (define-skeleton verilog-sk-case | |
9708 "Build skeleton case statement, prompting for the selector expression, | |
9709 and the case items." | |
9710 "[selector expression]: " | |
9711 > "case (" str ") " \n | |
9712 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n ) | |
9713 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)) | |
9714 | |
9715 (define-skeleton verilog-sk-casex | |
9716 "Build skeleton casex statement, prompting for the selector expression, | |
9717 and the case items." | |
9718 "[selector expression]: " | |
9719 > "casex (" str ") " \n | |
9720 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n ) | |
9721 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)) | |
9722 | |
9723 (define-skeleton verilog-sk-casez | |
9724 "Build skeleton casez statement, prompting for the selector expression, | |
9725 and the case items." | |
9726 "[selector expression]: " | |
9727 > "casez (" str ") " \n | |
9728 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n ) | |
9729 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)) | |
9730 | |
9731 (define-skeleton verilog-sk-if | |
9732 "Insert a skeleton if statement." | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9733 > "if (" '(verilog-sk-prompt-condition) & ")" " begin" \n |
79545 | 9734 > _ \n |
9735 > (- verilog-indent-level-behavioral) "end " \n ) | |
9736 | |
9737 (define-skeleton verilog-sk-else-if | |
9738 "Insert a skeleton else if statement." | |
9739 > (verilog-indent-line) "else if (" | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9740 (progn (setq verilog-sk-p (point)) nil) '(verilog-sk-prompt-condition) (if (> (point) verilog-sk-p) ") " -1 ) & " begin" \n |
79545 | 9741 > _ \n |
9742 > "end" (progn (electric-verilog-terminate-line) nil)) | |
9743 | |
9744 (define-skeleton verilog-sk-datadef | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
9745 "Common routine to get data definition." |
79545 | 9746 () |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9747 '(verilog-sk-prompt-width) | -1 ("name (RET to end):" str ", ") -2 ";" \n) |
79545 | 9748 |
9749 (define-skeleton verilog-sk-input | |
9750 "Insert an input definition." | |
9751 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9752 > "input [" '(verilog-sk-datadef)) |
79545 | 9753 |
9754 (define-skeleton verilog-sk-output | |
9755 "Insert an output definition." | |
9756 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9757 > "output [" '(verilog-sk-datadef)) |
79545 | 9758 |
9759 (define-skeleton verilog-sk-inout | |
9760 "Insert an inout definition." | |
9761 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9762 > "inout [" '(verilog-sk-datadef)) |
79545 | 9763 |
9764 (defvar verilog-sk-signal nil) | |
9765 (define-skeleton verilog-sk-def-reg | |
9766 "Insert a reg definition." | |
9767 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9768 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-signal ";" \n (verilog-pretty-declarations) ) |
79545 | 9769 |
9770 (defun verilog-sk-define-signal () | |
9771 "Insert a definition of signal under point at top of module." | |
9772 (interactive "*") | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9773 (let* ((sig-re "[a-zA-Z0-9_]*") |
79545 | 9774 (v1 (buffer-substring |
9775 (save-excursion | |
9776 (skip-chars-backward sig-re) | |
9777 (point)) | |
9778 (save-excursion | |
9779 (skip-chars-forward sig-re) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9780 (point))))) |
79545 | 9781 (if (not (member v1 verilog-keywords)) |
9782 (save-excursion | |
9783 (setq verilog-sk-signal v1) | |
9784 (verilog-beg-of-defun) | |
9785 (verilog-end-of-statement) | |
9786 (verilog-forward-syntactic-ws) | |
9787 (verilog-sk-def-reg) | |
9788 (message "signal at point is %s" v1)) | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9789 (message "object at point (%s) is a keyword" v1)))) |
79545 | 9790 |
9791 (define-skeleton verilog-sk-wire | |
9792 "Insert a wire definition." | |
9793 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9794 > "wire [" '(verilog-sk-datadef)) |
79545 | 9795 |
9796 (define-skeleton verilog-sk-reg | |
9797 "Insert a reg definition." | |
9798 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9799 > "reg [" '(verilog-sk-datadef)) |
79545 | 9800 |
9801 (define-skeleton verilog-sk-assign | |
9802 "Insert a skeleton assign statement." | |
9803 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9804 > "assign " '(verilog-sk-prompt-name) " = " _ ";" \n) |
79545 | 9805 |
9806 (define-skeleton verilog-sk-while | |
9807 "Insert a skeleton while loop statement." | |
9808 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9809 > "while (" '(verilog-sk-prompt-condition) ") begin" \n |
79545 | 9810 > _ \n |
9811 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil)) | |
9812 | |
9813 (define-skeleton verilog-sk-repeat | |
9814 "Insert a skeleton repeat loop statement." | |
9815 () | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9816 > "repeat (" '(verilog-sk-prompt-condition) ") begin" \n |
79545 | 9817 > _ \n |
9818 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil)) | |
9819 | |
9820 (define-skeleton verilog-sk-for | |
9821 "Insert a skeleton while loop statement." | |
9822 () | |
9823 > "for (" | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9824 '(verilog-sk-prompt-init) "; " |
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9825 '(verilog-sk-prompt-condition) "; " |
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9826 '(verilog-sk-prompt-inc) |
79545 | 9827 ") begin" \n |
9828 > _ \n | |
9829 > (- verilog-indent-level-behavioral) "end " (progn (electric-verilog-terminate-line) nil)) | |
9830 | |
9831 (define-skeleton verilog-sk-comment | |
9832 "Inserts three comment lines, making a display comment." | |
9833 () | |
9834 > "/*\n" | |
9835 > "* " _ \n | |
9836 > "*/") | |
9837 | |
9838 (define-skeleton verilog-sk-state-machine | |
9839 "Insert a state machine definition." | |
9840 "Name of state variable: " | |
9841 '(setq input "state") | |
9842 > "// State registers for " str | -23 \n | |
9843 '(setq verilog-sk-state str) | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9844 > "reg [" '(verilog-sk-prompt-width) | -1 verilog-sk-state ", next_" verilog-sk-state ?; \n |
79545 | 9845 '(setq input nil) |
9846 > \n | |
9847 > "// State FF for " verilog-sk-state \n | |
9848 > "always @ ( " (read-string "clock:" "posedge clk") " or " (verilog-sk-prompt-reset) " ) begin" \n | |
9849 > "if ( " verilog-sk-reset " ) " verilog-sk-state " = 0; else" \n | |
9850 > verilog-sk-state " = next_" verilog-sk-state ?; \n | |
9851 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil) | |
9852 > \n | |
9853 > "// Next State Logic for " verilog-sk-state \n | |
9854 > "always @ ( /*AUTOSENSE*/ ) begin\n" | |
79986
c592638ac955
(verilog-sk-prompt-msb)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79810
diff
changeset
|
9855 > "case (" '(verilog-sk-prompt-state-selector) ") " \n |
79545 | 9856 > ("case selector: " str ": begin" \n > "next_" verilog-sk-state " = " _ ";" \n > (- verilog-indent-level-behavioral) "end" \n ) |
9857 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil) | |
9858 > (- verilog-indent-level-behavioral) "end" (progn (electric-verilog-terminate-line) nil)) | |
9859 | |
9860 | |
9861 ;; | |
9862 ;; Include file loading with mouse/return event | |
9863 ;; | |
9864 ;; idea & first impl.: M. Rouat (eldo-mode.el) | |
9865 ;; second (emacs/xemacs) impl.: G. Van der Plas (spice-mode.el) | |
9866 | |
9867 (if (featurep 'xemacs) | |
9868 (require 'overlay) | |
9869 (require 'lucid)) ;; what else can we do ?? | |
9870 | |
9871 (defconst verilog-include-file-regexp | |
9872 "^`include\\s-+\"\\([^\n\"]*\\)\"" | |
9873 "Regexp that matches the include file.") | |
9874 | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9875 (defvar verilog-mode-mouse-map |
79545 | 9876 (let ((map (make-sparse-keymap))) ; as described in info pages, make a map |
9877 (set-keymap-parent map verilog-mode-map) | |
9878 ;; mouse button bindings | |
9879 (define-key map "\r" 'verilog-load-file-at-point) | |
9880 (if (featurep 'xemacs) | |
9881 (define-key map 'button2 'verilog-load-file-at-mouse);ffap-at-mouse ? | |
9882 (define-key map [mouse-2] 'verilog-load-file-at-mouse)) | |
9883 (if (featurep 'xemacs) | |
9884 (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
|
9885 (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
|
9886 map) |
79546 | 9887 "Map containing mouse bindings for `verilog-mode'.") |
9888 | |
79545 | 9889 |
9890 (defun verilog-colorize-include-files (beg end old-len) | |
9891 "This function colorizes included files when the mouse passes over them. | |
9892 Clicking on the middle-mouse button loads them in a buffer (as in dired)." | |
9893 (save-excursion | |
9894 (save-match-data | |
9895 (let (end-point) | |
9896 (goto-char end) | |
9897 (setq end-point (verilog-get-end-of-line)) | |
9898 (goto-char beg) | |
9899 (beginning-of-line) ; scan entire line ! | |
9900 ;; delete overlays existing on this line | |
9901 (let ((overlays (overlays-in (point) end-point))) | |
9902 (while overlays | |
9903 (if (and | |
9904 (overlay-get (car overlays) 'detachable) | |
9905 (overlay-get (car overlays) 'verilog-include-file)) | |
9906 (delete-overlay (car overlays))) | |
9907 (setq overlays (cdr overlays)))) ; let | |
9908 ;; make new ones, could reuse deleted one ? | |
9909 (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
|
9910 (let (ov) |
79545 | 9911 (goto-char (match-beginning 1)) |
79550
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
9912 (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
|
9913 (overlay-put ov 'start-closed 't) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
9914 (overlay-put ov 'end-closed 't) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
9915 (overlay-put ov 'evaporate 't) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
9916 (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
|
9917 (overlay-put ov 'mouse-face 'highlight) |
7f3b93a179a2
* progmodes/verilog-mode.el (verilog-mode-map)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79549
diff
changeset
|
9918 (overlay-put ov 'local-map verilog-mode-mouse-map))))))) |
79545 | 9919 |
9920 | |
9921 (defun verilog-colorize-include-files-buffer () | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
9922 "Colorize an include file." |
79545 | 9923 (interactive) |
9924 ;; delete overlays | |
9925 (let ((overlays (overlays-in (point-min) (point-max)))) | |
9926 (while overlays | |
9927 (if (and | |
9928 (overlay-get (car overlays) 'detachable) | |
9929 (overlay-get (car overlays) 'verilog-include-file)) | |
9930 (delete-overlay (car overlays))) | |
9931 (setq overlays (cdr overlays)))) ; let | |
9932 ;; remake overlays | |
9933 (verilog-colorize-include-files (point-min) (point-max) nil)) | |
9934 | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
9935 ;; ffap-at-mouse isn't useful for Verilog mode. It uses library paths. |
79545 | 9936 ;; so define this function to do more or less the same as ffap-at-mouse |
9937 ;; but first resolve filename... | |
9938 (defun verilog-load-file-at-mouse (event) | |
9939 "Load file under button 2 click's EVENT. | |
9940 Files are checked based on `verilog-library-directories'." | |
9941 (interactive "@e") | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
9942 (save-excursion ;; implement a Verilog specific ffap-at-mouse |
79545 | 9943 (mouse-set-point event) |
9944 (beginning-of-line) | |
9945 (if (looking-at verilog-include-file-regexp) | |
9946 (if (and (car (verilog-library-filenames | |
9947 (match-string 1) (buffer-file-name))) | |
9948 (file-readable-p (car (verilog-library-filenames | |
9949 (match-string 1) (buffer-file-name))))) | |
9950 (find-file (car (verilog-library-filenames | |
9951 (match-string 1) (buffer-file-name)))) | |
9952 (progn | |
9953 (message | |
9954 "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
|
9955 (match-string 1))))))) |
79545 | 9956 |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
9957 ;; ffap isn't useable for Verilog mode. It uses library paths. |
79545 | 9958 ;; so define this function to do more or less the same as ffap |
9959 ;; but first resolve filename... | |
9960 (defun verilog-load-file-at-point () | |
9961 "Load file under point. | |
9962 Files are checked based on `verilog-library-directories'." | |
9963 (interactive) | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
9964 (save-excursion ;; implement a Verilog specific ffap |
79545 | 9965 (beginning-of-line) |
9966 (if (looking-at verilog-include-file-regexp) | |
9967 (if (and | |
9968 (car (verilog-library-filenames | |
9969 (match-string 1) (buffer-file-name))) | |
9970 (file-readable-p (car (verilog-library-filenames | |
9971 (match-string 1) (buffer-file-name))))) | |
9972 (find-file (car (verilog-library-filenames | |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9973 (match-string 1) (buffer-file-name)))))))) |
79545 | 9974 |
9975 | |
9976 ;; | |
9977 ;; Bug reporting | |
9978 ;; | |
9979 | |
9980 (defun verilog-faq () | |
9981 "Tell the user their current version, and where to get the FAQ etc." | |
9982 (interactive) | |
9983 (with-output-to-temp-buffer "*verilog-mode help*" | |
9984 (princ (format "You are using verilog-mode %s\n" verilog-mode-version)) | |
9985 (princ "\n") | |
9986 (princ "For new releases, see http://www.verilog.com\n") | |
9987 (princ "\n") | |
9988 (princ "For frequently asked questions, see http://www.veripool.com/verilog-mode-faq.html\n") | |
9989 (princ "\n") | |
9990 (princ "To submit a bug, use M-x verilog-submit-bug-report\n") | |
9991 (princ "\n"))) | |
9992 | |
79691
d3e3c91e18f6
* progmodes/verilog-mode.el (top-level): Don't require compile.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79555
diff
changeset
|
9993 (autoload 'reporter-submit-bug-report "reporter") |
79799
57956dd69d3f
(top-level): Fix spacing.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
79717
diff
changeset
|
9994 (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
|
9995 |
79545 | 9996 (defun verilog-submit-bug-report () |
9997 "Submit via mail a bug report on verilog-mode.el." | |
9998 (interactive) | |
9999 (let ((reporter-prompt-for-summary-p t)) | |
10000 (reporter-submit-bug-report | |
10001 "mac@verilog.com" | |
10002 (concat "verilog-mode v" verilog-mode-version) | |
10003 '( | |
10004 verilog-align-ifelse | |
10005 verilog-auto-endcomments | |
10006 verilog-auto-hook | |
10007 verilog-auto-indent-on-newline | |
10008 verilog-auto-inst-vector | |
10009 verilog-auto-inst-template-numbers | |
10010 verilog-auto-lineup | |
10011 verilog-auto-newline | |
10012 verilog-auto-save-policy | |
10013 verilog-auto-sense-defines-constant | |
10014 verilog-auto-sense-include-inputs | |
10015 verilog-before-auto-hook | |
10016 verilog-case-indent | |
10017 verilog-cexp-indent | |
10018 verilog-compiler | |
10019 verilog-coverage | |
10020 verilog-highlight-translate-off | |
10021 verilog-indent-begin-after-if | |
10022 verilog-indent-declaration-macros | |
10023 verilog-indent-level | |
10024 verilog-indent-level-behavioral | |
10025 verilog-indent-level-declaration | |
10026 verilog-indent-level-directive | |
10027 verilog-indent-level-module | |
10028 verilog-indent-lists | |
10029 verilog-library-flags | |
10030 verilog-library-directories | |
10031 verilog-library-extensions | |
10032 verilog-library-files | |
10033 verilog-linter | |
10034 verilog-minimum-comment-distance | |
10035 verilog-mode-hook | |
10036 verilog-simulator | |
10037 verilog-tab-always-indent | |
10038 verilog-tab-to-comment | |
10039 ) | |
10040 nil nil | |
10041 (concat "Hi Mac, | |
10042 | |
10043 I want to report a bug. I've read the `Bugs' section of `Info' on | |
10044 Emacs, so I know how to make a clear and unambiguous report. To get | |
10045 to that Info section, I typed | |
10046 | |
10047 M-x info RET m " invocation-name " RET m bugs RET | |
10048 | |
10049 Before I go further, I want to say that Verilog mode has changed my life. | |
10050 I save so much time, my files are colored nicely, my co workers respect | |
10051 my coding ability... until now. I'd really appreciate anything you | |
10052 could do to help me out with this minor deficiency in the product. | |
10053 | |
10054 If you have bugs with the AUTO functions, please CC the AUTOAUTHOR Wilson | |
10055 Snyder (wsnyder@wsnyder.org) and/or see http://www.veripool.com. | |
10056 You may also want to look at the Verilog-Mode FAQ, see | |
10057 http://www.veripool.com/verilog-mode-faq.html. | |
10058 | |
10059 To reproduce the bug, start a fresh Emacs via " invocation-name " | |
80165
411da0873a97
Re-commit doc fixes accidentally reverted.
Juanma Barranquero <lekktu@gmail.com>
parents:
80163
diff
changeset
|
10060 -no-init-file -no-site-file'. In a new buffer, in Verilog mode, type |
79545 | 10061 the code included below. |
10062 | |
10063 Given those lines, I expected [[Fill in here]] to happen; | |
10064 but instead, [[Fill in here]] happens!. | |
10065 | |
10066 == The code: ==")))) | |
10067 | |
79546 | 10068 (provide 'verilog-mode) |
10069 | |
79545 | 10070 ;; Local Variables: |
10071 ;; checkdoc-permit-comma-termination-flag:t | |
10072 ;; checkdoc-force-docstrings-flag:nil | |
10073 ;; End: | |
10074 | |
79552 | 10075 ;; arch-tag: 87923725-57b3-41b5-9494-be21118c6a6f |
79545 | 10076 ;;; verilog-mode.el ends here |