;; verilog-mode.el --- major mode for editing verilog source in Emacs ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. ;; Author: Michael McNamara (mac@verilog.com) ;; http://www.verilog.com ;; ;; AUTO features, signal, modsig; by: Wilson Snyder ;; (wsnyder@wsnyder.org) ;; http://www.veripool.org ;; Keywords: languages ;; Yoni Rabkin 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. ;; This code supports Emacs 21.1 and later ;; And XEmacs 21.1 and later ;; Please do not make changes that break Emacs 21. Thanks! ;; ;; ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; 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 ;; along with GNU Emacs. If not, see . ;;; Commentary: ;; This mode borrows heavily from the Pascal-mode and the cc-mode of Emacs ;; USAGE ;; ===== ;; A major mode for editing Verilog HDL source code. 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 ;; ;; KNOWN BUGS / BUG REPORTS ;; ======================= ;; Verilog is a rapidly evolving language, and hence this mode is ;; under continuous development. Hence this is beta code, and likely ;; has bugs. Please report any and all bugs to me at mac@verilog.com. ;; 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 ;; your Emacs environment. Sometimes this is difficult for local ;; 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 ;; ;; The short list of installation instructions are: To set up ;; automatic Verilog mode, put this file in your load path, and put ;; 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 ) ; (add-to-list 'auto-mode-alist '("\\.[ds]?v\\'" . verilog-mode)) ;; If you want to customize Verilog mode to fit your needs better, ;; you may add these lines (the values of the variables presented ;; here are the defaults). Note also that if you use an Emacs that ;; 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 ; verilog-auto-lineup '(all) ; verilog-highlight-p1800-keywords nil ; verilog-linter "my_lint_shell_command" ; ) ;; ;;; History: ;; ;; See commit history at http://www.veripool.org/verilog-mode.html ;; (This section is required to appease checkdoc.) ;;; Code: ;; This variable will always hold the version number of the mode (defconst verilog-mode-version (substring "$$Revision: 463 $$" 12 -3) "Version of this Verilog mode.") (defconst verilog-mode-release-date (substring "$$Date: 2008-11-21 21:16:37 +0000 (Fri, 21 Nov 2008) $$" 8 -3) "Release date of this Verilog mode.") (defconst verilog-mode-release-emacs nil "If non-nil, this version of Verilog mode was released with Emacs itself.") (defun verilog-version () "Inform caller of the version of this file." (interactive) (message "Using verilog-mode version %s" verilog-mode-version)) ;; Insure we have certain packages, and deal with it if we don't ;; Be sure to note which Emacs flavor and version added each feature. (eval-when-compile ;; Provide stuff if we are XEmacs (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. 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." (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) (current-buffer))))) ) (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 "Sorry, Customize is not available with this version of Emacs")) (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)) ) (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)) )) ;; 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)))) ) ;; Provide a regular expression optimization routine, using regexp-opt ;; if provided by the user's elisp libraries (eval-and-compile ;; The below were disabled when GNU Emacs 22 was released; ;; perhaps some still need to be there to support Emacs 21. (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 ;with just a two input regexp (defun verilog-regexp-opt (a b) "Deal with differing number of required arguments for `regexp-opt'. Call 'regexp-opt' on A and B." (regexp-opt a b 't)) (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))) (eval-when-compile (defun verilog-regexp-words (a) "Call 'regexp-opt' with word delimiters for the words A." (concat "\\<" (verilog-regexp-opt a t) "\\>"))) (defun verilog-easy-menu-filter (menu) "Filter a easy-menu-define to support new features." (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"])) (defun verilog-customize () "Customize variables and other settings used by Verilog-Mode." (interactive) (customize-group 'verilog-mode)) (defun verilog-font-customize () "Customize fonts used by Verilog-Mode." (interactive) (if (fboundp 'customize-apropos) (customize-apropos "font-lock-*" 'faces))) (defun verilog-booleanp (value) "Return t if VALUE is boolean. This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs. This function may be removed when Emacs 21 is no longer supported." (or (equal value t) (equal value nil))) (defalias 'verilog-syntax-ppss (if (fboundp 'syntax-ppss) 'syntax-ppss (lambda (&optional pos) (parse-partial-sexp (point-min) (or pos (point)))))) (defgroup verilog-mode nil "Facilitates easy editing of Verilog source text." :version "22.2" :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 "Customize indentation and highlighting of Verilog source text." :group 'verilog-mode) (defgroup verilog-mode-actions nil "Customize actions on Verilog source text." :group 'verilog-mode) (defgroup verilog-mode-auto nil "Customize AUTO actions when expanding Verilog source text." :group 'verilog-mode) (defcustom verilog-linter "echo 'No verilog-linter set, see \"M-x describe-variable verilog-linter\"'" "*Unix program and arguments to call to run a lint checker on Verilog source. 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) ;; We don't mark it safe, as it's used as a shell command (defcustom verilog-coverage "echo 'No verilog-coverage set, see \"M-x describe-variable verilog-coverage\"'" "*Program and arguments to use to annotate for coverage Verilog source. 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) ;; We don't mark it safe, as it's used as a shell command (defcustom verilog-simulator "echo 'No verilog-simulator set, see \"M-x describe-variable verilog-simulator\"'" "*Program and arguments to use to interpret Verilog source. 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) ;; We don't mark it safe, as it's used as a shell command (defcustom verilog-compiler "echo 'No verilog-compiler set, see \"M-x describe-variable verilog-compiler\"'" "*Program and arguments to use to compile Verilog source. 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) ;; We don't mark it safe, as it's used as a shell command (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) ;; Note we don't use :safe, as that would break on Emacsen before 22.0. (put 'verilog-highlight-translate-off 'safe-local-variable 'verilog-booleanp) (defcustom verilog-indent-level 3 "*Indentation of Verilog statements with respect to containing block." :group 'verilog-mode-indent :type 'integer) (put 'verilog-indent-level 'safe-local-variable 'integerp) (defcustom verilog-indent-level-module 3 "*Indentation of Module level Verilog statements (eg always, initial). Set to 0 to get initial and always statements lined up on the left side of your screen." :group 'verilog-mode-indent :type 'integer) (put 'verilog-indent-level-module 'safe-local-variable 'integerp) (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) (put 'verilog-indent-level-declaration 'safe-local-variable 'integerp) (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) (put 'verilog-indent-declaration-macros 'safe-local-variable 'verilog-booleanp) (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) (put 'verilog-indent-lists 'safe-local-variable 'verilog-booleanp) (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) (put 'verilog-indent-level-behavioral 'safe-local-variable 'integerp) (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) (put 'verilog-indent-level-directive 'safe-local-variable 'integerp) (defcustom verilog-cexp-indent 2 "*Indentation of Verilog statements split across lines." :group 'verilog-mode-indent :type 'integer) (put 'verilog-cexp-indent 'safe-local-variable 'integerp) (defcustom verilog-case-indent 2 "*Indentation for case statements." :group 'verilog-mode-indent :type 'integer) (put 'verilog-case-indent 'safe-local-variable 'integerp) (defcustom verilog-auto-newline t "*True means automatically newline after semicolons." :group 'verilog-mode-indent :type 'boolean) (put 'verilog-auto-newline 'safe-local-variable 'verilog-booleanp) (defcustom verilog-auto-indent-on-newline t "*True means automatically indent line after newline." :group 'verilog-mode-indent :type 'boolean) (put 'verilog-auto-indent-on-newline 'safe-local-variable 'verilog-booleanp) (defcustom verilog-tab-always-indent t "*True means TAB should always re-indent the current line. A nil value means TAB will only reindent when at the beginning of the line." :group 'verilog-mode-indent :type 'boolean) (put 'verilog-tab-always-indent 'safe-local-variable 'verilog-booleanp) (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) (put 'verilog-tab-to-comment 'safe-local-variable 'verilog-booleanp) (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 :type 'boolean) (put 'verilog-indent-begin-after-if 'safe-local-variable 'verilog-booleanp) (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 :type 'boolean) (put 'verilog-align-ifelse 'safe-local-variable 'verilog-booleanp) (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 default avoids too many redundant comments in tight quarters." :group 'verilog-mode-indent :type 'integer) (put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp) (defcustom verilog-auto-lineup '(declaration) "*Algorithm for lining up statements on multiple lines. If this list contains the symbol 'all', then all line ups described below are done. If this list contains the symbol 'declaration', then declarations are lined up with any preceding declarations, taking into account widths and the like, so for example the code: reg [31:0] a; reg b; would become reg [31:0] a; reg b; If this list contains the symbol '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;" ;; The following is not implemented: ;If this list contains the symbol 'case', then case items are lined up ;with any preceding case items, so for example the code ; case (a) begin ; a_long_state : a = 3; ; b: a = 4; ; endcase ;would become ; case (a) begin ; a_long_state : a = 3; ; b : a = 4; ; endcase ; :group 'verilog-mode-indent :type 'list) (put 'verilog-auto-lineup 'safe-local-variable 'listp) (defcustom verilog-highlight-p1800-keywords nil "*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. A nil value means highlight these words as appropriate for the SystemVerilog IEEE-1800 standard. Note that changing this will require restarting Emacs to see the effect as font color choices are cached by Emacs." :group 'verilog-mode-indent :type 'boolean) (put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp) (defcustom verilog-highlight-grouping-keywords nil "*True means highlight grouping keywords 'begin' and 'end' more dramatically. 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 grouping constructs allow the structure of the code to be understood at a glance." :group 'verilog-mode-indent :type 'boolean) (put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp) (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 :type 'boolean) (put 'verilog-auto-endcomments 'safe-local-variable 'verilog-booleanp) (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 :type 'boolean) (put 'verilog-auto-read-includes 'safe-local-variable 'verilog-booleanp) (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) (put 'verilog-auto-star-expand 'safe-local-variable 'verilog-booleanp) (defcustom verilog-auto-star-save nil "*Non-nil indicates to save to disk SystemVerilog .* instance expansions. A nil value indicates direct connections will be removed before saving. Only meaningful to those created due to `verilog-auto-star-expand' being set. Instead of setting this, you may want to use /*AUTOINST*/, which will always be saved." :group 'verilog-mode-actions :type 'boolean) (put 'verilog-auto-star-save 'safe-local-variable 'verilog-booleanp) (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.") (defvar verilog-error-regexp-add-didit nil) (defvar verilog-error-regexp nil) (setq verilog-error-regexp-add-didit nil verilog-error-regexp '( ; SureLint ;; ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2) ; Most SureFire tools ("\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\), \\(line \\|\\)\\([0-9]+\\):" 2 4 ) ("\ \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\ :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5) ; xsim ; Error! in file /homes/mac/Axis/Xsim/test.v at line 13 [OBJ_NOT_DECLARED] ("\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3) ; vcs ("\\(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) ; Verilator ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4) ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4) ; vxl ("\\(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) ; nc-verilog (".*\\*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 1 2) ; Leda ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 1 2) ) ; "*List of regexps for Verilog compilers, like verilint. See compilation-error-regexp-alist for the formatting." ) (defvar verilog-error-font-lock-keywords '( ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t) ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t) ("\\(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) ) "*Keywords to also highlight in Verilog *compilation* buffers.") (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 are only insured to be correct when the file is first visited. Thus if you 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)) (put 'verilog-library-flags 'safe-local-variable 'listp) (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 are only insured to be correct when the file is first visited. Thus if you 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)) (put 'verilog-library-directories 'safe-local-variable 'listp) (defcustom verilog-library-files '() "*List of files to search for modules. AUTOINST will use this when it needs to resolve a module name. 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 are only insured to be correct when the file is first visited. Thus if you 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)) (put 'verilog-library-files 'safe-local-variable 'listp) (defcustom verilog-library-extensions '(".v" ".sv") "*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) (put 'verilog-library-extensions 'safe-local-variable 'listp) (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) (put 'verilog-active-low-regexp 'safe-local-variable 'stringp) (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." :group 'verilog-mode-auto :type 'boolean) (put 'verilog-auto-sense-include-inputs 'safe-local-variable 'verilog-booleanp) (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 of each Verilog file that requires it, rather than being set globally." :group 'verilog-mode-auto :type 'boolean) (put 'verilog-auto-sense-defines-constant 'safe-local-variable 'verilog-booleanp) (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 the MSB or LSB of a signal inside an AUTORESET." :type 'boolean :group 'verilog-mode-auto) (put 'verilog-auto-reset-widths 'safe-local-variable 'verilog-booleanp) (defcustom verilog-assignment-delay "" "*Text used for delays in delayed assignments. Add a trailing space if set." :group 'verilog-mode-auto :type 'string) (put 'verilog-assignment-delay 'safe-local-variable 'stringp) (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) (put 'verilog-auto-inst-param-value 'safe-local-variable 'verilog-booleanp) (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 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." :group 'verilog-mode-auto :type 'boolean) (put 'verilog-auto-inst-vector 'safe-local-variable 'verilog-booleanp) (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 :type 'boolean) (put 'verilog-auto-inst-template-numbers 'safe-local-variable 'verilog-booleanp) (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) (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 :type 'string) (put 'verilog-auto-input-ignore-regexp 'safe-local-variable 'stringp) (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 :type 'string) (put 'verilog-auto-inout-ignore-regexp 'safe-local-variable 'stringp) (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 :type 'string) (put 'verilog-auto-output-ignore-regexp 'safe-local-variable 'stringp) (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 :type 'string) (put 'verilog-auto-unused-ignore-regexp 'safe-local-variable 'stringp) (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 :type 'string) (put 'verilog-typedef-regexp 'safe-local-variable 'stringp) (defcustom verilog-mode-hook 'verilog-set-compile-command "*Hook run after Verilog mode is loaded." :type 'hook :group 'verilog-mode) (defcustom verilog-auto-hook nil "*Hook run after `verilog-mode' updates AUTOs." :group 'verilog-mode-auto :type 'hook) (defcustom verilog-before-auto-hook nil "*Hook run before `verilog-mode' updates AUTOs." :group 'verilog-mode-auto :type 'hook) (defcustom verilog-delete-auto-hook nil "*Hook run after `verilog-mode' deletes AUTOs." :group 'verilog-mode-auto :type 'hook) (defcustom verilog-before-delete-auto-hook nil "*Hook run before `verilog-mode' deletes AUTOs." :group 'verilog-mode-auto :type 'hook) (defcustom verilog-getopt-flags-hook nil "*Hook run after `verilog-getopt-flags' determines the Verilog option lists." :group 'verilog-mode-auto :type 'hook) (defcustom verilog-before-getopt-flags-hook nil "*Hook run before `verilog-getopt-flags' determines the Verilog option lists." :group 'verilog-mode-auto :type 'hook) (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)) "Imenu expression for Verilog mode. See `imenu-generic-expression'.") ;; ;; 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 "*Default name of Company for Verilog header. If set will become buffer local.") (make-variable-buffer-local 'verilog-company) (defvar verilog-project nil "*Default name of Project for Verilog header. If set will become buffer local.") (make-variable-buffer-local 'verilog-project) (defvar verilog-mode-map (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) (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)) (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) (define-key map "\C-c\C-h" 'verilog-header) map) "Keymap used in Verilog mode.") ;; menus (easy-menu-define verilog-menu verilog-mode-map "Menu for Verilog mode" (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"] ["AUTOINOUTCOMP" (describe-function 'verilog-auto-inout-complement) :help "Help on AUTOINOUTCOMP - copying complemented i/o from another file"] ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module) :help "Help on AUTOINOUTMODULE - copying i/o from another file"] ["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."]))) (easy-menu-define verilog-stmt-menu verilog-mode-map "Menu for statement templates in Verilog." (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"]))) (defvar verilog-mode-abbrev-table nil "Abbrev table in use in Verilog-mode buffers.") (define-abbrev-table 'verilog-mode-abbrev-table ()) ;; ;; 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) start (min (length string) (+ (match-beginning 0) (length to-string))))) 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." (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))) (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." (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))) (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))))) (defvar compile-command) ;; compilation program (defun verilog-set-compile-command () "Function to compute shell command to compile Verilog. This reads `verilog-tool' and sets `compile-command'. This specifies the program that executes when you type \\[compile] or \\[verilog-auto-save-compile]. By default `verilog-tool' uses a Makefile if one exists in the current directory. If not, it is set to the `verilog-linter', `verilog-coverage', `verilog-simulator', or `verilog-compiler' variables, as selected with the Verilog -> \"Choose Compilation Action\" menu. You should set `verilog-tool' or the other variables to the path and arguments for your Verilog simulator. For example: \"vcs -p123 -O\" or a string like: \"(cd /tmp; surecov %s)\". In the former case, the path to the current buffer is concat'ed to the value of `verilog-tool'; in the later, the path to the current buffer is substituted for the %s. Where __FILE__ appears in the string, the `buffer-file-name' of the current buffer, without the directory portion, will be substituted." (interactive) (cond ((or (file-exists-p "makefile") ;If there is a makefile, use it (file-exists-p "Makefile")) (make-local-variable 'compile-command) (setq compile-command "make ")) (t (make-local-variable 'compile-command) (setq compile-command (if verilog-tool (if (string-match "%s" (eval verilog-tool)) (format (eval verilog-tool) (or buffer-file-name "")) (concat (eval verilog-tool) " " (or buffer-file-name ""))) "")))) (verilog-modify-compile-command)) (defun verilog-modify-compile-command () "Replace meta-information in `compile-command'. Where __FILE__ appears in the string, the current buffer's file-name, without the directory portion, will be substituted." (when (and (stringp compile-command) (string-match "\\b__FILE__\\b" compile-command)) (make-local-variable 'compile-command) (setq compile-command (verilog-string-replace-matches "\\b__FILE__\\b" (file-name-nondirectory (buffer-file-name)) t t compile-command)))) ;; Following code only gets called from compilation-mode-hook. (defvar compilation-error-regexp-alist) (defun verilog-error-regexp-add () "Add the messages to the `compilation-error-regexp-alist'. Called by `compilation-mode-hook'. This allows \\[next-error] to find the errors." (if (not verilog-error-regexp-add-didit) (progn (setq verilog-error-regexp-add-didit t) (setq-default compilation-error-regexp-alist (append verilog-error-regexp (default-value 'compilation-error-regexp-alist))) ;; Could be buffer local at this point; maybe also in let; change all three (setq compilation-error-regexp-alist (default-value 'compilation-error-regexp-alist)) (set (make-local-variable 'compilation-error-regexp-alist) (default-value 'compilation-error-regexp-alist))))) (add-hook 'compilation-mode-hook 'verilog-error-regexp-add) (defconst verilog-directive-re ;; "`case" "`default" "`define" "`define" "`else" "`endfor" "`endif" ;; "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef" ;; "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale" ;; "`time_scale" "`undef" "`while" "\\<`\\(case\\|def\\(ault\\|ine\\(\\)?\\)\\|e\\(lse\\|nd\\(for\\|if\\|protect\\|switch\\|while\\)\\)\\|for\\(mat\\)?\\|i\\(f\\(def\\|ndef\\)?\\|nclude\\)\\|let\\|protect\\|switch\\|time\\(_scale\\|scale\\)\\|undef\\|while\\)\\>") (defconst verilog-directive-re-1 (concat "[ \t]*" verilog-directive-re)) (defconst verilog-directive-begin "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>") (defconst verilog-directive-middle "\\<`\\(else\\|default\\|case\\)\\>") (defconst verilog-directive-end "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>") (defconst verilog-ovm-begin-re (eval-when-compile (verilog-regexp-opt '( "`ovm_component_utils_begin" "`ovm_field_utils_begin" "`ovm_object_utils_begin" "`ovm_sequence_utils_begin" "`ovm_sequencer_utils_begin" ) nil ))) (defconst verilog-ovm-end-re (eval-when-compile (verilog-regexp-opt '( "`ovm_component_utils_end" "`ovm_field_utils_end" "`ovm_object_utils_end" "`ovm_sequence_utils_end" "`ovm_sequencer_utils_end" ) nil ))) (defconst verilog-ovm-statement-re (eval-when-compile (verilog-regexp-opt '( ;; Statements "`DUT_ERROR" "`MESSAGE" "`dut_error" "`message" "`ovm_analysis_imp_decl" "`ovm_blocking_get_imp_decl" "`ovm_blocking_get_peek_imp_decl" "`ovm_blocking_master_imp_decl" "`ovm_blocking_peek_imp_decl" "`ovm_blocking_put_imp_decl" "`ovm_blocking_slave_imp_decl" "`ovm_blocking_transport_imp_decl" "`ovm_component_registry" "`ovm_component_registry_param" "`ovm_component_utils" "`ovm_create" "`ovm_create_seq" "`ovm_declare_sequence_lib" "`ovm_do" "`ovm_do_seq" "`ovm_do_seq_with" "`ovm_do_with" "`ovm_error" "`ovm_fatal" "`ovm_field_aa_int_byte" "`ovm_field_aa_int_byte_unsigned" "`ovm_field_aa_int_int" "`ovm_field_aa_int_int_unsigned" "`ovm_field_aa_int_integer" "`ovm_field_aa_int_integer_unsigned" "`ovm_field_aa_int_key" "`ovm_field_aa_int_longint" "`ovm_field_aa_int_longint_unsigned" "`ovm_field_aa_int_shortint" "`ovm_field_aa_int_shortint_unsigned" "`ovm_field_aa_int_string" "`ovm_field_aa_object_int" "`ovm_field_aa_object_string" "`ovm_field_aa_string_int" "`ovm_field_aa_string_string" "`ovm_field_array_int" "`ovm_field_array_object" "`ovm_field_array_string" "`ovm_field_enum" "`ovm_field_event" "`ovm_field_int" "`ovm_field_object" "`ovm_field_queue_int" "`ovm_field_queue_object" "`ovm_field_queue_string" "`ovm_field_sarray_int" "`ovm_field_string" "`ovm_field_utils" "`ovm_file" "`ovm_get_imp_decl" "`ovm_get_peek_imp_decl" "`ovm_info" "`ovm_info1" "`ovm_info2" "`ovm_info3" "`ovm_info4" "`ovm_line" "`ovm_master_imp_decl" "`ovm_msg_detail" "`ovm_non_blocking_transport_imp_decl" "`ovm_nonblocking_get_imp_decl" "`ovm_nonblocking_get_peek_imp_decl" "`ovm_nonblocking_master_imp_decl" "`ovm_nonblocking_peek_imp_decl" "`ovm_nonblocking_put_imp_decl" "`ovm_nonblocking_slave_imp_decl" "`ovm_object_registry" "`ovm_object_registry_param" "`ovm_object_utils" "`ovm_peek_imp_decl" "`ovm_phase_func_decl" "`ovm_phase_task_decl" "`ovm_print_aa_int_object" "`ovm_print_aa_string_int" "`ovm_print_aa_string_object" "`ovm_print_aa_string_string" "`ovm_print_array_int" "`ovm_print_array_object" "`ovm_print_array_string" "`ovm_print_object_queue" "`ovm_print_queue_int" "`ovm_print_string_queue" "`ovm_put_imp_decl" "`ovm_rand_send" "`ovm_rand_send_with" "`ovm_send" "`ovm_sequence_utils" "`ovm_slave_imp_decl" "`ovm_transport_imp_decl" "`ovm_update_sequence_lib" "`ovm_update_sequence_lib_and_item" "`ovm_warning" "`static_dut_error" "`static_message") nil ))) ;; ;; Regular expressions used to calculate indent, etc. ;; (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>") (defconst verilog-case-re "\\(\\\\|\\\\)") ;; Want to match ;; aa : ;; aa,bb : ;; a[34:32] : ;; a, ;; b : (defconst verilog-no-indent-begin-re "\\<\\(if\\|else\\|while\\|for\\|repeat\\|always\\|always_comb\\|always_ff\\|always_latch\\)\\>") (defconst verilog-ends-re ;; Parenthesis indicate type of keyword found (concat "\\(\\\\)\\|" ; 1 "\\(\\\\)\\|" ; 2 "\\(\\\\)\\|" ; 3 "\\(\\\\)\\|" ; 4 "\\(\\\\)\\|" ; 5 "\\(\\\\)\\|" ; 6 "\\(\\\\)\\|" ; 7 "\\(\\\\)\\|" ; 8 "\\(\\\\)\\|" ; 9 "\\(\\\\)\\|" ; 10 "\\(\\\\)\\|" ; 11 "\\(\\\\)\\|" ; 12 ;; OVM "\\(\\<`ovm_component_utils_end\\>\\)\\|" "\\(\\<`ovm_field_utils_end\\>\\)\\|" "\\(\\<`ovm_object_utils_end\\>\\)\\|" "\\(\\<`ovm_sequence_utils_end\\>\\)\\|" "\\(\\<`ovm_sequencer_utils_end\\>\\)" )) (defconst verilog-auto-end-comment-lines-re ;; Matches to names in this list cause auto-end-commentation (concat "\\(" verilog-directive-re "\\)\\|\\(" (eval-when-compile (verilog-regexp-words `( "begin" "else" "end" "endcase" "endclass" "endclocking" "endgroup" "endfunction" "endmodule" "endprogram" "endprimitive" "endinterface" "endpackage" "endsequence" "endspecify" "endtable" "endtask" "join" "join_any" "join_none" "module" "macromodule" "primitive" "interface" "package"))) "\\)")) ;;; NOTE: verilog-leap-to-head expects that verilog-end-block-re and ;;; verilog-end-block-ordered-re matches exactly the same strings. (defconst verilog-end-block-ordered-re ;; Parenthesis indicate type of keyword found (concat "\\(\\\\)\\|" ; 1 "\\(\\\\)\\|" ; 2 "\\(\\\\)")) (defconst verilog-end-block-re (eval-when-compile (verilog-regexp-words `("end" ;; closes begin "endcase" ;; closes any of case, casex casez or randcase "join" "join_any" "join_none" ;; closes fork "endclass" "endtable" "endspecify" "endfunction" "endgenerate" "endtask" "endgroup" "endproperty" "endinterface" "endpackage" "endprogram" "endsequence" "endclocking" ;; OVM "`ovm_component_utils_end" "`ovm_field_utils_end" "`ovm_object_utils_end" "`ovm_sequence_utils_end" "`ovm_sequencer_utils_end" )))) (defconst verilog-endcomment-reason-re ;; Parenthesis indicate type of keyword found (concat "\\(\\\\)\\|" "\\(\\\\)\\|" "\\(\\\\)\\|" "\\(\\\\)\\|" "\\(\\\\)\\|" "\\(\\.*\\\\)\\|" "\\(\\\\)\\|" "\\(\\\\)\\|" "\\(\\\\)\\|" "\\(\\\\)\\|" "\\(\\\\)\\|" "\\(\\\\)\\|" "\\(\\\\(\[ \t\]*@\\)?\\)\\|" "\\(\\\\(\[ \t\]*@\\)?\\)\\|" "\\(\\\\(\[ \t\]*@\\)?\\)\\|" "\\(\\\\(\[ \t\]*@\\)?\\)\\|" "\\(@\\)\\|" "\\(\\\\)\\|" "\\(\\\\)\\|" "\\(\\\\)\\|\\(\\\\)\\|" "#")) (defconst verilog-named-block-re "begin[ \t]*:") ;; These words begin a block which can occur inside a module which should be indented, ;; and closed with the respective word from the end-block list (defconst verilog-beg-block-re (eval-when-compile (verilog-regexp-words `("begin" "case" "casex" "casez" "randcase" "clocking" "generate" "fork" "function" "property" "specify" "table" "task" ;;; OVM "`ovm_component_utils_begin" "`ovm_field_utils_begin" "`ovm_object_utils_begin" "`ovm_sequence_utils_begin" "`ovm_sequencer_utils_begin" )))) ;; These are the same words, in a specific order in the regular ;; expression so that matching will work nicely for ;; verilog-forward-sexp and verilog-calc-indent (defconst verilog-beg-block-re-ordered ( concat "\\(\\\\)" ;1 "\\|\\(\\\\|\\(\\\\)" ; 2,3 "\\|\\(\\(\\\\s-+\\)?fork\\>\\)" ;4,5 "\\|\\(\\\\)" ;6 "\\|\\(\\\\)" ;7 "\\|\\(\\\\)" ;8 "\\|\\(\\\\)" ;9 "\\|\\(\\(\\(\\\\s-+\\)\\|\\(\\\\s-+\\)\\)*\\\\)" ;10 "\\|\\(\\\\)" ;14 "\\|\\(\\(\\(\\\\s-+\\)\\|\\(\\\\s-+\\)\\)*\\\\)" ;15 "\\|\\(\\\\)" ;18 "\\|\\(\\\\)" ;16 20 "\\|\\(\\(\\(\\\\s-+\\)\\|\\(\\\\s-+\\)\\)*\\\\)" ;17 21 "\\|\\(\\<\\(rand\\)?sequence\\>\\)" ;21 25 "\\|\\(\\\\)" ;22 27 "\\|\\(\\<`ovm_[a-z_]+_begin\\>\\)" ;28 ;; )) (defconst verilog-end-block-ordered-rry [ "\\(\\\\)\\|\\(\\\\)\\|\\(\\\\)\\|\\(\\\\)" "\\(\\\\|\\\\)\\|\\(\\\\)" "\\(\\\\)\\|\\(\\\\)" "\\(\\\\)\\|\\(\\\\)" "\\(\\\\)\\|\\(\\\\)" "\\(\\\\)\\|\\(\\\\)" "\\(\\\\)\\|\\(\\\\)" "\\(\\\\)\\|\\(\\\\)" "\\(\\\\)\\|\\(\\\\)" "\\(\\\\)\\|\\(\\\\)" "\\(\\\\)\\|\\(\\\\)" "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\\\)" "\\(\\\\)\\|\\(\\\\)" ] ) (defconst verilog-nameable-item-re (eval-when-compile (verilog-regexp-words `("begin" "fork" "join" "join_any" "join_none" "end" "endcase" "endconfig" "endclass" "endclocking" "endfunction" "endgenerate" "endmodule" "endprimative" "endinterface" "endpackage" "endspecify" "endtable" "endtask" ) ))) (defconst verilog-declaration-opener (eval-when-compile (verilog-regexp-words `("module" "begin" "task" "function")))) (defconst verilog-declaration-prefix-re (eval-when-compile (verilog-regexp-words `( ;; port direction "inout" "input" "output" "ref" ;; changeableness "const" "static" "protected" "local" ;; parameters "localparam" "parameter" "var" ;; type creation "typedef" )))) (defconst verilog-declaration-core-re (eval-when-compile (verilog-regexp-words `( ;; port direction (by themselves) "inout" "input" "output" ;; integer_atom_type "byte" "shortint" "int" "longint" "integer" "time" ;; integer_vector_type "bit" "logic" "reg" ;; non_integer_type "shortreal" "real" "realtime" ;; net_type "supply0" "supply1" "tri" "triand" "trior" "trireg" "tri0" "tri1" "uwire" "wire" "wand" "wor" ;; misc "string" "event" "chandle" "virtual" "enum" "genvar" "struct" "union" ;; builtin classes "mailbox" "semaphore" )))) (defconst verilog-declaration-re (concat "\\(" verilog-declaration-prefix-re "\\s-*\\)?" verilog-declaration-core-re)) (defconst verilog-range-re "\\(\\[[^]]*\\]\\s-*\\)+") (defconst verilog-optional-signed-re "\\s-*\\(signed\\)?") (defconst verilog-optional-signed-range-re (concat "\\s-*\\(\\<\\(reg\\|wire\\)\\>\\s-*\\)?\\(\\\\s-*\\)?\\(" verilog-range-re "\\)?")) (defconst verilog-macroexp-re "`\\sw+") (defconst verilog-delay-re "#\\s-*\\(\\([0-9_]+\\('s?[hdxbo][0-9a-fA-F_xz]+\\)?\\)\\|\\(([^()]*)\\)\\|\\(\\sw+\\)\\)") (defconst verilog-declaration-re-2-no-macro (concat "\\s-*" verilog-declaration-re "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)" "\\)?")) (defconst verilog-declaration-re-2-macro (concat "\\s-*" verilog-declaration-re "\\s-*\\(\\(" verilog-optional-signed-range-re "\\)\\|\\(" verilog-delay-re "\\)" "\\|\\(" verilog-macroexp-re "\\)" "\\)?")) (defconst verilog-declaration-re-1-macro (concat "^" verilog-declaration-re-2-macro)) (defconst verilog-declaration-re-1-no-macro (concat "^" verilog-declaration-re-2-no-macro)) (defconst verilog-defun-re (eval-when-compile (verilog-regexp-words `("macromodule" "module" "class" "program" "interface" "package" "primitive" "config")))) (defconst verilog-end-defun-re (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig")))) (defconst verilog-zero-indent-re (concat verilog-defun-re "\\|" verilog-end-defun-re)) (defconst verilog-behavioral-block-beg-re (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff" "function" "task")))) (defconst verilog-coverpoint-re "\\w+\\s*:\\s*\\(coverpoint\\|cross\\constraint\\)" ) (defconst verilog-indent-re (eval-when-compile (verilog-regexp-words `( "{" "always" "always_latch" "always_ff" "always_comb" "begin" "end" ; "unique" "priority" "case" "casex" "casez" "randcase" "endcase" "class" "endclass" "clocking" "endclocking" "config" "endconfig" "covergroup" "endgroup" "fork" "join" "join_any" "join_none" "function" "endfunction" "final" "generate" "endgenerate" "initial" "interface" "endinterface" "module" "macromodule" "endmodule" "package" "endpackage" "primitive" "endprimative" "program" "endprogram" "property" "endproperty" "sequence" "randsequence" "endsequence" "specify" "endspecify" "table" "endtable" "task" "endtask" "virtual" "`case" "`default" "`define" "`undef" "`if" "`ifdef" "`ifndef" "`else" "`endif" "`while" "`endwhile" "`for" "`endfor" "`format" "`include" "`let" "`protect" "`endprotect" "`switch" "`endswitch" "`timescale" "`time_scale" ;; OVM Begin tokens "`ovm_component_utils_begin" "`ovm_field_utils_begin" "`ovm_object_utils_begin" "`ovm_sequence_utils_begin" "`ovm_sequencer_utils_begin" ;; OVM End tokens "`ovm_component_utils_end" "`ovm_field_utils_end" "`ovm_object_utils_end" "`ovm_sequence_utils_end" "`ovm_sequencer_utils_end" )))) (defconst verilog-defun-level-not-generate-re (eval-when-compile (verilog-regexp-words `( "module" "macromodule" "primitive" "class" "program" "interface" "package" "config")))) (defconst verilog-defun-level-re (eval-when-compile (verilog-regexp-words (append `( "module" "macromodule" "primitive" "class" "program" "interface" "package" "config") `( "initial" "final" "always" "always_comb" "always_ff" "always_latch" "endtask" "endfunction" ))))) (defconst verilog-defun-level-generate-only-re (eval-when-compile (verilog-regexp-words `( "initial" "final" "always" "always_comb" "always_ff" "always_latch" "endtask" "endfunction" )))) (defconst verilog-cpp-level-re (eval-when-compile (verilog-regexp-words `( "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass" )))) (defconst verilog-disable-fork-re "disable\\s-+fork") (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?") (defconst verilog-extended-complete-re (concat "\\(\\\\|\\\\)" "\\|\\(\\\\s-+\\)*\\(\\\\|\\\\|\\\\)" "\\|" verilog-extended-case-re )) (defconst verilog-basic-complete-re (eval-when-compile (verilog-regexp-words `( "always" "assign" "always_latch" "always_ff" "always_comb" "constraint" "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while" "if" "for" "forever" "foreach" "else" "parameter" "do" )))) (defconst verilog-complete-reg (concat verilog-extended-complete-re "\\|" verilog-basic-complete-re)) (defconst verilog-end-statement-re (concat "\\(" verilog-beg-block-re "\\)\\|\\(" verilog-end-block-re "\\)")) (defconst verilog-endcase-re (concat verilog-case-re "\\|" "\\(endcase\\)\\|" verilog-defun-re )) (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----" "String used to mark beginning of excluded text.") (defconst verilog-exclude-str-end " -----/\\----- EXCLUDED -----/\\----- */" "String used to mark end of excluded text.") (defconst verilog-preprocessor-re (eval-when-compile (verilog-regexp-words `( "`define" "`include" "`ifdef" "`ifndef" "`if" "`endif" "`else" )))) (defconst verilog-keywords '( "`case" "`default" "`define" "`else" "`endfor" "`endif" "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef" "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale" "`time_scale" "`undef" "`while" "after" "alias" "always" "always_comb" "always_ff" "always_latch" "and" "assert" "assign" "assume" "automatic" "before" "begin" "bind" "bins" "binsof" "bit" "break" "buf" "bufif0" "bufif1" "byte" "case" "casex" "casez" "cell" "chandle" "class" "clocking" "cmos" "config" "const" "constraint" "context" "continue" "cover" "covergroup" "coverpoint" "cross" "deassign" "default" "defparam" "design" "disable" "dist" "do" "edge" "else" "end" "endcase" "endclass" "endclocking" "endconfig" "endfunction" "endgenerate" "endgroup" "endinterface" "endmodule" "endpackage" "endprimitive" "endprogram" "endproperty" "endspecify" "endsequence" "endtable" "endtask" "enum" "event" "expect" "export" "extends" "extern" "final" "first_match" "for" "force" "foreach" "forever" "fork" "forkjoin" "function" "generate" "genvar" "highz0" "highz1" "if" "iff" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir" "include" "initial" "inout" "input" "inside" "instance" "int" "integer" "interface" "intersect" "join" "join_any" "join_none" "large" "liblist" "library" "local" "localparam" "logic" "longint" "macromodule" "mailbox" "matches" "medium" "modport" "module" "nand" "negedge" "new" "nmos" "nor" "noshowcancelled" "not" "notif0" "notif1" "null" "or" "output" "package" "packed" "parameter" "pmos" "posedge" "primitive" "priority" "program" "property" "protected" "pull0" "pull1" "pulldown" "pullup" "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc" "randcase" "randsequence" "rcmos" "real" "realtime" "ref" "reg" "release" "repeat" "return" "rnmos" "rpmos" "rtran" "rtranif0" "rtranif1" "scalared" "semaphore" "sequence" "shortint" "shortreal" "showcancelled" "signed" "small" "solve" "specify" "specparam" "static" "string" "strong0" "strong1" "struct" "super" "supply0" "supply1" "table" "tagged" "task" "this" "throughout" "time" "timeprecision" "timeunit" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1" "triand" "trior" "trireg" "type" "typedef" "union" "unique" "unsigned" "use" "uwire" "var" "vectored" "virtual" "void" "wait" "wait_order" "wand" "weak0" "weak1" "while" "wildcard" "wire" "with" "within" "wor" "xnor" "xor" ) "List of Verilog keywords.") (defconst verilog-comment-start-regexp "//\\|/\\*" "Dual comment value for `comment-start-regexp'.") (defvar verilog-mode-syntax-table (let ((table (make-syntax-table))) ;; Populate the syntax TABLE. (modify-syntax-entry ?\\ "\\" table) (modify-syntax-entry ?+ "." table) (modify-syntax-entry ?- "." table) (modify-syntax-entry ?= "." table) (modify-syntax-entry ?% "." table) (modify-syntax-entry ?< "." table) (modify-syntax-entry ?> "." table) (modify-syntax-entry ?& "." table) (modify-syntax-entry ?| "." table) (modify-syntax-entry ?` "w" table) (modify-syntax-entry ?_ "w" table) (modify-syntax-entry ?\' "." table) ;; Set up TABLE to handle block and line style comments. (if (featurep 'xemacs) (progn ;; XEmacs (formerly Lucid) has the best implementation (modify-syntax-entry ?/ ". 1456" table) (modify-syntax-entry ?* ". 23" table) (modify-syntax-entry ?\n "> b" table)) ;; Emacs does things differently, but we can work with it (modify-syntax-entry ?/ ". 124b" table) (modify-syntax-entry ?* ". 23" table) (modify-syntax-entry ?\n "> b" table)) table) "Syntax table used in Verilog mode buffers.") (defvar verilog-font-lock-keywords nil "Default highlighting for Verilog mode.") (defvar verilog-font-lock-keywords-1 nil "Subdued level highlighting for Verilog mode.") (defvar verilog-font-lock-keywords-2 nil "Medium level highlighting for Verilog mode. See also `verilog-font-lock-extra-types'.") (defvar verilog-font-lock-keywords-3 nil "Gaudy level highlighting for Verilog mode. See also `verilog-font-lock-extra-types'.") (defvar verilog-font-lock-translate-off-face 'verilog-font-lock-translate-off-face "Font to use for translated off regions.") (defface verilog-font-lock-translate-off-face '((((class color) (background light)) (:background "gray90" :italic t )) (((class color) (background dark)) (:background "gray10" :italic t )) (((class grayscale) (background light)) (:foreground "DimGray" :italic t)) (((class grayscale) (background dark)) (:foreground "LightGray" :italic t)) (t (:italis t))) "Font lock mode face used to background highlight translate-off regions." :group 'font-lock-highlighting-faces) (defvar verilog-font-lock-p1800-face 'verilog-font-lock-p1800-face "Font to use for p1800 keywords.") (defface verilog-font-lock-p1800-face '((((class color) (background light)) (:foreground "DarkOrange3" :bold t )) (((class color) (background dark)) (:foreground "orange1" :bold t )) (t (:italic t))) "Font lock mode face used to highlight P1800 keywords." :group 'font-lock-highlighting-faces) (defvar verilog-font-lock-ams-face 'verilog-font-lock-ams-face "Font to use for Analog/Mixed Signal keywords.") (defface verilog-font-lock-ams-face '((((class color) (background light)) (:foreground "Purple" :bold t )) (((class color) (background dark)) (:foreground "orange1" :bold t )) (t (:italic t))) "Font lock mode face used to highlight AMS keywords." :group 'font-lock-highlighting-faces) (defvar verilog-font-grouping-keywords-face 'verilog-font-lock-grouping-keywords-face "Font to use for Verilog Grouping Keywords (such as begin..end).") (defface verilog-font-lock-grouping-keywords-face '((((class color) (background light)) (:foreground "red4" :bold t )) (((class color) (background dark)) (:foreground "red4" :bold t )) (t (:italic t))) "Font lock mode face used to highlight verilog grouping keywords." :group 'font-lock-highlighting-faces) (let* ((verilog-type-font-keywords (eval-when-compile (verilog-regexp-opt '( "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam" "event" "genvar" "inout" "input" "integer" "localparam" "logic" "mailbox" "nand" "nmos" "not" "notif0" "notif1" "or" "output" "parameter" "pmos" "pull0" "pull1" "pullup" "rcmos" "real" "realtime" "reg" "rnmos" "rpmos" "rtran" "rtranif0" "rtranif1" "semaphore" "signed" "struct" "supply" "supply0" "supply1" "time" "tran" "tranif0" "tranif1" "tri" "tri0" "tri1" "triand" "trior" "trireg" "typedef" "uwire" "vectored" "wand" "wire" "wor" "xnor" "xor" ) nil ))) (verilog-pragma-keywords (eval-when-compile (verilog-regexp-opt '("surefire" "synopsys" "rtl_synthesis" "verilint" "leda" "0in") nil ))) (verilog-p1800-keywords (eval-when-compile (verilog-regexp-opt '("alias" "assert" "assume" "automatic" "before" "bind" "bins" "binsof" "break" "byte" "cell" "chandle" "class" "clocking" "config" "const" "constraint" "context" "continue" "cover" "covergroup" "coverpoint" "cross" "deassign" "design" "dist" "do" "edge" "endclass" "endclocking" "endconfig" "endgroup" "endprogram" "endproperty" "endsequence" "enum" "expect" "export" "extends" "extern" "first_match" "foreach" "forkjoin" "genvar" "highz0" "highz1" "ifnone" "ignore_bins" "illegal_bins" "import" "incdir" "include" "inside" "instance" "int" "intersect" "large" "liblist" "library" "local" "longint" "matches" "medium" "modport" "new" "noshowcancelled" "null" "packed" "program" "property" "protected" "pull0" "pull1" "pulsestyle_onevent" "pulsestyle_ondetect" "pure" "rand" "randc" "randcase" "randsequence" "ref" "release" "return" "scalared" "sequence" "shortint" "shortreal" "showcancelled" "small" "solve" "specparam" "static" "string" "strong0" "strong1" "struct" "super" "tagged" "this" "throughout" "timeprecision" "timeunit" "type" "union" "unsigned" "use" "var" "virtual" "void" "wait_order" "weak0" "weak1" "wildcard" "with" "within" ) nil ))) (verilog-ams-keywords (eval-when-compile (verilog-regexp-opt '("above" "abs" "absdelay" "acos" "acosh" "ac_stim" "aliasparam" "analog" "analysis" "asin" "asinh" "atan" "atan2" "atanh" "branch" "ceil" "connectmodule" "connectrules" "cos" "cosh" "ddt" "ddx" "discipline" "driver_update" "enddiscipline" "endconnectrules" "endnature" "endparamset" "exclude" "exp" "final_step" "flicker_noise" "floor" "flow" "from" "ground" "hypot" "idt" "idtmod" "inf" "initial_step" "laplace_nd" "laplace_np" "laplace_zd" "laplace_zp" "last_crossing" "limexp" "ln" "log" "max" "min" "nature" "net_resolution" "noise_table" "paramset" "potential" "pow" "sin" "sinh" "slew" "sqrt" "tan" "tanh" "timer" "transition" "white_noise" "wreal" "zi_nd" "zi_np" "zi_zd" ) nil ))) (verilog-font-keywords (eval-when-compile (verilog-regexp-opt '( "assign" "case" "casex" "casez" "randcase" "deassign" "default" "disable" "else" "endcase" "endfunction" "endgenerate" "endinterface" "endmodule" "endprimitive" "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break" "continue" "forever" "fork" "function" "generate" "if" "iff" "initial" "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge" "package" "endpackage" "always" "always_comb" "always_ff" "always_latch" "posedge" "primitive" "priority" "release" "repeat" "specify" "table" "task" "unique" "wait" "while" "class" "program" "endclass" "endprogram" ) nil ))) (verilog-font-grouping-keywords (eval-when-compile (verilog-regexp-opt '( "begin" "end" ) nil )))) (setq verilog-font-lock-keywords (list ;; Fontify all builtin keywords (concat "\\<\\(" verilog-font-keywords "\\|" ;; And user/system tasks and functions "\\$[a-zA-Z][a-zA-Z0-9_\\$]*" "\\)\\>") ;; Fontify all types (if verilog-highlight-grouping-keywords (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>") 'verilog-font-lock-ams-face) (cons (concat "\\<\\(" verilog-font-grouping-keywords "\\)\\>") 'font-lock-type-face)) (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>") 'font-lock-type-face) ;; Fontify IEEE-P1800 keywords appropriately (if verilog-highlight-p1800-keywords (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>") 'verilog-font-lock-p1800-face) (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>") 'font-lock-type-face)) ;; Fontify Verilog-AMS keywords (cons (concat "\\<\\(" verilog-ams-keywords "\\)\\>") 'verilog-font-lock-ams-face))) (setq verilog-font-lock-keywords-1 (append verilog-font-lock-keywords (list ;; Fontify module definitions (list "\\<\\(\\(macro\\)?module\\|primitive\\|class\\|program\\|interface\\|package\\|task\\)\\>\\s-*\\(\\sw+\\)" '(1 font-lock-keyword-face) '(3 font-lock-function-name-face 'prepend)) ;; Fontify function definitions (list (concat "\\\\s-+\\(integer\\|real\\(time\\)?\\|time\\)\\s-+\\(\\sw+\\)" ) '(1 font-lock-keyword-face) '(3 font-lock-reference-face prepend)) '("\\\\s-+\\(\\[[^]]+\\]\\)\\s-+\\(\\sw+\\)" (1 font-lock-keyword-face) (2 font-lock-reference-face append)) '("\\\\s-+\\(\\sw+\\)" 1 'font-lock-reference-face append)))) (setq verilog-font-lock-keywords-2 (append verilog-font-lock-keywords-1 (list ;; Fontify pragmas (concat "\\(//\\s-*" verilog-pragma-keywords "\\s-.*\\)") ;; Fontify escaped names '("\\(\\\\\\S-*\\s-\\)" 0 font-lock-function-name-face) ;; Fontify macro definitions/ uses '("`\\s-*[A-Za-z][A-Za-z0-9_]*" 0 (if (boundp 'font-lock-preprocessor-face) 'font-lock-preprocessor-face 'font-lock-type-face)) ;; Fontify delays/numbers '("\\(@\\)\\|\\(#\\s-*\\(\\(\[0-9_.\]+\\('s?[hdxbo][0-9a-fA-F_xz]*\\)?\\)\\|\\(([^()]+)\\|\\sw+\\)\\)\\)" 0 font-lock-type-face append) ;; Fontify instantiation names '("\\([A-Za-z][A-Za-z0-9_]+\\)\\s-*(" 1 font-lock-function-name-face) ))) (setq verilog-font-lock-keywords-3 (append verilog-font-lock-keywords-2 (when verilog-highlight-translate-off (list ;; Fontify things in translate off regions '(verilog-match-translate-off (0 'verilog-font-lock-translate-off-face prepend)) ))))) (defun verilog-inside-comment-p () "Check if point inside a nested comment." (save-excursion (let ((st-point (point)) hitbeg) (or (search-backward "//" (verilog-get-beg-of-line) t) (if (progn ;; This is for tricky case //*, we keep searching if /* ;; is proceeded by // on same line. (while (and (setq hitbeg (search-backward "/*" nil t)) (progn (forward-char 1) (search-backward "//" (verilog-get-beg-of-line) t)))) hitbeg) (not (search-forward "*/" st-point t))))))) (defun verilog-declaration-end () (search-forward ";")) (defun verilog-point-text (&optional pointnum) "Return text describing where POINTNUM or current point is (for errors). Use filename, if current buffer being edited shorten to just buffer name." (concat (or (and (equal (window-buffer (selected-window)) (current-buffer)) (buffer-name)) buffer-file-name (buffer-name)) ":" (int-to-string (count-lines (point-min) (or pointnum (point)))))) (defun electric-verilog-backward-sexp () "Move backward over one balanced expression." (interactive) ;; before that see if we are in a comment (verilog-backward-sexp)) (defun electric-verilog-forward-sexp () "Move forward over one balanced expression." (interactive) ;; before that see if we are in a comment (verilog-forward-sexp)) ;;;used by hs-minor-mode (defun verilog-forward-sexp-function (arg) (if (< arg 0) (verilog-backward-sexp) (verilog-forward-sexp))) (defun verilog-backward-sexp () (let ((reg) (elsec 1) (found nil) (st (point))) (if (not (looking-at "\\<")) (forward-word -1)) (cond ((verilog-skip-backward-comment-or-string)) ((looking-at "\\") (setq reg (concat verilog-end-block-re "\\|\\(\\\\)" "\\|\\(\\\\)")) (while (and (not found) (verilog-re-search-backward reg nil 'move)) (cond ((match-end 1) ; matched verilog-end-block-re ; try to leap back to matching outward block by striding across ; indent level changing tokens then immediately ; previous line governs indentation. (verilog-leap-to-head)) ((match-end 2) ; else, we're in deep (setq elsec (1+ elsec))) ((match-end 3) ; found it (setq elsec (1- elsec)) (if (= 0 elsec) ;; Now previous line describes syntax (setq found 't)))))) ((looking-at verilog-end-block-re) (verilog-leap-to-head)) ((looking-at "\\(endmodule\\>\\)\\|\\(\\\\)\\|\\(\\\\)\\|\\(\\\\)\\|\\(\\\\)\\|\\(\\\\)") (cond ((match-end 1) (verilog-re-search-backward "\\<\\(macro\\)?module\\>" nil 'move)) ((match-end 2) (verilog-re-search-backward "\\" nil 'move)) ((match-end 3) (verilog-re-search-backward "\\" nil 'move)) ((match-end 4) (verilog-re-search-backward "\\" nil 'move)) ((match-end 5) (verilog-re-search-backward "\\" nil 'move)) ((match-end 6) (verilog-re-search-backward "\\" nil 'move)) (t (goto-char st) (backward-sexp 1)))) (t (goto-char st) (backward-sexp))))) (defun verilog-forward-sexp () (let ((reg) (md 2) (st (point)) (nest 'yes)) (if (not (looking-at "\\<")) (forward-word -1)) (cond ((verilog-skip-forward-comment-or-string) (verilog-forward-syntactic-ws)) ((looking-at verilog-beg-block-re-ordered) (cond ((match-end 1); ;; Search forward for matching end (setq reg "\\(\\\\)\\|\\(\\\\)" )) ((match-end 2) ;; Search forward for matching endcase (setq reg "\\(\\\\|\\(\\\\s-+\\|\\\\s-+\\)?\\[^:]\\)\\|\\(\\\\)" ) (setq md 3) ;; ender is third item in regexp ) ((match-end 4) ;; might be "disable fork" (if (or (looking-at verilog-disable-fork-re) (and (looking-at "fork") (progn (forward-word -1) (looking-at verilog-disable-fork-re)))) (progn (goto-char (match-end 0)) (forward-word 1) (setq reg nil)) (progn ;; Search forward for matching join (setq reg "\\(\\\\)\\|\\(\\\\)" )))) ((match-end 6) ;; Search forward for matching endclass (setq reg "\\(\\\\)\\|\\(\\\\)" )) ((match-end 7) ;; Search forward for matching endtable (setq reg "\\" ) (setq nest 'no)) ((match-end 8) ;; Search forward for matching endspecify (setq reg "\\(\\\\)\\|\\(\\\\)" )) ((match-end 9) ;; Search forward for matching endfunction (setq reg "\\" ) (setq nest 'no)) ((match-end 10) ;; Search forward for matching endfunction (setq reg "\\" ) (setq nest 'no)) ((match-end 14) ;; Search forward for matching endtask (setq reg "\\" ) (setq nest 'no)) ((match-end 15) ;; Search forward for matching endtask (setq reg "\\" ) (setq nest 'no)) ((match-end 19) ;; Search forward for matching endgenerate (setq reg "\\(\\\\)\\|\\(\\\\)" )) ((match-end 20) ;; Search forward for matching endgroup (setq reg "\\(\\\\)\\|\\(\\\\)" )) ((match-end 21) ;; Search forward for matching endproperty (setq reg "\\(\\\\)\\|\\(\\\\)" )) ((match-end 25) ;; Search forward for matching endsequence (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\\\)" ) (setq md 3)) ; 3 to get to endsequence in the reg above ((match-end 27) ;; Search forward for matching endclocking (setq reg "\\(\\\\)\\|\\(\\\\)" ))) (if (and reg (forward-word 1)) (catch 'skip (if (eq nest 'yes) (let ((depth 1)) (while (verilog-re-search-forward reg nil 'move) (cond ((match-end md) ; the closer in reg, so we are climbing out (setq depth (1- depth)) (if (= 0 depth) ; we are out! (throw 'skip 1))) ((match-end 1) ; the opener in reg, so we are deeper now (setq depth (1+ depth)))))) (if (verilog-re-search-forward reg nil 'move) (throw 'skip 1)))))) ((looking-at (concat "\\(\\<\\(macro\\)?module\\>\\)\\|" "\\(\\\\)\\|" "\\(\\\\)\\|" "\\(\\\\)\\|" "\\(\\\\)\\|" "\\(\\\\)")) (cond ((match-end 1) (verilog-re-search-forward "\\" nil 'move)) ((match-end 2) (verilog-re-search-forward "\\" nil 'move)) ((match-end 3) (verilog-re-search-forward "\\" nil 'move)) ((match-end 4) (verilog-re-search-forward "\\" nil 'move)) ((match-end 5) (verilog-re-search-forward "\\" nil 'move)) ((match-end 6) (verilog-re-search-forward "\\" nil 'move)) (t (goto-char st) (if (= (following-char) ?\) ) (forward-char 1) (forward-sexp 1))))) (t (goto-char st) (if (= (following-char) ?\) ) (forward-char 1) (forward-sexp 1)))))) (defun verilog-declaration-beg () (verilog-re-search-backward verilog-declaration-re (bobp) t)) ;; ;; ;; Mode ;; (defvar verilog-which-tool 1) ;;;###autoload (defun verilog-mode () "Major mode for editing Verilog code. \\ See \\[describe-function] verilog-auto (\\[verilog-auto]) for details on how AUTOs can improve coding efficiency. Use \\[verilog-faq] for a pointer to frequently asked questions. NEWLINE, TAB indents for Verilog code. Delete converts tabs to spaces as it moves back. Supports highlighting. Turning on Verilog mode calls the value of the variable `verilog-mode-hook' with no args, if that value is non-nil. Variables controlling indentation/edit style: variable `verilog-indent-level' (default 3) Indentation of Verilog statements with respect to containing block. `verilog-indent-level-module' (default 3) Absolute indentation of Module level Verilog statements. Set to 0 to get initial and always statements lined up on the left side of your screen. `verilog-indent-level-declaration' (default 3) Indentation of declarations with respect to containing block. Set to 0 to get them list right under containing block. `verilog-indent-level-behavioral' (default 3) Indentation of first begin in a task or function block Set to 0 to get such code to lined up underneath the task or function keyword. `verilog-indent-level-directive' (default 1) Indentation of `ifdef/`endif blocks. `verilog-cexp-indent' (default 1) Indentation of Verilog statements broken across lines i.e.: if (a) begin `verilog-case-indent' (default 2) Indentation for case statements. `verilog-auto-newline' (default nil) Non-nil means automatically newline after semicolons and the punctuation mark after an end. `verilog-auto-indent-on-newline' (default t) Non-nil means automatically indent line after newline. `verilog-tab-always-indent' (default t) Non-nil means TAB in Verilog mode should always reindent the current line, regardless of where in the line point is when the TAB command is used. `verilog-indent-begin-after-if' (default t) Non-nil means to indent begin statements following a preceding if, else, while, for and repeat statements, if any. Otherwise, the begin is lined up with the preceding token. If t, you get: if (a) begin // amount of indent based on `verilog-cexp-indent' otherwise you get: if (a) begin `verilog-auto-endcomments' (default t) Non-nil means a comment /* ... */ is set after the ends which ends cases, tasks, functions and modules. The type and name of the object will be set between the braces. `verilog-minimum-comment-distance' (default 10) Minimum distance (in lines) between begin and end required before a comment will be inserted. Setting this variable to zero results in every end acquiring a comment; the default avoids too many redundant comments in tight quarters. `verilog-auto-lineup' (default `(all)) List of contexts where auto lineup of code should be done. Variables controlling other actions: `verilog-linter' (default surelint) Unix program to call to run the lint checker. This is the default command for \\[compile-command] and \\[verilog-auto-save-compile]. See \\[customize] for the complete list of variables. AUTO expansion functions are, in part: \\[verilog-auto] Expand AUTO statements. \\[verilog-delete-auto] Remove the AUTOs. \\[verilog-inject-auto] Insert AUTOs for the first time. Some other functions are: \\[verilog-complete-word] Complete word with appropriate possibilities. \\[verilog-mark-defun] Mark function. \\[verilog-beg-of-defun] Move to beginning of current function. \\[verilog-end-of-defun] Move to end of current function. \\[verilog-label-be] Label matching begin ... end, fork ... join, etc statements. \\[verilog-comment-region] Put marked area in a comment. \\[verilog-uncomment-region] Uncomment an area commented with \\[verilog-comment-region]. \\[verilog-insert-block] Insert begin ... end. \\[verilog-star-comment] Insert /* ... */. \\[verilog-sk-always] Insert an always @(AS) begin .. end block. \\[verilog-sk-begin] Insert a begin .. end block. \\[verilog-sk-case] Insert a case block, prompting for details. \\[verilog-sk-for] Insert a for (...) begin .. end block, prompting for details. \\[verilog-sk-generate] Insert a generate .. endgenerate block. \\[verilog-sk-header] Insert a header block at the top of file. \\[verilog-sk-initial] Insert an initial begin .. end block. \\[verilog-sk-fork] Insert a fork begin .. end .. join block. \\[verilog-sk-module] Insert a module .. (/*AUTOARG*/);.. endmodule block. \\[verilog-sk-primitive] Insert a primitive .. (.. );.. endprimitive block. \\[verilog-sk-repeat] Insert a repeat (..) begin .. end block. \\[verilog-sk-specify] Insert a specify .. endspecify block. \\[verilog-sk-task] Insert a task .. begin .. end endtask block. \\[verilog-sk-while] Insert a while (...) begin .. end block, prompting for details. \\[verilog-sk-casex] Insert a casex (...) item: begin.. end endcase block, prompting for details. \\[verilog-sk-casez] Insert a casez (...) item: begin.. end endcase block, prompting for details. \\[verilog-sk-if] Insert an if (..) begin .. end block. \\[verilog-sk-else-if] Insert an else if (..) begin .. end block. \\[verilog-sk-comment] Insert a comment block. \\[verilog-sk-assign] Insert an assign .. = ..; statement. \\[verilog-sk-function] Insert a function .. begin .. end endfunction block. \\[verilog-sk-input] Insert an input declaration, prompting for details. \\[verilog-sk-output] Insert an output declaration, prompting for details. \\[verilog-sk-state-machine] Insert a state machine definition, prompting for details. \\[verilog-sk-inout] Insert an inout declaration, prompting for details. \\[verilog-sk-wire] Insert a wire declaration, prompting for details. \\[verilog-sk-reg] Insert a register declaration, prompting for details. \\[verilog-sk-define-signal] Define signal under point as a register at the top of the module. All key bindings can be seen in a Verilog-buffer with \\[describe-bindings]. Key bindings specific to `verilog-mode-map' are: \\{verilog-mode-map}" (interactive) (kill-all-local-variables) (use-local-map verilog-mode-map) (setq major-mode 'verilog-mode) (setq mode-name "Verilog") (setq local-abbrev-table verilog-mode-abbrev-table) (set (make-local-variable 'beginning-of-defun-function) 'verilog-beg-of-defun) (set (make-local-variable 'end-of-defun-function) 'verilog-end-of-defun) (set-syntax-table verilog-mode-syntax-table) (make-local-variable 'indent-line-function) (setq indent-line-function 'verilog-indent-line-relative) (setq comment-indent-function 'verilog-comment-indent) (make-local-variable 'parse-sexp-ignore-comments) (setq parse-sexp-ignore-comments nil) (make-local-variable 'comment-start) (make-local-variable 'comment-end) (make-local-variable 'comment-multi-line) (make-local-variable 'comment-start-skip) (setq comment-start "// " comment-end "" comment-start-skip "/\\*+ *\\|// *" comment-multi-line nil) ;; Set up for compilation (setq verilog-which-tool 1) (setq verilog-tool 'verilog-linter) (verilog-set-compile-command) (when (boundp 'hack-local-variables-hook) ;; Also modify any file-local-variables (add-hook 'hack-local-variables-hook 'verilog-modify-compile-command t)) ;; Setting up menus (when (featurep 'xemacs) (easy-menu-add verilog-stmt-menu) (easy-menu-add verilog-menu) (setq mode-popup-menu (cons "Verilog Mode" verilog-stmt-menu))) ;; Stuff for GNU Emacs (set (make-local-variable 'font-lock-defaults) `((verilog-font-lock-keywords verilog-font-lock-keywords-1 verilog-font-lock-keywords-2 verilog-font-lock-keywords-3) nil nil nil ,(if (functionp 'syntax-ppss) ;; verilog-beg-of-defun uses syntax-ppss, and syntax-ppss uses ;; font-lock-beginning-of-syntax-function, so ;; font-lock-beginning-of-syntax-function, can't use ;; verilog-beg-of-defun. nil 'verilog-beg-of-defun))) ;;------------------------------------------------------------ ;; now hook in 'verilog-colorize-include-files (eldo-mode.el&spice-mode.el) ;; all buffer local: (when (featurep 'xemacs) (make-local-hook 'font-lock-mode-hook) (make-local-hook 'font-lock-after-fontify-buffer-hook); doesn't exist in Emacs (make-local-hook 'after-change-functions)) (add-hook 'font-lock-mode-hook 'verilog-colorize-include-files-buffer t t) (add-hook 'font-lock-after-fontify-buffer-hook 'verilog-colorize-include-files-buffer t t) ; not in Emacs (add-hook 'after-change-functions 'verilog-colorize-include-files t t) ;; Tell imenu how to handle Verilog. (make-local-variable 'imenu-generic-expression) (setq imenu-generic-expression verilog-imenu-generic-expression) ;; Tell which-func-modes that imenu knows about verilog (when (boundp 'which-function-modes) (add-to-list 'which-func-modes 'verilog-mode)) ;; hideshow support (when (boundp 'hs-special-modes-alist) (unless (assq 'verilog-mode hs-special-modes-alist) (setq hs-special-modes-alist (cons '(verilog-mode-mode "\\" "\\" nil verilog-forward-sexp-function) hs-special-modes-alist)))) ;; Stuff for autos (add-hook 'write-contents-hooks 'verilog-auto-save-check) ; already local (run-hooks 'verilog-mode-hook)) ;; ;; Electric functions ;; (defun electric-verilog-terminate-line (&optional arg) "Terminate line and indent next line. With optional ARG, remove existing end of line comments." (interactive) ;; before that see if we are in a comment (let ((state (save-excursion (verilog-syntax-ppss)))) (cond ((nth 7 state) ; Inside // comment (if (eolp) (progn (delete-horizontal-space) (newline)) (progn (newline) (insert "// ") (beginning-of-line))) (verilog-indent-line)) ((nth 4 state) ; Inside any comment (hence /**/) (newline) (verilog-more-comment)) ((eolp) ;; First, check if current line should be indented (if (save-excursion (delete-horizontal-space) (beginning-of-line) (skip-chars-forward " \t") (if (looking-at verilog-auto-end-comment-lines-re) (let ((indent-str (verilog-indent-line))) ;; Maybe we should set some endcomments (if verilog-auto-endcomments (verilog-set-auto-endcomments indent-str arg)) (end-of-line) (delete-horizontal-space) (if arg () (newline)) nil) (progn (end-of-line) (delete-horizontal-space) 't))) ;; see if we should line up assignments (progn (if (or (memq 'all verilog-auto-lineup) (memq 'assignments verilog-auto-lineup)) (verilog-pretty-expr)) (newline)) (forward-line 1)) ;; Indent next line (if verilog-auto-indent-on-newline (verilog-indent-line))) (t (newline))))) (defun electric-verilog-terminate-and-indent () "Insert a newline and indent for the next statement." (interactive) (electric-verilog-terminate-line 1)) (defun electric-verilog-semi () "Insert `;' character and reindent the line." (interactive) (insert last-command-char) (if (or (verilog-in-comment-or-string-p) (verilog-in-escaped-name-p)) () (save-excursion (beginning-of-line) (verilog-forward-ws&directives) (verilog-indent-line)) (if (and verilog-auto-newline (not (verilog-parenthesis-depth))) (electric-verilog-terminate-line)))) (defun electric-verilog-semi-with-comment () "Insert `;' character, reindent the line and indent for comment." (interactive) (insert "\;") (save-excursion (beginning-of-line) (verilog-indent-line)) (indent-for-comment)) (defun electric-verilog-colon () "Insert `:' and do all indentations except line indent on this line." (interactive) (insert last-command-char) ;; Do nothing if within string. (if (or (verilog-within-string) (not (verilog-in-case-region-p))) () (save-excursion (let ((p (point)) (lim (progn (verilog-beg-of-statement) (point)))) (goto-char p) (verilog-backward-case-item lim) (verilog-indent-line))) ;; (let ((verilog-tab-always-indent nil)) ;; (verilog-indent-line)) )) ;;(defun electric-verilog-equal () ;; "Insert `=', and do indentation if within block." ;; (interactive) ;; (insert last-command-char) ;; Could auto line up expressions, but not yet ;; (if (eq (car (verilog-calculate-indent)) 'block) ;; (let ((verilog-tab-always-indent nil)) ;; (verilog-indent-command))) ;; ) (defun electric-verilog-tick () "Insert back-tick, and indent to column 0 if this is a CPP directive." (interactive) (insert last-command-char) (save-excursion (if (progn (beginning-of-line) (looking-at verilog-directive-re-1)) (verilog-indent-line)))) (defun electric-verilog-tab () "Function called when TAB is pressed in Verilog mode." (interactive) ;; If verilog-tab-always-indent, indent the beginning of the line. (cond ;; The region is active, indent it. ((and (region-active-p) (not (eq (region-beginning) (region-end)))) (indent-region (region-beginning) (region-end) nil)) ((or verilog-tab-always-indent (save-excursion (skip-chars-backward " \t") (bolp))) (let* ((oldpnt (point)) (boi-point (save-excursion (beginning-of-line) (skip-chars-forward " \t") (verilog-indent-line) (back-to-indentation) (point)))) (if (< (point) boi-point) (back-to-indentation) (cond ((not verilog-tab-to-comment)) ((not (eolp)) (end-of-line)) (t (indent-for-comment) (when (and (eolp) (= oldpnt (point))) ; kill existing comment (beginning-of-line) (re-search-forward comment-start-skip oldpnt 'move) (goto-char (match-beginning 0)) (skip-chars-backward " \t") (kill-region (point) oldpnt))))))) (t (progn (insert "\t"))))) ;; ;; Interactive functions ;; (defun verilog-indent-buffer () "Indent-region the entire buffer as Verilog code. To call this from the command line, see \\[verilog-batch-indent]." (interactive) (verilog-mode) (indent-region (point-min) (point-max) nil)) (defun verilog-insert-block () "Insert Verilog begin ... end; block in the code with right indentation." (interactive) (verilog-indent-line) (insert "begin") (electric-verilog-terminate-line) (save-excursion (electric-verilog-terminate-line) (insert "end") (beginning-of-line) (verilog-indent-line))) (defun verilog-star-comment () "Insert Verilog star comment at point." (interactive) (verilog-indent-line) (insert "/*") (save-excursion (newline) (insert " */")) (newline) (insert " * ")) (defun verilog-insert-1 (fmt max) "Use format string FMT to insert integers 0 to MAX - 1. Inserts one integer per line, at the current column. Stops early if it reaches the end of the buffer." (let ((col (current-column)) (n 0)) (save-excursion (while (< n max) (insert (format fmt n)) (forward-line 1) ;; Note that this function does not bother to check for lines ;; shorter than col. (if (eobp) (setq n max) (setq n (1+ n)) (move-to-column col)))))) (defun verilog-insert-indices (max) "Insert a set of indices into a rectangle. The upper left corner is defined by point. Indices begin with 0 and extend to the MAX - 1. If no prefix arg is given, the user is prompted for a value. The indices are surrounded by square brackets \[]. For example, the following code with the point located after the first 'a' gives: a = b a[ 0] = b a = b a[ 1] = b a = b a[ 2] = b a = b a[ 3] = b a = b ==> insert-indices ==> a[ 4] = b a = b a[ 5] = b a = b a[ 6] = b a = b a[ 7] = b a = b a[ 8] = b" (interactive "NMAX: ") (verilog-insert-1 "[%3d]" max)) (defun verilog-generate-numbers (max) "Insert a set of generated numbers into a rectangle. The upper left corner is defined by point. The numbers are padded to three digits, starting with 000 and extending to (MAX - 1). If no prefix argument is supplied, then the user is prompted for the MAX number. Consider the following code fragment: buf buf buf buf000 buf buf buf buf001 buf buf buf buf002 buf buf buf buf003 buf buf ==> generate-numbers ==> buf buf004 buf buf buf buf005 buf buf buf buf006 buf buf buf buf007 buf buf buf buf008" (interactive "NMAX: ") (verilog-insert-1 "%3.3d" max)) (defun verilog-mark-defun () "Mark the current Verilog function (or procedure). This puts the mark at the end, and point at the beginning." (interactive) (if (featurep 'xemacs) (progn (push-mark (point)) (verilog-end-of-defun) (push-mark (point)) (verilog-beg-of-defun) (if (fboundp 'zmacs-activate-region) (zmacs-activate-region))) (mark-defun))) (defun verilog-comment-region (start end) ; checkdoc-params: (start end) "Put the region into a Verilog comment. The comments that are in this area are \"deformed\": `*)' becomes `!(*' and `}' becomes `!{'. These deformed comments are returned to normal if you use \\[verilog-uncomment-region] to undo the commenting. The commented area starts with `verilog-exclude-str-start', and ends with `verilog-exclude-str-end'. But if you change these variables, \\[verilog-uncomment-region] won't recognize the comments." (interactive "r") (save-excursion ;; Insert start and endcomments (goto-char end) (if (and (save-excursion (skip-chars-forward " \t") (eolp)) (not (save-excursion (skip-chars-backward " \t") (bolp)))) (forward-line 1) (beginning-of-line)) (insert verilog-exclude-str-end) (setq end (point)) (newline) (goto-char start) (beginning-of-line) (insert verilog-exclude-str-start) (newline) ;; Replace end-comments within commented area (goto-char end) (save-excursion (while (re-search-backward "\\*/" start t) (replace-match "*-/" t t))) (save-excursion (let ((s+1 (1+ start))) (while (re-search-backward "/\\*" s+1 t) (replace-match "/-*" t t)))))) (defun verilog-uncomment-region () "Uncomment a commented area; change deformed comments back to normal. This command does nothing if the pointer is not in a commented area. See also `verilog-comment-region'." (interactive) (save-excursion (let ((start (point)) (end (point))) ;; Find the boundaries of the comment (save-excursion (setq start (progn (search-backward verilog-exclude-str-start nil t) (point))) (setq end (progn (search-forward verilog-exclude-str-end nil t) (point)))) ;; Check if we're really inside a comment (if (or (equal start (point)) (<= end (point))) (message "Not standing within commented area.") (progn ;; Remove endcomment (goto-char end) (beginning-of-line) (let ((pos (point))) (end-of-line) (delete-region pos (1+ (point)))) ;; Change comments back to normal (save-excursion (while (re-search-backward "\\*-/" start t) (replace-match "*/" t t))) (save-excursion (while (re-search-backward "/-\\*" start t) (replace-match "/*" t t))) ;; Remove start comment (goto-char start) (beginning-of-line) (let ((pos (point))) (end-of-line) (delete-region pos (1+ (point))))))))) (defun verilog-beg-of-defun () "Move backward to the beginning of the current function or procedure." (interactive) (verilog-re-search-backward verilog-defun-re nil 'move)) (defun verilog-end-of-defun () "Move forward to the end of the current function or procedure." (interactive) (verilog-re-search-forward verilog-end-defun-re nil 'move)) (defun verilog-get-beg-of-defun (&optional warn) (save-excursion (cond ((verilog-re-search-forward-quick verilog-defun-re nil t) (point)) (t (error "%s: Can't find module beginning" (verilog-point-text)) (point-max))))) (defun verilog-get-end-of-defun (&optional warn) (save-excursion (cond ((verilog-re-search-forward-quick verilog-end-defun-re nil t) (point)) (t (error "%s: Can't find endmodule" (verilog-point-text)) (point-max))))) (defun verilog-label-be (&optional arg) "Label matching begin ... end, fork ... join and case ... endcase statements. With ARG, first kill any existing labels." (interactive) (let ((cnt 0) (oldpos (point)) (b (progn (verilog-beg-of-defun) (point-marker))) (e (progn (verilog-end-of-defun) (point-marker)))) (goto-char (marker-position b)) (if (> (- e b) 200) (message "Relabeling module...")) (while (and (> (marker-position e) (point)) (verilog-re-search-forward (concat "\\" "\\|\\(`endif\\)\\|\\(`else\\)") nil 'move)) (goto-char (match-beginning 0)) (let ((indent-str (verilog-indent-line))) (verilog-set-auto-endcomments indent-str 't) (end-of-line) (delete-horizontal-space)) (setq cnt (1+ cnt)) (if (= 9 (% cnt 10)) (message "%d..." cnt))) (goto-char oldpos) (if (or (> (- e b) 200) (> cnt 20)) (message "%d lines auto commented" cnt)))) (defun verilog-beg-of-statement () "Move backward to beginning of statement." (interactive) ;; Move back token by token until we see the end ;; of some ealier line. (while ;; If the current point does not begin a new ;; statement, as in the character ahead of us is a ';', or SOF ;; or the string after us unambiguosly starts a statement, ;; or the token before us unambiguously ends a statement, ;; then move back a token and test again. (not (or (bolp) (= (preceding-char) ?\;) (looking-at "\\w+\\W*:\\W*\\(coverpoint\\|cross\\|constraint\\)") (not (or (looking-at "\\<") (forward-word -1))) (and (looking-at verilog-extended-complete-re) (not (save-excursion (verilog-backward-token) (looking-at verilog-extended-complete-re)))) (looking-at verilog-basic-complete-re) (save-excursion (verilog-backward-token) (or (looking-at verilog-end-block-re) (looking-at verilog-preprocessor-re))))) (verilog-backward-syntactic-ws) (verilog-backward-token)) ;; Now point is where the previous line ended. (verilog-forward-syntactic-ws)) (defun verilog-beg-of-statement-1 () "Move backward to beginning of statement." (interactive) (let ((pt (point))) (while (and (not (looking-at verilog-complete-reg)) (setq pt (point)) (verilog-backward-token) (not (looking-at verilog-complete-reg)) (verilog-backward-syntactic-ws) (setq pt (point)) (not (bolp)) (not (= (preceding-char) ?\;)))) (goto-char pt) (verilog-forward-ws&directives))) (defun verilog-end-of-statement () "Move forward to end of current statement." (interactive) (let ((nest 0) pos) (or (looking-at verilog-beg-block-re) ;; Skip to end of statement (setq pos (catch 'found (while t (forward-sexp 1) (verilog-skip-forward-comment-or-string) (cond ((looking-at "[ \t]*;") (skip-chars-forward "^;") (forward-char 1) (throw 'found (point))) ((save-excursion (forward-sexp -1) (looking-at verilog-beg-block-re)) (goto-char (match-beginning 0)) (throw 'found nil)) ((looking-at "[ \t]*)") (throw 'found (point))) ((eobp) (throw 'found (point)))))))) (if (not pos) ;; Skip a whole block (catch 'found (while t (verilog-re-search-forward verilog-end-statement-re nil 'move) (setq nest (if (match-end 1) (1+ nest) (1- nest))) (cond ((eobp) (throw 'found (point))) ((= 0 nest) (throw 'found (verilog-end-of-statement)))))) pos))) (defun verilog-in-case-region-p () "Return true if in a case region. More specifically, point @ in the line foo : @ begin" (interactive) (save-excursion (if (and (progn (verilog-forward-syntactic-ws) (looking-at "\\")) (progn (verilog-backward-syntactic-ws) (= (preceding-char) ?\:))) (catch 'found (let ((nest 1)) (while t (verilog-re-search-backward (concat "\\(\\\\)\\|\\(\\\\|\\[^:]\\)\\|" "\\(\\\\)\\>") nil 'move) (cond ((match-end 3) (setq nest (1+ nest))) ((match-end 2) (if (= nest 1) (throw 'found 1)) (setq nest (1- nest))) (t (throw 'found (= nest 0))))))) nil))) (defun verilog-in-struct-region-p () "Return true if in a struct region. More specifically, in a list after a struct|union keyword." (interactive) (save-excursion (let* ((state (verilog-syntax-ppss)) (depth (nth 0 state))) (if depth (progn (backward-up-list depth) (verilog-beg-of-statement) (looking-at "\\?\\s-*\\")))))) (defun verilog-in-generate-region-p () "Return true if in a generate region. More specifically, after a generate and before an endgenerate." (interactive) (let ((nest 1)) (save-excursion (catch 'done (while (and (/= nest 0) (verilog-re-search-backward "\\<\\(module\\)\\|\\(generate\\)\\|\\(endgenerate\\)\\>" nil 'move) (cond ((match-end 1) ; module - we have crawled out (throw 'done 1)) ((match-end 2) ; generate (setq nest (1- nest))) ((match-end 3) ; endgenerate (setq nest (1+ nest)))))))) (= nest 0) )) ; return nest (defun verilog-in-fork-region-p () "Return true if between a fork and join." (interactive) (let ((lim (save-excursion (verilog-beg-of-defun) (point))) (nest 1)) (save-excursion (while (and (/= nest 0) (verilog-re-search-backward "\\<\\(fork\\)\\|\\(join\\(_any\\|_none\\)?\\)\\>" lim 'move) (cond ((match-end 1) ; fork (setq nest (1- nest))) ((match-end 2) ; join (setq nest (1+ nest))))))) (= nest 0) )) ; return nest (defun verilog-backward-case-item (lim) "Skip backward to nearest enclosing case item. Limit search to point LIM." (interactive) (let ((str 'nil) (lim1 (progn (save-excursion (verilog-re-search-backward verilog-endcomment-reason-re lim 'move) (point))))) ;; Try to find the real : (if (save-excursion (search-backward ":" lim1 t)) (let ((colon 0) b e ) (while (and (< colon 1) (verilog-re-search-backward "\\(\\[\\)\\|\\(\\]\\)\\|\\(:\\)" lim1 'move)) (cond ((match-end 1) ;; [ (setq colon (1+ colon)) (if (>= colon 0) (error "%s: unbalanced [" (verilog-point-text)))) ((match-end 2) ;; ] (setq colon (1- colon))) ((match-end 3) ;; : (setq colon (1+ colon))))) ;; Skip back to beginning of case item (skip-chars-backward "\t ") (verilog-skip-backward-comment-or-string) (setq e (point)) (setq b (progn (if (verilog-re-search-backward "\\<\\(case[zx]?\\)\\>\\|;\\|\\" nil 'move) (progn (cond ((match-end 1) (goto-char (match-end 1)) (verilog-forward-ws&directives) (if (looking-at "(") (progn (forward-sexp) (verilog-forward-ws&directives))) (point)) (t (goto-char (match-end 0)) (verilog-forward-ws&directives) (point)))) (error "Malformed case item")))) (setq str (buffer-substring b e)) (if (setq e (string-match "[ \t]*\\(\\(\n\\)\\|\\(//\\)\\|\\(/\\*\\)\\)" str)) (setq str (concat (substring str 0 e) "..."))) str) 'nil))) ;; ;; Other functions ;; (defun verilog-kill-existing-comment () "Kill auto comment on this line." (save-excursion (let* ( (e (progn (end-of-line) (point))) (b (progn (beginning-of-line) (search-forward "//" e t)))) (if b (delete-region (- b 2) e))))) (defconst verilog-directive-nest-re (concat "\\(`else\\>\\)\\|" "\\(`endif\\>\\)\\|" "\\(`if\\>\\)\\|" "\\(`ifdef\\>\\)\\|" "\\(`ifndef\\>\\)")) (defun verilog-set-auto-endcomments (indent-str kill-existing-comment) "Add ending comment with given INDENT-STR. With KILL-EXISTING-COMMENT, remove what was there before. Insert `// case: 7 ' or `// NAME ' on this line if appropriate. Insert `// case expr ' if this line ends a case block. Insert `// ifdef FOO ' if this line ends code conditional on FOO. Insert `// NAME ' if this line ends a function, task, module, primitive or interface named NAME." (save-excursion (cond (; Comment close preprocessor directives (and (looking-at "\\(`endif\\)\\|\\(`else\\)") (or kill-existing-comment (not (save-excursion (end-of-line) (search-backward "//" (verilog-get-beg-of-line) t))))) (let ((nest 1) b e m (else (if (match-end 2) "!" " "))) (end-of-line) (if kill-existing-comment (verilog-kill-existing-comment)) (delete-horizontal-space) (save-excursion (backward-sexp 1) (while (and (/= nest 0) (verilog-re-search-backward verilog-directive-nest-re nil 'move)) (cond ((match-end 1) ; `else (if (= nest 1) (setq else "!"))) ((match-end 2) ; `endif (setq nest (1+ nest))) ((match-end 3) ; `if (setq nest (1- nest))) ((match-end 4) ; `ifdef (setq nest (1- nest))) ((match-end 5) ; `ifndef (setq nest (1- nest))))) (if (match-end 0) (setq m (buffer-substring (match-beginning 0) (match-end 0)) b (progn (skip-chars-forward "^ \t") (verilog-forward-syntactic-ws) (point)) e (progn (skip-chars-forward "a-zA-Z0-9_") (point))))) (if b (if (> (count-lines (point) b) verilog-minimum-comment-distance) (insert (concat " // " else m " " (buffer-substring b e)))) (progn (insert " // unmatched `else or `endif") (ding 't))))) (; Comment close case/class/function/task/module and named block (and (looking-at "\\") (setq str "randcase") (setq err nil)) ((match-end 0) (goto-char (match-end 1)) (if nil (let (s f) (setq s (match-beginning 1)) (setq f (progn (end-of-line) (point))) (setq str (buffer-substring s f))) (setq err nil)) (setq str (concat (buffer-substring (match-beginning 1) (match-end 1)) " " (verilog-get-expr)))))) (end-of-line) (if kill-existing-comment (verilog-kill-existing-comment)) (delete-horizontal-space) (insert (concat " // " str )) (if err (ding 't)))) (;- This is a begin..end block (match-end 2) ;; of verilog-end-block-ordered-re (let ((str " // UNMATCHED !!") (err 't) (here (point)) there cntx) (save-excursion (verilog-leap-to-head) (setq there (point)) (if (not (match-end 0)) (progn (goto-char here) (end-of-line) (if kill-existing-comment (verilog-kill-existing-comment)) (delete-horizontal-space) (insert str) (ding 't)) (let ((lim (save-excursion (verilog-beg-of-defun) (point))) (here (point))) (cond (;-- handle named block differently (looking-at verilog-named-block-re) (search-forward ":") (setq there (point)) (setq str (verilog-get-expr)) (setq err nil) (setq str (concat " // block: " str ))) ((verilog-in-case-region-p) ;-- handle case item differently (goto-char here) (setq str (verilog-backward-case-item lim)) (setq there (point)) (setq err nil) (setq str (concat " // case: " str ))) (;- try to find "reason" for this begin (cond (; (eq here (progn (verilog-backward-token) (verilog-beg-of-statement-1) (point)))