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

3
;; Copyright (C) 1996-2014 Free Software Foundation, Inc.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
4

5 6
;; Author: Michael McNamara <mac@verilog.com>
;;    Wilson Snyder <wsnyder@wsnyder.org>
Wilson Snyder's avatar
Wilson Snyder committed
7 8
;;    http://www.verilog.com
;;    http://www.veripool.org
9
;; Created: 3 Jan 1996
Dan Nicolaescu's avatar
Dan Nicolaescu committed
10 11
;; Keywords: languages

12 13 14 15 16
;; 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
17 18 19 20 21 22
;;    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
23 24
;; This file is part of GNU Emacs.

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

Glenn Morris's avatar
Glenn Morris committed
30
;; GNU Emacs is distributed in the hope that it will be useful,
Dan Nicolaescu's avatar
Dan Nicolaescu committed
31 32 33 34 35
;; 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
36
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
37 38 39 40 41 42

;;; Commentary:

;; USAGE
;; =====

43 44 45 46 47
;; A major mode for editing Verilog and SystemVerilog HDL source code (IEEE
;; 1364-2005 and IEEE 1800-2012 standards).  When you have 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>
Dan Nicolaescu's avatar
Dan Nicolaescu committed
48 49 50 51

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

52 53 54 55 56 57
;; SystemVerilog is a rapidly evolving language, and hence this mode is
;; under continuous development.  Please report any issues to the issue
;; tracker at
;;
;;    http://www.veripool.org/verilog-mode
;;
Dan Nicolaescu's avatar
Dan Nicolaescu committed
58
;; Please use verilog-submit-bug-report to submit a report; type C-c
59
;; C-b to invoke this and as a result we will have a much easier time
Dan Nicolaescu's avatar
Dan Nicolaescu committed
60 61 62 63 64 65 66
;; 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
67
;; your Emacs environment.  Sometimes this is difficult for local
Dan Nicolaescu's avatar
Dan Nicolaescu committed
68 69 70 71 72 73 74 75
;; 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
76
;; automatic Verilog mode, put this file in your load path, and put
Dan Nicolaescu's avatar
Dan Nicolaescu committed
77 78 79 80
;; 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 )
81
; (add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
82

Wilson Snyder's avatar
Wilson Snyder committed
83 84 85
;; 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
86
;; If you want to customize Verilog mode to fit your needs better,
Wilson Snyder's avatar
Wilson Snyder committed
87
;; you may add the below lines (the values of the variables presented
Dan Nicolaescu's avatar
Dan Nicolaescu committed
88
;; here are the defaults). Note also that if you use an Emacs that
Dan Nicolaescu's avatar
Dan Nicolaescu committed
89
;; supports custom, it's probably better to use the custom menu to
90
;; edit these.  If working as a member of a large team these settings
Wilson Snyder's avatar
Wilson Snyder committed
91 92 93
;; 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
94
;;
Wilson Snyder's avatar
Wilson Snyder committed
95 96 97
; ;; Enable syntax highlighting of **all** languages
; (global-font-lock-mode t)
;
Dan Nicolaescu's avatar
Dan Nicolaescu committed
98 99 100 101 102 103 104 105 106 107 108 109 110
; ;; 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
111
;       verilog-auto-lineup              'declarations
Dan Nicolaescu's avatar
Dan Nicolaescu committed
112
;       verilog-highlight-p1800-keywords nil
113 114
;       verilog-linter			 "my_lint_shell_command"
;       )
Dan Nicolaescu's avatar
Dan Nicolaescu committed
115 116 117 118

;; 

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

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

;; This variable will always hold the version number of the mode
126
(defconst verilog-mode-version "2014-05-31-3cd8144-vpo"
127
  "Version of this Verilog mode.")
