verilog-mode.el 401 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  Free Software Foundation, Inc.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
5 6 7 8 9 10

;; Author: Michael McNamara (mac@verilog.com)
;;  http://www.verilog.com
;;
;; AUTO features, signal, modsig; by: Wilson Snyder
;;	(wsnyder@wsnyder.org)
11
;;	http://www.veripool.org
Dan Nicolaescu's avatar
Dan Nicolaescu committed
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 )
82
; (add-to-list 'auto-mode-alist '("\\.[ds]?v\\'" . verilog-mode))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
83 84 85

;; If you want to customize Verilog mode to fit your needs better,
;; you may add these lines (the values of the variables presented
Dan Nicolaescu's avatar
Dan Nicolaescu committed
86
;; here are the defaults). Note also that if you use an Emacs that
Dan Nicolaescu's avatar
Dan Nicolaescu committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
;; supports custom, it's probably better to use the custom menu to
;; edit these.
;;
;; Be sure to examine at the help for verilog-auto, and the other
;; verilog-auto-* functions for some major coding time savers.
;;
; ;; 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
106
;       verilog-auto-lineup              'declarations
Dan Nicolaescu's avatar
Dan Nicolaescu committed
107 108 109 110 111 112 113
;       verilog-highlight-p1800-keywords nil
;	verilog-linter			 "my_lint_shell_command"
;	)

;; 

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

Dan Nicolaescu's avatar
Dan Nicolaescu committed
118 119 120
;;; Code:

;; This variable will always hold the version number of the mode
121
(defconst verilog-mode-version "525"
122
  "Version of this Verilog mode.")
123
(defconst verilog-mode-release-date "2009-07-02-GNU"
124
  "Release date of this Verilog mode.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
125
(defconst verilog-mode-release-emacs t
126
  "If non-nil, this version of Verilog mode was released with Emacs itself.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
127 128 129 130

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

;; Insure we have certain packages, and deal with it if we don't
Dan Nicolaescu's avatar
Dan Nicolaescu committed
134
;; Be sure to note which Emacs flavor and version added each feature.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
135
(eval-when-compile
136
  ;; Provide stuff if we are XEmacs
137 138 139 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 166 167 168 169 170 171 172 173 174 175 176 177 178
  (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
179 180 181 182
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."
183 184 185 186 187 188 189 190 191
            (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
192 193
                                                  (current-buffer)))))
	  )
194 195 196 197 198 199 200
      (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
201
	 "Sorry, Customize is not available with this version of Emacs"))
202 203 204 205 206 207 208 209
      (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
210

211 212 213 214 215
    (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))
216 217 218 219 220 221 222
      ))
  ;; 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
223 224 225 226

;; 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
227 228
  ;; The below were disabled when GNU Emacs 22 was released;
  ;; perhaps some still need to be there to support Emacs 21.
