verilog-mode.el 437 KB
Newer Older
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1 2
;; verilog-mode.el --- major mode for editing verilog source in Emacs

Glenn Morris's avatar
Glenn Morris committed
3
;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
Glenn Morris's avatar
Glenn Morris committed
4
;;   2005, 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
5

Wilson Snyder's avatar
Wilson Snyder committed
6 7 8 9 10
;; Author: Michael McNamara (mac@verilog.com),
;;    Wilson Snyder (wsnyder@wsnyder.org)
;; Please see our web sites:
;;    http://www.verilog.com
;;    http://www.veripool.org
Dan Nicolaescu's avatar
Dan Nicolaescu committed
11 12 13
;;
;; Keywords: languages

14 15 16 17 18
;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
;; file on 19/3/2008, and the maintainer agreed that when a bug is
;; filed in the Emacs bug reporting system against this file, a copy
;; of the bug report be sent to the maintainer's email address.

Dan Nicolaescu's avatar
Dan Nicolaescu committed
19 20 21 22 23 24
;;    This code supports Emacs 21.1 and later
;;    And XEmacs 21.1 and later
;;    Please do not make changes that break Emacs 21.  Thanks!
;;
;;

Glenn Morris's avatar
Glenn Morris committed
25 26
;; This file is part of GNU Emacs.

27
;; GNU Emacs is free software: you can redistribute it and/or modify
Dan Nicolaescu's avatar
Dan Nicolaescu committed
28
;; it under the terms of the GNU General Public License as published by
29 30
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
31

Glenn Morris's avatar
Glenn Morris committed
32
;; GNU Emacs is distributed in the hope that it will be useful,
Dan Nicolaescu's avatar
Dan Nicolaescu committed
33 34 35 36 37
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
38
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
39 40 41

;;; Commentary:

Dan Nicolaescu's avatar
Dan Nicolaescu committed
42
;; This mode borrows heavily from the Pascal-mode and the cc-mode of Emacs
Dan Nicolaescu's avatar
Dan Nicolaescu committed
43 44 45 46

;; USAGE
;; =====

Dan Nicolaescu's avatar
Dan Nicolaescu committed
47
;; A major mode for editing Verilog HDL source code.  When you have
Dan Nicolaescu's avatar
Dan Nicolaescu committed
48 49 50 51 52 53 54 55
;; entered Verilog mode, you may get more info by pressing C-h m. You
;; may also get online help describing various functions by: C-h f
;; <Name of function you want described>

;; KNOWN BUGS / BUG REPORTS
;; =======================

;; Verilog is a rapidly evolving language, and hence this mode is
Dan Nicolaescu's avatar
Dan Nicolaescu committed
56
;; under continuous development.  Hence this is beta code, and likely
57 58
;; has bugs.  Please report any issues to the issue tracker at
;; http://www.veripool.org/verilog-mode
Dan Nicolaescu's avatar
Dan Nicolaescu committed
59 60 61 62 63 64 65 66 67
;; Please use verilog-submit-bug-report to submit a report; type C-c
;; C-b to invoke this and as a result I will have a much easier time
;; of reproducing the bug you find, and hence fixing it.

;; INSTALLING THE MODE
;; ===================

;; An older version of this mode may be already installed as a part of
;; your environment, and one method of updating would be to update
Dan Nicolaescu's avatar
Dan Nicolaescu committed
68
;; your Emacs environment.  Sometimes this is difficult for local
Dan Nicolaescu's avatar
Dan Nicolaescu committed
69 70 71 72 73 74 75 76
;; political/control reasons, and hence you can always install a
;; private copy (or even a shared copy) which overrides the system
;; default.

;; You can get step by step help in installing this file by going to
;; <http://www.verilog.com/emacs_install.html>

;; The short list of installation instructions are: To set up
77
;; automatic Verilog mode, put this file in your load path, and put
Dan Nicolaescu's avatar
Dan Nicolaescu committed
78 79 80 81
;; the following in code (please un comment it first!) in your
;; .emacs, or in your site's site-load.el