128
(defconst verilog-mode-release-emacs t
129
  "If non-nil, this version of Verilog mode was released with Emacs itself.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
130 131 132 133

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

;; Insure we have certain packages, and deal with it if we don't
Dan Nicolaescu's avatar
Dan Nicolaescu committed
137
;; Be sure to note which Emacs flavor and version added each feature.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
138
(eval-when-compile
139
  ;; Provide stuff if we are XEmacs
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
  (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
166
          (defmacro store-match-data (&rest _args) nil))
167 168 169 170
      (error nil))
    (condition-case nil
        (if (fboundp 'char-before)
            nil ;; great
171
          (defmacro char-before (&rest _body)
172 173
            (char-after (1- (point)))))
      (error nil))
174 175 176 177 178 179 180 181 182 183 184 185
    (condition-case nil
        (if (fboundp 'when)
            nil ;; fab
          (defsubst point-at-bol (&optional N)
            (save-excursion (beginning-of-line N) (point))))
      (error nil))
    (condition-case nil
        (if (fboundp 'when)
            nil ;; fab
          (defsubst point-at-eol (&optional N)
            (save-excursion (end-of-line N) (point))))
      (error nil))
186 187 188 189 190 191 192 193
    (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
194 195 196 197
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."
198 199 200 201 202 203 204 205 206
            (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
207 208
                                                  (current-buffer)))))
	  )
209 210 211 212
      (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!
213 214
      (defmacro defgroup (&rest _args)  nil)
      (defmacro customize (&rest _args)
215
        (message
216
	 "Sorry, Customize is not available with this version of Emacs"))
217
      (defmacro defcustom (var value doc &rest _args)
218 219 220 221
        `(defvar ,var ,value ,doc))
      )
    (if (fboundp 'defface)
        nil				; great!
222
      (defmacro defface (var values doc &rest _args)
223 224
        `(make-face ,var))
      )
Dan Nicolaescu's avatar
Dan Nicolaescu committed
225

226 227 228
    (if (and (featurep 'custom) (fboundp 'customize-group))
        nil ;; We've got what we needed
      ;; We have an intermediate custom-library, hack around it!
229
      (defmacro customize-group (var &rest _args)
230
        `(customize ,var))
Wilson Snyder's avatar
Wilson Snyder committed
231 232 233 234 235 236 237 238
      )

    (unless (boundp 'inhibit-point-motion-hooks)
      (defvar inhibit-point-motion-hooks nil))
    (unless (boundp 'deactivate-mark)
      (defvar deactivate-mark nil))
    )
  ;;
239 240 241 242 243 244
  ;; 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
245 246 247 248

;; 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
249 250
  ;; The below were disabled when GNU Emacs 22 was released;
  ;; perhaps some still need to be there to support Emacs 21.
251 252 253 254 255 256 257 258
  (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
259
					;with just a two input regexp
260 261
                      (defun verilog-regexp-opt (a b)
                        "Deal with differing number of required arguments for  `regexp-opt'.
262 263
         Call `regexp-opt' on A and B."
                        (regexp-opt a b t))
264 265 266 267
                    (error nil))
                  )
                 ((eq args 2) ;; It takes 2
                  (defun verilog-regexp-opt (a b)
268
                    "Call `regexp-opt' on A and B."
269 270 271 272 273
                    (regexp-opt a b))
                  )
                 (t nil)))
            ;; We can't tell; assume it takes 2
            (defun verilog-regexp-opt (a b)
274
              "Call `regexp-opt' on A and B."
275 276 277
              (regexp-opt a b))
            )
        ;; There is no regexp-opt, provide our own