229 230 231 232 233 234 235 236
  (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
237
					;with just a two input regexp
238 239
                      (defun verilog-regexp-opt (a b)
                        "Deal with differing number of required arguments for  `regexp-opt'.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
240
         Call 'regexp-opt' on A and B."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
241
                        (regexp-opt a b 't))
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
                    (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
262

263 264 265 266
(eval-when-compile
  (defun verilog-regexp-words (a)
    "Call 'regexp-opt' with word delimiters for the words A."
    (concat "\\<" (verilog-regexp-opt a t) "\\>")))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
267

268
(defun verilog-easy-menu-filter (menu)
269
  "Filter `easy-menu-define' MENU to support new features."
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
  (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
290
(defun verilog-customize ()
291
  "Customize variables and other settings used by Verilog-Mode."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
292 293 294 295
  (interactive)
  (customize-group 'verilog-mode))

(defun verilog-font-customize ()
296
  "Customize fonts used by Verilog-Mode."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
297
  (interactive)
298 299
  (if (fboundp 'customize-apropos)
      (customize-apropos "font-lock-*" 'faces)))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
300

301 302
(defun verilog-booleanp (value)
  "Return t if VALUE is boolean.
303 304
This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs.
This function may be removed when Emacs 21 is no longer supported."
305 306
  (or (equal value t) (equal value nil)))

307 308 309 310 311 312 313 314
(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)))

315 316 317 318
(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
319
(defgroup verilog-mode nil
320
  "Facilitates easy editing of Verilog source text."
321
  :version "22.2"
Dan Nicolaescu's avatar
Dan Nicolaescu committed
322 323 324 325 326 327 328 329
  :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
330
  "Customize indentation and highlighting of Verilog source text."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
331 332 333
  :group 'verilog-mode)

(defgroup verilog-mode-actions nil
334
  "Customize actions on Verilog source text."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
335 336 337
  :group 'verilog-mode)

(defgroup verilog-mode-auto nil
338
  "Customize AUTO actions when expanding Verilog source text."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
339 340 341 342
  :group 'verilog-mode)

(defcustom verilog-linter
  "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'"
343
  "*Unix program and arguments to call to run a lint checker on Verilog source.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
344 345 346 347 348
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
349
;; We don't mark it safe, as it's used as a shell command
Dan Nicolaescu's avatar
Dan Nicolaescu committed
350 351 352

(defcustom verilog-coverage
  "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'"
353
  "*Program and arguments to use to annotate for coverage Verilog source.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
354 355 356 357 358
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
359
;; We don't mark it safe, as it's used as a shell command
Dan Nicolaescu's avatar
Dan Nicolaescu committed
360 361 362

(defcustom verilog-simulator
  "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'"
363
  "*Program and arguments to use to interpret Verilog source.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
364 365 366 367 368
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
369
;; We don't mark it safe, as it's used as a shell command
Dan Nicolaescu's avatar
Dan Nicolaescu committed
370 371 372

(defcustom verilog-compiler
  "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'"
373
  "*Program and arguments to use to compile Verilog source.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
374 375 376 377 378
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
379
;; We don't mark it safe, as it's used as a shell command
Dan Nicolaescu's avatar
Dan Nicolaescu committed
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398

(defvar verilog-tool 'verilog-linter
  "Which tool to use for building compiler-command.
Either nil, `verilog-linter, `verilog-coverage, `verilog-simulator, or
`verilog-compiler.  Alternatively use the \"Choose Compilation Action\"
menu.  See `verilog-set-compile-command' for more information.")

(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
399
;; Note we don't use :safe, as that would break on Emacsen before 22.0.
400
(put 'verilog-highlight-translate-off 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
401

402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
(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 )
		(const :tag "Line up Declarartions" declarations)
		(function :tag "Other"))
  :group 'verilog-mode-indent )

Dan Nicolaescu's avatar
Dan Nicolaescu committed
433 434 435 436
(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
437
(put 'verilog-indent-level 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
438 439

(defcustom verilog-indent-level-module 3
440
  "*Indentation of Module level Verilog statements (eg always, initial).
Dan Nicolaescu's avatar
Dan Nicolaescu committed
441 442 443 444
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
445
(put 'verilog-indent-level-module 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
446 447 448 449 450 451

(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
452
(put 'verilog-indent-level-declaration 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
453 454 455 456 457 458 459 460 461 462 463 464 465

(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)
466
(put 'verilog-indent-declaration-macros 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
467 468 469 470 471 472 473 474 475 476 477 478

(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)
479
(put 'verilog-indent-lists 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
480 481 482 483 484 485

(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
486
(put 'verilog-indent-level-behavioral 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
487 488 489 490 491 492

(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
493
(put 'verilog-indent-level-directive 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
494 495 496 497 498

(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
499
(put 'verilog-cexp-indent 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
500 501 502 503 504

(defcustom verilog-case-indent 2
  "*Indentation for case statements."
  :group 'verilog-mode-indent
  :type 'integer)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
505
(put 'verilog-case-indent 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
506 507 508 509 510

(defcustom verilog-auto-newline t
  "*True means automatically newline after semicolons."
  :group 'verilog-mode-indent
  :type 'boolean)
511
(put 'verilog-auto-newline 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
512 513 514 515 516

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

(defcustom verilog-tab-always-indent t
  "*True means TAB should always re-indent the current line.
521
A nil value means TAB will only reindent when at the beginning of the line."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
522 523
  :group 'verilog-mode-indent
  :type 'boolean)
524
(put 'verilog-tab-always-indent 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
525 526 527 528 529

(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)
530
(put 'verilog-tab-to-comment 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
531 532 533 534 535

(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
536
  :type 'boolean)
537
(put 'verilog-indent-begin-after-if 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
538 539 540 541 542 543


(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
544
  :type 'boolean)
545
(put 'verilog-align-ifelse 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
546 547 548 549

(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
550
default avoids too many redundant comments in tight quarters."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
551 552
  :group 'verilog-mode-indent
  :type 'integer)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
553
(put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
554 555

(defcustom verilog-highlight-p1800-keywords nil
Dan Nicolaescu's avatar
Dan Nicolaescu committed
556 557 558
  "*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.
559
A nil value means highlight these words as appropriate for the SystemVerilog
Dan Nicolaescu's avatar
Dan Nicolaescu committed
560
IEEE-1800 standard.  Note that changing this will require restarting Emacs
561
to see the effect as font color choices are cached by Emacs."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
562 563
  :group 'verilog-mode-indent
  :type 'boolean)
564
(put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
565

566 567
(defcustom verilog-highlight-grouping-keywords nil
  "*True means highlight grouping keywords 'begin' and 'end' more dramatically.
568 569
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
570 571 572
grouping constructs allow the structure of the code to be understood at a glance."
  :group 'verilog-mode-indent
  :type 'boolean)
573
(put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp)
574

Dan Nicolaescu's avatar
Dan Nicolaescu committed
575 576 577 578
(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
579
  :type 'boolean)
580
(put 'verilog-auto-endcomments 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
581 582 583 584 585 586 587 588

(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
589
  :type 'boolean)
590
(put 'verilog-auto-read-includes 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610

(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)
611
(put 'verilog-auto-star-expand 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
612 613 614

(defcustom verilog-auto-star-save nil
  "*Non-nil indicates to save to disk SystemVerilog .* instance expansions.
615 616
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
617 618 619 620 621

Instead of setting this, you may want to use /*AUTOINST*/, which will
always be saved."
  :group 'verilog-mode-actions
  :type 'boolean)
622
(put 'verilog-auto-star-save 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
623 624 625 626 627 628 629

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

630 631
;;; Compile support
(require 'compile)
632
(defvar verilog-error-regexp-added nil)
633 634
; List of regexps for Verilog compilers, like verilint. See compilation-error-regexp-alist
;   for the formatting.
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
; Here is the version for Emacs 22:
(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
     ".*\\*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)" 1 2)
    (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
     "In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):
.*
.*
.*
\\(Warning\\|Error\\|Failure\\)" 1 2)
    ))
;; And the version for XEmacs:
(defvar verilog-error-regexp-xemacs-alist
  '(verilog
    ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2)
    ("\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\),\\s-+\\(line \\)?\\([0-9]+\\):" 2 4 )
    ("\
Dan Nicolaescu's avatar
Dan Nicolaescu committed
677 678
\\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
:\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
679 680
; xsim
; Error! in file /homes/mac/Axis/Xsim/test.v at line 13		[OBJ_NOT_DECLARED]
681
    ("\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3)
682
; vcs
683 684 685 686
    ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3)
    ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2)
    ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3)
    ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
687
; Verilator
688
    ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
689
; verilog-xl
690 691 692
    ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
    ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 1 2)	       ; vxl
    ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 1 2)
693
; nc-verilog
694
    (".*\\*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 1 2)
695
; Leda
696 697 698
    ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 1 2)
    )
  )
Dan Nicolaescu's avatar
Dan Nicolaescu committed
699 700 701 702 703

(defvar verilog-error-font-lock-keywords
  '(
    ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t)
    ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t)
704
    
Dan Nicolaescu's avatar
Dan Nicolaescu committed
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
    ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 2 bold t)
    ("\\(WARNING\\|ERROR\\|INFO\\): \\([^,]+\\), line \\([0-9]+\\):" 3 bold t)

    ("\
\\([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)

    ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 bold t)
    ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 3 bold t)

    ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 bold t)
    ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 4 bold t)

    ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)
    ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 bold t)

    ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
    ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 3 bold t)

    ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 bold t)
    ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 2 bold t)
       ; vxl
    ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)
    ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 bold t)

    ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 1 bold t)
    ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 2 bold t)

    ("([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]+\\):.*$" 2 bold t)
        ; nc-verilog
    (".*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 1 bold t)
    (".*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 2 bold t)
       ; 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
745
  "*Keywords to also highlight in Verilog *compilation* buffers.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769

(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
770
are only insured to be correct when the file is first visited.  Thus if you
Dan Nicolaescu's avatar
Dan Nicolaescu committed
771 772 773 774 775
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
776
(put 'verilog-library-flags 'safe-local-variable 'listp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791

(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
792
are only insured to be correct when the file is first visited.  Thus if you
Dan Nicolaescu's avatar
Dan Nicolaescu committed
793 794 795 796 797 798
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
799
(put 'verilog-library-directories 'safe-local-variable 'listp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
800 801

(defcustom verilog-library-files '()
Dan Nicolaescu's avatar
Dan Nicolaescu committed
802 803
  "*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
804 805 806 807 808 809 810 811 812 813 814
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
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 `verilog-library-flags', `verilog-library-directories'."
  :group 'verilog-mode-auto
  :type '(repeat directory))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
821
(put 'verilog-library-files 'safe-local-variable 'listp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
822

823
(defcustom verilog-library-extensions '(".v" ".sv")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
824 825 826 827
  "*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
828
(put 'verilog-library-extensions 'safe-local-variable 'listp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
829 830 831 832 833 834 835

(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
836
(put 'verilog-active-low-regexp 'safe-local-variable 'stringp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
837 838 839 840 841

(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
842 843
  :group 'verilog-mode-auto
  :type 'boolean)
844
(put 'verilog-auto-sense-include-inputs 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
845 846 847 848 849

(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
850
of each Verilog file that requires it, rather than being set globally."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
851 852
  :group 'verilog-mode-auto
  :type 'boolean)
853
(put 'verilog-auto-sense-defines-constant 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
854 855 856 857 858 859

(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
860
the MSB or LSB of a signal inside an AUTORESET."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
861 862
  :type 'boolean
  :group 'verilog-mode-auto)
863
(put 'verilog-auto-reset-widths 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
864 865 866

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

871 872 873 874 875 876 877 878 879 880
(defcustom verilog-auto-arg-sort nil
  "*If set, AUTOARG will sort signal names, rather than leave them in
declaration 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."
  :group 'verilog-mode-auto
  :type 'boolean)
(put 'verilog-auto-arg-sort 'safe-local-variable 'verilog-booleanp)

881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915
(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:

	module InstModule (o,i)
	   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)
916
(put 'verilog-auto-inst-param-value 'safe-local-variable 'verilog-booleanp)
917

Dan Nicolaescu's avatar
Dan Nicolaescu committed
918 919 920 921
(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
922 923
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
924
  :group 'verilog-mode-auto
Dan Nicolaescu's avatar
Dan Nicolaescu committed
925
  :type 'boolean)
926
(put 'verilog-auto-inst-vector 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
927 928 929 930 931 932 933

(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
934
  :type 'boolean)
935
(put 'verilog-auto-inst-template-numbers 'safe-local-variable 'verilog-booleanp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
936

937 938 939 940 941
(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
942 943 944 945 946

(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
947 948
  :type 'string)
(put 'verilog-auto-input-ignore-regexp 'safe-local-variable 'stringp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
949 950 951 952 953

(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
954 955
  :type 'string)
(put 'verilog-auto-inout-ignore-regexp 'safe-local-variable 'stringp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
956 957 958 959 960

(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
961 962
  :type 'string)
(put 'verilog-auto-output-ignore-regexp 'safe-local-variable 'stringp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
963 964 965 966 967

(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
968 969
  :type 'string)
(put 'verilog-auto-unused-ignore-regexp 'safe-local-variable 'stringp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
970 971 972 973 974

(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
975 976
  :type 'string)
(put 'verilog-typedef-regexp 'safe-local-variable 'stringp)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
977 978

(defcustom verilog-mode-hook   'verilog-set-compile-command
979
  "*Hook run after Verilog mode is loaded."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
980 981 982 983 984
  :type 'hook
  :group 'verilog-mode)

(defcustom verilog-auto-hook nil
  "*Hook run after `verilog-mode' updates AUTOs."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
985 986
  :group 'verilog-mode-auto
  :type 'hook)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
987 988 989

(defcustom verilog-before-auto-hook nil
  "*Hook run before `verilog-mode' updates AUTOs."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
990 991
  :group 'verilog-mode-auto
  :type 'hook)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
992 993 994

(defcustom verilog-delete-auto-hook nil
  "*Hook run after `verilog-mode' deletes AUTOs."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
995 996
  :group 'verilog-mode-auto
  :type 'hook)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
997 998 999

(defcustom verilog-before-delete-auto-hook nil
  "*Hook run before `verilog-mode' deletes AUTOs."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1000 1001
  :group 'verilog-mode-auto
  :type 'hook)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1002 1003 1004

(defcustom verilog-getopt-flags-hook nil
  "*Hook run after `verilog-getopt-flags' determines the Verilog option lists."
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1005 1006
  :group 'verilog-mode-auto
  :type 'hook)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1007 1008 1009

(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
1010 1011
  :group 'verilog-mode-auto
  :type 'hook)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1012 1013 1014 1015

(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))
1016
  "Imenu expression for Verilog mode.  See `imenu-generic-expression'.")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027

;;
;; 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
1028
  "*Default name of Company for Verilog header.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1029
If set will become buffer local.")
1030 1031
(make-variable-buffer-local 'verilog-company)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
1032
(defvar verilog-project nil
1033
  "*Default name of Project for Verilog header.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1034
If set will become buffer local.")
1035 1036
(make-variable-buffer-local 'verilog-project)

1037
(defvar verilog-mode-map
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
  (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)
1065 1066 1067 1068
    (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
1069 1070 1071 1072 1073 1074
    (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)
    (define-key map "\C-c\C-z" 'verilog-inject-auto)
    (define-key map "\C-c\C-e" 'verilog-expand-vector)
1075 1076
    (define-key map "\C-c\C-h" 'verilog-header)
    map)
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1077 1078 1079
  "Keymap used in Verilog mode.")

;; menus
1080 1081
(easy-menu-define
  verilog-menu verilog-mode-map "Menu for Verilog mode"
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 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 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 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 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
  (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"]
      )
     ("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"]
1196 1197
      ["AUTOINOUTCOMP"			(describe-function 'verilog-auto-inout-complement)
       :help		"Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
1198 1199
      ["AUTOINOUTMODULE"		(describe-function 'verilog-auto-inout-module)
       :help		"Help on AUTOINOUTMODULE - copying i/o from another file"]
1200 1201
      ["AUTOINSERTLISP"			(describe-function 'verilog-auto-insert-lisp)
       :help		"Help on AUTOINSERTLISP - insert text from a lisp function"]
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
      ["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."])))
1240 1241 1242

(easy-menu-define
  verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog."
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 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
  (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
1301 1302 1303 1304 1305 1306

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

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

1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
;;
;;  Macros
;;

(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)
1320
	    start (min (length string) (+ (match-beginning 0) (length to-string)))))
1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332
    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."
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
  (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)))
1345 1346 1347 1348

(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."
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360
  (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)))
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400

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

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

Dan Nicolaescu's avatar
Dan Nicolaescu committed
1401 1402
(defvar compile-command)

Dan Nicolaescu's avatar
Dan Nicolaescu committed
1403 1404
;; compilation program
(defun verilog-set-compile-command ()
1405
  "Function to compute shell command to compile Verilog.
Dan Nicolaescu's avatar
Dan Nicolaescu committed
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422