; (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
Wilson Snyder's avatar
Wilson Snyder committed
82
; (add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
83

Wilson Snyder's avatar
Wilson Snyder committed
84 85 86
;; Be sure to examine at the help for verilog-auto, and the other
;; verilog-auto-* functions for some major coding time savers.
;;
Dan Nicolaescu's avatar
Dan Nicolaescu committed
87
;; If you want to customize Verilog mode to fit your needs better,
Wilson Snyder's avatar
Wilson Snyder committed
88
;; you may add the below lines (the values of the variables presented
Dan Nicolaescu's avatar
Dan Nicolaescu committed
89
;; here are the defaults). Note also that if you use an Emacs that
Dan Nicolaescu's avatar
Dan Nicolaescu committed
90
;; supports custom, it's probably better to use the custom menu to
Wilson Snyder's avatar
Wilson Snyder committed
91 92 93 94
;; edit these. If working as a member of a large team these settings
;; should be common across all users (in a site-start file), or set
;; in Local Variables in every file.  Otherwise, different people's
;; AUTO expansion may result different whitespace changes.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
95
;;
Wilson Snyder's avatar
Wilson Snyder committed
96 97 98
; ;; Enable syntax highlighting of **all** languages
; (global-font-lock-mode t)
;
Dan Nicolaescu's avatar
Dan Nicolaescu committed
99 100 101 102 103 104 105 106 107 108 109 110 111
; ;; User customization for Verilog mode
; (setq verilog-indent-level             3
;       verilog-indent-level-module      3
;       verilog-indent-level-declaration 3
;       verilog-indent-level-behavioral  3
;       verilog-indent-level-directive   1
;       verilog-case-indent              2
;       verilog-auto-newline             t
;       verilog-auto-indent-on-newline   t
;       verilog-tab-always-indent        t
;       verilog-auto-endcomments         t
;       verilog-minimum-comment-distance 40
;       verilog-indent-begin-after-if    t
112
;       verilog-auto-lineup              'declarations
Dan Nicolaescu's avatar
Dan Nicolaescu committed
113 114 115 116 117 118 119
;       verilog-highlight-p1800-keywords nil
;	verilog-linter			 "my_lint_shell_command"
;	)

;; 

;;; History:
120
;;
121
;; See commit history at http://www.veripool.org/verilog-mode.html
Dan Nicolaescu's avatar
Dan Nicolaescu committed
122 123
;; (This section is required to appease checkdoc.)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
124 125 126
;;; Code:

;; This variable will always hold the version number of the mode
127
(defconst verilog-mode-version "650"
128
  "Version of this Verilog mode.")
129
(defconst verilog-mode-release-date "2010-11-05-GNU"
130
  "Release date of this Verilog mode.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
131
(defconst verilog-mode-release-emacs t
132
  "If non-nil, this version of Verilog mode was released with Emacs itself.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
133 134 135 136

(defun verilog-version ()
  "Inform caller of the version of this file."
  (interactive)
137
  (message "Using verilog-mode version %s" verilog-mode-version))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
138 139

;; Insure we have certain packages, and deal with it if we don't
Dan Nicolaescu's avatar
Dan Nicolaescu committed
140
;; Be sure to note which Emacs flavor and version added each feature.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
141
(eval-when-compile
142
  ;; Provide stuff if we are XEmacs
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
  (when (featurep 'xemacs)
    (condition-case nil
        (require 'easymenu)
      (error nil))
    (condition-case nil
        (require 'regexp-opt)
      (error nil))
    ;; Bug in 19.28 through 19.30 skeleton.el, not provided.
    (condition-case nil
        (load "skeleton")
      (error nil))
    (condition-case nil
        (if (fboundp 'when)
            nil ;; fab
          (defmacro when (cond &rest body)
            (list 'if cond (cons 'progn body))))
      (error nil))
    (condition-case nil
        (if (fboundp 'unless)
            nil ;; fab
          (defmacro unless (cond &rest body)
            (cons 'if (cons cond (cons nil body)))))
      (error nil))
    (condition-case nil
        (if (fboundp 'store-match-data)
            nil ;; fab
          (defmacro store-match-data (&rest args) nil))
      (error nil))
    (condition-case nil
        (if (fboundp 'char-before)
            nil ;; great
          (defmacro char-before (&rest body)
            (char-after (1- (point)))))
      (error nil))
    (condition-case nil
        (require 'custom)
      (error nil))
    (condition-case nil
        (if (fboundp 'match-string-no-properties)
            nil ;; great
          (defsubst match-string-no-properties (num &optional string)
            "Return string of text matched by last search, without text properties.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
185 186 187 188
NUM specifies which parenthesized expression in the last regexp.
 Value is nil if NUMth pair didn't match, or there were less than NUM pairs.
Zero means the entire text matched by the whole regexp or whole string.
STRING should be given if the last search was by `string-match' on STRING."
189 190 191 192 193 194 195 196 197
            (if (match-beginning num)
                (if string
                    (let ((result
                           (substring string
				      (match-beginning num) (match-end num))))
                      (set-text-properties 0 (length result) nil result)
                      result)
                  (buffer-substring-no-properties (match-beginning num)
                                                  (match-end num)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
198 199
                                                  (current-buffer)))))
	  )
200 201 202 203 204 205 206
      (error nil))
    (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
        nil ;; We've got what we needed
      ;; We have the old custom-library, hack around it!
      (defmacro defgroup (&rest args)  nil)
      (defmacro customize (&rest args)
        (message
207
	 "Sorry, Customize is not available with this version of Emacs"))
208 209 210 211 212 213 214 215
      (defmacro defcustom (var value doc &rest args)
        `(defvar ,var ,value ,doc))
      )
    (if (fboundp 'defface)
        nil				; great!
      (defmacro defface (var values doc &rest args)
        `(make-face ,var))
      )
Dan Nicolaescu's avatar
Dan Nicolaescu committed
216

217 218 219 220 221
    (if (and (featurep 'custom) (fboundp 'customize-group))
        nil ;; We've got what we needed
      ;; We have an intermediate custom-library, hack around it!
      (defmacro customize-group (var &rest args)
        `(customize ,var))
Wilson Snyder's avatar
Wilson Snyder committed
222 223 224 225 226 227 228 229
      )

    (unless (boundp 'inhibit-point-motion-hooks)
      (defvar inhibit-point-motion-hooks nil))
    (unless (boundp 'deactivate-mark)
      (defvar deactivate-mark nil))
    )
  ;;
230 231 232 233 234 235
  ;; OK, do this stuff if we are NOT XEmacs:
  (unless (featurep 'xemacs)
    (unless (fboundp 'region-active-p)
      (defmacro region-active-p ()
	`(and transient-mark-mode mark-active))))
  )
Dan Nicolaescu's avatar
Dan Nicolaescu committed
236 237 238 239

;; Provide a regular expression optimization routine, using regexp-opt
;; if provided by the user's elisp libraries
(eval-and-compile
Dan Nicolaescu's avatar
Dan Nicolaescu committed
240 241
  ;; The below were disabled when GNU Emacs 22 was released;
  ;; perhaps some still need to be there to support Emacs 21.
242 243 244 245 246 247 248 249
  (if (featurep 'xemacs)
      (if (fboundp 'regexp-opt)
          ;; regexp-opt is defined, does it take 3 or 2 arguments?
          (if (fboundp 'function-max-args)
              (let ((args (function-max-args `regexp-opt)))
                (cond
                 ((eq args 3) ;; It takes 3
                  (condition-case nil	; Hide this defun from emacses
Dan Nicolaescu's avatar
Dan Nicolaescu committed
250
					;with just a two input regexp
251 252
                      (defun verilog-regexp-opt (a b)
                        "Deal with differing number of required arguments for  `regexp-opt'.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
253
         Call 'regexp-opt' on A and B."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
254
                        (regexp-opt a b 't))
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
                    (error nil))
                  )
                 ((eq args 2) ;; It takes 2
                  (defun verilog-regexp-opt (a b)
                    "Call 'regexp-opt' on A and B."
                    (regexp-opt a b))
                  )
                 (t nil)))
            ;; We can't tell; assume it takes 2
            (defun verilog-regexp-opt (a b)
              "Call 'regexp-opt' on A and B."
              (regexp-opt a b))
            )
        ;; There is no regexp-opt, provide our own
        (defun verilog-regexp-opt (strings &optional paren shy)
          (let ((open (if paren "\\(" "")) (close (if paren "\\)" "")))
            (concat open (mapconcat 'regexp-quote strings "\\|") close)))
        )
    ;; Emacs.
    (defalias 'verilog-regexp-opt 'regexp-opt)))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
275

Wilson Snyder's avatar
Wilson Snyder committed
276 277 278 279 280 281 282
(eval-and-compile
  ;; Both xemacs and emacs
  (condition-case nil
      (unless (fboundp 'buffer-chars-modified-tick)  ;; Emacs 22 added
	(defmacro buffer-chars-modified-tick () (buffer-modified-tick)))
    (error nil)))

283 284 285 286
(eval-when-compile
  (defun verilog-regexp-words (a)
    "Call 'regexp-opt' with word delimiters for the words A."
    (concat "\\<" (verilog-regexp-opt a t) "\\>")))
Wilson Snyder's avatar
Wilson Snyder committed
287 288 289 290
(defun verilog-regexp-words (a)
  "Call 'regexp-opt' with word delimiters for the words A."
  ;; The FAQ references this function, so user LISP sometimes calls it
  (concat "\\<" (verilog-regexp-opt a t) "\\>"))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
291

292
(defun verilog-easy-menu-filter (menu)
293
  "Filter `easy-menu-define' MENU to support new features."
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
  (cond ((not (featurep 'xemacs))
	 menu) ;; GNU Emacs - passthru
	;; Xemacs doesn't support :help.  Strip it.
	;; Recursively filter the a submenu
	((listp menu)
	 (mapcar 'verilog-easy-menu-filter menu))
	;; Look for [:help "blah"] and remove
	((vectorp menu)
	 (let ((i 0) (out []))
	   (while (< i (length menu))
	     (if (equal `:help (aref menu i))
		 (setq i (+ 2 i))
	       (setq out (vconcat out (vector (aref menu i)))
		     i (1+ i))))
	   out))
	(t menu))) ;; Default - ok
;;(verilog-easy-menu-filter
;;  `("Verilog" ("MA" ["SAA" nil :help "Help SAA"] ["SAB" nil :help "Help SAA"])
;;     "----" ["MB" nil :help "Help MB"]))

Dan Nicolaescu's avatar
Dan Nicolaescu committed
314
(defun verilog-customize ()
315
  "Customize variables and other settings used by Verilog-Mode."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
316 317 318 319
  (interactive)
  (customize-group 'verilog-mode))

(defun verilog-font-customize ()
320
  "Customize fonts used by Verilog-Mode."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
321
  (interactive)
322 323
  (if (fboundp 'customize-apropos)
      (customize-apropos "font-lock-*" 'faces)))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
324

325 326
(defun verilog-booleanp (value)
  "Return t if VALUE is boolean.
327 328
This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs.
This function may be removed when Emacs 21 is no longer supported."
329 330
  (or (equal value t) (equal value nil)))

331 332 333 334 335 336 337 338
(defun verilog-insert-last-command-event ()
  "Insert the `last-command-event'."
  (insert (if (featurep 'xemacs)
	      ;; XEmacs 21.5 doesn't like last-command-event
	      last-command-char
	    ;; And GNU Emacs 22 has obsoleted last-command-char
	    last-command-event)))

339 340 341 342
(defalias 'verilog-syntax-ppss
  (if (fboundp 'syntax-ppss) 'syntax-ppss
    (lambda (&optional pos) (parse-partial-sexp (point-min) (or pos (point))))))

Dan Nicolaescu's avatar
Dan Nicolaescu committed
343
(defgroup verilog-mode nil
344
  "Facilitates easy editing of Verilog source text."
345
  :version "22.2"
Dan Nicolaescu's avatar
Dan Nicolaescu committed
346 347 348 349 350 351 352 353
  :group 'languages)

; (defgroup verilog-mode-fonts nil
;   "Facilitates easy customization fonts used in Verilog source text"
;   :link '(customize-apropos "font-lock-*" 'faces)
;  :group 'verilog-mode)

(defgroup verilog-mode-indent nil
354
  "Customize indentation and highlighting of Verilog source text."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
355 356 357
  :group 'verilog-mode)

(defgroup verilog-mode-actions nil
358
  "Customize actions on Verilog source text."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
359 360 361
  :group 'verilog-mode)

(defgroup verilog-mode-auto nil
362
  "Customize AUTO actions when expanding Verilog source text."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
363 364
  :group 'verilog-mode)

Wilson Snyder's avatar
Wilson Snyder committed
365 366 367
(defvar verilog-debug nil
  "If set, enable debug messages for `verilog-mode' internals.")

Dan Nicolaescu's avatar
Dan Nicolaescu committed
368 369
(defcustom verilog-linter
  "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
370
  "*Unix program and arguments to call to run a lint checker on Verilog source.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
371 372 373 374 375
Depending on the `verilog-set-compile-command', this may be invoked when
you type \\[compile].  When the compile completes, \\[next-error] will take
you to the next lint error."
  :type 'string
  :group 'verilog-mode-actions)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
376
;; We don't mark it safe, as it's used as a shell command
Dan Nicolaescu's avatar
Dan Nicolaescu committed
377 378 379

(defcustom verilog-coverage
  "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'"
380
  "*Program and arguments to use to annotate for coverage Verilog source.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
381 382 383 384 385
Depending on the `verilog-set-compile-command', this may be invoked when
you type \\[compile].  When the compile completes, \\[next-error] will take
you to the next lint error."
  :type 'string
  :group 'verilog-mode-actions)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
386
;; We don't mark it safe, as it's used as a shell command
Dan Nicolaescu's avatar
Dan Nicolaescu committed
387 388 389

(defcustom verilog-simulator
  "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'"
390
  "*Program and arguments to use to interpret Verilog source.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
391 392 393 394 395
Depending on the `verilog-set-compile-command', this may be invoked when
you type \\[compile].  When the compile completes, \\[next-error] will take
you to the next lint error."
  :type 'string
  :group 'verilog-mode-actions)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
396
;; We don't mark it safe, as it's used as a shell command
Dan Nicolaescu's avatar
Dan Nicolaescu committed
397 398 399

(defcustom verilog-compiler
  "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'"
400
  "*Program and arguments to use to compile Verilog source.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
401 402 403 404 405
Depending on the `verilog-set-compile-command', this may be invoked when
you type \\[compile].  When the compile completes, \\[next-error] will take
you to the next lint error."
  :type 'string
  :group 'verilog-mode-actions)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
406
;; We don't mark it safe, as it's used as a shell command
Dan Nicolaescu's avatar
Dan Nicolaescu committed
407

Wilson Snyder's avatar
Wilson Snyder committed
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
(defcustom verilog-preprocessor
  ;; Very few tools give preprocessed output, so we'll default to Verilog-Perl
  "vppreproc __FLAGS__ __FILE__"
  "*Program and arguments to use to preprocess Verilog source.
This is invoked with `verilog-preprocess', and depending on the
`verilog-set-compile-command', may also be invoked when you type
\\[compile].  When the compile completes, \\[next-error] will
take you to the next lint error."
  :type 'string
  :group 'verilog-mode-actions)
;; We don't mark it safe, as it's used as a shell command

(defvar verilog-preprocess-history nil
  "History for `verilog-preprocess'.")

Dan Nicolaescu's avatar
Dan Nicolaescu committed
423 424
(defvar verilog-tool 'verilog-linter
  "Which tool to use for building compiler-command.
Wilson Snyder's avatar
Wilson Snyder committed
425 426 427 428
Either nil, `verilog-linter, `verilog-compiler,
`verilog-coverage, `verilog-preprocessor, or `verilog-simulator.
Alternatively use the \"Choose Compilation Action\" menu.  See
`verilog-set-compile-command' for more information.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
429 430 431 432 433 434 435 436 437 438 439 440 441

(defcustom verilog-highlight-translate-off nil
  "*Non-nil means background-highlight code excluded from translation.
That is, all code between \"// synopsys translate_off\" and
\"// synopsys translate_on\" is highlighted using a different background color
\(face `verilog-font-lock-translate-off-face').

Note: This will slow down on-the-fly fontification (and thus editing).

Note: Activate the new setting in a Verilog buffer by re-fontifying it (menu
entry \"Fontify Buffer\").  XEmacs: turn off and on font locking."
  :type 'boolean
  :group 'verilog-mode-indent)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
442
;; Note we don't use :safe, as that would break on Emacsen before 22.0.
443
(put 'verilog-highlight-translate-off 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
444

445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
(defcustom verilog-auto-lineup 'declarations
  "*Type of statements to lineup across multiple lines.
If 'all' is selected, then all line ups described below are done.

If 'declaration', then just declarations are lined up with any
preceding declarations, taking into account widths and the like,
so or example the code:
 	reg [31:0] a;
 	reg b;
would become
 	reg [31:0] a;
 	reg        b;

If 'assignment', then assignments are lined up with any preceding
assignments, so for example the code
	a_long_variable <= b + c;
	d = e + f;
would become
	a_long_variable <= b + c;
	d                = e + f;

In order to speed up editing, large blocks of statements are lined up
only when a \\[verilog-pretty-expr] is typed; and large blocks of declarations
are lineup only when \\[verilog-pretty-declarations] is typed."

  :type '(radio (const :tag "Line up Assignments and Declarations" all)
		(const :tag "Line up Assignment statements" assignments )
472
		(const :tag "Line up Declarations" declarations)
473 474 475
		(function :tag "Other"))
  :group 'verilog-mode-indent )

Dan Nicolaescu's avatar
Dan Nicolaescu committed
476 477 478 479
(defcustom verilog-indent-level 3
  "*Indentation of Verilog statements with respect to containing block."
  :group 'verilog-mode-indent
  :type 'integer)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
480
(put 'verilog-indent-level 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
481 482

(defcustom verilog-indent-level-module 3
483
  "*Indentation of Module level Verilog statements (eg always, initial).
Dan Nicolaescu's avatar
Dan Nicolaescu committed
484 485 486 487
Set to 0 to get initial and always statements lined up on the left side of
your screen."
  :group 'verilog-mode-indent
  :type 'integer)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
488
(put 'verilog-indent-level-module 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
489 490 491 492 493 494

(defcustom verilog-indent-level-declaration 3
  "*Indentation of declarations with respect to containing block.
Set to 0 to get them list right under containing block."
  :group 'verilog-mode-indent
  :type 'integer)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
495
(put 'verilog-indent-level-declaration 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
496 497 498 499 500 501 502 503 504 505 506 507 508

(defcustom verilog-indent-declaration-macros nil
  "*How to treat macro expansions in a declaration.
If nil, indent as:
	input [31:0] a;
	input        `CP;
	output       c;
If non nil, treat as:
	input [31:0] a;
	input `CP    ;
	output       c;"
  :group 'verilog-mode-indent
  :type 'boolean)
509
(put 'verilog-indent-declaration-macros 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
510 511 512 513 514 515 516 517 518 519 520 521

(defcustom verilog-indent-lists t
  "*How to treat indenting items in a list.
If t (the default), indent as:
	always @( posedge a or
	          reset ) begin

If nil, treat as:
	always @( posedge a or
	   reset ) begin"
  :group 'verilog-mode-indent
  :type 'boolean)
522
(put 'verilog-indent-lists 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
523 524 525 526 527 528

(defcustom verilog-indent-level-behavioral 3
  "*Absolute indentation of first begin in a task or function block.
Set to 0 to get such code to start at the left side of the screen."
  :group 'verilog-mode-indent
  :type 'integer)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
529
(put 'verilog-indent-level-behavioral 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
530 531 532 533 534 535

(defcustom verilog-indent-level-directive 1
  "*Indentation to add to each level of `ifdef declarations.
Set to 0 to have all directives start at the left side of the screen."
  :group 'verilog-mode-indent
  :type 'integer)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
536
(put 'verilog-indent-level-directive 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
537 538 539 540 541

(defcustom verilog-cexp-indent 2
  "*Indentation of Verilog statements split across lines."
  :group 'verilog-mode-indent
  :type 'integer)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
542
(put 'verilog-cexp-indent 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
543 544 545 546 547

(defcustom verilog-case-indent 2
  "*Indentation for case statements."
  :group 'verilog-mode-indent
  :type 'integer)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
548
(put 'verilog-case-indent 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
549 550 551 552 553

(defcustom verilog-auto-newline t
  "*True means automatically newline after semicolons."
  :group 'verilog-mode-indent
  :type 'boolean)
554
(put 'verilog-auto-newline 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
555 556 557 558 559

(defcustom verilog-auto-indent-on-newline t
  "*True means automatically indent line after newline."
  :group 'verilog-mode-indent
  :type 'boolean)
560
(put 'verilog-auto-indent-on-newline 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
561 562 563

(defcustom verilog-tab-always-indent t
  "*True means TAB should always re-indent the current line.
564
A nil value means TAB will only reindent when at the beginning of the line."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
565 566
  :group 'verilog-mode-indent
  :type 'boolean)
567
(put 'verilog-tab-always-indent 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
568 569 570 571 572

(defcustom verilog-tab-to-comment nil
  "*True means TAB moves to the right hand column in preparation for a comment."
  :group 'verilog-mode-actions
  :type 'boolean)
573
(put 'verilog-tab-to-comment 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
574 575 576 577 578

(defcustom verilog-indent-begin-after-if t
  "*If true, indent begin statements following if, else, while, for and repeat.
Otherwise, line them up."
  :group 'verilog-mode-indent
Dan Nicolaescu's avatar
Dan Nicolaescu committed
579
  :type 'boolean)
580
(put 'verilog-indent-begin-after-if 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
581 582 583 584 585 586


(defcustom verilog-align-ifelse nil
  "*If true, align `else' under matching `if'.
Otherwise else is lined up with first character on line holding matching if."
  :group 'verilog-mode-indent
Dan Nicolaescu's avatar
Dan Nicolaescu committed
587
  :type 'boolean)
588
(put 'verilog-align-ifelse 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
589 590 591 592

(defcustom verilog-minimum-comment-distance 10
  "*Minimum distance (in lines) between begin and end required before a comment.
Setting this variable to zero results in every end acquiring a comment; the
593
default avoids too many redundant comments in tight quarters."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
594 595
  :group 'verilog-mode-indent
  :type 'integer)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
596
(put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
597 598

(defcustom verilog-highlight-p1800-keywords nil
Dan Nicolaescu's avatar
Dan Nicolaescu committed
599 600 601
  "*True means highlight words newly reserved by IEEE-1800.
These will appear in `verilog-font-lock-p1800-face' in order to gently
suggest changing where these words are used as variables to something else.
602
A nil value means highlight these words as appropriate for the SystemVerilog
Dan Nicolaescu's avatar
Dan Nicolaescu committed
603
IEEE-1800 standard.  Note that changing this will require restarting Emacs
604
to see the effect as font color choices are cached by Emacs."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
605 606
  :group 'verilog-mode-indent
  :type 'boolean)
607
(put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
608

609 610
(defcustom verilog-highlight-grouping-keywords nil
  "*True means highlight grouping keywords 'begin' and 'end' more dramatically.
611 612
If false, these words are in the `font-lock-type-face'; if True then they are in
`verilog-font-lock-ams-face'.  Some find that special highlighting on these
613 614 615
grouping constructs allow the structure of the code to be understood at a glance."
  :group 'verilog-mode-indent
  :type 'boolean)
616
(put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp)
617

Wilson Snyder's avatar
Wilson Snyder committed
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
(defcustom verilog-highlight-modules nil
  "*True means highlight module statements for `verilog-load-file-at-point'.
When true, mousing over module names will allow jumping to the
module definition.  If false, this is not supported.  Setting
this is experimental, and may lead to bad performance."
  :group 'verilog-mode-indent
  :type 'boolean)
(put 'verilog-highlight-modules 'safe-local-variable 'verilog-booleanp)

(defcustom verilog-highlight-includes t
  "*True means highlight module statements for `verilog-load-file-at-point'.
When true, mousing over include file names will allow jumping to the
file referenced.  If false, this is not supported."
  :group 'verilog-mode-indent
  :type 'boolean)
(put 'verilog-highlight-includes 'safe-local-variable 'verilog-booleanp)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
635 636 637 638
(defcustom verilog-auto-endcomments t
  "*True means insert a comment /* ... */ after 'end's.
The name of the function or case will be set between the braces."
  :group 'verilog-mode-actions
Dan Nicolaescu's avatar
Dan Nicolaescu committed
639
  :type 'boolean)
640
(put 'verilog-auto-endcomments 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
641

642 643 644 645 646 647 648 649 650 651
(defcustom verilog-auto-ignore-concat nil
  "*True means ignore signals in {...} concatenations for AUTOWIRE etc.
This will exclude signals referenced as pin connections in {...}
from AUTOWIRE, AUTOOUTPUT and friends.  This flag should be set
for backward compatibility only and not set in new designs; it
may be removed in future versions."
  :group 'verilog-mode-actions
  :type 'boolean)
(put 'verilog-auto-ignore-concat 'safe-local-variable 'verilog-booleanp)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
652 653 654 655 656 657 658
(defcustom verilog-auto-read-includes nil
  "*True means to automatically read includes before AUTOs.
This will do a `verilog-read-defines' and `verilog-read-includes' before
each AUTO expansion.  This makes it easier to embed defines and includes,
but can result in very slow reading times if there are many or large
include files."
  :group 'verilog-mode-actions
Dan Nicolaescu's avatar
Dan Nicolaescu committed
659
  :type 'boolean)
660
(put 'verilog-auto-read-includes 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680

(defcustom verilog-auto-save-policy nil
  "*Non-nil indicates action to take when saving a Verilog buffer with AUTOs.
A value of `force' will always do a \\[verilog-auto] automatically if
needed on every save.  A value of `detect' will do \\[verilog-auto]
automatically when it thinks necessary.  A value of `ask' will query the
user when it thinks updating is needed.

You should not rely on the 'ask or 'detect policies, they are safeguards
only.  They do not detect when AUTOINSTs need to be updated because a
sub-module's port list has changed."
  :group 'verilog-mode-actions
  :type '(choice (const nil) (const ask) (const detect) (const force)))

(defcustom verilog-auto-star-expand t
  "*Non-nil indicates to expand a SystemVerilog .* instance ports.
They will be expanded in the same way as if there was a AUTOINST in the
instantiation.  See also `verilog-auto-star' and `verilog-auto-star-save'."
  :group 'verilog-mode-actions
  :type 'boolean)
681
(put 'verilog-auto-star-expand 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
682 683 684

(defcustom verilog-auto-star-save nil
  "*Non-nil indicates to save to disk SystemVerilog .* instance expansions.
685 686
A nil value indicates direct connections will be removed before saving.
Only meaningful to those created due to `verilog-auto-star-expand' being set.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
687 688 689 690 691

Instead of setting this, you may want to use /*AUTOINST*/, which will
always be saved."
  :group 'verilog-mode-actions
  :type 'boolean)
692
(put 'verilog-auto-star-save 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
693 694 695 696 697 698 699

(defvar verilog-auto-update-tick nil
  "Modification tick at which autos were last performed.")

(defvar verilog-auto-last-file-locals nil
  "Text from file-local-variables during last evaluation.")

700 701
;;; Compile support
(require 'compile)
702
(defvar verilog-error-regexp-added nil)
Wilson Snyder's avatar
Wilson Snyder committed
703

704 705 706 707 708 709 710
(defvar verilog-error-regexp-emacs-alist
  '(
    (verilog-xl-1
     "\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
    (verilog-xl-2
     "([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 3)
    (verilog-IES
Wilson Snyder's avatar
Wilson Snyder committed
711
     ".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)" 2 3)
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
    (verilog-surefire-1
     "[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2)
    (verilog-surefire-2
     "\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\),\\s-+\\(line \\)?\\([0-9]+\\):" 2 4 )
    (verilog-verbose
     "\
\\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
:\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
    (verilog-xsim
     "\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3)
    (verilog-vcs-1
     "\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3)
    (verilog-vcs-2
     "Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2)
    (verilog-vcs-3
     "\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3)
    (verilog-vcs-4
     "syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
    (verilog-verilator
     "%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
    (verilog-leda
Wilson Snyder's avatar
Wilson Snyder committed
733
     "^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 2)
734
    )
Wilson Snyder's avatar
Wilson Snyder committed
735 736 737 738 739 740 741 742 743 744
  "List of regexps for Verilog compilers.
See `compilation-error-regexp-alist' for the formatting.  For Emacs 22+.")

(defvar verilog-error-regexp-xemacs-alist
  ;; Emacs form is '((v-tool "re" 1 2) ...)
  ;; XEmacs form is '(verilog ("re" 1 2) ...)
  ;; So we can just map from Emacs to Xemacs
  (cons 'verilog (mapcar 'cdr verilog-error-regexp-emacs-alist))
  "List of regexps for Verilog compilers.
See `compilation-error-regexp-alist-alist' for the formatting.  For XEmacs.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
745 746 747

(defvar verilog-error-font-lock-keywords
  '(
Wilson Snyder's avatar
Wilson Snyder committed
748 749 750 751 752 753 754 755 756 757
    ;; verilog-xl-1
    ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
    ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
    ;; verilog-xl-2
    ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 1 bold t)
    ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\(line[ \t]+\\)?\\([0-9]+\\):.*$" 3 bold t)
    ;; verilog-IES (nc-verilog)
    (".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t)
    (".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)|" 3 bold t)
    ;; verilog-surefire-1
Dan Nicolaescu's avatar
Dan Nicolaescu committed
758 759
    ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t)
    ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t)
Wilson Snyder's avatar
Wilson Snyder committed
760
    ;; verilog-surefire-2
Dan Nicolaescu's avatar
Dan Nicolaescu committed
761 762
    ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t)
    ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t)
Wilson Snyder's avatar
Wilson Snyder committed
763
    ;; verilog-verbose
Dan Nicolaescu's avatar
Dan Nicolaescu committed
764 765 766 767 768 769
    ("\
\\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
:\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
    ("\
\\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
:\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 bold t)
Wilson Snyder's avatar
Wilson Snyder committed
770
    ;; verilog-vcs-1
Dan Nicolaescu's avatar
Dan Nicolaescu committed
771 772
    ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t)
    ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t)
Wilson Snyder's avatar
Wilson Snyder committed
773
    ;; verilog-vcs-2
Dan Nicolaescu's avatar
Dan Nicolaescu committed
774 775
    ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
    ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
Wilson Snyder's avatar
Wilson Snyder committed
776
    ;; verilog-vcs-3
Dan Nicolaescu's avatar
Dan Nicolaescu committed
777 778
    ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
    ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t)
Wilson Snyder's avatar
Wilson Snyder committed
779
    ;; verilog-vcs-4
Dan Nicolaescu's avatar
Dan Nicolaescu committed
780 781
    ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t)
    ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
Wilson Snyder's avatar
Wilson Snyder committed
782 783 784 785 786 787
    ;; verilog-verilator
    (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t)
    (".*%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t)
    ;; verilog-leda
    ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 bold t)
    ("^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 2 bold t)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
788
    )
Wilson Snyder's avatar
Wilson Snyder committed
789 790
  "*Keywords to also highlight in Verilog *compilation* buffers.
Only used in XEmacs; GNU Emacs uses `verilog-error-regexp-emacs-alist'.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814

(defcustom verilog-library-flags '("")
  "*List of standard Verilog arguments to use for /*AUTOINST*/.
These arguments are used to find files for `verilog-auto', and match
the flags accepted by a standard Verilog-XL simulator.

    -f filename     Reads more `verilog-library-flags' from the filename.
    +incdir+dir     Adds the directory to `verilog-library-directories'.
    -Idir           Adds the directory to `verilog-library-directories'.
    -y dir          Adds the directory to `verilog-library-directories'.
    +libext+.v      Adds the extensions to `verilog-library-extensions'.
    -v filename     Adds the filename to `verilog-library-files'.

    filename        Adds the filename to `verilog-library-files'.
                    This is not recommended, -v is a better choice.

You might want these defined in each file; put at the *END* of your file
something like:

    // Local Variables:
    // verilog-library-flags:(\"-y dir -y otherdir\")
    // End:

Verilog-mode attempts to detect changes to this local variable, but they
815
are only insured to be correct when the file is first visited.  Thus if you
Dan Nicolaescu's avatar
Dan Nicolaescu committed
816 817 818 819 820
have problems, use \\[find-alternate-file] RET to have these take effect.

See also the variables mentioned above."
  :group 'verilog-mode-auto
  :type '(repeat string))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
821
(put 'verilog-library-flags 'safe-local-variable 'listp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836

(defcustom verilog-library-directories '(".")
  "*List of directories when looking for files for /*AUTOINST*/.
The directory may be relative to the current file, or absolute.
Environment variables are also expanded in the directory names.
Having at least the current directory is a good idea.

You might want these defined in each file; put at the *END* of your file
something like:

    // Local Variables:
    // verilog-library-directories:(\".\" \"subdir\" \"subdir2\")
    // End:

Verilog-mode attempts to detect changes to this local variable, but they
837
are only insured to be correct when the file is first visited.  Thus if you
Dan Nicolaescu's avatar
Dan Nicolaescu committed
838 839 840 841 842 843
have problems, use \\[find-alternate-file] RET to have these take effect.

See also `verilog-library-flags', `verilog-library-files'
and `verilog-library-extensions'."
  :group 'verilog-mode-auto
  :type '(repeat file))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
844
(put 'verilog-library-directories 'safe-local-variable 'listp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
845 846

(defcustom verilog-library-files '()
Dan Nicolaescu's avatar
Dan Nicolaescu committed
847 848
  "*List of files to search for modules.
AUTOINST will use this when it needs to resolve a module name.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
849 850 851 852 853 854 855 856 857 858 859
This is a complete path, usually to a technology file with many standard
cells defined in it.

You might want these defined in each file; put at the *END* of your file
something like:

    // Local Variables:
    // verilog-library-files:(\"/some/path/technology.v\" \"/some/path/tech2.v\")
    // End:

Verilog-mode attempts to detect changes to this local variable, but they
860
are only insured to be correct when the file is first visited.  Thus if you
Dan Nicolaescu's avatar
Dan Nicolaescu committed
861 862 863 864 865
have problems, use \\[find-alternate-file] RET to have these take effect.

See also `verilog-library-flags', `verilog-library-directories'."
  :group 'verilog-mode-auto
  :type '(repeat directory))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
866
(put 'verilog-library-files 'safe-local-variable 'listp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
867

868
(defcustom verilog-library-extensions '(".v" ".sv")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
869 870 871 872
  "*List of extensions to use when looking for files for /*AUTOINST*/.
See also `verilog-library-flags', `verilog-library-directories'."
  :type '(repeat string)
  :group 'verilog-mode-auto)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
873
(put 'verilog-library-extensions 'safe-local-variable 'listp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
874 875 876 877 878 879 880

(defcustom verilog-active-low-regexp nil
  "*If set, treat signals matching this regexp as active low.
This is used for AUTORESET and AUTOTIEOFF.  For proper behavior,
you will probably also need `verilog-auto-reset-widths' set."
  :group 'verilog-mode-auto
  :type 'string)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
881
(put 'verilog-active-low-regexp 'safe-local-variable 'stringp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
882 883 884 885 886

(defcustom verilog-auto-sense-include-inputs nil
  "*If true, AUTOSENSE should include all inputs.
If nil, only inputs that are NOT output signals in the same block are
included."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
887 888
  :group 'verilog-mode-auto
  :type 'boolean)
889
(put 'verilog-auto-sense-include-inputs 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
890 891 892 893 894

(defcustom verilog-auto-sense-defines-constant nil
  "*If true, AUTOSENSE should assume all defines represent constants.
When true, the defines will not be included in sensitivity lists.  To
maintain compatibility with other sites, this should be set at the bottom
895
of each Verilog file that requires it, rather than being set globally."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
896 897
  :group 'verilog-mode-auto
  :type 'boolean)
898
(put 'verilog-auto-sense-defines-constant 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
899 900 901 902 903 904

(defcustom verilog-auto-reset-widths t
  "*If true, AUTORESET should determine the width of signals.
This is then used to set the width of the zero (32'h0 for example).  This
is required by some lint tools that aren't smart enough to ignore widths of
the constant zero.  This may result in ugly code when parameters determine
905
the MSB or LSB of a signal inside an AUTORESET."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
906 907
  :type 'boolean
  :group 'verilog-mode-auto)
908
(put 'verilog-auto-reset-widths 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
909 910 911

(defcustom verilog-assignment-delay ""
  "*Text used for delays in delayed assignments.  Add a trailing space if set."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
912 913 914
  :group 'verilog-mode-auto
  :type 'string)
(put 'verilog-assignment-delay 'safe-local-variable 'stringp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
915

916
(defcustom verilog-auto-arg-sort nil
917 918 919 920 921
  "*If set, AUTOARG signal names will be sorted, not in delaration order.
Declaration order is advantageous with order based instantiations
and is the default for backward compatibility.  Sorted order
reduces changes when declarations are moved around in a file, and
it's bad practice to rely on order based instantiations anyhow."
922 923 924 925
  :group 'verilog-mode-auto
  :type 'boolean)
(put 'verilog-auto-arg-sort 'safe-local-variable 'verilog-booleanp)

Wilson Snyder's avatar
Wilson Snyder committed
926 927 928 929 930 931 932 933 934 935
(defcustom verilog-auto-inst-dot-name nil
  "*If true, when creating ports with AUTOINST, use .name syntax.
This will use \".port\" instead of \".port(port)\" when possible.
This is only legal in SystemVerilog files, and will confuse older
simulators.  Setting `verilog-auto-inst-vector' to nil may also
be desirable to increase how often .name will be used."
  :group 'verilog-mode-auto
  :type 'boolean)
(put 'verilog-auto-inst-dot-name 'safe-local-variable 'verilog-booleanp)

936 937 938 939 940 941 942 943 944 945 946
(defcustom verilog-auto-inst-param-value nil
  "*If set, AUTOINST will replace parameters with the parameter value.
If nil, leave parameters as symbolic names.

Parameters must be in Verilog 2001 format #(...), and if a parameter is not
listed as such there (as when the default value is acceptable), it will not
be replaced, and will remain symbolic.

For example, imagine a submodule uses parameters to declare the size of its
inputs.  This is then used by a upper module:

Wilson Snyder's avatar
Wilson Snyder committed
947
	module InstModule (o,i);
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
	   parameter WIDTH;
	   input [WIDTH-1:0] i;
	endmodule

	module ExampInst;
	   InstModule
 	     #(PARAM(10))
	    instName
	     (/*AUTOINST*/
	      .i 	(i[PARAM-1:0]));

Note even though PARAM=10, the AUTOINST has left the parameter as a
symbolic name.  If `verilog-auto-inst-param-value' is set, this will
instead expand to:

	module ExampInst;
	   InstModule
 	     #(PARAM(10))
	    instName
	     (/*AUTOINST*/
	      .i 	(i[9:0]));"
  :group 'verilog-mode-auto
  :type 'boolean)
971
(put 'verilog-auto-inst-param-value 'safe-local-variable 'verilog-booleanp)
972

Dan Nicolaescu's avatar
Dan Nicolaescu committed
973 974 975 976
(defcustom verilog-auto-inst-vector t
  "*If true, when creating default ports with AUTOINST, use bus subscripts.
If nil, skip the subscript when it matches the entire bus as declared in
the module (AUTOWIRE signals always are subscripted, you must manually
977 978
declare the wire to have the subscripts removed.)  Setting this to nil may
speed up some simulators, but is less general and harder to read, so avoid."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
979
  :group 'verilog-mode-auto
Dan Nicolaescu's avatar
Dan Nicolaescu committed
980
  :type 'boolean)
981
(put 'verilog-auto-inst-vector 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
982 983 984 985 986 987 988

(defcustom verilog-auto-inst-template-numbers nil
  "*If true, when creating templated ports with AUTOINST, add a comment.
The comment will add the line number of the template that was used for that
port declaration.  Setting this aids in debugging, but nil is suggested for
regular use to prevent large numbers of merge conflicts."
  :group 'verilog-mode-auto
Dan Nicolaescu's avatar
Dan Nicolaescu committed
989
  :type 'boolean)
990
(put 'verilog-auto-inst-template-numbers 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
991

992 993 994 995 996
(defcustom verilog-auto-inst-column 40
  "*Indent-to column number for net name part of AUTOINST created pin."
  :group 'verilog-mode-indent
  :type 'integer)
(put 'verilog-auto-inst-column 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
997 998 999 1000 1001

(defcustom verilog-auto-input-ignore-regexp nil
  "*If set, when creating AUTOINPUT list, ignore signals matching this regexp.
See the \\[verilog-faq] for examples on using this."
  :group 'verilog-mode-auto
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1002 1003
  :type 'string)
(put 'verilog-auto-input-ignore-regexp 'safe-local-variable 'stringp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1004 1005 1006 1007 1008

(defcustom verilog-auto-inout-ignore-regexp nil
  "*If set, when creating AUTOINOUT list, ignore signals matching this regexp.
See the \\[verilog-faq] for examples on using this."
  :group 'verilog-mode-auto
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1009 1010
  :type 'string)
(put 'verilog-auto-inout-ignore-regexp 'safe-local-variable 'stringp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1011 1012 1013 1014 1015

(defcustom verilog-auto-output-ignore-regexp nil
  "*If set, when creating AUTOOUTPUT list, ignore signals matching this regexp.
See the \\[verilog-faq] for examples on using this."
  :group 'verilog-mode-auto
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1016 1017
  :type 'string)
(put 'verilog-auto-output-ignore-regexp 'safe-local-variable 'stringp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1018

Wilson Snyder's avatar
Wilson Snyder committed
1019 1020 1021 1022 1023 1024 1025
(defcustom verilog-auto-tieoff-ignore-regexp nil
  "*If set, when creating AUTOTIEOFF list, ignore signals matching this regexp.
See the \\[verilog-faq] for examples on using this."
  :group 'verilog-mode-auto
  :type 'string)
(put 'verilog-auto-tieoff-ignore-regexp 'safe-local-variable 'stringp)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
1026 1027 1028 1029
(defcustom verilog-auto-unused-ignore-regexp nil
  "*If set, when creating AUTOUNUSED list, ignore signals matching this regexp.
See the \\[verilog-faq] for examples on using this."
  :group 'verilog-mode-auto
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1030 1031
  :type 'string)
(put 'verilog-auto-unused-ignore-regexp 'safe-local-variable 'stringp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1032 1033 1034 1035 1036

(defcustom verilog-typedef-regexp nil
  "*If non-nil, regular expression that matches Verilog-2001 typedef names.
For example, \"_t$\" matches typedefs named with _t, as in the C language."
  :group 'verilog-mode-auto
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1037 1038
  :type 'string)
(put 'verilog-typedef-regexp 'safe-local-variable 'stringp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1039 1040

(defcustom verilog-mode-hook   'verilog-set-compile-command
1041
  "*Hook run after Verilog mode is loaded."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1042 1043 1044 1045 1046
  :type 'hook
  :group 'verilog-mode)

(defcustom verilog-auto-hook nil
  "*Hook run after `verilog-mode' updates AUTOs."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1047 1048
  :group 'verilog-mode-auto
  :type 'hook)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1049 1050 1051

(defcustom verilog-before-auto-hook nil
  "*Hook run before `verilog-mode' updates AUTOs."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1052 1053
  :group 'verilog-mode-auto
  :type 'hook)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1054 1055 1056

(defcustom verilog-delete-auto-hook nil
  "*Hook run after `verilog-mode' deletes AUTOs."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1057 1058
  :group 'verilog-mode-auto
  :type 'hook)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1059 1060 1061

(defcustom verilog-before-delete-auto-hook nil
  "*Hook run before `verilog-mode' deletes AUTOs."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1062 1063
  :group 'verilog-mode-auto
  :type 'hook)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1064 1065 1066

(defcustom verilog-getopt-flags-hook nil
  "*Hook run after `verilog-getopt-flags' determines the Verilog option lists."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1067 1068
  :group 'verilog-mode-auto
  :type 'hook)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1069 1070 1071

(defcustom verilog-before-getopt-flags-hook nil
  "*Hook run before `verilog-getopt-flags' determines the Verilog option lists."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1072 1073
  :group 'verilog-mode-auto
  :type 'hook)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1074 1075 1076 1077

(defvar verilog-imenu-generic-expression
  '((nil "^\\s-*\\(\\(m\\(odule\\|acromodule\\)\\)\\|primitive\\)\\s-+\\([a-zA-Z0-9_.:]+\\)" 4)
    ("*Vars*" "^\\s-*\\(reg\\|wire\\)\\s-+\\(\\|\\[[^]]+\\]\\s-+\\)\\([A-Za-z0-9_]+\\)" 3))
1078
  "Imenu expression for Verilog mode.  See `imenu-generic-expression'.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089

;;
;; provide a verilog-header function.
;; Customization variables:
;;
(defvar verilog-date-scientific-format nil
  "*If non-nil, dates are written in scientific format (e.g.  1997/09/17).
If nil, in European format (e.g.  17.09.1997).  The brain-dead American
format (e.g.  09/17/1997) is not supported.")

(defvar verilog-company nil
1090
  "*Default name of Company for Verilog header.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1091
If set will become buffer local.")
1092 1093
(make-variable-buffer-local 'verilog-company)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
1094
(defvar verilog-project nil
1095
  "*Default name of Project for Verilog header.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1096
If set will become buffer local.")
1097 1098
(make-variable-buffer-local 'verilog-project)

1099
(defvar verilog-mode-map
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
  (let ((map (make-sparse-keymap)))
    (define-key map ";"        'electric-verilog-semi)
    (define-key map [(control 59)]    'electric-verilog-semi-with-comment)
    (define-key map ":"        'electric-verilog-colon)
    ;;(define-key map "="        'electric-verilog-equal)
    (define-key map "\`"       'electric-verilog-tick)
    (define-key map "\t"       'electric-verilog-tab)
    (define-key map "\r"       'electric-verilog-terminate-line)
    ;; backspace/delete key bindings
    (define-key map [backspace]    'backward-delete-char-untabify)
    (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
      (define-key map [delete]       'delete-char)
      (define-key map [(meta delete)] 'kill-word))
    (define-key map "\M-\C-b"  'electric-verilog-backward-sexp)
    (define-key map "\M-\C-f"  'electric-verilog-forward-sexp)
    (define-key map "\M-\r"    `electric-verilog-terminate-and-indent)
    (define-key map "\M-\t"    'verilog-complete-word)
    (define-key map "\M-?"     'verilog-show-completions)
    (define-key map "\C-c\`"   'verilog-lint-off)
    (define-key map "\C-c\*"   'verilog-delete-auto-star-implicit)
    (define-key map "\C-c\C-r" 'verilog-label-be)
    (define-key map "\C-c\C-i" 'verilog-pretty-declarations)
    (define-key map "\C-c="    'verilog-pretty-expr)
    (define-key map "\C-c\C-b" 'verilog-submit-bug-report)
    (define-key map "\M-*"     'verilog-star-comment)
    (define-key map "\C-c\C-c" 'verilog-comment-region)
    (define-key map "\C-c\C-u" 'verilog-uncomment-region)
1127 1128 1129 1130
    (when (featurep 'xemacs)
      (define-key map [(meta control h)] 'verilog-mark-defun)
      (define-key map "\M-\C-a"  'verilog-beg-of-defun)
      (define-key map "\M-\C-e"  'verilog-end-of-defun))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1131 1132 1133 1134
    (define-key map "\C-c\C-d" 'verilog-goto-defun)
    (define-key map "\C-c\C-k" 'verilog-delete-auto)
    (define-key map "\C-c\C-a" 'verilog-auto)
    (define-key map "\C-c\C-s" 'verilog-auto-save-compile)
Wilson Snyder's avatar
Wilson Snyder committed
1135
    (define-key map "\C-c\C-p" 'verilog-preprocess)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1136 1137
    (define-key map "\C-c\C-z" 'verilog-inject-auto)
    (define-key map "\C-c\C-e" 'verilog-expand-vector)
1138 1139
    (define-key map "\C-c\C-h" 'verilog-header)
    map)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1140 1141 1142
  "Keymap used in Verilog mode.")

;; menus
1143 1144
(easy-menu-define
  verilog-menu verilog-mode-map "Menu for Verilog mode"
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182
  (verilog-easy-menu-filter
   '("Verilog"
     ("Choose Compilation Action"
      ["None"
       (progn
	 (setq verilog-tool nil)
	 (verilog-set-compile-command))
       :style radio
       :selected (equal verilog-tool nil)
       :help "When invoking compilation, use compile-command"]
      ["Lint"
       (progn
	 (setq verilog-tool 'verilog-linter)
	 (verilog-set-compile-command))
       :style radio
       :selected (equal verilog-tool `verilog-linter)
       :help "When invoking compilation, use lint checker"]
      ["Coverage"
       (progn
	 (setq verilog-tool 'verilog-coverage)
	 (verilog-set-compile-command))
       :style radio
       :selected (equal verilog-tool `verilog-coverage)
       :help "When invoking compilation, annotate for coverage"]
      ["Simulator"
       (progn
	 (setq verilog-tool 'verilog-simulator)
	 (verilog-set-compile-command))
       :style radio
       :selected (equal verilog-tool `verilog-simulator)
       :help "When invoking compilation, interpret Verilog source"]
      ["Compiler"
       (progn
	 (setq verilog-tool 'verilog-compiler)
	 (verilog-set-compile-command))
       :style radio
       :selected (equal verilog-tool `verilog-compiler)
       :help "When invoking compilation, compile Verilog source"]
Wilson Snyder's avatar
Wilson Snyder committed
1183 1184 1185 1186 1187 1188 1189
      ["Preprocessor"
       (progn
	 (setq verilog-tool 'verilog-preprocessor)
	 (verilog-set-compile-command))
       :style radio
       :selected (equal verilog-tool `verilog-preprocessor)
       :help "When invoking compilation, preprocess Verilog source, see also `verilog-preprocess'"]
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
      )
     ("Move"
      ["Beginning of function"		verilog-beg-of-defun
       :keys "C-M-a"
       :help		"Move backward to the beginning of the current function or procedure"]
      ["End of function"		verilog-end-of-defun
       :keys "C-M-e"
       :help		"Move forward to the end of the current function or procedure"]
      ["Mark function"			verilog-mark-defun
       :keys "C-M-h"
       :help		"Mark the current Verilog function or procedure"]
      ["Goto function/module"		verilog-goto-defun
       :help		"Move to specified Verilog module/task/function"]
      ["Move to beginning of block"	electric-verilog-backward-sexp
       :help		"Move backward over one balanced expression"]
      ["Move to end of block"		electric-verilog-forward-sexp
       :help		"Move forward over one balanced expression"]
      )
     ("Comments"
      ["Comment Region"			verilog-comment-region
       :help		"Put marked area into a comment"]
      ["UnComment Region"		verilog-uncomment-region
       :help		"Uncomment an area commented with Comment Region"]
      ["Multi-line comment insert"	verilog-star-comment
       :help		"Insert Verilog /* */ comment at point"]
      ["Lint error to comment"		verilog-lint-off
       :help		"Convert a Verilog linter warning line into a disable statement"]
      )
     "----"
     ["Compile"				compile
      :help		"Perform compilation-action (above) on the current buffer"]
     ["AUTO, Save, Compile"		verilog-auto-save-compile
      :help		"Recompute AUTOs, save buffer, and compile"]
     ["Next Compile Error"		next-error
      :help		"Visit next compilation error message and corresponding source code"]
     ["Ignore Lint Warning at point"	verilog-lint-off
      :help		"Convert a Verilog linter warning line into a disable statement"]
     "----"
     ["Line up declarations around point"	verilog-pretty-declarations
      :help		"Line up declarations around point"]
     ["Line up equations around point"		verilog-pretty-expr
      :help		"Line up expressions around point"]
     ["Redo/insert comments on every end"	verilog-label-be
      :help		"Label matching begin ... end statements"]
     ["Expand [x:y] vector line"	verilog-expand-vector
      :help		"Take a signal vector on the current line and expand it to multiple lines"]
     ["Insert begin-end block"		verilog-insert-block
      :help		"Insert begin ... end"]
     ["Complete word"			verilog-complete-word
      :help		"Complete word at point"]
     "----"
     ["Recompute AUTOs"			verilog-auto
      :help		"Expand AUTO meta-comment statements"]
     ["Kill AUTOs"			verilog-delete-auto
      :help		"Remove AUTO expansions"]
     ["Inject AUTOs"			verilog-inject-auto
      :help		"Inject AUTOs into legacy non-AUTO buffer"]
     ("AUTO Help..."
      ["AUTO General"			(describe-function 'verilog-auto)
       :help		"Help introduction on AUTOs"]
      ["AUTO Library Flags"		(describe-variable 'verilog-library-flags)
       :help		"Help on verilog-library-flags"]
      ["AUTO Library Path"		(describe-variable 'verilog-library-directories)
       :help		"Help on verilog-library-directories"]
      ["AUTO Library Files"		(describe-variable 'verilog-library-files)
       :help		"Help on verilog-library-files"]
      ["AUTO Library Extensions"	(describe-variable 'verilog-library-extensions)
       :help		"Help on verilog-library-extensions"]
      ["AUTO `define Reading"		(describe-function 'verilog-read-defines)
       :help		"Help on reading `defines"]
      ["AUTO `include Reading"		(describe-function 'verilog-read-includes)
       :help		"Help on parsing `includes"]
      ["AUTOARG"			(describe-function 'verilog-auto-arg)
       :help		"Help on AUTOARG - declaring module port list"]
      ["AUTOASCIIENUM"			(describe-function 'verilog-auto-ascii-enum)
       :help		"Help on AUTOASCIIENUM - creating ASCII for enumerations"]
1266
      ["AUTOINOUTCOMP"			(describe-function 'verilog-auto-inout-comp)
1267
       :help		"Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
1268 1269
      ["AUTOINOUTMODULE"		(describe-function 'verilog-auto-inout-module)
       :help		"Help on AUTOINOUTMODULE - copying i/o from another file"]
1270 1271
      ["AUTOINSERTLISP"			(describe-function 'verilog-auto-insert-lisp)
       :help		"Help on AUTOINSERTLISP - insert text from a lisp function"]
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309
      ["AUTOINOUT"			(describe-function 'verilog-auto-inout)
       :help		"Help on AUTOINOUT - adding inouts from cells"]
      ["AUTOINPUT"			(describe-function 'verilog-auto-input)
       :help		"Help on AUTOINPUT - adding inputs from cells"]
      ["AUTOINST"			(describe-function 'verilog-auto-inst)
       :help		"Help on AUTOINST - adding pins for cells"]
      ["AUTOINST (.*)"			(describe-function 'verilog-auto-star)
       :help		"Help on expanding Verilog-2001 .* pins"]
      ["AUTOINSTPARAM"			(describe-function 'verilog-auto-inst-param)
       :help		"Help on AUTOINSTPARAM - adding parameter pins to cells"]
      ["AUTOOUTPUT"			(describe-function 'verilog-auto-output)
       :help		"Help on AUTOOUTPUT - adding outputs from cells"]
      ["AUTOOUTPUTEVERY"		(describe-function 'verilog-auto-output-every)
       :help		"Help on AUTOOUTPUTEVERY - adding outputs of all signals"]
      ["AUTOREG"			(describe-function 'verilog-auto-reg)
       :help		"Help on AUTOREG - declaring registers for non-wires"]
      ["AUTOREGINPUT"			(describe-function 'verilog-auto-reg-input)
       :help		"Help on AUTOREGINPUT - declaring inputs for non-wires"]
      ["AUTORESET"			(describe-function 'verilog-auto-reset)
       :help		"Help on AUTORESET - resetting always blocks"]
      ["AUTOSENSE"			(describe-function 'verilog-auto-sense)
       :help		"Help on AUTOSENSE - sensitivity lists for always blocks"]
      ["AUTOTIEOFF"			(describe-function 'verilog-auto-tieoff)
       :help		"Help on AUTOTIEOFF - tieing off unused outputs"]
      ["AUTOUNUSED"			(describe-function 'verilog-auto-unused)
       :help		"Help on AUTOUNUSED - terminating unused inputs"]
      ["AUTOWIRE"			(describe-function 'verilog-auto-wire)
       :help		"Help on AUTOWIRE - declaring wires for cells"]
      )
     "----"
     ["Submit bug report"		verilog-submit-bug-report
      :help		"Submit via mail a bug report on verilog-mode.el"]
     ["Version and FAQ"			verilog-faq
      :help		"Show the current version, and where to get the FAQ etc"]
     ["Customize Verilog Mode..."	verilog-customize
      :help		"Customize variables and other settings used by Verilog-Mode"]
     ["Customize Verilog Fonts & Colors"	verilog-font-customize
      :help		"Customize fonts used by Verilog-Mode."])))
1310 1311 1312

(easy-menu-define
  verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog."
1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370
  (verilog-easy-menu-filter
   '("Statements"
     ["Header"		verilog-sk-header
      :help		"Insert a header block at the top of file"]
     ["Comment"		verilog-sk-comment
      :help		"Insert a comment block"]
     "----"
     ["Module"		verilog-sk-module
      :help		"Insert a module .. (/*AUTOARG*/);.. endmodule block"]
     ["Primitive"	verilog-sk-primitive
      :help		"Insert a primitive .. (.. );.. endprimitive block"]
     "----"
     ["Input"		verilog-sk-input
      :help		"Insert an input declaration"]
     ["Output"		verilog-sk-output
      :help		"Insert an output declaration"]
     ["Inout"		verilog-sk-inout
      :help		"Insert an inout declaration"]
     ["Wire"		verilog-sk-wire
      :help		"Insert a wire declaration"]
     ["Reg"		verilog-sk-reg
      :help		"Insert a register declaration"]
     ["Define thing under point as a register" verilog-sk-define-signal
      :help		"Define signal under point as a register at the top of the module"]
     "----"
     ["Initial"		verilog-sk-initial
      :help		"Insert an initial begin .. end block"]
     ["Always"		verilog-sk-always
      :help		"Insert an always @(AS) begin .. end block"]
     ["Function"	verilog-sk-function
      :help		"Insert a function .. begin .. end endfunction block"]
     ["Task"		verilog-sk-task
      :help		"Insert a task .. begin .. end endtask block"]
     ["Specify"		verilog-sk-specify
      :help		"Insert a specify .. endspecify block"]
     ["Generate"	verilog-sk-generate
      :help		"Insert a generate .. endgenerate block"]
     "----"
     ["Begin"		verilog-sk-begin
      :help		"Insert a begin .. end block"]
     ["If"		verilog-sk-if
      :help		"Insert an if (..) begin .. end block"]
     ["(if) else"	verilog-sk-else-if
      :help		"Insert an else if (..) begin .. end block"]
     ["For"		verilog-sk-for
      :help		"Insert a for (...) begin .. end block"]
     ["While"		verilog-sk-while
      :help		"Insert a while (...) begin .. end block"]
     ["Fork"		verilog-sk-fork
      :help		"Insert a fork begin .. end .. join block"]
     ["Repeat"		verilog-sk-repeat
      :help		"Insert a repeat (..) begin .. end block"]
     ["Case"		verilog-sk-case
      :help		"Insert a case block, prompting for details"]
     ["Casex"		verilog-sk-casex
      :help		"Insert a casex (...) item: begin.. end endcase block"]
     ["Casez"		verilog-sk-casez
      :help		"Insert a casez (...) item: begin.. end endcase block"])))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1371 1372 1373 1374 1375 1376

(defvar verilog-mode-abbrev-table nil
  "Abbrev table in use in Verilog-mode buffers.")

(define-abbrev-table 'verilog-mode-abbrev-table ())

1377 1378 1379 1380
;;
;;  Macros
;;

Wilson Snyder's avatar
Wilson Snyder committed
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394
(defsubst verilog-get-beg-of-line (&optional arg)
  (save-excursion
    (beginning-of-line arg)
    (point)))

(defsubst verilog-get-end-of-line (&optional arg)
  (save-excursion
    (end-of-line arg)
    (point)))

(defsubst verilog-within-string ()
  (save-excursion
    (nth 3 (parse-partial-sexp (verilog-get-beg-of-line) (point)))))

1395 1396 1397 1398 1399 1400 1401 1402 1403
(defsubst verilog-string-replace-matches (from-string to-string fixedcase literal string)
  "Replace occurrences of FROM-STRING with TO-STRING.
FIXEDCASE and LITERAL as in `replace-match`.  STRING is what to replace.
The case (verilog-string-replace-matches \"o\" \"oo\" nil nil \"foobar\")
will break, as the o's continuously replace.  xa -> x works ok though."
  ;; Hopefully soon to a emacs built-in
  (let ((start 0))
    (while (string-match from-string string start)
      (setq string (replace-match to-string fixedcase literal string)
1404
	    start (min (length string) (+ (match-beginning 0) (length to-string)))))
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416
    string))

(defsubst verilog-string-remove-spaces (string)
  "Remove spaces surrounding STRING."
  (save-match-data
    (setq string (verilog-string-replace-matches "^\\s-+" "" nil nil string))
    (setq string (verilog-string-replace-matches "\\s-+$" "" nil nil string))
    string))

(defsubst verilog-re-search-forward (REGEXP BOUND NOERROR)
  ; checkdoc-params: (REGEXP BOUND NOERROR)
  "Like `re-search-forward', but skips over match in comments or strings."
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428
  (let ((mdata '(nil nil)))  ;; So match-end will return nil if no matches found
    (while (and
	    (re-search-forward REGEXP BOUND NOERROR)
	    (setq mdata (match-data))
	    (and (verilog-skip-forward-comment-or-string)
		 (progn
		   (setq mdata '(nil nil))
		   (if BOUND
		       (< (point) BOUND)
		     t)))))
    (store-match-data mdata)
    (match-end 0)))
1429 1430 1431 1432

(defsubst verilog-re-search-backward (REGEXP BOUND NOERROR)
  ; checkdoc-params: (REGEXP BOUND NOERROR)
  "Like `re-search-backward', but skips over match in comments or strings."
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444
  (let ((mdata '(nil nil)))  ;; So match-end will return nil if no matches found
    (while (and
	    (re-search-backward REGEXP BOUND NOERROR)
	    (setq mdata (match-data))
	    (and (verilog-skip-backward-comment-or-string)
		 (progn
		   (setq mdata '(nil nil))
		   (if BOUND
		       (> (point) BOUND)
		     t)))))
    (store-match-data mdata)
    (match-end 0)))
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470

(defsubst verilog-re-search-forward-quick (regexp bound noerror)
  "Like `verilog-re-search-forward', including use of REGEXP BOUND and NOERROR,
but trashes match data and is faster for REGEXP that doesn't match often.
This may at some point use text properties to ignore comments,
so there may be a large up front penalty for the first search."
  (let (pt)
    (while (and (not pt)
		(re-search-forward regexp bound noerror))
      (if (not (verilog-inside-comment-p))
	  (setq pt (match-end 0))))
    pt))

(defsubst verilog-re-search-backward-quick (regexp bound noerror)
  ; checkdoc-params: (REGEXP BOUND NOERROR)
  "Like `verilog-re-search-backward', including use of REGEXP BOUND and NOERROR,
but trashes match data and is faster for REGEXP that doesn't match often.
This may at some point use text properties to ignore comments,
so there may be a large up front penalty for the first search."
  (let (pt)
    (while (and (not pt)
		(re-search-backward regexp bound noerror))
      (if (not (verilog-inside-comment-p))
	  (setq pt (match-end 0))))
    pt))

Wilson Snyder's avatar
Wilson Snyder committed
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509
(defsubst verilog-re-search-forward-substr (substr regexp bound noerror)
  "Like `re-search-forward', but first search for SUBSTR constant.
Then searched for the normal REGEXP (which contains SUBSTR), with given
BOUND and NOERROR.  The REGEXP must fit within a single line.
This speeds up complicated regexp matches."
  ;; Problem with overlap: search-forward BAR then FOOBARBAZ won't match.
  ;; thus require matches to be on one line, and use beginning-of-line.
  (let (done)
    (while (and (not done)
		(search-forward substr bound noerror))
      (save-excursion
	(beginning-of-line)
	(setq done (re-search-forward regexp (verilog-get-end-of-line) noerror)))
      (unless (and (<= (match-beginning 0) (point))
		   (>= (match-end 0) (point)))
	(setq done nil)))
    (when done (goto-char done))
    done))
;;(verilog-re-search-forward-substr "-end" "get-end-of" nil t) ;;-end (test bait)

(defsubst verilog-re-search-backward-substr (substr regexp bound noerror)
  "Like `re-search-backward', but first search for SUBSTR constant.
Then searched for the normal REGEXP (which contains SUBSTR), with given
BOUND and NOERROR.  The REGEXP must fit within a single line.
This speeds up complicated regexp matches."
  ;; Problem with overlap: search-backward BAR then FOOBARBAZ won't match.
  ;; thus require matches to be on one line, and use beginning-of-line.
  (let (done)
    (while (and (not done)
		(search-backward substr bound noerror))
      (save-excursion
	(end-of-line)
	(setq done (re-search-backward regexp (verilog-get-beg-of-line) noerror)))
      (unless (and (<= (match-beginning 0) (point))
		   (>= (match-end 0) (point)))
	(setq done nil)))
    (when done (goto-char done))
    done))
;;(verilog-re-search-backward-substr "-end" "get-end-of" nil t) ;;-end (test bait)
1510

Dan Nicolaescu's avatar
Dan Nicolaescu committed
1511 1512
(defvar compile-command)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
1513 1514
;; compilation program
(defun verilog-set-compile-command ()