278
        (defun verilog-regexp-opt (strings &optional paren _shy)
279 280 281 282 283
          (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
284

Wilson Snyder's avatar
Wilson Snyder committed
285 286
(eval-and-compile
  ;; Both xemacs and emacs
287 288 289 290 291 292
  (condition-case nil
      (require 'diff) ;; diff-command and diff-switches
    (error nil))
  (condition-case nil
      (require 'compile) ;; compilation-error-regexp-alist-alist
    (error nil))
Wilson Snyder's avatar
Wilson Snyder committed
293 294 295
  (condition-case nil
      (unless (fboundp 'buffer-chars-modified-tick)  ;; Emacs 22 added
	(defmacro buffer-chars-modified-tick () (buffer-modified-tick)))
296 297 298 299 300
    (error nil))
  ;; Added in Emacs 24.1
  (condition-case nil
      (unless (fboundp 'prog-mode)
	(define-derived-mode prog-mode fundamental-mode "Prog"))
Wilson Snyder's avatar
Wilson Snyder committed
301 302
    (error nil)))

303 304 305 306
(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
307 308 309 310
(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
311

312
(defun verilog-easy-menu-filter (menu)
313
  "Filter `easy-menu-define' MENU to support new features."
314 315
  (cond ((not (featurep 'xemacs))
	 menu) ;; GNU Emacs - passthru
Juanma Barranquero's avatar
Juanma Barranquero committed
316
	;; XEmacs doesn't support :help.  Strip it.
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
	;; 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"]))

334 335 336 337 338 339 340 341
(defun verilog-define-abbrev (table name expansion &optional hook)
  "Filter `define-abbrev' TABLE NAME EXPANSION and call HOOK.
Provides SYSTEM-FLAG in newer Emacs."
  (condition-case nil
      (define-abbrev table name expansion hook 0 t)
    (error
     (define-abbrev table name expansion hook))))

Dan Nicolaescu's avatar
Dan Nicolaescu committed
342
(defun verilog-customize ()
343
  "Customize variables and other settings used by Verilog-Mode."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
344 345 346 347
  (interactive)
  (customize-group 'verilog-mode))

(defun verilog-font-customize ()
348
  "Customize fonts used by Verilog-Mode."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
349
  (interactive)
350 351
  (if (fboundp 'customize-apropos)
      (customize-apropos "font-lock-*" 'faces)))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
352

353 354
(defun verilog-booleanp (value)
  "Return t if VALUE is boolean.
355 356
This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs.
This function may be removed when Emacs 21 is no longer supported."
357 358
  (or (equal value t) (equal value nil)))

359 360 361 362 363 364 365 366
(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)))

367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
(defvar verilog-no-change-functions nil
  "True if `after-change-functions' is disabled.
Use of `syntax-ppss' may break, as ppss's cache may get corrupted.")

(defvar verilog-in-hooks nil
  "True when within a `verilog-run-hooks' block.")

(defmacro verilog-run-hooks (&rest hooks)
  "Run each hook in HOOKS using `run-hooks'.
Set `verilog-in-hooks' during this time, to assist AUTO caches."
  `(let ((verilog-in-hooks t))
     (run-hooks ,@hooks)))

(defun verilog-syntax-ppss (&optional pos)
  (when verilog-no-change-functions
    (if verilog-in-hooks
	(verilog-scan-cache-flush)
      ;; else don't let the AUTO code itself get away with flushing the cache,
      ;; as that'll make things very slow
      (backtrace)
      (error "%s: Internal problem; use of syntax-ppss when cache may be corrupt"
	     (verilog-point-text))))
  (if (fboundp 'syntax-ppss)
      (syntax-ppss pos)
    (parse-partial-sexp (point-min) (or pos (point)))))
392

Dan Nicolaescu's avatar
Dan Nicolaescu committed
393
(defgroup verilog-mode nil
394
  "Major mode for Verilog source code."
395
  :version "22.2"
Dan Nicolaescu's avatar
Dan Nicolaescu committed
396 397 398 399 400 401 402 403
  :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
404
  "Customize indentation and highlighting of Verilog source text."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
405 406 407
  :group 'verilog-mode)

(defgroup verilog-mode-actions nil
408
  "Customize actions on Verilog source text."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
409 410 411
  :group 'verilog-mode)

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

Wilson Snyder's avatar
Wilson Snyder committed
415
(defvar verilog-debug nil
416 417 418 419
  "Non-nil means enable debug messages for `verilog-mode' internals.")

(defvar verilog-warn-fatal nil
  "Non-nil means `verilog-warn-error' warnings are fatal `error's.")
Wilson Snyder's avatar
Wilson Snyder committed
420

Dan Nicolaescu's avatar
Dan Nicolaescu committed
421 422
(defcustom verilog-linter
  "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
423
  "Unix program and arguments to call to run a lint checker on Verilog source.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
424 425 426 427 428
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
429
;; We don't mark it safe, as it's used as a shell command
Dan Nicolaescu's avatar
Dan Nicolaescu committed
430 431 432

(defcustom verilog-coverage
  "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'"
433
  "Program and arguments to use to annotate for coverage Verilog source.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
434 435 436 437 438
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
439
;; We don't mark it safe, as it's used as a shell command
Dan Nicolaescu's avatar
Dan Nicolaescu committed
440 441 442

(defcustom verilog-simulator
  "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'"
443
  "Program and arguments to use to interpret Verilog source.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
444 445 446 447 448
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
449
;; We don't mark it safe, as it's used as a shell command
Dan Nicolaescu's avatar
Dan Nicolaescu committed
450 451 452

(defcustom verilog-compiler
  "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'"
453
  "Program and arguments to use to compile Verilog source.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
454 455 456 457 458
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
459
;; We don't mark it safe, as it's used as a shell command
Dan Nicolaescu's avatar
Dan Nicolaescu committed
460

Wilson Snyder's avatar
Wilson Snyder committed
461 462 463
(defcustom verilog-preprocessor
  ;; Very few tools give preprocessed output, so we'll default to Verilog-Perl
  "vppreproc __FLAGS__ __FILE__"
464
  "Program and arguments to use to preprocess Verilog source.
Wilson Snyder's avatar
Wilson Snyder committed
465 466 467 468 469 470 471 472 473 474 475
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
476 477
(defvar verilog-tool 'verilog-linter
  "Which tool to use for building compiler-command.
Wilson Snyder's avatar
Wilson Snyder committed
478 479 480 481
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
482 483

(defcustom verilog-highlight-translate-off nil
484
  "Non-nil means background-highlight code excluded from translation.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
485 486 487 488 489 490 491 492 493 494
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
495
;; Note we don't use :safe, as that would break on Emacsen before 22.0.
496
(put 'verilog-highlight-translate-off 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
497

498
(defcustom verilog-auto-lineup 'declarations
499
  "Type of statements to lineup across multiple lines.
500 501
If 'all' is selected, then all line ups described below are done.

502
If 'declarations', then just declarations are lined up with any
503 504
preceding declarations, taking into account widths and the like,
so or example the code:
505 506
	reg [31:0] a;
	reg b;
507
would become
508 509
	reg [31:0] a;
	reg        b;
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524

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 )
525
		(const :tag "Line up Declarations" declarations)
526 527
		(function :tag "Other"))
  :group 'verilog-mode-indent )
528 529
(put 'verilog-auto-lineup 'safe-local-variable
     '(lambda (x) (memq x '(nil all assignments declarations))))
530

Dan Nicolaescu's avatar
Dan Nicolaescu committed
531
(defcustom verilog-indent-level 3
532
  "Indentation of Verilog statements with respect to containing block."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
533 534
  :group 'verilog-mode-indent
  :type 'integer)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
535
(put 'verilog-indent-level 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
536 537

(defcustom verilog-indent-level-module 3
538
  "Indentation of Module level Verilog statements (eg always, initial).
Dan Nicolaescu's avatar
Dan Nicolaescu committed
539 540 541 542
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
543
(put 'verilog-indent-level-module 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
544 545

(defcustom verilog-indent-level-declaration 3
546
  "Indentation of declarations with respect to containing block.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
547 548 549
Set to 0 to get them list right under containing block."
  :group 'verilog-mode-indent
  :type 'integer)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
550
(put 'verilog-indent-level-declaration 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
551 552

(defcustom verilog-indent-declaration-macros nil
553
  "How to treat macro expansions in a declaration.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
554 555 556 557 558 559 560 561 562 563
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)
564
(put 'verilog-indent-declaration-macros 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
565 566

(defcustom verilog-indent-lists t
567
  "How to treat indenting items in a list.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
568 569 570 571 572 573 574 575 576
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)
577
(put 'verilog-indent-lists 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
578 579

(defcustom verilog-indent-level-behavioral 3
580
  "Absolute indentation of first begin in a task or function block.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
581 582 583
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
584
(put 'verilog-indent-level-behavioral 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
585 586

(defcustom verilog-indent-level-directive 1
587
  "Indentation to add to each level of `ifdef declarations.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
588 589 590
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
591
(put 'verilog-indent-level-directive 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
592 593

(defcustom verilog-cexp-indent 2
594
  "Indentation of Verilog statements split across lines."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
595 596
  :group 'verilog-mode-indent
  :type 'integer)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
597
(put 'verilog-cexp-indent 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
598 599

(defcustom verilog-case-indent 2
600
  "Indentation for case statements."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
601 602
  :group 'verilog-mode-indent
  :type 'integer)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
603
(put 'verilog-case-indent 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
604 605

(defcustom verilog-auto-newline t
606
  "Non-nil means automatically newline after semicolons."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
607 608
  :group 'verilog-mode-indent
  :type 'boolean)
609
(put 'verilog-auto-newline 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
610 611

(defcustom verilog-auto-indent-on-newline t
612
  "Non-nil means automatically indent line after newline."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
613 614
  :group 'verilog-mode-indent
  :type 'boolean)
615
(put 'verilog-auto-indent-on-newline 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
616 617

(defcustom verilog-tab-always-indent t
618
  "Non-nil means TAB should always re-indent the current line.
619
A nil value means TAB will only reindent when at the beginning of the line."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
620 621
  :group 'verilog-mode-indent
  :type 'boolean)
622
(put 'verilog-tab-always-indent 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
623 624

(defcustom verilog-tab-to-comment nil
625
  "Non-nil means TAB moves to the right hand column in preparation for a comment."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
626 627
  :group 'verilog-mode-actions
  :type 'boolean)
628
(put 'verilog-tab-to-comment 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
629 630

(defcustom verilog-indent-begin-after-if t
631
  "Non-nil means indent begin statements following if, else, while, etc.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
632 633
Otherwise, line them up."
  :group 'verilog-mode-indent
Dan Nicolaescu's avatar
Dan Nicolaescu committed
634
  :type 'boolean)
635
(put 'verilog-indent-begin-after-if 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
636 637

(defcustom verilog-align-ifelse nil
638
  "Non-nil means align `else' under matching `if'.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
639 640
Otherwise else is lined up with first character on line holding matching if."
  :group 'verilog-mode-indent
Dan Nicolaescu's avatar
Dan Nicolaescu committed
641
  :type 'boolean)
642
(put 'verilog-align-ifelse 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
643 644

(defcustom verilog-minimum-comment-distance 10
645
  "Minimum distance (in lines) between begin and end required before a comment.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
646
Setting this variable to zero results in every end acquiring a comment; the
647
default avoids too many redundant comments in tight quarters."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
648 649
  :group 'verilog-mode-indent
  :type 'integer)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
650
(put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
651 652

(defcustom verilog-highlight-p1800-keywords nil
653
  "Non-nil means highlight words newly reserved by IEEE-1800.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
654 655
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.
656
A nil value means highlight these words as appropriate for the SystemVerilog
Dan Nicolaescu's avatar
Dan Nicolaescu committed
657
IEEE-1800 standard.  Note that changing this will require restarting Emacs
658
to see the effect as font color choices are cached by Emacs."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
659 660
  :group 'verilog-mode-indent
  :type 'boolean)
661
(put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
662

663
(defcustom verilog-highlight-grouping-keywords nil
664
  "Non-nil means highlight grouping keywords more dramatically.
665 666
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
667 668 669
grouping constructs allow the structure of the code to be understood at a glance."
  :group 'verilog-mode-indent
  :type 'boolean)
670
(put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp)
671

Wilson Snyder's avatar
Wilson Snyder committed
672
(defcustom verilog-highlight-modules nil
673
  "Non-nil means highlight module statements for `verilog-load-file-at-point'.
Wilson Snyder's avatar
Wilson Snyder committed
674 675 676 677 678 679 680 681
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
682
  "Non-nil means highlight module statements for `verilog-load-file-at-point'.
Wilson Snyder's avatar
Wilson Snyder committed
683 684 685 686 687 688
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)

689
(defcustom verilog-auto-declare-nettype nil
690
  "Non-nil specifies the data type to use with `verilog-auto-input' etc.
691 692 693
Set this to \"wire\" if the Verilog code uses \"`default_nettype
none\".  Note using `default_nettype none isn't recommended practice; this
mode is experimental."
694
  :version "24.1"  ;; rev670
695 696 697 698 699
  :group 'verilog-mode-actions
  :type 'boolean)
(put 'verilog-auto-declare-nettype 'safe-local-variable `stringp)

(defcustom verilog-auto-wire-type nil
700
  "Non-nil specifies the data type to use with `verilog-auto-wire' etc.
701
Set this to \"logic\" for SystemVerilog code, or use `verilog-auto-logic'."
702
  :version "24.1"  ;; rev673
703 704 705 706
  :group 'verilog-mode-actions
  :type 'boolean)
(put 'verilog-auto-wire-type 'safe-local-variable `stringp)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
707
(defcustom verilog-auto-endcomments t
708
  "Non-nil means insert a comment /* ... */ after 'end's.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
709 710
The name of the function or case will be set between the braces."
  :group 'verilog-mode-actions
Dan Nicolaescu's avatar
Dan Nicolaescu committed
711
  :type 'boolean)
712
(put 'verilog-auto-endcomments 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
713

714
(defcustom verilog-auto-delete-trailing-whitespace nil
715 716
  "Non-nil means to `delete-trailing-whitespace' in `verilog-auto'."
  :version "24.1"  ;; rev703
717 718 719 720
  :group 'verilog-mode-actions
  :type 'boolean)
(put 'verilog-auto-delete-trailing-whitespace 'safe-local-variable 'verilog-booleanp)

721
(defcustom verilog-auto-ignore-concat nil
722
  "Non-nil means ignore signals in {...} concatenations for AUTOWIRE etc.
723 724 725 726 727 728 729 730
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
731
(defcustom verilog-auto-read-includes nil
732
  "Non-nil means to automatically read includes before AUTOs.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
733 734 735 736 737
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
738
  :type 'boolean)
739
(put 'verilog-auto-read-includes 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
740 741

(defcustom verilog-auto-save-policy nil
742
  "Non-nil indicates action to take when saving a Verilog buffer with AUTOs.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
743 744 745 746 747 748 749 750 751 752 753 754
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
755 756
  "Non-nil means to expand SystemVerilog .* instance ports.
They will be expanded in the same way as if there was an AUTOINST in the
Dan Nicolaescu's avatar
Dan Nicolaescu committed
757 758 759
instantiation.  See also `verilog-auto-star' and `verilog-auto-star-save'."
  :group 'verilog-mode-actions
  :type 'boolean)
760
(put 'verilog-auto-star-expand 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
761 762

(defcustom verilog-auto-star-save nil
763
  "Non-nil means save to disk SystemVerilog .* instance expansions.
764 765
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
766 767 768 769 770

Instead of setting this, you may want to use /*AUTOINST*/, which will
always be saved."
  :group 'verilog-mode-actions
  :type 'boolean)
771
(put 'verilog-auto-star-save 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
772 773 774 775 776 777 778

(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.")

779
(defvar verilog-diff-function 'verilog-diff-report
780
  "Function to run when `verilog-diff-auto' detects differences.
781 782 783 784
Function takes three arguments, the original buffer, the
difference buffer, and the point in original buffer with the
first difference.")

785 786
;;; Compile support
(require 'compile)
787
(defvar verilog-error-regexp-added nil)
Wilson Snyder's avatar
Wilson Snyder committed
788

789 790 791 792 793 794 795
(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
796
     ".*\\*[WE],[0-9A-Z]+\\(\[[0-9A-Z_,]+\]\\)? (\\([^ \t,]+\\),\\([0-9]+\\)" 2 3)
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
    (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
818
     "^In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\(Warning\\|Error\\|Failure\\)[^\n]*" 1 2)
819
    )
Wilson Snyder's avatar
Wilson Snyder committed
820 821 822 823 824 825
  "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) ...)
Juanma Barranquero's avatar
Juanma Barranquero committed
826
  ;; So we can just map from Emacs to XEmacs
Wilson Snyder's avatar
Wilson Snyder committed
827 828 829
  (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
830 831 832

(defvar verilog-error-font-lock-keywords
  '(
Wilson Snyder's avatar
Wilson Snyder committed
833 834 835 836 837 838 839 840 841 842
    ;; 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
843 844
    ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t)
    ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t)
Wilson Snyder's avatar
Wilson Snyder committed
845
    ;; verilog-surefire-2
Dan Nicolaescu's avatar
Dan Nicolaescu committed
846 847
    ("\\(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
848
    ;; verilog-verbose
Dan Nicolaescu's avatar
Dan Nicolaescu committed
849 850 851 852 853 854
    ("\
\\([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
855
    ;; verilog-vcs-1
Dan Nicolaescu's avatar
Dan Nicolaescu committed
856 857
    ("\\(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
858
    ;; verilog-vcs-2
Dan Nicolaescu's avatar
Dan Nicolaescu committed
859 860
    ("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
861
    ;; verilog-vcs-3
Dan Nicolaescu's avatar
Dan Nicolaescu committed
862 863
    ("\\(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
864
    ;; verilog-vcs-4
Dan Nicolaescu's avatar
Dan Nicolaescu committed
865 866
    ("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
867 868 869 870 871 872
    ;; 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
873
    )
874
  "Keywords to also highlight in Verilog *compilation* buffers.
Wilson Snyder's avatar
Wilson Snyder committed
875
Only used in XEmacs; GNU Emacs uses `verilog-error-regexp-emacs-alist'.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
876 877

(defcustom verilog-library-flags '("")
878
  "List of standard Verilog arguments to use for /*AUTOINST*/.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
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
900
are only insured to be correct when the file is first visited.  Thus if you
Dan Nicolaescu's avatar
Dan Nicolaescu committed
901 902 903 904 905
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
906
(put 'verilog-library-flags 'safe-local-variable 'listp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
907 908

(defcustom verilog-library-directories '(".")
909
  "List of directories when looking for files for /*AUTOINST*/.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
910 911 912 913 914 915 916 917 918 919 920 921
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
922
are only insured to be correct when the file is first visited.  Thus if you
Dan Nicolaescu's avatar
Dan Nicolaescu committed
923 924 925 926 927 928
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
929
(put 'verilog-library-directories 'safe-local-variable 'listp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
930 931

(defcustom verilog-library-files '()
932
  "List of files to search for modules.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
933
AUTOINST will use this when it needs to resolve a module name.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
934 935 936 937 938 939 940 941 942 943 944
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
945
are only insured to be correct when the file is first visited.  Thus if you
Dan Nicolaescu's avatar
Dan Nicolaescu committed
946 947 948 949 950
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
951
(put 'verilog-library-files 'safe-local-variable 'listp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
952

953
(defcustom verilog-library-extensions '(".v" ".sv")
954
  "List of extensions to use when looking for files for /*AUTOINST*/.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
955 956 957
See also `verilog-library-flags', `verilog-library-directories'."
  :type '(repeat string)
  :group 'verilog-mode-auto)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
958
(put 'verilog-library-extensions 'safe-local-variable 'listp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
959 960

(defcustom verilog-active-low-regexp nil
961
  "If true, treat signals matching this regexp as active low.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
962 963 964
This is used for AUTORESET and AUTOTIEOFF.  For proper behavior,
you will probably also need `verilog-auto-reset-widths' set."
  :group 'verilog-mode-auto
965
  :type '(choice (const nil) regexp))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
966
(put 'verilog-active-low-regexp 'safe-local-variable 'stringp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
967 968

(defcustom verilog-auto-sense-include-inputs nil
969
  "Non-nil means AUTOSENSE should include all inputs.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
970 971
If nil, only inputs that are NOT output signals in the same block are
included."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
972 973
  :group 'verilog-mode-auto
  :type 'boolean)
974
(put 'verilog-auto-sense-include-inputs 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
975 976

(defcustom verilog-auto-sense-defines-constant nil
977
  "Non-nil means AUTOSENSE should assume all defines represent constants.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
978 979
When true, the defines will not be included in sensitivity lists.  To
maintain compatibility with other sites, this should be set at the bottom
980
of each Verilog file that requires it, rather than being set globally."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
981 982
  :group 'verilog-mode-auto
  :type 'boolean)
983
(put 'verilog-auto-sense-defines-constant 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
984

985
(defcustom verilog-auto-reset-blocking-in-non t
986 987 988 989
  "Non-nil means AUTORESET will reset blocking statements.
When true, AUTORESET will reset in blocking statements those
signals which were assigned with blocking assignments (=) even in
a block with non-blocking assignments (<=).
Paul Eggert's avatar
Paul Eggert committed
990

991 992 993 994
If nil, all blocking assigned signals are ignored when any
non-blocking assignment is in the AUTORESET block.  This allows
blocking assignments to be used for temporary values and not have
those temporaries reset.  See example in `verilog-auto-reset'."
995
  :version "24.1"  ;; rev718
996 997 998 999
  :type 'boolean
  :group 'verilog-mode-auto)
(put 'verilog-auto-reset-blocking-in-non 'safe-local-variable 'verilog-booleanp)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
1000
(defcustom verilog-auto-reset-widths t
1001
  "True means AUTORESET should determine the width of signals.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1002 1003
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
1004
the constant zero.  This may result in ugly code when parameters determine
1005 1006 1007 1008 1009 1010 1011
the MSB or LSB of a signal inside an AUTORESET.

If nil, AUTORESET uses \"0\" as the constant.

If 'unbased', AUTORESET used the unbased unsized literal \"'0\"
as the constant. This setting is strongly recommended for
SystemVerilog designs."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1012 1013
  :type 'boolean
  :group 'verilog-mode-auto)
1014 1015
(put 'verilog-auto-reset-widths 'safe-local-variable
     '(lambda (x) (memq x '(nil t unbased))))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1016 1017

(defcustom verilog-assignment-delay ""
1018
  "Text used for delays in delayed assignments.  Add a trailing space if set."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1019 1020 1021
  :group 'verilog-mode-auto
  :type 'string)
(put 'verilog-assignment-delay 'safe-local-variable 'stringp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1022

1023 1024 1025 1026 1027 1028 1029
(defcustom verilog-auto-arg-format 'packed
  "Formatting to use for AUTOARG signal names.
If 'packed', then as many inputs and outputs that fit within
`fill-column' will be put onto one line.

If 'single', then a single input or output will be put onto each
line."
Stefan Monnier's avatar
Stefan Monnier committed
1030
  :version "25.1"
1031 1032 1033 1034 1035 1036
  :type '(radio (const :tag "Line up Assignments and Declarations" packed)
		(const :tag "Line up Assignment statements" single))
  :group 'verilog-mode-auto)
(put 'verilog-auto-arg-format 'safe-local-variable
     '(lambda (x) (memq x '(packed single))))

1037
(defcustom verilog-auto-arg-sort nil
1038
  "Non-nil means AUTOARG signal names will be sorted, not in declaration order.
1039 1040 1041
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
1042 1043 1044
it's bad practice to rely on order based instantiations anyhow.

See also `verilog-auto-inst-sort'."
1045 1046 1047 1048
  :group 'verilog-mode-auto
  :type 'boolean)
(put 'verilog-auto-arg-sort 'safe-local-variable 'verilog-booleanp)

Wilson Snyder's avatar
Wilson Snyder committed
1049
(defcustom verilog-auto-inst-dot-name nil
1050
  "Non-nil means when creating ports with AUTOINST, use .name syntax.
Wilson Snyder's avatar
Wilson Snyder committed
1051 1052 1053 1054 1055 1056 1057 1058
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)

1059
(defcustom verilog-auto-inst-param-value nil
1060
  "Non-nil means AUTOINST will replace parameters with the parameter value.
1061 1062 1063 1064 1065 1066 1067
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
1068
inputs.  This is then used by an upper module:
1069

Wilson Snyder's avatar
Wilson Snyder committed
1070
	module InstModule (o,i);
1071 1072 1073 1074 1075 1076
	   parameter WIDTH;
	   input [WIDTH-1:0] i;
	endmodule

	module ExampInst;
	   InstModule
1077
	     #(.PARAM(10))
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
	    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
1088
	     #(.PARAM(10))
1089 1090 1091 1092 1093
	    instName
	     (/*AUTOINST*/
	      .i 	(i[9:0]));"
  :group 'verilog-mode-auto
  :type 'boolean)
1094
(put 'verilog-auto-inst-param-value 'safe-local-variable 'verilog-booleanp)
1095

1096
(defcustom verilog-auto-inst-sort nil
1097
  "Non-nil means AUTOINST signals will be sorted, not in declaration order.
1098 1099 1100 1101 1102 1103
Also affects AUTOINSTPARAM.  Declaration order is the default for
backward compatibility, and as some teams prefer signals that are
declared together to remain together.  Sorted order reduces
changes when declarations are moved around in a file.

See also `verilog-auto-arg-sort'."
1104
  :version "24.1"  ;; rev688
1105 1106 1107 1108
  :group 'verilog-mode-auto
  :type 'boolean)
(put 'verilog-auto-inst-sort 'safe-local-variable 'verilog-booleanp)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
1109
(defcustom verilog-auto-inst-vector t
1110
  "Non-nil means when creating default ports with AUTOINST, use bus subscripts.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1111 1112
If nil, skip the subscript when it matches the entire bus as declared in
the module (AUTOWIRE signals always are subscripted, you must manually
1113 1114
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
1115
  :group 'verilog-mode-auto
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1116
  :type 'boolean)
1117
(put 'verilog-auto-inst-vector 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1118 1119

(defcustom verilog-auto-inst-template-numbers nil
1120
  "If true, when creating templated ports with AUTOINST, add a comment.
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130

If t, the comment will add the line number of the template that
was used for that port declaration.  This setting is suggested
only for debugging use, as regular use may cause a large numbers
of merge conflicts.

If 'lhs', the comment will show the left hand side of the
AUTO_TEMPLATE rule that is matched.  This is less precise than
numbering (t) when multiple rules have the same pin name, but
won't merge conflict."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1131
  :group 'verilog-mode-auto
1132 1133 1134
  :type '(choice (const nil) (const t) (const lhs)))
(put 'verilog-auto-inst-template-numbers 'safe-local-variable
     '(lambda (x) (memq x '(nil t lhs))))
Dan Nicolaescu's avatar