comparison lisp/progmodes/verilog-mode.el @ 103616:af77bf73dfe0

* verilog-mode.el (verilog-beg-of-statement) (verilog-endcomment-reason-re): Support unique case and priority case. (verilog-basic-complete-re): Support localparam lineup. (verilog-beg-of-statement-1): Fix for robustness, unique case. (verilog-set-auto-endcomments): Fix for unique case, always_comb commenting. (verilog-leap-to-case-head): Now support *nested* unique & priority case statements. (verilog-auto-lineup): Make just declarations the default (as it had been). (verilog-leap-to-case-head): Support priority/unique case statements. (verilog-auto-lineup): Rework to give users radio buttons to select the various styles of automatic lineup (verilog-error-regexp-alist): Rework to support the XEmacs style of error regular expressions from compilers, lint tools & simulators. Note that GNU Emacs has made it impossible for a mode to load such things. (electric-verilog-terminate-line, verilog-indent-declaration) (verilog-auto-wiure): Rework for radio button selection of auto-lineup selection of specification of auto lineup. (verilog-beg-of-statement-1): Redesign to support proper operation in additional code, based on testing with auto-lineup. (verilog-calculate-indent, assignments & declarations) (verilog-backward-token): Enhance to support auto-lineup of assignments & declarations. (verilog-in-directive-p, verilog-at-struct-p): New function for easy test of whether we are. (verilog-pretty-declarations, verilog-pretty-expr): Massive rework to support safe execution at almost anyline. (verilog-calc-1): Properly support indenting deep inside generate blocks. (verilog-init-font) Remove definition & use of verilog-init-font, as it is redundant with font-lock-defaults. (verilog-mode): Alter the definition of verilog-font-lock-defualts to avoid circular calls if syntax-ppss is a function (as is the case now in 22.x GNU Emacs) as that function would sometimes call itself, leading to (nearly) infinite recursion (verilog-ovm-begin-re, verilog-ovm-end-re) (verilog-ovm-statement-re, verilog-leap-to-head) (verilog-backward-token): Add support for OVM macros. Some are complete statements, and others open and close scopes like begin and end. (verilog-defun-level-not-generate-re, verilog-defun-level-re) (verilog-defun-level-generate-only-re): Really fix the defun-list compilation issue (verilog-calc-1) (verilog-beg-of-statement): Enhance support for coverpoint, constraint and cross statements (verilog-defun-level-list, verilog-generate-defun-level-list) (verilog-all-defun-level-list): Redo these specifications - it is too hard to support eval-when compile aggregation of lists also built at when-compile time. (verilog-defun-level-list): Place defconsts of variables used in building regular expressions which are built in eval-when-compile bodies in the same eval-when-compile body to facilitate compile without load. (verilog-beg-block-re-ordered): Support indenting virtual/protected tasks and functions. (verilog-defun-level-list,verilog-in-generate-region-p) (verilog-backward-ws&directives, verilog-calc-1): Speed up indentation of some module items (generate items). (verilog-forward-sexp, verilog-leap-to-head): Support stepping across virtual/protected tasks and functions. * verilog-mode.el (verilog-auto-arg, verilog-auto-arg-sort): Allow sorting AUTOARG lists. Suggested by Andrea Fedeli. (verilog-read-sub-decls-line): Fix AUTOWIRE signals getting lost in concatenations. Reported by Yishay Belkind. (verilog-auto-ascii-enum): Support one-hot state machines in AUTOASCIIENUM. Suggested by Lloyd Gomez. (verilog-auto-inst, verilog-auto-inst-port): Include interface modport in AUTOINST and add vl-modport for users. Reported by David Rogoff. (verilog-auto-inout-module, verilog-auto-inst) (verilog-decls-get-interfaces, verilog-insert-definition) (verilog-insert-one-definition, verilog-read-decls) (verilog-read-sub-decls, verilog-read-sub-decls-sig) (verilog-sig-modport, verilog-signals-combine-bus) (verilog-subdecls-get-interfaces): Fix expansion of SystemVerilog interfaces in AUTOINOUTMODULE, AUTOINOUTCOMP, and AUTOINST. Suggested by David Rogoff. (verilog-repair-open-comma): Fix non-insertion of comma when `DEFINE occurs in V2K argument list. Reported by Lane Brooks. (verilog-make-width-expression): Simplify [A-1:0] expression widths to just {A{1'b0}}. (verilog-mode): Cleanup checkdoc warnings. (verilog-auto-inout-module, verilog-signals-matching-dir-re): Add third optional regexp to AUTOINOUTMODULE to allow selecting only inputs/outputs or data type. Suggested by Vasu Kandadi. (next-error-last-buffer): Fix byte-compiler warning. (verilog-auto, verilog-auto-insert-lisp, verilog-auto-inst) (verilog-delete-auto): Add AUTOINSERTLISP to insert arbitrary lisp or shell command text during AUTO expansion. Suggested by Tad Truex. (verilog-read-sub-decls-expr, verilog-read-sub-decls-line) (verilog-read-sub-decls-sig, verilog-symbol-detick-text): Fix dotted nets {a.b,c.d} and excaped identifiers being mis-included in AUTOINOUT. Reported by Matthew Lovell. (verilog-read-always-signals-recurse): Fix AUTORESET "if (a<=b)" causing use of <= assignments. Reported by Alex Reed. (verilog-read-decls): Fix triand, trior, wand, wor to be recognized by AUTOWIRE. Reported by Spencer Isaacson. (verilog-extended-complete-re): Support import "DPI-C" functions. (verilog-read-always-signals-recurse): Fix AUTORESET of "x <= y[a+1:a+1]" to not include a in reset list. Reported by Dan Dever. (verilog-insert-date, verilog-insert-year) (verilog-sk-header-tmpl): Fix verilog-header inserting error on Windows systems. Reported by Michael Potts. (verilog-read-module-name): Fix AUTOINST when the child module declaration's name is a tick define. Reported by Elliot Mednick. (verilog-read-decls): Fix V2K parameter bit subscripts getting passed to next parameter's definition. Reported by Bruce T. (verilog-read-decls): Fix detecting "parameter int" when using AUTOINSTPARAM. Reported by Bruce T. (verilog-goto-defun): Fix goto not finding modules unless first perform a verilog-auto expansion. Suggested by Lawrence Butcher. (verilog-mode): Expand -f flag arguments on entry to mode so verilog-goto-defun will work. Reported by Lawrence Butcher. (verilog-getopt): Expand environment variables in -f file arguments. Suggested by Lawrence Butcher. (verilog-set-define): Fix "Symbol's value as variable is void" when reading enumerations. (verilog-auto-ascii-enum): Fix duplicate labels in AUTOASCIIENUM. Suggested by Stephen Peltan. (verilog-read-defines): Fix reading of enumerations in include files. Reported by Steve Peltan.
author Dan Nicolaescu <dann@ics.uci.edu>
date Sun, 28 Jun 2009 17:52:45 +0000
parents e2dc5f14229e
children 503d12c87acd
comparison
equal deleted inserted replaced
103615:fe1b52515c0f 103616:af77bf73dfe0
52 ;; KNOWN BUGS / BUG REPORTS 52 ;; KNOWN BUGS / BUG REPORTS
53 ;; ======================= 53 ;; =======================
54 54
55 ;; Verilog is a rapidly evolving language, and hence this mode is 55 ;; Verilog is a rapidly evolving language, and hence this mode is
56 ;; under continuous development. Hence this is beta code, and likely 56 ;; under continuous development. Hence this is beta code, and likely
57 ;; has bugs. Please report any and all bugs to me at mac@verilog.com. 57 ;; has bugs. Please report any issues to the issue tracker at
58 ;; http://www.veripool.org/verilog-mode
58 ;; Please use verilog-submit-bug-report to submit a report; type C-c 59 ;; Please use verilog-submit-bug-report to submit a report; type C-c
59 ;; C-b to invoke this and as a result I will have a much easier time 60 ;; C-b to invoke this and as a result I will have a much easier time
60 ;; of reproducing the bug you find, and hence fixing it. 61 ;; of reproducing the bug you find, and hence fixing it.
61 62
62 ;; INSTALLING THE MODE 63 ;; INSTALLING THE MODE
100 ; verilog-auto-indent-on-newline t 101 ; verilog-auto-indent-on-newline t
101 ; verilog-tab-always-indent t 102 ; verilog-tab-always-indent t
102 ; verilog-auto-endcomments t 103 ; verilog-auto-endcomments t
103 ; verilog-minimum-comment-distance 40 104 ; verilog-minimum-comment-distance 40
104 ; verilog-indent-begin-after-if t 105 ; verilog-indent-begin-after-if t
105 ; verilog-auto-lineup '(all) 106 ; verilog-auto-lineup 'declarations
106 ; verilog-highlight-p1800-keywords nil 107 ; verilog-highlight-p1800-keywords nil
107 ; verilog-linter "my_lint_shell_command" 108 ; verilog-linter "my_lint_shell_command"
108 ; ) 109 ; )
109 110
110 ;; 111 ;;
115 ;; (This section is required to appease checkdoc.) 116 ;; (This section is required to appease checkdoc.)
116 117
117 ;;; Code: 118 ;;; Code:
118 119
119 ;; This variable will always hold the version number of the mode 120 ;; This variable will always hold the version number of the mode
120 (defconst verilog-mode-version "436" 121 (defconst verilog-mode-version "520"
121 "Version of this Verilog mode.") 122 "Version of this Verilog mode.")
122 (defconst verilog-mode-release-date "2008-09-02-GNU" 123 (defconst verilog-mode-release-date "2009-06-12-GNU"
123 "Release date of this Verilog mode.") 124 "Release date of this Verilog mode.")
124 (defconst verilog-mode-release-emacs t 125 (defconst verilog-mode-release-emacs t
125 "If non-nil, this version of Verilog mode was released with Emacs itself.") 126 "If non-nil, this version of Verilog mode was released with Emacs itself.")
126 127
127 (defun verilog-version () 128 (defun verilog-version ()
263 (defun verilog-regexp-words (a) 264 (defun verilog-regexp-words (a)
264 "Call 'regexp-opt' with word delimiters for the words A." 265 "Call 'regexp-opt' with word delimiters for the words A."
265 (concat "\\<" (verilog-regexp-opt a t) "\\>"))) 266 (concat "\\<" (verilog-regexp-opt a t) "\\>")))
266 267
267 (defun verilog-easy-menu-filter (menu) 268 (defun verilog-easy-menu-filter (menu)
268 "Filter a easy-menu-define to support new features." 269 "Filter `easy-menu-define' MENU to support new features."
269 (cond ((not (featurep 'xemacs)) 270 (cond ((not (featurep 'xemacs))
270 menu) ;; GNU Emacs - passthru 271 menu) ;; GNU Emacs - passthru
271 ;; Xemacs doesn't support :help. Strip it. 272 ;; Xemacs doesn't support :help. Strip it.
272 ;; Recursively filter the a submenu 273 ;; Recursively filter the a submenu
273 ((listp menu) 274 ((listp menu)
297 (if (fboundp 'customize-apropos) 298 (if (fboundp 'customize-apropos)
298 (customize-apropos "font-lock-*" 'faces))) 299 (customize-apropos "font-lock-*" 'faces)))
299 300
300 (defun verilog-booleanp (value) 301 (defun verilog-booleanp (value)
301 "Return t if VALUE is boolean. 302 "Return t if VALUE is boolean.
302 This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs. 303 This implements GNU Emacs 22.1's `booleanp' function in earlier Emacs.
303 This function may be removed when Emacs 21 is no longer supported." 304 This function may be removed when Emacs 21 is no longer supported."
304 (or (equal value t) (equal value nil))) 305 (or (equal value t) (equal value nil)))
306
307 (defun verilog-insert-last-command-event ()
308 "Insert the `last-command-event'."
309 (insert (if (featurep 'xemacs)
310 ;; XEmacs 21.5 doesn't like last-command-event
311 last-command-char
312 ;; And GNU Emacs 22 has obsoleted last-command-char
313 last-command-event)))
305 314
306 (defalias 'verilog-syntax-ppss 315 (defalias 'verilog-syntax-ppss
307 (if (fboundp 'syntax-ppss) 'syntax-ppss 316 (if (fboundp 'syntax-ppss) 'syntax-ppss
308 (lambda (&optional pos) (parse-partial-sexp (point-min) (or pos (point)))))) 317 (lambda (&optional pos) (parse-partial-sexp (point-min) (or pos (point))))))
309 318
387 entry \"Fontify Buffer\"). XEmacs: turn off and on font locking." 396 entry \"Fontify Buffer\"). XEmacs: turn off and on font locking."
388 :type 'boolean 397 :type 'boolean
389 :group 'verilog-mode-indent) 398 :group 'verilog-mode-indent)
390 ;; Note we don't use :safe, as that would break on Emacsen before 22.0. 399 ;; Note we don't use :safe, as that would break on Emacsen before 22.0.
391 (put 'verilog-highlight-translate-off 'safe-local-variable 'verilog-booleanp) 400 (put 'verilog-highlight-translate-off 'safe-local-variable 'verilog-booleanp)
401
402 (defcustom verilog-auto-lineup 'declarations
403 "*Type of statements to lineup across multiple lines.
404 If 'all' is selected, then all line ups described below are done.
405
406 If 'declaration', then just declarations are lined up with any
407 preceding declarations, taking into account widths and the like,
408 so or example the code:
409 reg [31:0] a;
410 reg b;
411 would become
412 reg [31:0] a;
413 reg b;
414
415 If 'assignment', then assignments are lined up with any preceding
416 assignments, so for example the code
417 a_long_variable <= b + c;
418 d = e + f;
419 would become
420 a_long_variable <= b + c;
421 d = e + f;
422
423 In order to speed up editing, large blocks of statements are lined up
424 only when a \\[verilog-pretty-expr] is typed; and large blocks of declarations
425 are lineup only when \\[verilog-pretty-declarations] is typed."
426
427 :type '(radio (const :tag "Line up Assignments and Declarations" all)
428 (const :tag "Line up Assignment statements" assignments )
429 (const :tag "Line up Declarartions" declarations)
430 (function :tag "Other"))
431 :group 'verilog-mode-indent )
392 432
393 (defcustom verilog-indent-level 3 433 (defcustom verilog-indent-level 3
394 "*Indentation of Verilog statements with respect to containing block." 434 "*Indentation of Verilog statements with respect to containing block."
395 :group 'verilog-mode-indent 435 :group 'verilog-mode-indent
396 :type 'integer) 436 :type 'integer)
510 default avoids too many redundant comments in tight quarters." 550 default avoids too many redundant comments in tight quarters."
511 :group 'verilog-mode-indent 551 :group 'verilog-mode-indent
512 :type 'integer) 552 :type 'integer)
513 (put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp) 553 (put 'verilog-minimum-comment-distance 'safe-local-variable 'integerp)
514 554
515 (defcustom verilog-auto-lineup '(declaration)
516 "*Algorithm for lining up statements on multiple lines.
517
518 If this list contains the symbol 'all', then all line ups described below
519 are done.
520
521 If this list contains the symbol 'declaration', then declarations are lined up
522 with any preceding declarations, taking into account widths and the like, so
523 for example the code:
524 reg [31:0] a;
525 reg b;
526 would become
527 reg [31:0] a;
528 reg b;
529
530 If this list contains the symbol 'assignment', then assignments are lined up
531 with any preceding assignments, so for example the code
532 a_long_variable = b + c;
533 d = e + f;
534 would become
535 a_long_variable = b + c;
536 d = e + f;"
537
538 ;; The following is not implemented:
539 ;If this list contains the symbol 'case', then case items are lined up
540 ;with any preceding case items, so for example the code
541 ; case (a) begin
542 ; a_long_state : a = 3;
543 ; b: a = 4;
544 ; endcase
545 ;would become
546 ; case (a) begin
547 ; a_long_state : a = 3;
548 ; b : a = 4;
549 ; endcase
550 ;
551
552 :group 'verilog-mode-indent
553 :type 'list)
554 (put 'verilog-auto-lineup 'safe-local-variable 'listp)
555
556 (defcustom verilog-highlight-p1800-keywords nil 555 (defcustom verilog-highlight-p1800-keywords nil
557 "*True means highlight words newly reserved by IEEE-1800. 556 "*True means highlight words newly reserved by IEEE-1800.
558 These will appear in `verilog-font-lock-p1800-face' in order to gently 557 These will appear in `verilog-font-lock-p1800-face' in order to gently
559 suggest changing where these words are used as variables to something else. 558 suggest changing where these words are used as variables to something else.
560 A nil value means highlight these words as appropriate for the SystemVerilog 559 A nil value means highlight these words as appropriate for the SystemVerilog
564 :type 'boolean) 563 :type 'boolean)
565 (put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp) 564 (put 'verilog-highlight-p1800-keywords 'safe-local-variable 'verilog-booleanp)
566 565
567 (defcustom verilog-highlight-grouping-keywords nil 566 (defcustom verilog-highlight-grouping-keywords nil
568 "*True means highlight grouping keywords 'begin' and 'end' more dramatically. 567 "*True means highlight grouping keywords 'begin' and 'end' more dramatically.
569 If false, these words are in the font-lock-type-face; if True then they are in 568 If false, these words are in the `font-lock-type-face'; if True then they are in
570 `verilog-font-lock-ams-face'. Some find that special highlighting on these 569 `verilog-font-lock-ams-face'. Some find that special highlighting on these
571 grouping constructs allow the structure of the code to be understood at a glance." 570 grouping constructs allow the structure of the code to be understood at a glance."
572 :group 'verilog-mode-indent 571 :group 'verilog-mode-indent
573 :type 'boolean) 572 :type 'boolean)
574 (put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp) 573 (put 'verilog-highlight-grouping-keywords 'safe-local-variable 'verilog-booleanp)
575 574
628 (defvar verilog-auto-last-file-locals nil 627 (defvar verilog-auto-last-file-locals nil
629 "Text from file-local-variables during last evaluation.") 628 "Text from file-local-variables during last evaluation.")
630 629
631 (defvar verilog-error-regexp-add-didit nil) 630 (defvar verilog-error-regexp-add-didit nil)
632 (defvar verilog-error-regexp nil) 631 (defvar verilog-error-regexp nil)
633 (setq verilog-error-regexp-add-didit nil 632 ;;; Compile support
634 verilog-error-regexp 633 (require 'compile)
635 '( 634 (make-variable-buffer-local 'compilation-error-regexp-systems-list)
636 ; SureLint 635 (defvar compilation-error-regexp-alist) ; in case not
637 ;; ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2) 636 (make-variable-buffer-local 'compilation-error-regexp-alist)
638 ; Most SureFire tools 637
639 ("\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\), \\(line \\|\\)\\([0-9]+\\):" 2 4 ) 638 ; List of regexps for Verilog compilers, like verilint. See compilation-error-regexp-alist
640 ("\ 639 ; for the formatting.
640 (defvar verilog-error-regexp-alist
641 '(verilog
642 ; SureLint
643 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 2)
644 ("\\(WARNING\\|ERROR\\|INFO\\)[^:]*: \\([^,]+\\), \\(line \\|\\)\\([0-9]+\\):" 2 4 )
645 ("\
641 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\ 646 \\([a-zA-Z]?:?[^:( \t\n]+\\)[:(][ \t]*\\([0-9]+\\)\\([) \t]\\|\
642 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5) 647 :\\([^0-9\n]\\|\\([0-9]+:\\)\\)\\)" 1 2 5)
643 ; xsim 648 ; xsim
644 ; Error! in file /homes/mac/Axis/Xsim/test.v at line 13 [OBJ_NOT_DECLARED] 649 ; Error! in file /homes/mac/Axis/Xsim/test.v at line 13 [OBJ_NOT_DECLARED]
645 ("\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3) 650 ("\\(Error\\|Warning\\).*in file (\\([^ \t]+\\) at line *\\([0-9]+\\))" 2 3)
646 ; vcs 651 ; vcs
647 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3) 652 ("\\(Error\\|Warning\\):[^(]*(\\([^ \t]+\\) line *\\([0-9]+\\))" 2 3)
648 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2) 653 ("Warning:.*(port.*(\\([^ \t]+\\) line \\([0-9]+\\))" 1 2)
649 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3) 654 ("\\(Error\\|Warning\\):[\n.]*\\([^ \t]+\\) *\\([0-9]+\\):" 2 3)
650 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2) 655 ("syntax error:.*\n\\([^ \t]+\\) *\\([0-9]+\\):" 1 2)
651 ; Verilator 656 ; Verilator
652 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4) 657 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
653 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4) 658 ("%?\\(Error\\|Warning\\)\\(-[^:]+\\|\\):[\n ]*\\([^ \t:]+\\):\\([0-9]+\\):" 3 4)
654 ; vxl 659 ; verilog-xl
655 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3) 660 ("\\(Error\\|Warning\\)!.*\n?.*\"\\([^\"]+\\)\", \\([0-9]+\\)" 2 3)
656 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 1 2) ; vxl 661 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+\\([0-9]+\\):.*$" 1 2) ; vxl
657 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 1 2) 662 ("([WE][0-9A-Z]+)[ \t]+\\([^ \t\n,]+\\)[, \t]+line[ \t]+\\([0-9]+\\):.*$" 1 2)
658 ; nc-verilog 663 ; nc-verilog
659 (".*\\*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 1 2) 664 (".*\\*[WE],[0-9A-Z]+ (\\([^ \t,]+\\),\\([0-9]+\\)|" 1 2)
660 ; Leda 665 ; Leda
661 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 1 2) 666 ("In file \\([^ \t]+\\)[ \t]+line[ \t]+\\([0-9]+\\):\n[^\n]*\n[^\n]*\n\\[\\(Warning\\|Error\\|Failure\\)\\][^\n]*" 1 2)
662 ) 667 ))
663 ; "*List of regexps for Verilog compilers, like verilint. See compilation-error-regexp-alist for the formatting."
664 )
665 668
666 (defvar verilog-error-font-lock-keywords 669 (defvar verilog-error-font-lock-keywords
667 '( 670 '(
668 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t) 671 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 1 bold t)
669 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t) 672 ("[^\n]*\\[\\([^:]+\\):\\([0-9]+\\)\\]" 2 bold t)
831 (defcustom verilog-assignment-delay "" 834 (defcustom verilog-assignment-delay ""
832 "*Text used for delays in delayed assignments. Add a trailing space if set." 835 "*Text used for delays in delayed assignments. Add a trailing space if set."
833 :group 'verilog-mode-auto 836 :group 'verilog-mode-auto
834 :type 'string) 837 :type 'string)
835 (put 'verilog-assignment-delay 'safe-local-variable 'stringp) 838 (put 'verilog-assignment-delay 'safe-local-variable 'stringp)
839
840 (defcustom verilog-auto-arg-sort nil
841 "*If set, AUTOARG will sort signal names, rather than leave them in
842 declaration order. Declaration order is advantageous with order based
843 instantiations and is the default for backward compatibility. Sorted order
844 reduces changes when declarations are moved around in a file, and it's bad
845 practice to rely on order based instantiations anyhow."
846 :group 'verilog-mode-auto
847 :type 'boolean)
848 (put 'verilog-auto-arg-sort 'safe-local-variable 'verilog-booleanp)
836 849
837 (defcustom verilog-auto-inst-param-value nil 850 (defcustom verilog-auto-inst-param-value nil
838 "*If set, AUTOINST will replace parameters with the parameter value. 851 "*If set, AUTOINST will replace parameters with the parameter value.
839 If nil, leave parameters as symbolic names. 852 If nil, leave parameters as symbolic names.
840 853
1151 :help "Help on AUTOASCIIENUM - creating ASCII for enumerations"] 1164 :help "Help on AUTOASCIIENUM - creating ASCII for enumerations"]
1152 ["AUTOINOUTCOMP" (describe-function 'verilog-auto-inout-complement) 1165 ["AUTOINOUTCOMP" (describe-function 'verilog-auto-inout-complement)
1153 :help "Help on AUTOINOUTCOMP - copying complemented i/o from another file"] 1166 :help "Help on AUTOINOUTCOMP - copying complemented i/o from another file"]
1154 ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module) 1167 ["AUTOINOUTMODULE" (describe-function 'verilog-auto-inout-module)
1155 :help "Help on AUTOINOUTMODULE - copying i/o from another file"] 1168 :help "Help on AUTOINOUTMODULE - copying i/o from another file"]
1169 ["AUTOINSERTLISP" (describe-function 'verilog-auto-insert-lisp)
1170 :help "Help on AUTOINSERTLISP - insert text from a lisp function"]
1156 ["AUTOINOUT" (describe-function 'verilog-auto-inout) 1171 ["AUTOINOUT" (describe-function 'verilog-auto-inout)
1157 :help "Help on AUTOINOUT - adding inouts from cells"] 1172 :help "Help on AUTOINOUT - adding inouts from cells"]
1158 ["AUTOINPUT" (describe-function 'verilog-auto-input) 1173 ["AUTOINPUT" (describe-function 'verilog-auto-input)
1159 :help "Help on AUTOINPUT - adding inputs from cells"] 1174 :help "Help on AUTOINPUT - adding inputs from cells"]
1160 ["AUTOINST" (describe-function 'verilog-auto-inst) 1175 ["AUTOINST" (describe-function 'verilog-auto-inst)
1406 (setq compile-command 1421 (setq compile-command
1407 (verilog-string-replace-matches 1422 (verilog-string-replace-matches
1408 "\\b__FILE__\\b" (file-name-nondirectory (buffer-file-name)) 1423 "\\b__FILE__\\b" (file-name-nondirectory (buffer-file-name))
1409 t t compile-command)))) 1424 t t compile-command))))
1410 1425
1411 ;; Following code only gets called from compilation-mode-hook. 1426 ;; Following code only gets called from compilation-mode-hook on XEmacs to add error handling.
1412 (defvar compilation-error-regexp-alist) 1427 ;; There is no way to add this on the fly to Emacs; instead we must update compile.el
1413 1428 (if (featurep 'xemacs)
1414 (defun verilog-error-regexp-add () 1429 (defun verilog-error-regexp-add-xemacs ()
1415 "Add the messages to the `compilation-error-regexp-alist'. 1430 "Teach XEmacs about verilog errors.
1416 Called by `compilation-mode-hook'. This allows \\[next-error] to 1431 Called by `compilation-mode-hook'. This allows \\[next-error] to
1417 find the errors." 1432 find the errors."
1418 (if (not verilog-error-regexp-add-didit) 1433 (interactive)
1419 (progn 1434 (if 't ; (not verilog-error-regexp-add-didit)
1420 (setq verilog-error-regexp-add-didit t) 1435 (progn
1421 (setq-default compilation-error-regexp-alist 1436 (if (or (equal compilation-error-regexp-systems-list 'all)
1422 (append verilog-error-regexp 1437 (not (member 'verilog compilation-error-regexp-systems-list)))
1423 (default-value 'compilation-error-regexp-alist))) 1438 (setq compilation-error-regexp-systems-list
1424 ;; Could be buffer local at this point; maybe also in let; change all three 1439 (if (listp compilation-error-regexp-systems-list)
1425 (setq compilation-error-regexp-alist 1440 (nconc compilation-error-regexp-systems-list 'verilog)
1426 (default-value 'compilation-error-regexp-alist)) 1441 'verilog)))
1427 (set (make-local-variable 'compilation-error-regexp-alist) 1442 (if (not (assoc 'verilog compilation-error-regexp-alist-alist))
1428 (default-value 'compilation-error-regexp-alist))))) 1443 (setcdr compilation-error-regexp-alist-alist
1429 1444 (cons verilog-error-regexp-alist
1430 (add-hook 'compilation-mode-hook 'verilog-error-regexp-add) 1445 (cdr compilation-error-regexp-alist-alist))))
1446 ;; Need to re-run compilation-error-regexp builder
1447 (compilation-build-compilation-error-regexp-alist))))
1448 )
1449 (defun verilog-error-regexp-add-emacs ()
1450 "Tell Emacs compile that we are Verilog.
1451 Called by `compilation-mode-hook'. This allows \\[next-error] to
1452 find the errors."
1453 (interactive)
1454 ;; Turned off because there seems no way to do this outside of compile.el
1455 ;;
1456 ;; (if (or (equal compilation-error-regexp-alist 'all)
1457 ;; (not (member 'verilog compilation-error-regexp-alist)))
1458 ;; (setq compilation-error-regexp-alist
1459 ;; (if (listp compilation-error-regexp-alist)
1460 ;; (append '(verilog) compilation-error-regexp-alist)
1461 ;; '(verilog) )))
1462 )
1463
1464 (if (featurep 'xemacs)
1465 (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-xemacs)
1466 (add-hook 'compilation-mode-hook 'verilog-error-regexp-add-emacs))
1431 1467
1432 (defconst verilog-directive-re 1468 (defconst verilog-directive-re
1433 ;; "`case" "`default" "`define" "`define" "`else" "`endfor" "`endif" 1469 ;; "`case" "`default" "`define" "`define" "`else" "`endfor" "`endif"
1434 ;; "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef" 1470 ;; "`endprotect" "`endswitch" "`endwhile" "`for" "`format" "`if" "`ifdef"
1435 ;; "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale" 1471 ;; "`ifndef" "`include" "`let" "`protect" "`switch" "`timescale"
1436 ;; "`time_scale" "`undef" "`while" 1472 ;; "`time_scale" "`undef" "`while"
1437 "\\<`\\(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\\)\\>") 1473 "\\<`\\(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\\)\\>")
1438 1474
1475 (defconst verilog-directive-re-1
1476 (concat "[ \t]*" verilog-directive-re))
1477
1439 (defconst verilog-directive-begin 1478 (defconst verilog-directive-begin
1440 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>") 1479 "\\<`\\(for\\|i\\(f\\|fdef\\|fndef\\)\\|switch\\|while\\)\\>")
1441 1480
1442 (defconst verilog-directive-middle 1481 (defconst verilog-directive-middle
1443 "\\<`\\(else\\|default\\|case\\)\\>") 1482 "\\<`\\(else\\|default\\|case\\)\\>")
1444 1483
1445 (defconst verilog-directive-end 1484 (defconst verilog-directive-end
1446 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>") 1485 "`\\(endfor\\|endif\\|endswitch\\|endwhile\\)\\>")
1447 1486
1448 (defconst verilog-directive-re-1 1487 (defconst verilog-ovm-begin-re
1449 (concat "[ \t]*" verilog-directive-re)) 1488 (eval-when-compile
1489 (verilog-regexp-opt
1490 '(
1491 "`ovm_component_utils_begin"
1492 "`ovm_field_utils_begin"
1493 "`ovm_object_utils_begin"
1494 "`ovm_sequence_utils_begin"
1495 "`ovm_sequencer_utils_begin"
1496 ) nil )))
1497
1498 (defconst verilog-ovm-end-re
1499 (eval-when-compile
1500 (verilog-regexp-opt
1501 '(
1502 "`ovm_component_utils_end"
1503 "`ovm_field_utils_end"
1504 "`ovm_object_utils_end"
1505 "`ovm_sequence_utils_end"
1506 "`ovm_sequencer_utils_end"
1507 ) nil )))
1508
1509 (defconst verilog-ovm-statement-re
1510 (eval-when-compile
1511 (verilog-regexp-opt
1512 '(
1513 ;; Statements
1514 "`DUT_ERROR"
1515 "`MESSAGE"
1516 "`dut_error"
1517 "`message"
1518 "`ovm_analysis_imp_decl"
1519 "`ovm_blocking_get_imp_decl"
1520 "`ovm_blocking_get_peek_imp_decl"
1521 "`ovm_blocking_master_imp_decl"
1522 "`ovm_blocking_peek_imp_decl"
1523 "`ovm_blocking_put_imp_decl"
1524 "`ovm_blocking_slave_imp_decl"
1525 "`ovm_blocking_transport_imp_decl"
1526 "`ovm_component_registry"
1527 "`ovm_component_registry_param"
1528 "`ovm_component_utils"
1529 "`ovm_create"
1530 "`ovm_create_seq"
1531 "`ovm_declare_sequence_lib"
1532 "`ovm_do"
1533 "`ovm_do_seq"
1534 "`ovm_do_seq_with"
1535 "`ovm_do_with"
1536 "`ovm_error"
1537 "`ovm_fatal"
1538 "`ovm_field_aa_int_byte"
1539 "`ovm_field_aa_int_byte_unsigned"
1540 "`ovm_field_aa_int_int"
1541 "`ovm_field_aa_int_int_unsigned"
1542 "`ovm_field_aa_int_integer"
1543 "`ovm_field_aa_int_integer_unsigned"
1544 "`ovm_field_aa_int_key"
1545 "`ovm_field_aa_int_longint"
1546 "`ovm_field_aa_int_longint_unsigned"
1547 "`ovm_field_aa_int_shortint"
1548 "`ovm_field_aa_int_shortint_unsigned"
1549 "`ovm_field_aa_int_string"
1550 "`ovm_field_aa_object_int"
1551 "`ovm_field_aa_object_string"
1552 "`ovm_field_aa_string_int"
1553 "`ovm_field_aa_string_string"
1554 "`ovm_field_array_int"
1555 "`ovm_field_array_object"
1556 "`ovm_field_array_string"
1557 "`ovm_field_enum"
1558 "`ovm_field_event"
1559 "`ovm_field_int"
1560 "`ovm_field_object"
1561 "`ovm_field_queue_int"
1562 "`ovm_field_queue_object"
1563 "`ovm_field_queue_string"
1564 "`ovm_field_sarray_int"
1565 "`ovm_field_string"
1566 "`ovm_field_utils"
1567 "`ovm_file"
1568 "`ovm_get_imp_decl"
1569 "`ovm_get_peek_imp_decl"
1570 "`ovm_info"
1571 "`ovm_info1"
1572 "`ovm_info2"
1573 "`ovm_info3"
1574 "`ovm_info4"
1575 "`ovm_line"
1576 "`ovm_master_imp_decl"
1577 "`ovm_msg_detail"
1578 "`ovm_non_blocking_transport_imp_decl"
1579 "`ovm_nonblocking_get_imp_decl"
1580 "`ovm_nonblocking_get_peek_imp_decl"
1581 "`ovm_nonblocking_master_imp_decl"
1582 "`ovm_nonblocking_peek_imp_decl"
1583 "`ovm_nonblocking_put_imp_decl"
1584 "`ovm_nonblocking_slave_imp_decl"
1585 "`ovm_object_registry"
1586 "`ovm_object_registry_param"
1587 "`ovm_object_utils"
1588 "`ovm_peek_imp_decl"
1589 "`ovm_phase_func_decl"
1590 "`ovm_phase_task_decl"
1591 "`ovm_print_aa_int_object"
1592 "`ovm_print_aa_string_int"
1593 "`ovm_print_aa_string_object"
1594 "`ovm_print_aa_string_string"
1595 "`ovm_print_array_int"
1596 "`ovm_print_array_object"
1597 "`ovm_print_array_string"
1598 "`ovm_print_object_queue"
1599 "`ovm_print_queue_int"
1600 "`ovm_print_string_queue"
1601 "`ovm_put_imp_decl"
1602 "`ovm_rand_send"
1603 "`ovm_rand_send_with"
1604 "`ovm_send"
1605 "`ovm_sequence_utils"
1606 "`ovm_slave_imp_decl"
1607 "`ovm_transport_imp_decl"
1608 "`ovm_update_sequence_lib"
1609 "`ovm_update_sequence_lib_and_item"
1610 "`ovm_warning"
1611 "`static_dut_error"
1612 "`static_message") nil )))
1613
1450 1614
1451 ;; 1615 ;;
1452 ;; Regular expressions used to calculate indent, etc. 1616 ;; Regular expressions used to calculate indent, etc.
1453 ;; 1617 ;;
1454 (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>") 1618 (defconst verilog-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
1455 (defconst verilog-case-re "\\(\\<case[xz]?\\>\\|\\<randcase\\>\\)")
1456 ;; Want to match 1619 ;; Want to match
1457 ;; aa : 1620 ;; aa :
1458 ;; aa,bb : 1621 ;; aa,bb :
1459 ;; a[34:32] : 1622 ;; a[34:32] :
1460 ;; a, 1623 ;; a,
1475 "\\(\\<endspecify\\>\\)\\|" ; 7 1638 "\\(\\<endspecify\\>\\)\\|" ; 7
1476 "\\(\\<endtable\\>\\)\\|" ; 8 1639 "\\(\\<endtable\\>\\)\\|" ; 8
1477 "\\(\\<endgenerate\\>\\)\\|" ; 9 1640 "\\(\\<endgenerate\\>\\)\\|" ; 9
1478 "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10 1641 "\\(\\<join\\(_any\\|_none\\)?\\>\\)\\|" ; 10
1479 "\\(\\<endclass\\>\\)\\|" ; 11 1642 "\\(\\<endclass\\>\\)\\|" ; 11
1480 "\\(\\<endgroup\\>\\)" ; 12 1643 "\\(\\<endgroup\\>\\)\\|" ; 12
1644 ;; OVM
1645 "\\(\\<`ovm_component_utils_end\\>\\)\\|"
1646 "\\(\\<`ovm_field_utils_end\\>\\)\\|"
1647 "\\(\\<`ovm_object_utils_end\\>\\)\\|"
1648 "\\(\\<`ovm_sequence_utils_end\\>\\)\\|"
1649 "\\(\\<`ovm_sequencer_utils_end\\>\\)"
1650
1481 )) 1651 ))
1482 1652
1483 (defconst verilog-auto-end-comment-lines-re 1653 (defconst verilog-auto-end-comment-lines-re
1484 ;; Matches to names in this list cause auto-end-commentation 1654 ;; Matches to names in this list cause auto-end-commentation
1485 (concat "\\(" 1655 (concat "\\("
1551 "endinterface" 1721 "endinterface"
1552 "endpackage" 1722 "endpackage"
1553 "endprogram" 1723 "endprogram"
1554 "endsequence" 1724 "endsequence"
1555 "endclocking" 1725 "endclocking"
1726 ;; OVM
1727 "`ovm_component_utils_end"
1728 "`ovm_field_utils_end"
1729 "`ovm_object_utils_end"
1730 "`ovm_sequence_utils_end"
1731 "`ovm_sequencer_utils_end"
1732
1556 )))) 1733 ))))
1557 1734
1558 1735
1559 (defconst verilog-endcomment-reason-re 1736 (defconst verilog-endcomment-reason-re
1560 ;; Parenthesis indicate type of keyword found 1737 ;; Parenthesis indicate type of keyword found
1561 (concat 1738 (concat
1562 "\\(\\<fork\\>\\)\\|" 1739 "\\(\\<begin\\>\\)\\|" ; 1
1563 "\\(\\<begin\\>\\)\\|" 1740 "\\(\\<else\\>\\)\\|" ; 2
1741 "\\(\\<end\\>\\s-+\\<else\\>\\)\\|" ; 3
1742 "\\(\\<always_comb\\>\\(\[ \t\]*@\\)?\\)\\|" ; 4
1743 "\\(\\<always_ff\\>\\(\[ \t\]*@\\)?\\)\\|" ; 5
1744 "\\(\\<always_latch\\>\\(\[ \t\]*@\\)?\\)\\|" ; 6
1745 "\\(\\<fork\\>\\)\\|" ; 7
1746 "\\(\\<always\\>\\(\[ \t\]*@\\)?\\)\\|"
1564 "\\(\\<if\\>\\)\\|" 1747 "\\(\\<if\\>\\)\\|"
1565 "\\(\\<clocking\\>\\)\\|" 1748 "\\(\\<clocking\\>\\)\\|"
1566 "\\(\\<else\\>\\)\\|" 1749 "\\(\\<task\\>\\)\\|"
1567 "\\(\\<end\\>.*\\<else\\>\\)\\|" 1750 "\\(\\<function\\>\\)\\|"
1568 "\\(\\<task\\>\\)\\|"
1569 "\\(\\<function\\>\\)\\|"
1570 "\\(\\<initial\\>\\)\\|" 1751 "\\(\\<initial\\>\\)\\|"
1571 "\\(\\<interface\\>\\)\\|" 1752 "\\(\\<interface\\>\\)\\|"
1572 "\\(\\<package\\>\\)\\|" 1753 "\\(\\<package\\>\\)\\|"
1573 "\\(\\<final\\>\\)\\|" 1754 "\\(\\<final\\>\\)\\|"
1574 "\\(\\<always\\>\\(\[ \t\]*@\\)?\\)\\|"
1575 "\\(\\<always_comb\\>\\(\[ \t\]*@\\)?\\)\\|"
1576 "\\(\\<always_ff\\>\\(\[ \t\]*@\\)?\\)\\|"
1577 "\\(\\<always_latch\\>\\(\[ \t\]*@\\)?\\)\\|"
1578 "\\(@\\)\\|" 1755 "\\(@\\)\\|"
1579 "\\(\\<while\\>\\)\\|" 1756 "\\(\\<while\\>\\)\\|"
1580 "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|" 1757 "\\(\\<for\\(ever\\|each\\)?\\>\\)\\|"
1581 "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|" 1758 "\\(\\<repeat\\>\\)\\|\\(\\<wait\\>\\)\\|"
1582 "#")) 1759 "#"))
1597 "function" 1774 "function"
1598 "property" 1775 "property"
1599 "specify" 1776 "specify"
1600 "table" 1777 "table"
1601 "task" 1778 "task"
1779 ;;; OVM
1780 "`ovm_component_utils_begin"
1781 "`ovm_field_utils_begin"
1782 "`ovm_object_utils_begin"
1783 "`ovm_sequence_utils_begin"
1784 "`ovm_sequencer_utils_begin"
1785
1602 )))) 1786 ))))
1603 ;; These are the same words, in a specific order in the regular 1787 ;; These are the same words, in a specific order in the regular
1604 ;; expression so that matching will work nicely for 1788 ;; expression so that matching will work nicely for
1605 ;; verilog-forward-sexp and verilog-calc-indent 1789 ;; verilog-forward-sexp and verilog-calc-indent
1606
1607 (defconst verilog-beg-block-re-ordered 1790 (defconst verilog-beg-block-re-ordered
1608 ( concat "\\(\\<begin\\>\\)" ;1 1791 ( concat "\\(\\<begin\\>\\)" ;1
1609 "\\|\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?case[xz]?\\>\\)" ; 2,3 1792 "\\|\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?case[xz]?\\>\\)" ; 2,3
1610 "\\|\\(\\(\\<disable\\>\\s-+\\)?fork\\>\\)" ;4,5 1793 "\\|\\(\\(\\<disable\\>\\s-+\\)?fork\\>\\)" ;4,5
1611 "\\|\\(\\<class\\>\\)" ;6 1794 "\\|\\(\\<class\\>\\)" ;6
1612 "\\|\\(\\<table\\>\\)" ;7 1795 "\\|\\(\\<table\\>\\)" ;7
1613 "\\|\\(\\<specify\\>\\)" ;8 1796 "\\|\\(\\<specify\\>\\)" ;8
1614 "\\|\\(\\<function\\>\\)" ;9 1797 "\\|\\(\\<function\\>\\)" ;9
1615 "\\|\\(\\<task\\>\\)" ;10 1798 "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<function\\>\\)" ;10
1616 "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<task\\>\\)" ;11 1799 "\\|\\(\\<task\\>\\)" ;14
1617 "\\|\\(\\<generate\\>\\)" ;15 1800 "\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)*\\<task\\>\\)" ;15
1618 "\\|\\(\\<covergroup\\>\\)" ;16 1801 "\\|\\(\\<generate\\>\\)" ;18
1619 "\\|\\(\\(\\(\\<cover\\>\\s-+\\)\\|\\(\\<assert\\>\\s-+\\)\\)*\\<property\\>\\)" ;17 1802 "\\|\\(\\<covergroup\\>\\)" ;16 20
1620 "\\|\\(\\<\\(rand\\)?sequence\\>\\)" ;21 1803 "\\|\\(\\(\\(\\<cover\\>\\s-+\\)\\|\\(\\<assert\\>\\s-+\\)\\)*\\<property\\>\\)" ;17 21
1621 "\\|\\(\\<clocking\\>\\)" ;22 1804 "\\|\\(\\<\\(rand\\)?sequence\\>\\)" ;21 25
1805 "\\|\\(\\<clocking\\>\\)" ;22 27
1806 "\\|\\(\\<`ovm_[a-z_]+_begin\\>\\)" ;28
1807 ;;
1808
1622 )) 1809 ))
1623 1810
1624 (defconst verilog-end-block-ordered-rry 1811 (defconst verilog-end-block-ordered-rry
1625 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" 1812 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
1626 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)" 1813 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)"
1729 (concat verilog-defun-re "\\|" verilog-end-defun-re)) 1916 (concat verilog-defun-re "\\|" verilog-end-defun-re))
1730 1917
1731 (defconst verilog-behavioral-block-beg-re 1918 (defconst verilog-behavioral-block-beg-re
1732 (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff" 1919 (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff"
1733 "function" "task")))) 1920 "function" "task"))))
1734 1921 (defconst verilog-coverpoint-re "\\w+\\s*:\\s*\\(coverpoint\\|cross\\constraint\\)" )
1735 (defconst verilog-indent-re 1922 (defconst verilog-indent-re
1736 (eval-when-compile 1923 (eval-when-compile
1737 (verilog-regexp-words 1924 (verilog-regexp-words
1738 `( 1925 `(
1739 "{" 1926 "{"
1772 "`let" 1959 "`let"
1773 "`protect" "`endprotect" 1960 "`protect" "`endprotect"
1774 "`switch" "`endswitch" 1961 "`switch" "`endswitch"
1775 "`timescale" 1962 "`timescale"
1776 "`time_scale" 1963 "`time_scale"
1964 ;; OVM Begin tokens
1965 "`ovm_component_utils_begin"
1966 "`ovm_field_utils_begin"
1967 "`ovm_object_utils_begin"
1968 "`ovm_sequence_utils_begin"
1969 "`ovm_sequencer_utils_begin"
1970 ;; OVM End tokens
1971 "`ovm_component_utils_end"
1972 "`ovm_field_utils_end"
1973 "`ovm_object_utils_end"
1974 "`ovm_sequence_utils_end"
1975 "`ovm_sequencer_utils_end"
1777 )))) 1976 ))))
1977
1978 (defconst verilog-defun-level-not-generate-re
1979 (eval-when-compile
1980 (verilog-regexp-words
1981 `( "module" "macromodule" "primitive" "class" "program"
1982 "interface" "package" "config"))))
1778 1983
1779 (defconst verilog-defun-level-re 1984 (defconst verilog-defun-level-re
1780 (eval-when-compile 1985 (eval-when-compile
1781 (verilog-regexp-words 1986 (verilog-regexp-words
1782 `( 1987 (append
1783 "module" "macromodule" "primitive" "class" "program" "initial" "final" "always" "always_comb" 1988 `( "module" "macromodule" "primitive" "class" "program"
1784 "always_ff" "always_latch" "endtask" "endfunction" "interface" "package" 1989 "interface" "package" "config")
1785 "config")))) 1990 `( "initial" "final" "always" "always_comb" "always_ff"
1786 1991 "always_latch" "endtask" "endfunction" )))))
1787 (defconst verilog-defun-level-not-generate-re 1992
1993 (defconst verilog-defun-level-generate-only-re
1788 (eval-when-compile 1994 (eval-when-compile
1789 (verilog-regexp-words 1995 (verilog-regexp-words
1790 `( 1996 `( "initial" "final" "always" "always_comb" "always_ff"
1791 "module" "macromodule" "primitive" "class" "program" "interface" "package" "config")))) 1997 "always_latch" "endtask" "endfunction" ))))
1792 1998
1793 (defconst verilog-cpp-level-re 1999 (defconst verilog-cpp-level-re
1794 (eval-when-compile 2000 (eval-when-compile
1795 (verilog-regexp-words 2001 (verilog-regexp-words
1796 `( 2002 `(
1799 (defconst verilog-disable-fork-re "disable\\s-+fork") 2005 (defconst verilog-disable-fork-re "disable\\s-+fork")
1800 (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?") 2006 (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?")
1801 (defconst verilog-extended-complete-re 2007 (defconst verilog-extended-complete-re
1802 (concat "\\(\\<extern\\s-+\\|\\<virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)" 2008 (concat "\\(\\<extern\\s-+\\|\\<virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)"
1803 "\\|\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)" 2009 "\\|\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)"
2010 "\\|\\(\\<import\\>\\s-+\\)?\"DPI-C\"\\s-+\\(function\\>\\|task\\>\\)"
1804 "\\|" verilog-extended-case-re )) 2011 "\\|" verilog-extended-case-re ))
1805 (defconst verilog-basic-complete-re 2012 (defconst verilog-basic-complete-re
1806 (eval-when-compile 2013 (eval-when-compile
1807 (verilog-regexp-words 2014 (verilog-regexp-words
1808 `( 2015 `(
1809 "always" "assign" "always_latch" "always_ff" "always_comb" "constraint" 2016 "always" "assign" "always_latch" "always_ff" "always_comb" "constraint"
1810 "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while" 2017 "import" "initial" "final" "module" "macromodule" "repeat" "randcase" "while"
1811 "if" "for" "forever" "foreach" "else" "parameter" "do" 2018 "if" "for" "forever" "foreach" "else" "parameter" "do" "localparam"
1812 )))) 2019 ))))
1813 (defconst verilog-complete-reg 2020 (defconst verilog-complete-reg
1814 (concat 2021 (concat
1815 verilog-extended-complete-re 2022 verilog-extended-complete-re
1816 "\\|" 2023 "\\|"
1819 (defconst verilog-end-statement-re 2026 (defconst verilog-end-statement-re
1820 (concat "\\(" verilog-beg-block-re "\\)\\|\\(" 2027 (concat "\\(" verilog-beg-block-re "\\)\\|\\("
1821 verilog-end-block-re "\\)")) 2028 verilog-end-block-re "\\)"))
1822 2029
1823 (defconst verilog-endcase-re 2030 (defconst verilog-endcase-re
1824 (concat verilog-case-re "\\|" 2031 (concat verilog-extended-case-re "\\|"
1825 "\\(endcase\\)\\|" 2032 "\\(endcase\\)\\|"
1826 verilog-defun-re 2033 verilog-defun-re
1827 )) 2034 ))
1828 2035
1829 (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----" 2036 (defconst verilog-exclude-str-start "/* -----\\/----- EXCLUDED -----\\/-----"
2258 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" ) 2465 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
2259 (setq md 3) ;; ender is third item in regexp 2466 (setq md 3) ;; ender is third item in regexp
2260 ) 2467 )
2261 ((match-end 4) 2468 ((match-end 4)
2262 ;; might be "disable fork" 2469 ;; might be "disable fork"
2263 (if (or 2470 (if (or
2264 (looking-at verilog-disable-fork-re) 2471 (looking-at verilog-disable-fork-re)
2265 (and (looking-at "fork") 2472 (and (looking-at "fork")
2266 (progn 2473 (progn
2267 (forward-word -1) 2474 (forward-word -1)
2268 (looking-at verilog-disable-fork-re)))) 2475 (looking-at verilog-disable-fork-re))))
2269 (progn 2476 (progn
2270 (goto-char (match-end 0)) 2477 (goto-char (match-end 0))
2271 (forward-word) 2478 (forward-word 1)
2272 (setq reg nil)) 2479 (setq reg nil))
2273 (progn 2480 (progn
2274 ;; Search forward for matching join 2481 ;; Search forward for matching join
2275 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))) 2482 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))))
2276 ((match-end 6) 2483 ((match-end 6)
2277 ;; Search forward for matching endclass 2484 ;; Search forward for matching endclass
2278 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" )) 2485 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
2279 2486
2280 ((match-end 7) 2487 ((match-end 7)
2281 ;; Search forward for matching endtable 2488 ;; Search forward for matching endtable
2282 (setq reg "\\<endtable\\>" ) 2489 (setq reg "\\<endtable\\>" )
2283 (setq nest 'no)) 2490 (setq nest 'no))
2284 ((match-end 8) 2491 ((match-end 8)
2287 ((match-end 9) 2494 ((match-end 9)
2288 ;; Search forward for matching endfunction 2495 ;; Search forward for matching endfunction
2289 (setq reg "\\<endfunction\\>" ) 2496 (setq reg "\\<endfunction\\>" )
2290 (setq nest 'no)) 2497 (setq nest 'no))
2291 ((match-end 10) 2498 ((match-end 10)
2292 ;; Search forward for matching endtask 2499 ;; Search forward for matching endfunction
2293 (setq reg "\\<endtask\\>" ) 2500 (setq reg "\\<endfunction\\>" )
2294 (setq nest 'no)) 2501 (setq nest 'no))
2295 ((match-end 11) 2502 ((match-end 14)
2296 ;; Search forward for matching endtask 2503 ;; Search forward for matching endtask
2297 (setq reg "\\<endtask\\>" ) 2504 (setq reg "\\<endtask\\>" )
2298 (setq nest 'no)) 2505 (setq nest 'no))
2299 ((match-end 15) 2506 ((match-end 15)
2507 ;; Search forward for matching endtask
2508 (setq reg "\\<endtask\\>" )
2509 (setq nest 'no))
2510 ((match-end 19)
2300 ;; Search forward for matching endgenerate 2511 ;; Search forward for matching endgenerate
2301 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" )) 2512 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
2302 ((match-end 16) 2513 ((match-end 20)
2303 ;; Search forward for matching endgroup 2514 ;; Search forward for matching endgroup
2304 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )) 2515 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
2305 ((match-end 17) 2516 ((match-end 21)
2306 ;; Search forward for matching endproperty 2517 ;; Search forward for matching endproperty
2307 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" )) 2518 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
2308 ((match-end 18) 2519 ((match-end 25)
2309 ;; Search forward for matching endsequence 2520 ;; Search forward for matching endsequence
2310 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ) 2521 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )
2311 (setq md 3)) ; 3 to get to endsequence in the reg above 2522 (setq md 3)) ; 3 to get to endsequence in the reg above
2312 ((match-end 19) 2523 ((match-end 27)
2313 ;; Search forward for matching endclocking 2524 ;; Search forward for matching endclocking
2314 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" ))) 2525 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )))
2315 (if (and reg 2526 (if (and reg
2316 (forward-word 1)) 2527 (forward-word 1))
2317 (catch 'skip 2528 (catch 'skip
2318 (if (eq nest 'yes) 2529 (if (eq nest 'yes)
2319 (let ((depth 1)) 2530 (let ((depth 1))
2320 (while (verilog-re-search-forward reg nil 'move) 2531 (while (verilog-re-search-forward reg nil 'move)
2321 (cond 2532 (cond
2322 ((match-end md) ; the closer in reg, so we are climbing out 2533 ((match-end md) ; the closer in reg, so we are climbing out
2323 (setq depth (1- depth)) 2534 (setq depth (1- depth))
2325 (throw 'skip 1))) 2536 (throw 'skip 1)))
2326 ((match-end 1) ; the opener in reg, so we are deeper now 2537 ((match-end 1) ; the opener in reg, so we are deeper now
2327 (setq depth (1+ depth)))))) 2538 (setq depth (1+ depth))))))
2328 (if (verilog-re-search-forward reg nil 'move) 2539 (if (verilog-re-search-forward reg nil 'move)
2329 (throw 'skip 1)))))) 2540 (throw 'skip 1))))))
2330 2541
2331 ((looking-at (concat 2542 ((looking-at (concat
2332 "\\(\\<\\(macro\\)?module\\>\\)\\|" 2543 "\\(\\<\\(macro\\)?module\\>\\)\\|"
2333 "\\(\\<primitive\\>\\)\\|" 2544 "\\(\\<primitive\\>\\)\\|"
2334 "\\(\\<class\\>\\)\\|" 2545 "\\(\\<class\\>\\)\\|"
2335 "\\(\\<program\\>\\)\\|" 2546 "\\(\\<program\\>\\)\\|"
2359 (forward-char 1) 2570 (forward-char 1)
2360 (forward-sexp 1)))))) 2571 (forward-sexp 1))))))
2361 2572
2362 (defun verilog-declaration-beg () 2573 (defun verilog-declaration-beg ()
2363 (verilog-re-search-backward verilog-declaration-re (bobp) t)) 2574 (verilog-re-search-backward verilog-declaration-re (bobp) t))
2364
2365 (defun verilog-font-lock-init ()
2366 "Initialize fontification."
2367 ;; highlight keywords and standardized types, attributes, enumeration
2368 ;; values, and subprograms
2369 (setq verilog-font-lock-keywords-3
2370 (append verilog-font-lock-keywords-2
2371 (when verilog-highlight-translate-off
2372 (list
2373 ;; Fontify things in translate off regions
2374 '(verilog-match-translate-off
2375 (0 'verilog-font-lock-translate-off-face prepend))))))
2376 ;; FIXME: This XEmacs setting is redundant with the setting done later
2377 ;; for Emacs (because XEmacs obeys Emacs's setting as well).
2378 (put 'verilog-mode 'font-lock-defaults
2379 '((verilog-font-lock-keywords
2380 verilog-font-lock-keywords-1
2381 verilog-font-lock-keywords-2
2382 verilog-font-lock-keywords-3)
2383 nil ; nil means highlight strings & comments as well as keywords
2384 nil ; nil means keywords must match case
2385 nil ; syntax table handled elsewhere
2386 ;; Function to move to beginning of reasonable region to highlight
2387 verilog-beg-of-defun)))
2388
2389 ;; initialize fontification for Verilog Mode
2390 (verilog-font-lock-init)
2391 2575
2392 ;; 2576 ;;
2393 ;; 2577 ;;
2394 ;; Mode 2578 ;; Mode
2395 ;; 2579 ;;
2458 `verilog-minimum-comment-distance' (default 10) 2642 `verilog-minimum-comment-distance' (default 10)
2459 Minimum distance (in lines) between begin and end required before a comment 2643 Minimum distance (in lines) between begin and end required before a comment
2460 will be inserted. Setting this variable to zero results in every 2644 will be inserted. Setting this variable to zero results in every
2461 end acquiring a comment; the default avoids too many redundant 2645 end acquiring a comment; the default avoids too many redundant
2462 comments in tight quarters. 2646 comments in tight quarters.
2463 `verilog-auto-lineup' (default `(all)) 2647 `verilog-auto-lineup' (default 'declarations)
2464 List of contexts where auto lineup of code should be done. 2648 List of contexts where auto lineup of code should be done.
2465 2649
2466 Variables controlling other actions: 2650 Variables controlling other actions:
2467 2651
2468 `verilog-linter' (default surelint) 2652 `verilog-linter' (default surelint)
2564 (set (make-local-variable 'font-lock-defaults) 2748 (set (make-local-variable 'font-lock-defaults)
2565 `((verilog-font-lock-keywords verilog-font-lock-keywords-1 2749 `((verilog-font-lock-keywords verilog-font-lock-keywords-1
2566 verilog-font-lock-keywords-2 2750 verilog-font-lock-keywords-2
2567 verilog-font-lock-keywords-3) 2751 verilog-font-lock-keywords-3)
2568 nil nil nil 2752 nil nil nil
2569 ,(if (functionp 'syntax-ppss) 2753 ,(if (functionp 'syntax-ppss)
2570 ;; verilog-beg-of-defun uses syntax-ppss, and syntax-ppss uses 2754 ;; verilog-beg-of-defun uses syntax-ppss, and syntax-ppss uses
2571 ;; font-lock-beginning-of-syntax-function, so 2755 ;; font-lock-beginning-of-syntax-function, so
2572 ;; font-lock-beginning-of-syntax-function, can't use 2756 ;; font-lock-beginning-of-syntax-function, can't use
2573 ;; verilog-beg-of-defun. 2757 ;; verilog-beg-of-defun.
2574 nil 2758 nil
2575 'verilog-beg-of-defun))) 2759 'verilog-beg-of-defun)))
2576 ;;------------------------------------------------------------ 2760 ;;------------------------------------------------------------
2577 ;; now hook in 'verilog-colorize-include-files (eldo-mode.el&spice-mode.el) 2761 ;; now hook in 'verilog-colorize-include-files (eldo-mode.el&spice-mode.el)
2578 ;; all buffer local: 2762 ;; all buffer local:
2579 (when (featurep 'xemacs) 2763 (when (featurep 'xemacs)
2580 (make-local-hook 'font-lock-mode-hook) 2764 (make-local-hook 'font-lock-mode-hook)
2598 verilog-forward-sexp-function) 2782 verilog-forward-sexp-function)
2599 hs-special-modes-alist)))) 2783 hs-special-modes-alist))))
2600 2784
2601 ;; Stuff for autos 2785 ;; Stuff for autos
2602 (add-hook 'write-contents-hooks 'verilog-auto-save-check) ; already local 2786 (add-hook 'write-contents-hooks 'verilog-auto-save-check) ; already local
2603 ;; (verilog-auto-reeval-locals t) ; Save locals in case user changes them
2604 ;; (verilog-getopt-flags)
2605 (run-hooks 'verilog-mode-hook)) 2787 (run-hooks 'verilog-mode-hook))
2606 2788
2607 2789
2608 ;; 2790 ;;
2609 ;; Electric functions 2791 ;; Electric functions
2649 (end-of-line) 2831 (end-of-line)
2650 (delete-horizontal-space) 2832 (delete-horizontal-space)
2651 't))) 2833 't)))
2652 ;; see if we should line up assignments 2834 ;; see if we should line up assignments
2653 (progn 2835 (progn
2654 (if (or (memq 'all verilog-auto-lineup) 2836 (if (or (eq 'all verilog-auto-lineup)
2655 (memq 'assignments verilog-auto-lineup)) 2837 (eq 'assignments verilog-auto-lineup))
2656 (verilog-pretty-expr)) 2838 (verilog-pretty-expr t "\\(<\\|:\\)?=" ))
2657 (newline)) 2839 (newline))
2658 (forward-line 1)) 2840 (forward-line 1))
2659 ;; Indent next line 2841 ;; Indent next line
2660 (if verilog-auto-indent-on-newline 2842 (if verilog-auto-indent-on-newline
2661 (verilog-indent-line))) 2843 (verilog-indent-line)))
2668 (electric-verilog-terminate-line 1)) 2850 (electric-verilog-terminate-line 1))
2669 2851
2670 (defun electric-verilog-semi () 2852 (defun electric-verilog-semi ()
2671 "Insert `;' character and reindent the line." 2853 "Insert `;' character and reindent the line."
2672 (interactive) 2854 (interactive)
2673 (insert last-command-event) 2855 (verilog-insert-last-command-event)
2674 2856
2675 (if (or (verilog-in-comment-or-string-p) 2857 (if (or (verilog-in-comment-or-string-p)
2676 (verilog-in-escaped-name-p)) 2858 (verilog-in-escaped-name-p))
2677 () 2859 ()
2678 (save-excursion 2860 (save-excursion
2693 (indent-for-comment)) 2875 (indent-for-comment))
2694 2876
2695 (defun electric-verilog-colon () 2877 (defun electric-verilog-colon ()
2696 "Insert `:' and do all indentations except line indent on this line." 2878 "Insert `:' and do all indentations except line indent on this line."
2697 (interactive) 2879 (interactive)
2698 (insert last-command-event) 2880 (verilog-insert-last-command-event)
2699 ;; Do nothing if within string. 2881 ;; Do nothing if within string.
2700 (if (or 2882 (if (or
2701 (verilog-within-string) 2883 (verilog-within-string)
2702 (not (verilog-in-case-region-p))) 2884 (not (verilog-in-case-region-p)))
2703 () 2885 ()
2712 )) 2894 ))
2713 2895
2714 ;;(defun electric-verilog-equal () 2896 ;;(defun electric-verilog-equal ()
2715 ;; "Insert `=', and do indentation if within block." 2897 ;; "Insert `=', and do indentation if within block."
2716 ;; (interactive) 2898 ;; (interactive)
2717 ;; (insert last-command-event) 2899 ;; (verilog-insert-last-command-event)
2718 ;; Could auto line up expressions, but not yet 2900 ;; Could auto line up expressions, but not yet
2719 ;; (if (eq (car (verilog-calculate-indent)) 'block) 2901 ;; (if (eq (car (verilog-calculate-indent)) 'block)
2720 ;; (let ((verilog-tab-always-indent nil)) 2902 ;; (let ((verilog-tab-always-indent nil))
2721 ;; (verilog-indent-command))) 2903 ;; (verilog-indent-command)))
2722 ;; ) 2904 ;; )
2723 2905
2724 (defun electric-verilog-tick () 2906 (defun electric-verilog-tick ()
2725 "Insert back-tick, and indent to column 0 if this is a CPP directive." 2907 "Insert back-tick, and indent to column 0 if this is a CPP directive."
2726 (interactive) 2908 (interactive)
2727 (insert last-command-event) 2909 (verilog-insert-last-command-event)
2728 (save-excursion 2910 (save-excursion
2729 (if (progn 2911 (if (verilog-in-directive-p)
2730 (beginning-of-line) 2912 (verilog-indent-line))))
2731 (looking-at verilog-directive-re-1))
2732 (verilog-indent-line))))
2733 2913
2734 (defun electric-verilog-tab () 2914 (defun electric-verilog-tab ()
2735 "Function called when TAB is pressed in Verilog mode." 2915 "Function called when TAB is pressed in Verilog mode."
2736 (interactive) 2916 (interactive)
2737 ;; If verilog-tab-always-indent, indent the beginning of the line. 2917 ;; If verilog-tab-always-indent, indent the beginning of the line.
2765 (re-search-forward comment-start-skip oldpnt 'move) 2945 (re-search-forward comment-start-skip oldpnt 'move)
2766 (goto-char (match-beginning 0)) 2946 (goto-char (match-beginning 0))
2767 (skip-chars-backward " \t") 2947 (skip-chars-backward " \t")
2768 (kill-region (point) oldpnt))))))) 2948 (kill-region (point) oldpnt)))))))
2769 (t (progn (insert "\t"))))) 2949 (t (progn (insert "\t")))))
2770 2950
2771 2951
2772 2952
2773 ;; 2953 ;;
2774 ;; Interactive functions 2954 ;; Interactive functions
2775 ;; 2955 ;;
3023 ;; or the token before us unambiguously ends a statement, 3203 ;; or the token before us unambiguously ends a statement,
3024 ;; then move back a token and test again. 3204 ;; then move back a token and test again.
3025 (not (or 3205 (not (or
3026 (bolp) 3206 (bolp)
3027 (= (preceding-char) ?\;) 3207 (= (preceding-char) ?\;)
3208 (looking-at "\\w+\\W*:\\W*\\(coverpoint\\|cross\\|constraint\\)")
3028 (not (or 3209 (not (or
3029 (looking-at "\\<") 3210 (looking-at "\\<")
3030 (forward-word -1))) 3211 (forward-word -1)))
3031 (and 3212 (and
3032 (looking-at verilog-extended-complete-re) 3213 (looking-at verilog-extended-complete-re)
3045 (verilog-forward-syntactic-ws)) 3226 (verilog-forward-syntactic-ws))
3046 3227
3047 (defun verilog-beg-of-statement-1 () 3228 (defun verilog-beg-of-statement-1 ()
3048 "Move backward to beginning of statement." 3229 "Move backward to beginning of statement."
3049 (interactive) 3230 (interactive)
3231 (if (verilog-in-comment-p)
3232 (verilog-backward-syntactic-ws))
3050 (let ((pt (point))) 3233 (let ((pt (point)))
3051 3234 (catch 'done
3052 (while (and (not (looking-at verilog-complete-reg)) 3235 (while (not (looking-at verilog-complete-reg))
3053 (setq pt (point)) 3236 (setq pt (point))
3054 (verilog-backward-token) 3237 (verilog-backward-syntactic-ws)
3055 (not (looking-at verilog-complete-reg)) 3238 (if (or (bolp)
3056 (verilog-backward-syntactic-ws) 3239 (= (preceding-char) ?\;))
3057 (setq pt (point)) 3240 (progn
3058 (not (bolp)) 3241 (goto-char pt)
3059 (not (= (preceding-char) ?\;)))) 3242 (throw 'done t))
3060 (goto-char pt) 3243 (verilog-backward-token))))
3061 (verilog-forward-ws&directives))) 3244 (verilog-forward-syntactic-ws)))
3245 ;
3246 ; (while (and
3247 ; (not (looking-at verilog-complete-reg))
3248 ; (not (bolp))
3249 ; (not (= (preceding-char) ?\;)))
3250 ; (verilog-backward-token)
3251 ; (verilog-backward-syntactic-ws)
3252 ; (setq pt (point)))
3253 ; (goto-char pt)
3254 ; ;(verilog-forward-syntactic-ws)
3062 3255
3063 (defun verilog-end-of-statement () 3256 (defun verilog-end-of-statement ()
3064 "Move forward to end of current statement." 3257 "Move forward to end of current statement."
3065 (interactive) 3258 (interactive)
3066 (let ((nest 0) pos) 3259 (let ((nest 0) pos)
3067 (or (looking-at verilog-beg-block-re) 3260 (cond
3068 ;; Skip to end of statement 3261 ((verilog-in-directive-p)
3069 (setq pos (catch 'found 3262 (forward-line 1)
3070 (while t 3263 (backward-char 1))
3071 (forward-sexp 1) 3264
3072 (verilog-skip-forward-comment-or-string) 3265 ((looking-at verilog-beg-block-re)
3073 (cond ((looking-at "[ \t]*;") 3266 (verilog-forward-sexp))
3074 (skip-chars-forward "^;") 3267
3075 (forward-char 1) 3268 ((equal (char-after) ?\})
3076 (throw 'found (point))) 3269 (forward-char))
3077 ((save-excursion 3270
3078 (forward-sexp -1) 3271 ;; Skip to end of statement
3079 (looking-at verilog-beg-block-re)) 3272 ((condition-case nil
3080 (goto-char (match-beginning 0)) 3273 (setq pos
3081 (throw 'found nil)) 3274 (catch 'found
3082 ((looking-at "[ \t]*)") 3275 (while t
3083 (throw 'found (point))) 3276 (forward-sexp 1)
3084 ((eobp) 3277 (verilog-skip-forward-comment-or-string)
3085 (throw 'found (point)))))))) 3278 (if (eolp)
3086 (if (not pos) 3279 (forward-line 1))
3087 ;; Skip a whole block 3280 (cond ((looking-at "[ \t]*;")
3088 (catch 'found 3281 (skip-chars-forward "^;")
3089 (while t 3282 (forward-char 1)
3090 (verilog-re-search-forward verilog-end-statement-re nil 'move) 3283 (throw 'found (point)))
3091 (setq nest (if (match-end 1) 3284 ((save-excursion
3092 (1+ nest) 3285 (forward-sexp -1)
3093 (1- nest))) 3286 (looking-at verilog-beg-block-re))
3094 (cond ((eobp) 3287 (goto-char (match-beginning 0))
3095 (throw 'found (point))) 3288 (throw 'found nil))
3096 ((= 0 nest) 3289 ((looking-at "[ \t]*)")
3097 (throw 'found (verilog-end-of-statement)))))) 3290 (throw 'found (point)))
3098 pos))) 3291 ((eobp)
3292 (throw 'found (point)))
3293 )))
3294
3295 )
3296 (error nil))
3297 (if (not pos)
3298 ;; Skip a whole block
3299 (catch 'found
3300 (while t
3301 (verilog-re-search-forward verilog-end-statement-re nil 'move)
3302 (setq nest (if (match-end 1)
3303 (1+ nest)
3304 (1- nest)))
3305 (cond ((eobp)
3306 (throw 'found (point)))
3307 ((= 0 nest)
3308 (throw 'found (verilog-end-of-statement))))))
3309 pos)))))
3099 3310
3100 (defun verilog-in-case-region-p () 3311 (defun verilog-in-case-region-p ()
3101 "Return true if in a case region. 3312 "Return true if in a case region.
3102 More specifically, point @ in the line foo : @ begin" 3313 More specifically, point @ in the line foo : @ begin"
3103 (interactive) 3314 (interactive)
3138 3349
3139 (defun verilog-in-generate-region-p () 3350 (defun verilog-in-generate-region-p ()
3140 "Return true if in a generate region. 3351 "Return true if in a generate region.
3141 More specifically, after a generate and before an endgenerate." 3352 More specifically, after a generate and before an endgenerate."
3142 (interactive) 3353 (interactive)
3143 (let ((lim (save-excursion (verilog-beg-of-defun) (point))) 3354 (let ((nest 1))
3144 (nest 1))
3145 (save-excursion 3355 (save-excursion
3146 (while (and 3356 (catch 'done
3147 (/= nest 0) 3357 (while (and
3148 (verilog-re-search-backward "\\<\\(generate\\)\\|\\(endgenerate\\)\\>" lim 'move) 3358 (/= nest 0)
3149 (cond 3359 (verilog-re-search-backward
3150 ((match-end 1) ; generate 3360 "\\<\\(module\\)\\|\\(generate\\)\\|\\(endgenerate\\)\\>" nil 'move)
3151 (setq nest (1- nest))) 3361 (cond
3152 ((match-end 2) ; endgenerate 3362 ((match-end 1) ; module - we have crawled out
3153 (setq nest (1+ nest))))))) 3363 (throw 'done 1))
3364 ((match-end 2) ; generate
3365 (setq nest (1- nest)))
3366 ((match-end 3) ; endgenerate
3367 (setq nest (1+ nest))))))))
3154 (= nest 0) )) ; return nest 3368 (= nest 0) )) ; return nest
3155 3369
3156 (defun verilog-in-fork-region-p () 3370 (defun verilog-in-fork-region-p ()
3157 "Return true if between a fork and join." 3371 "Return true if between a fork and join."
3158 (interactive) 3372 (interactive)
3335 (verilog-leap-to-head) 3549 (verilog-leap-to-head)
3336 (cond 3550 (cond
3337 ((looking-at "\\<randcase\\>") 3551 ((looking-at "\\<randcase\\>")
3338 (setq str "randcase") 3552 (setq str "randcase")
3339 (setq err nil)) 3553 (setq err nil))
3340 ((match-end 0) 3554 ((looking-at "\\(\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)")
3341 (goto-char (match-end 1)) 3555 (goto-char (match-end 0))
3342 (if nil 3556 (setq str (concat (match-string 0) " " (verilog-get-expr)))
3343 (let (s f) 3557 (setq err nil))
3344 (setq s (match-beginning 1)) 3558 ))
3345 (setq f (progn (end-of-line)
3346 (point)))
3347 (setq str (buffer-substring s f)))
3348 (setq err nil))
3349 (setq str (concat (buffer-substring (match-beginning 1) (match-end 1))
3350 " "
3351 (verilog-get-expr))))))
3352 (end-of-line) 3559 (end-of-line)
3353 (if kill-existing-comment 3560 (if kill-existing-comment
3354 (verilog-kill-existing-comment)) 3561 (verilog-kill-existing-comment))
3355 (delete-horizontal-space) 3562 (delete-horizontal-space)
3356 (insert (concat " // " str )) 3563 (insert (concat " // " str ))
3403 (point))) 3610 (point)))
3404 (setq err nil) 3611 (setq err nil)
3405 (setq str "")) 3612 (setq str ""))
3406 ((looking-at verilog-endcomment-reason-re) 3613 ((looking-at verilog-endcomment-reason-re)
3407 (setq there (match-end 0)) 3614 (setq there (match-end 0))
3408 (setq cntx (concat 3615 (setq cntx (concat (match-string 0) " "))
3409 (buffer-substring (match-beginning 0) (match-end 0)) " "))
3410 (cond 3616 (cond
3411 (;- begin 3617 (;- begin
3412 (match-end 2) 3618 (match-end 1)
3413 (setq err nil) 3619 (setq err nil)
3414 (save-excursion 3620 (save-excursion
3415 (if (and (verilog-continued-line) 3621 (if (and (verilog-continued-line)
3416 (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>")) 3622 (looking-at "\\<repeat\\>\\|\\<wait\\>\\|\\<always\\>"))
3417 (progn 3623 (progn
3418 (goto-char (match-end 0)) 3624 (goto-char (match-end 0))
3419 (setq there (point)) 3625 (setq there (point))
3420 (setq str 3626 (setq str
3421 (concat " // " 3627 (concat " // " (match-string 0) " " (verilog-get-expr))))
3422 (buffer-substring (match-beginning 0) (match-end 0)) " "
3423 (verilog-get-expr))))
3424 (setq str "")))) 3628 (setq str ""))))
3425 3629
3426 (;- else 3630 (;- else
3427 (match-end 4) 3631 (match-end 2)
3428 (let ((nest 0) 3632 (let ((nest 0)
3429 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)")) 3633 ( reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)"))
3430 (catch 'skip 3634 (catch 'skip
3431 (while (verilog-re-search-backward reg nil 'move) 3635 (while (verilog-re-search-backward reg nil 'move)
3432 (cond 3636 (cond
3443 (setq str (verilog-get-expr)) 3647 (setq str (verilog-get-expr))
3444 (setq str (concat " // else: !if" str )) 3648 (setq str (concat " // else: !if" str ))
3445 (throw 'skip 1))))))))) 3649 (throw 'skip 1)))))))))
3446 3650
3447 (;- end else 3651 (;- end else
3448 (match-end 5) 3652 (match-end 3)
3449 (goto-char there) 3653 (goto-char there)
3450 (let ((nest 0) 3654 (let ((nest 0)
3451 (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)")) 3655 (reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<if\\>\\)"))
3452 (catch 'skip 3656 (catch 'skip
3453 (while (verilog-re-search-backward reg nil 'move) 3657 (while (verilog-re-search-backward reg nil 'move)
3463 (setq there (point)) 3667 (setq there (point))
3464 (setq err nil) 3668 (setq err nil)
3465 (setq str (verilog-get-expr)) 3669 (setq str (verilog-get-expr))
3466 (setq str (concat " // else: !if" str )) 3670 (setq str (concat " // else: !if" str ))
3467 (throw 'skip 1))))))))) 3671 (throw 'skip 1)))))))))
3672 (; always_comb, always_ff, always_latch
3673 (or (match-end 4) (match-end 5) (match-end 6))
3674 (goto-char (match-end 0))
3675 (setq there (point))
3676 (setq err nil)
3677 (setq str (concat " // " cntx )))
3468 3678
3469 (;- task/function/initial et cetera 3679 (;- task/function/initial et cetera
3470 t 3680 t
3471 (match-end 0) 3681 (match-end 0)
3472 (goto-char (match-end 0)) 3682 (goto-char (match-end 0))
3473 (setq there (point)) 3683 (setq there (point))
3474 (setq err nil) 3684 (setq err nil)
3475 (setq str (verilog-get-expr)) 3685 (setq str (concat " // " cntx (verilog-get-expr))))
3476 (setq str (concat " // " cntx str )))
3477 3686
3478 (;-- otherwise... 3687 (;-- otherwise...
3479 (setq str " // auto-endcomment confused ")))) 3688 (setq str " // auto-endcomment confused "))))
3480 3689
3481 ((and 3690 ((and
3780 ((equal linter `verilint) 3989 ((equal linter `verilint)
3781 (verilog-verilint-off)) 3990 (verilog-verilint-off))
3782 (t (error "Linter name not set"))))) 3991 (t (error "Linter name not set")))))
3783 3992
3784 (defvar compilation-last-buffer) 3993 (defvar compilation-last-buffer)
3994 (defvar next-error-last-buffer)
3785 3995
3786 (defun verilog-surelint-off () 3996 (defun verilog-surelint-off ()
3787 "Convert a SureLint warning line into a disable statement. 3997 "Convert a SureLint warning line into a disable statement.
3788 Run from Verilog source window; assumes there is a *compile* buffer 3998 Run from Verilog source window; assumes there is a *compile* buffer
3789 with point set appropriately. 3999 with point set appropriately.
4008 ;; if we are in a comment, done. 4218 ;; if we are in a comment, done.
4009 (if (verilog-in-star-comment-p) 4219 (if (verilog-in-star-comment-p)
4010 (throw 'nesting 'comment)) 4220 (throw 'nesting 'comment))
4011 4221
4012 ;; if we have a directive, done. 4222 ;; if we have a directive, done.
4013 (if (save-excursion (beginning-of-line) (looking-at verilog-directive-re-1)) 4223 (if (save-excursion (beginning-of-line)
4224 (and (looking-at verilog-directive-re-1)
4225 (not (looking-at "[ \t]*`ovm_"))))
4014 (throw 'nesting 'directive)) 4226 (throw 'nesting 'directive))
4227 ;; indent structs as if there were module level
4228 (if (verilog-in-struct-p)
4229 (throw 'nesting 'block))
4015 4230
4016 ;; unless we are in the newfangled coverpoint or constraint blocks 4231 ;; unless we are in the newfangled coverpoint or constraint blocks
4017 ;; if we are in a parenthesized list, and the user likes to indent these, return. 4232 ;; if we are in a parenthesized list, and the user likes to indent these, return.
4018 (if (and 4233 (if (and
4019 verilog-indent-lists 4234 verilog-indent-lists
4020 (not (verilog-in-coverage)) 4235 (verilog-in-paren)
4021 (verilog-in-paren)) 4236 (not (verilog-in-coverage-p))
4237 )
4022 (progn (setq par 1) 4238 (progn (setq par 1)
4023 (throw 'nesting 'block))) 4239 (throw 'nesting 'block)))
4024 4240
4025 ;; See if we are continuing a previous line 4241 ;; See if we are continuing a previous line
4026 (while t 4242 (while t
4027 ;; trap out if we crawl off the top of the buffer 4243 ;; trap out if we crawl off the top of the buffer
4028 (if (bobp) (throw 'nesting 'cpp)) 4244 (if (bobp) (throw 'nesting 'cpp))
4141 ;; Return type of block and indent level. 4357 ;; Return type of block and indent level.
4142 (if (not type) 4358 (if (not type)
4143 (setq type 'cpp)) 4359 (setq type 'cpp))
4144 (if (and 4360 (if (and
4145 verilog-indent-lists 4361 verilog-indent-lists
4146 (not (verilog-in-coverage)) 4362 (not(or (verilog-in-coverage-p)
4363 (verilog-in-struct-p)))
4147 (verilog-in-paren)) 4364 (verilog-in-paren))
4148 (setq depth 1) 4365 (setq depth 1)
4149 (cond 4366 (cond
4150 ((eq type 'case) 4367 ((eq type 'case)
4151 (setq depth (verilog-case-indent-level))) 4368 (setq depth (verilog-case-indent-level)))
4157 (setq depth (verilog-current-indent-level))))) 4374 (setq depth (verilog-current-indent-level)))))
4158 (message "You are at nesting %s depth %d" type depth)))) 4375 (message "You are at nesting %s depth %d" type depth))))
4159 4376
4160 (defun verilog-calc-1 () 4377 (defun verilog-calc-1 ()
4161 (catch 'nesting 4378 (catch 'nesting
4162 (while (verilog-re-search-backward (concat "\\({\\|}\\|" verilog-indent-re "\\)") nil 'move) 4379 (let ((re (concat "\\({\\|}\\|" verilog-indent-re "\\)")))
4163 (cond 4380 (while (verilog-re-search-backward re nil 'move)
4164 ((equal (char-after) ?\{) 4381 (catch 'continue
4165 (if (verilog-at-constraint-p) 4382 (cond
4166 (throw 'nesting 'block))) 4383 ((equal (char-after) ?\{)
4167 ((equal (char-after) ?\}) 4384 (if (verilog-at-constraint-p)
4168 4385 (throw 'nesting 'block)))
4169 (let ((there (verilog-at-close-constraint-p))) 4386
4170 (if there (goto-char there)))) 4387 ((equal (char-after) ?\})
4171 4388 (let ((there (verilog-at-close-constraint-p)))
4172 ((looking-at verilog-beg-block-re-ordered) 4389 (if there ;; we are at the } that closes a constraing. Find the { that opens it
4173 (cond 4390 (progn
4174 ((match-end 2) ; *sigh* could be "unique case" or "priority casex" 4391 (forward-char 1)
4175 (let ((here (point))) 4392 (backward-list 1)
4176 (verilog-beg-of-statement) 4393 (verilog-beg-of-statement)))))
4177 (if (looking-at verilog-extended-case-re) 4394
4178 (throw 'nesting 'case) 4395 ((looking-at verilog-beg-block-re-ordered)
4179 (goto-char here))) 4396 (cond
4180 (throw 'nesting 'case)) 4397 ((match-end 2) ; *sigh* could be "unique case" or "priority casex"
4181 4398 (let ((here (point)))
4182 ((match-end 4) ; *sigh* could be "disable fork" 4399 (verilog-beg-of-statement)
4183 (let ((here (point))) 4400 (if (looking-at verilog-extended-case-re)
4184 (verilog-beg-of-statement) 4401 (throw 'nesting 'case)
4185 (if (looking-at verilog-disable-fork-re) 4402 (goto-char here)))
4186 t ; is disable fork, this is a normal statement 4403 (throw 'nesting 'case))
4187 (progn ; or is fork, starts a new block 4404
4188 (goto-char here) 4405 ((match-end 4) ; *sigh* could be "disable fork"
4189 (throw 'nesting 'block))))) 4406 (let ((here (point)))
4190 4407 (verilog-beg-of-statement)
4191 4408 (if (looking-at verilog-disable-fork-re)
4192 ;; need to consider typedef struct here... 4409 t ; is disable fork, this is a normal statement
4193 ((looking-at "\\<class\\|struct\\|function\\|task\\>") 4410 (progn ; or is fork, starts a new block
4411 (goto-char here)
4412 (throw 'nesting 'block)))))
4413
4414
4415 ;; need to consider typedef struct here...
4416 ((looking-at "\\<class\\|struct\\|function\\|task\\>")
4194 ; *sigh* These words have an optional prefix: 4417 ; *sigh* These words have an optional prefix:
4195 ; extern {virtual|protected}? function a(); 4418 ; extern {virtual|protected}? function a();
4196 ; typedef class foo; 4419 ; typedef class foo;
4197 ; and we don't want to confuse this with 4420 ; and we don't want to confuse this with
4198 ; function a(); 4421 ; function a();
4199 ; property 4422 ; property
4200 ; ... 4423 ; ...
4201 ; endfunction 4424 ; endfunction
4202 (verilog-beg-of-statement) 4425 (verilog-beg-of-statement)
4203 (if (looking-at verilog-beg-block-re-ordered) 4426 (if (looking-at verilog-beg-block-re-ordered)
4204 (throw 'nesting 'block) 4427 (throw 'nesting 'block)
4205 (throw 'nesting 'defun))) 4428 (throw 'nesting 'defun)))
4206 4429
4207 ((looking-at "\\<property\\>") 4430 ((looking-at "\\<property\\>")
4208 ; *sigh* 4431 ; *sigh*
4209 ; {assert|assume|cover} property (); are complete 4432 ; {assert|assume|cover} property (); are complete
4210 ; but 4433 ; but
4211 ; property ID () ... needs end_property 4434 ; property ID () ... needs end_property
4212 (verilog-beg-of-statement) 4435 (verilog-beg-of-statement)
4213 (if (looking-at "\\(assert\\|assume\\|cover\\)\\s-+property\\>") 4436 (if (looking-at "\\(assert\\|assume\\|cover\\)\\s-+property\\>")
4214 (throw 'nesting 'statement) ; We don't need an endproperty for these 4437 (throw 'nesting 'statement) ; We don't need an endproperty for these
4215 (throw 'nesting 'block) ;We still need a endproperty 4438 (throw 'nesting 'block) ;We still need a endproperty
4216 )) 4439 ))
4217 4440
4218 (t (throw 'nesting 'block)))) 4441 (t (throw 'nesting 'block))))
4219 4442
4220 ((looking-at verilog-end-block-re) 4443 ((looking-at verilog-end-block-re)
4221 (verilog-leap-to-head) 4444 (verilog-leap-to-head)
4222 (if (verilog-in-case-region-p) 4445 (if (verilog-in-case-region-p)
4223 (progn 4446 (progn
4224 (verilog-leap-to-case-head) 4447 (verilog-leap-to-case-head)
4225 (if (looking-at verilog-case-re) 4448 (if (looking-at verilog-extended-case-re)
4226 (throw 'nesting 'case))))) 4449 (throw 'nesting 'case)))))
4227 4450
4228 ((looking-at (if (verilog-in-generate-region-p) 4451 ((looking-at verilog-defun-level-re)
4229 verilog-defun-level-not-generate-re 4452 (if (looking-at verilog-defun-level-generate-only-re)
4230 verilog-defun-level-re)) 4453 (if (verilog-in-generate-region-p)
4231 (throw 'nesting 'defun)) 4454 (throw 'continue 'foo) ; always block in a generate
4232 4455 (throw 'nesting 'defun))
4233 ((looking-at verilog-cpp-level-re) 4456 (throw 'nesting 'defun)))
4234 (throw 'nesting 'cpp)) 4457
4235 4458 ((looking-at verilog-cpp-level-re)
4236 ((bobp) 4459 (throw 'nesting 'cpp))
4237 (throw 'nesting 'cpp)))) 4460
4238 (throw 'nesting 'cpp))) 4461 ((bobp)
4462 (throw 'nesting 'cpp)))))
4463
4464 (throw 'nesting 'cpp))))
4239 4465
4240 (defun verilog-calculate-indent-directive () 4466 (defun verilog-calculate-indent-directive ()
4241 "Return indentation level for directive. 4467 "Return indentation level for directive.
4242 For speed, the searcher looks at the last directive, not the indent 4468 For speed, the searcher looks at the last directive, not the indent
4243 of the appropriate enclosing block." 4469 of the appropriate enclosing block."
4269 ind)) 4495 ind))
4270 4496
4271 (defun verilog-leap-to-case-head () 4497 (defun verilog-leap-to-case-head ()
4272 (let ((nest 1)) 4498 (let ((nest 1))
4273 (while (/= 0 nest) 4499 (while (/= 0 nest)
4274 (verilog-re-search-backward "\\(\\<randcase\\>\\|\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" nil 'move) 4500 (verilog-re-search-backward
4501 (concat
4502 "\\(\\<randcase\\>\\|\\(\\<unique\\s-+\\|priority\\s-+\\)?\\<case[xz]?\\>\\)"
4503 "\\|\\(\\<endcase\\>\\)" )
4504 nil 'move)
4275 (cond 4505 (cond
4276 ((match-end 1) 4506 ((match-end 1)
4507 (let ((here (point)))
4508 (verilog-beg-of-statement)
4509 (unless (looking-at verilog-extended-case-re)
4510 (goto-char here)))
4277 (setq nest (1- nest))) 4511 (setq nest (1- nest)))
4278 ((match-end 2) 4512 ((match-end 3)
4279 (setq nest (1+ nest))) 4513 (setq nest (1+ nest)))
4280 ((bobp) 4514 ((bobp)
4281 (ding 't) 4515 (ding 't)
4282 (setq nest 0)))))) 4516 (setq nest 0))))))
4283 4517
4292 ((looking-at "\\<end\\>") 4526 ((looking-at "\\<end\\>")
4293 ;; 1: Search back for matching begin 4527 ;; 1: Search back for matching begin
4294 (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|" 4528 (setq reg (concat "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|"
4295 "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))) 4529 "\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )))
4296 ((looking-at "\\<endtask\\>") 4530 ((looking-at "\\<endtask\\>")
4297 ;; 9: Search back for matching task 4531 ;; 2: Search back for matching task
4298 (setq reg "\\(\\<task\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<task\\>\\)") 4532 (setq reg "\\(\\<task\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<task\\>\\)")
4299 (setq nesting 'no)) 4533 (setq nesting 'no))
4300 ((looking-at "\\<endcase\\>") 4534 ((looking-at "\\<endcase\\>")
4301 ;; 2: Search back for matching case 4535 (catch 'nesting
4302 (setq reg "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)" )) 4536 (verilog-leap-to-case-head) )
4537 (setq reg nil) ; to force skip
4538 )
4539
4303 ((looking-at "\\<join\\(_any\\|_none\\)?\\>") 4540 ((looking-at "\\<join\\(_any\\|_none\\)?\\>")
4304 ;; 3: Search back for matching fork 4541 ;; 4: Search back for matching fork
4305 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )) 4542 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
4306 ((looking-at "\\<endclass\\>") 4543 ((looking-at "\\<endclass\\>")
4307 ;; 4: Search back for matching class 4544 ;; 5: Search back for matching class
4308 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" )) 4545 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
4309 ((looking-at "\\<endtable\\>") 4546 ((looking-at "\\<endtable\\>")
4310 ;; 5: Search back for matching table 4547 ;; 6: Search back for matching table
4311 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )) 4548 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
4312 ((looking-at "\\<endspecify\\>") 4549 ((looking-at "\\<endspecify\\>")
4313 ;; 6: Search back for matching specify 4550 ;; 7: Search back for matching specify
4314 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )) 4551 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
4315 ((looking-at "\\<endfunction\\>") 4552 ((looking-at "\\<endfunction\\>")
4316 ;; 7: Search back for matching function 4553 ;; 8: Search back for matching function
4317 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )) 4554 (setq reg "\\(\\<function\\>\\)\\|\\(\\(\\(\\<virtual\\>\\s-+\\)\\|\\(\\<protected\\>\\s-+\\)\\)+\\<function\\>\\)")
4555 (setq nesting 'no))
4556 ;;(setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
4318 ((looking-at "\\<endgenerate\\>") 4557 ((looking-at "\\<endgenerate\\>")
4319 ;; 8: Search back for matching generate 4558 ;; 8: Search back for matching generate
4320 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" )) 4559 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
4321 ((looking-at "\\<endgroup\\>") 4560 ((looking-at "\\<endgroup\\>")
4322 ;; 10: Search back for matching covergroup 4561 ;; 10: Search back for matching covergroup
4323 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )) 4562 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
4324 ((looking-at "\\<endproperty\\>") 4563 ((looking-at "\\<endproperty\\>")
4325 ;; 11: Search back for matching property 4564 ;; 11: Search back for matching property
4326 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" )) 4565 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
4566 ((looking-at verilog-ovm-end-re)
4567 ;; 12: Search back for matching sequence
4568 (setq reg (concat "\\(" verilog-ovm-begin-re "\\|" verilog-ovm-end-re "\\)")))
4327 ((looking-at "\\<endinterface\\>") 4569 ((looking-at "\\<endinterface\\>")
4328 ;; 12: Search back for matching interface 4570 ;; 12: Search back for matching interface
4329 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" )) 4571 (setq reg "\\(\\<interface\\>\\)\\|\\(\\<endinterface\\>\\)" ))
4330 ((looking-at "\\<endsequence\\>") 4572 ((looking-at "\\<endsequence\\>")
4331 ;; 12: Search back for matching sequence 4573 ;; 12: Search back for matching sequence
4362 (setq sreg reg) 4604 (setq sreg reg)
4363 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )) 4605 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))
4364 ))) 4606 )))
4365 ;no nesting 4607 ;no nesting
4366 (if (and 4608 (if (and
4367 (verilog-re-search-backward reg nil 'move) 4609 (verilog-re-search-backward reg nil 'move)
4368 (match-end 1)) ; task -> could be virtual and/or protected 4610 (match-end 1)) ; task -> could be virtual and/or protected
4369 (progn 4611 (progn
4370 (verilog-beg-of-statement) 4612 (verilog-beg-of-statement)
4371 (throw 'skip 1)) 4613 (throw 'skip 1))
4372 (throw 'skip 1))))))) 4614 (throw 'skip 1)))))))
4388 (setq continued (verilog-backward-token))))) 4630 (setq continued (verilog-backward-token)))))
4389 (setq continued nil)) 4631 (setq continued nil))
4390 continued)) 4632 continued))
4391 4633
4392 (defun verilog-backward-token () 4634 (defun verilog-backward-token ()
4393 "Step backward token, returning true if we are now at an end of line token." 4635 "Step backward token, returing true if nil if continued line."
4394 (interactive) 4636 (interactive)
4395 (verilog-backward-syntactic-ws) 4637 (verilog-backward-syntactic-ws)
4396 (cond 4638 (cond
4397 ((bolp) 4639 ((bolp)
4398 nil) 4640 nil)
4402 (; If a "}" is prefixed by a ";", then this is a complete statement 4644 (; If a "}" is prefixed by a ";", then this is a complete statement
4403 ; i.e.: constraint foo { a = b; } 4645 ; i.e.: constraint foo { a = b; }
4404 (= (preceding-char) ?\}) 4646 (= (preceding-char) ?\})
4405 (progn 4647 (progn
4406 (backward-char) 4648 (backward-char)
4407 (verilog-at-close-constraint-p))) 4649 (not(verilog-at-close-constraint-p))))
4408 (;-- constraint foo { a = b } 4650 (;-- constraint foo { a = b }
4409 ; is a complete statement. *sigh* 4651 ; is a complete statement. *sigh*
4410 (= (preceding-char) ?\{) 4652 (= (preceding-char) ?\{)
4411 (progn 4653 (progn
4412 (backward-char) 4654 (backward-char)
4413 (not (verilog-at-constraint-p)))) 4655 (not (verilog-at-constraint-p))))
4656 (;" string "
4657 (= (preceding-char) ?\")
4658 (backward-char)
4659 (verilog-skip-backward-comment-or-string)
4660 nil)
4661
4662 (; [3:4]
4663 (= (preceding-char) ?\])
4664 (backward-char)
4665 (verilog-backward-open-bracket)
4666 t)
4667
4414 (;-- Could be 'case (foo)' or 'always @(bar)' which is complete 4668 (;-- Could be 'case (foo)' or 'always @(bar)' which is complete
4415 ; also could be simply '@(foo)' 4669 ; also could be simply '@(foo)'
4416 ; or foo u1 #(a=8) 4670 ; or foo u1 #(a=8)
4417 ; (b, ... which ISN'T complete 4671 ; (b, ... which ISN'T complete
4418 ;;;; Do we need this??? 4672 ;;;; Do we need this???
4422 (backward-up-list 1) 4676 (backward-up-list 1)
4423 (verilog-backward-syntactic-ws) 4677 (verilog-backward-syntactic-ws)
4424 (let ((back (point))) 4678 (let ((back (point)))
4425 (forward-word -1) 4679 (forward-word -1)
4426 (cond 4680 (cond
4681 ;;XX
4427 ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>") 4682 ((looking-at "\\<\\(always\\(_latch\\|_ff\\|_comb\\)?\\|case\\(\\|[xz]\\)\\|for\\(\\|each\\|ever\\)\\|i\\(f\\|nitial\\)\\|repeat\\|while\\)\\>")
4428 (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]"))) 4683 (not (looking-at "\\<randcase\\>\\|\\<case[xz]?\\>[^:]")))
4684 ((looking-at verilog-ovm-statement-re)
4685 nil)
4686 ((looking-at verilog-ovm-begin-re)
4687 t)
4688 ((looking-at verilog-ovm-end-re)
4689 t)
4429 (t 4690 (t
4430 (goto-char back) 4691 (goto-char back)
4431 (cond 4692 (cond
4432 ((= (preceding-char) ?\@) 4693 ((= (preceding-char) ?\@)
4433 (backward-char) 4694 (backward-char)
4519 (verilog-skip-backward-comments) 4780 (verilog-skip-backward-comments)
4520 (setq p 4781 (setq p
4521 (save-excursion 4782 (save-excursion
4522 (beginning-of-line) 4783 (beginning-of-line)
4523 (cond 4784 (cond
4524 ((verilog-within-translate-off) 4785 ((and verilog-highlight-translate-off
4786 (verilog-within-translate-off))
4525 (verilog-back-to-start-translate-off (point-min))) 4787 (verilog-back-to-start-translate-off (point-min)))
4526 ((looking-at verilog-directive-re-1) 4788 ((looking-at verilog-directive-re-1)
4527 (point)) 4789 (point))
4528 (t 4790 (t
4529 nil)))) 4791 nil))))
4586 (backward-char) 4848 (backward-char)
4587 (skip-chars-backward "^ \t\n\f") 4849 (skip-chars-backward "^ \t\n\f")
4588 (if (equal (char-after (point) ) ?\\ ) 4850 (if (equal (char-after (point) ) ?\\ )
4589 t 4851 t
4590 nil))) 4852 nil)))
4853 (defun verilog-in-directive-p ()
4854 "Return true if in a star or // comment."
4855 (save-excursion
4856 (beginning-of-line)
4857 (looking-at verilog-directive-re-1)))
4591 4858
4592 (defun verilog-in-paren () 4859 (defun verilog-in-paren ()
4593 "Return true if in a parenthetical expression." 4860 "Return true if in a parenthetical expression."
4594 (let ((state (save-excursion (verilog-syntax-ppss)))) 4861 (let ((state (save-excursion (verilog-syntax-ppss))))
4595 (> (nth 0 state) 0 ))) 4862 (> (nth 0 state) 0 )))
4596 4863
4597 (defun verilog-in-coverage () 4864 (defun verilog-in-struct-p ()
4865 "Return true if in a struct declaration."
4866 (interactive)
4867 (save-excursion
4868 (if (verilog-in-paren)
4869 (progn
4870 (backward-up-list 1)
4871 (verilog-at-struct-p)
4872 )
4873 nil)))
4874
4875 (defun verilog-in-coverage-p ()
4598 "Return true if in a constraint or coverpoint expression." 4876 "Return true if in a constraint or coverpoint expression."
4599 (interactive) 4877 (interactive)
4600 (save-excursion 4878 (save-excursion
4601 (if (verilog-in-paren) 4879 (if (verilog-in-paren)
4602 (progn 4880 (progn
4627 (equal (char-before) ?\;)))) 4905 (equal (char-before) ?\;))))
4628 ;; maybe 4906 ;; maybe
4629 (verilog-re-search-backward "\\<constraint\\|coverpoint\\|cross\\>" nil 'move) 4907 (verilog-re-search-backward "\\<constraint\\|coverpoint\\|cross\\>" nil 'move)
4630 ;; not 4908 ;; not
4631 nil)) 4909 nil))
4910
4911 (defun verilog-at-struct-p ()
4912 "If at the { of a struct, return true, moving point to struct."
4913 (save-excursion
4914 (if (and (equal (char-after) ?\{)
4915 (verilog-backward-token))
4916 (looking-at "\\<struct\\|union\\|packed\\>")
4917 nil)))
4632 4918
4633 (defun verilog-parenthesis-depth () 4919 (defun verilog-parenthesis-depth ()
4634 "Return non zero if in parenthetical-expression." 4920 "Return non zero if in parenthetical-expression."
4635 (save-excursion (nth 1 (verilog-syntax-ppss)))) 4921 (save-excursion (nth 1 (verilog-syntax-ppss))))
4636 4922
4804 (forward-char 1) 5090 (forward-char 1)
4805 (skip-chars-forward " \t") 5091 (skip-chars-forward " \t")
4806 (current-column)))) 5092 (current-column))))
4807 (indent-line-to val) 5093 (indent-line-to val)
4808 )) 5094 ))
4809 5095
4810 (;-- Handle the ends 5096 (;-- Handle the ends
4811 (or 5097 (or
4812 (looking-at verilog-end-block-re ) 5098 (looking-at verilog-end-block-re )
4813 (verilog-at-close-constraint-p)) 5099 (verilog-at-close-constraint-p))
4814 (let ((val (if (eq type 'statement) 5100 (let ((val (if (eq type 'statement)
4867 (save-excursion 5153 (save-excursion
4868 (skip-chars-forward " \t") 5154 (skip-chars-forward " \t")
4869 (cond 5155 (cond
4870 ((looking-at verilog-named-block-re) 5156 ((looking-at verilog-named-block-re)
4871 (current-column)) 5157 (current-column))
4872 ((and (not (looking-at verilog-case-re)) 5158 ((and (not (looking-at verilog-extended-case-re))
4873 (looking-at "^[^:;]+[ \t]*:")) 5159 (looking-at "^[^:;]+[ \t]*:"))
4874 (verilog-re-search-forward ":" nil t) 5160 (verilog-re-search-forward ":" nil t)
4875 (skip-chars-forward " \t") 5161 (skip-chars-forward " \t")
4876 (current-column)) 5162 (current-column))
4877 (t 5163 (t
4935 (current-column))))) 5221 (current-column)))))
4936 5222
4937 ;; 5223 ;;
4938 5224
4939 (defun verilog-pretty-declarations (&optional quiet) 5225 (defun verilog-pretty-declarations (&optional quiet)
4940 "Line up declarations around point." 5226 "Line up declarations around point.
5227 Be verbose about progress unless optional QUIET set."
4941 (interactive) 5228 (interactive)
4942 (save-excursion 5229 (save-excursion
4943 (if (progn 5230 (if (progn
4944 (verilog-beg-of-statement-1) 5231 (verilog-beg-of-statement-1)
4945 (looking-at verilog-declaration-re)) 5232 (and (not (verilog-in-directive-p)) ;; could have `define input foo
4946 (let* ((m1 (make-marker)) 5233 (not (verilog-parenthesis-depth)) ;; could be in a #(param block )
4947 (e) (r) 5234 (looking-at verilog-declaration-re)))
4948 (here (point)) 5235 (let* ((m1 (make-marker))
4949 ;; Start of declaration range 5236 (e (point))
4950 (start 5237 (r)
4951 (progn 5238 (here (point))
4952 (verilog-beg-of-statement-1) 5239 ;; Start of declaration range
4953 (while (looking-at verilog-declaration-re) 5240 (start
4954 (beginning-of-line) 5241 (progn
4955 (setq e (point)) 5242 (verilog-beg-of-statement-1)
4956 (verilog-backward-syntactic-ws) 5243 (while (and (looking-at verilog-declaration-re)
4957 (backward-char) 5244 (not (bobp)))
4958 (verilog-beg-of-statement-1)) ;Ack, need to grok `define 5245 (skip-chars-backward " \t")
4959 e)) 5246 (setq e (point))
4960 ;; End of declaration range 5247 (beginning-of-line)
4961 (end 5248 (verilog-backward-syntactic-ws)
4962 (progn 5249 (backward-char)
4963 (goto-char here) 5250 (verilog-beg-of-statement-1))
4964 (verilog-end-of-statement) 5251 e))
4965 (setq e (point)) ;Might be on last line 5252 ;; End of declaration range
4966 (verilog-forward-syntactic-ws) 5253 (end
4967 (while (looking-at verilog-declaration-re) 5254 (progn
4968 (beginning-of-line) 5255 (goto-char here)
4969 (verilog-end-of-statement) 5256 (verilog-end-of-statement)
4970 (setq e (point)) 5257 (setq e (point)) ;Might be on last line
4971 (verilog-forward-syntactic-ws)) 5258 (verilog-forward-syntactic-ws)
4972 e)) 5259 (while (looking-at verilog-declaration-re)
4973 (edpos (set-marker (make-marker) end)) 5260 ;;(beginning-of-line)
4974 (ind) 5261 (verilog-end-of-statement)
4975 (base-ind 5262 (setq e (point))
4976 (progn 5263 (verilog-forward-syntactic-ws))
4977 (goto-char start) 5264 e))
4978 (verilog-do-indent (verilog-calculate-indent)) 5265 (edpos (set-marker (make-marker) end))
4979 (verilog-forward-ws&directives) 5266 (ind)
4980 (current-column)))) 5267 (base-ind
4981 (goto-char end) 5268 (progn
4982 (goto-char start) 5269 (goto-char start)
4983 (if (and (not quiet) 5270 (verilog-do-indent (verilog-calculate-indent))
4984 (> (- end start) 100)) 5271 (verilog-forward-ws&directives)
4985 (message "Lining up declarations..(please stand by)")) 5272 (current-column))))
4986 ;; Get the beginning of line indent first 5273 (goto-char start)
4987 (while (progn (setq e (marker-position edpos)) 5274 (if (and (not quiet)
4988 (< (point) e)) 5275 (> (- end start) 100))
4989 (cond 5276 (message "Lining up declarations..(please stand by)"))
4990 ( (save-excursion (skip-chars-backward " \t") 5277 ;; Get the beginning of line indent first
4991 (bolp)) 5278 (while (progn (setq e (marker-position edpos))
4992 (verilog-forward-ws&directives) 5279 (< (point) e))
4993 (indent-line-to base-ind) 5280 (cond
4994 (verilog-forward-ws&directives) 5281 ( (save-excursion (skip-chars-backward " \t")
4995 (verilog-re-search-forward "[ \t\n\f]" e 'move)) 5282 (bolp))
4996 (t 5283 (verilog-forward-ws&directives)
4997 (just-one-space) 5284 (indent-line-to base-ind)
4998 (verilog-re-search-forward "[ \t\n\f]" e 'move))) 5285 (verilog-forward-ws&directives)
4999 ;;(forward-line) 5286 (verilog-re-search-forward "[ \t\n\f]" e 'move))
5000 ) 5287 (t
5001 ;; Now find biggest prefix 5288 (just-one-space)
5002 (setq ind (verilog-get-lineup-indent start edpos)) 5289 (verilog-re-search-forward "[ \t\n\f]" e 'move)))
5003 ;; Now indent each line. 5290 ;;(forward-line)
5004 (goto-char start) 5291 )
5005 (while (progn (setq e (marker-position edpos)) 5292 ;; Now find biggest prefix
5006 (setq r (- e (point))) 5293 (setq ind (verilog-get-lineup-indent start edpos))
5007 (> r 0)) 5294 ;; Now indent each line.
5008 (setq e (point)) 5295 (goto-char start)
5009 (unless quiet (message "%d" r)) 5296 (while (progn (setq e (marker-position edpos))
5010 (cond 5297 (setq r (- e (point)))
5011 ((or (and verilog-indent-declaration-macros 5298 (> r 0))
5012 (looking-at verilog-declaration-re-1-macro)) 5299 (setq e (point))
5013 (looking-at verilog-declaration-re-1-no-macro)) 5300 (unless quiet (message "%d" r))
5014 (let ((p (match-end 0))) 5301 (verilog-indent-line)
5015 (set-marker m1 p) 5302 (cond
5016 (if (verilog-re-search-forward "[[#`]" p 'move) 5303 ((or (and verilog-indent-declaration-macros
5017 (progn 5304 (looking-at verilog-declaration-re-2-macro))
5018 (forward-char -1) 5305 (looking-at verilog-declaration-re-2-no-macro))
5019 (just-one-space) 5306 (let ((p (match-end 0)))
5020 (goto-char (marker-position m1)) 5307 (set-marker m1 p)
5021 (just-one-space) 5308 (if (verilog-re-search-forward "[[#`]" p 'move)
5022 (indent-to ind)) 5309 (progn
5023 (progn 5310 (forward-char -1)
5024 (just-one-space) 5311 (just-one-space)
5025 (indent-to ind))))) 5312 (goto-char (marker-position m1))
5026 ((verilog-continued-line-1 start) 5313 (just-one-space)
5027 (goto-char e) 5314 (indent-to ind))
5028 (indent-line-to ind)) 5315 (progn
5029 (t ; Must be comment or white space 5316 (just-one-space)
5030 (goto-char e) 5317 (indent-to ind)))))
5031 (verilog-forward-ws&directives) 5318 ((verilog-continued-line-1 start)
5032 (forward-line -1))) 5319 (goto-char e)
5033 (forward-line 1)) 5320 (indent-line-to ind))
5034 (unless quiet (message "")))))) 5321 ((verilog-in-struct-p)
5322 ;; could have a declaration of a user defined item
5323 (goto-char e)
5324 (verilog-end-of-statement))
5325 (t ; Must be comment or white space
5326 (goto-char e)
5327 (verilog-forward-ws&directives)
5328 (forward-line -1)))
5329 (forward-line 1))
5330 (unless quiet (message ""))))))
5035 5331
5036 (defun verilog-pretty-expr (&optional quiet myre) 5332 (defun verilog-pretty-expr (&optional quiet myre)
5037 "Line up expressions around point, or optional regexp MYRE." 5333 "Line up expressions around point, or optional regexp MYRE."
5038 (interactive "sRegular Expression: ((<|:)?=) ") 5334 (interactive "sRegular Expression: ((<|:)?=) ")
5039 (save-excursion 5335 (save-excursion
5040 (if (or (eq myre nil) 5336 (if (or (eq myre nil)
5041 (string-equal myre "")) 5337 (string-equal myre ""))
5042 (setq myre "\\(<\\|:\\)?=")) 5338 (setq myre "\\(<\\|:\\)?="))
5043 (setq myre (concat "\\(^[^;#<=>]*\\)\\(" myre "\\)")) 5339 (setq myre (concat "\\(^[^;#:<=>]*\\)\\(" myre "\\)"))
5044 (let ((rexp(concat "^\\s-*" verilog-complete-reg))) 5340 (let ((rexp(concat "^\\s-*" verilog-complete-reg)))
5045 (beginning-of-line) 5341 (beginning-of-line)
5046 (if (and (not (looking-at rexp )) 5342 (if (and (not (looking-at rexp ))
5047 (looking-at myre)) 5343 (looking-at myre)
5048 (let* ((here (point)) 5344 (save-excursion
5049 (e) (r) 5345 (goto-char (match-beginning 2))
5050 (start 5346 (not (verilog-in-comment-or-string-p))))
5051 (progn 5347 (let* ((here (point))
5052 (beginning-of-line) 5348 (e) (r)
5053 (setq e (point)) 5349 (start
5054 (verilog-backward-syntactic-ws) 5350 (progn
5055 (beginning-of-line) 5351 (beginning-of-line)
5056 (while (and (not (looking-at rexp )) 5352 (setq e (point))
5057 (looking-at myre) 5353 (verilog-backward-syntactic-ws)
5058 (not (bobp)) 5354 (beginning-of-line)
5059 ) 5355 (while (and (not (looking-at rexp ))
5060 (setq e (point)) 5356 (looking-at myre)
5061 (verilog-backward-syntactic-ws) 5357 (not (bobp))
5062 (beginning-of-line) 5358 )
5063 ) ;Ack, need to grok `define 5359 (setq e (point))
5064 e)) 5360 (verilog-backward-syntactic-ws)
5065 (end 5361 (beginning-of-line)
5066 (progn 5362 ) ;Ack, need to grok `define
5067 (goto-char here) 5363 e))
5068 (end-of-line) 5364 (end
5069 (setq e (point)) ;Might be on last line 5365 (progn
5070 (verilog-forward-syntactic-ws) 5366 (goto-char here)
5071 (beginning-of-line) 5367 (end-of-line)
5072 (while (and (not (looking-at rexp )) 5368 (setq e (point)) ;Might be on last line
5073 (looking-at myre)) 5369 (verilog-forward-syntactic-ws)
5074 (end-of-line) 5370 (beginning-of-line)
5075 (setq e (point)) 5371 (while (and
5076 (verilog-forward-syntactic-ws) 5372 (not (looking-at rexp ))
5077 (beginning-of-line) 5373 (looking-at myre)
5078 ) 5374 (progn
5079 e)) 5375 (end-of-line)
5080 (edpos (set-marker (make-marker) end)) 5376 (not (eq e (point)))))
5081 (ind) 5377 (setq e (point))
5082 ) 5378 (verilog-forward-syntactic-ws)
5083 (goto-char start) 5379 (beginning-of-line)
5084 (verilog-do-indent (verilog-calculate-indent)) 5380 )
5085 (if (and (not quiet) 5381 e))
5086 (> (- end start) 100)) 5382 (edpos (set-marker (make-marker) end))
5087 (message "Lining up expressions..(please stand by)")) 5383 (ind)
5088 5384 )
5089 ;; Set indent to minimum throughout region 5385 (goto-char start)
5090 (while (< (point) (marker-position edpos)) 5386 (verilog-do-indent (verilog-calculate-indent))
5091 (beginning-of-line) 5387 (if (and (not quiet)
5092 (verilog-just-one-space myre) 5388 (> (- end start) 100))
5093 (end-of-line) 5389 (message "Lining up expressions..(please stand by)"))
5094 (verilog-forward-syntactic-ws) 5390
5095 ) 5391 ;; Set indent to minimum throughout region
5096 5392 (while (< (point) (marker-position edpos))
5097 ;; Now find biggest prefix 5393 (beginning-of-line)
5098 (setq ind (verilog-get-lineup-indent-2 myre start edpos)) 5394 (verilog-just-one-space myre)
5099 5395 (end-of-line)
5100 ;; Now indent each line. 5396 (verilog-forward-syntactic-ws)
5101 (goto-char start) 5397 )
5102 (while (progn (setq e (marker-position edpos)) 5398
5103 (setq r (- e (point))) 5399 ;; Now find biggest prefix
5104 (> r 0)) 5400 (setq ind (verilog-get-lineup-indent-2 myre start edpos))
5105 (setq e (point)) 5401
5106 (if (not quiet) (message "%d" r)) 5402 ;; Now indent each line.
5107 (cond 5403 (goto-char start)
5108 ((looking-at myre) 5404 (while (progn (setq e (marker-position edpos))
5109 (goto-char (match-end 1)) 5405 (setq r (- e (point)))
5110 (if (not (verilog-parenthesis-depth)) ;; ignore parenthsized exprs 5406 (> r 0))
5111 (if (eq (char-after) ?=) 5407 (setq e (point))
5112 (indent-to (1+ ind)) ; line up the = of the <= with surrounding = 5408 (if (not quiet) (message "%d" r))
5113 (indent-to ind) 5409 (cond
5114 ))) 5410 ((looking-at myre)
5115 ((verilog-continued-line-1 start) 5411 (goto-char (match-beginning 2))
5116 (goto-char e) 5412 (if (not (verilog-parenthesis-depth)) ;; ignore parenthsized exprs
5117 (indent-line-to ind)) 5413 (if (eq (char-after) ?=)
5118 (t ; Must be comment or white space 5414 (indent-to (1+ ind)) ; line up the = of the <= with surrounding =
5119 (goto-char e) 5415 (indent-to ind)
5120 (verilog-forward-ws&directives) 5416 )))
5121 (forward-line -1)) 5417 ((verilog-continued-line-1 start)
5122 ) 5418 (goto-char e)
5123 (forward-line 1)) 5419 (indent-line-to ind))
5124 (unless quiet (message "")) 5420 (t ; Must be comment or white space
5125 ))))) 5421 (goto-char e)
5422 (verilog-forward-ws&directives)
5423 (forward-line -1))
5424 )
5425 (forward-line 1))
5426 (unless quiet (message ""))
5427 )))))
5126 5428
5127 (defun verilog-just-one-space (myre) 5429 (defun verilog-just-one-space (myre)
5128 "Remove extra spaces around regular expression MYRE." 5430 "Remove extra spaces around regular expression MYRE."
5129 (interactive) 5431 (interactive)
5130 (if (and (not(looking-at verilog-complete-reg)) 5432 (if (and (not(looking-at verilog-complete-reg))
5155 (setq val 5457 (setq val
5156 (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist))))) 5458 (+ baseind (eval (cdr (assoc 'declaration verilog-indent-alist)))))
5157 (indent-line-to val) 5459 (indent-line-to val)
5158 5460
5159 ;; Use previous declaration (in this module) as template. 5461 ;; Use previous declaration (in this module) as template.
5160 (if (or (memq 'all verilog-auto-lineup) 5462 (if (or (eq 'all verilog-auto-lineup)
5161 (memq 'declaration verilog-auto-lineup)) 5463 (eq 'declarations verilog-auto-lineup))
5162 (if (verilog-re-search-backward 5464 (if (verilog-re-search-backward
5163 (or (and verilog-indent-declaration-macros 5465 (or (and verilog-indent-declaration-macros
5164 verilog-declaration-re-1-macro) 5466 verilog-declaration-re-1-macro)
5165 verilog-declaration-re-1-no-macro) lim t) 5467 verilog-declaration-re-1-no-macro) lim t)
5166 (progn 5468 (progn
5695 (let* ((default (verilog-get-default-symbol)) 5997 (let* ((default (verilog-get-default-symbol))
5696 ;; The following variable is used in verilog-comp-function 5998 ;; The following variable is used in verilog-comp-function
5697 (verilog-buffer-to-use (current-buffer)) 5999 (verilog-buffer-to-use (current-buffer))
5698 (label (if (not (string= default "")) 6000 (label (if (not (string= default ""))
5699 ;; Do completion with default 6001 ;; Do completion with default
5700 (completing-read (concat "Label: (default " default ") ") 6002 (completing-read (concat "Goto-Label: (default "
6003 default ") ")
5701 'verilog-comp-defun nil nil "") 6004 'verilog-comp-defun nil nil "")
5702 ;; There is no default value. Complete without it 6005 ;; There is no default value. Complete without it
5703 (completing-read "Label: " 6006 (completing-read "Goto-Label: "
5704 'verilog-comp-defun nil nil ""))) 6007 'verilog-comp-defun nil nil "")))
5705 pt) 6008 pt)
6009 ;; Make sure library paths are correct, in case need to resolve module
6010 (verilog-auto-reeval-locals)
6011 (verilog-getopt-flags)
5706 ;; If there was no response on prompt, use default value 6012 ;; If there was no response on prompt, use default value
5707 (if (string= label "") 6013 (if (string= label "")
5708 (setq label default)) 6014 (setq label default))
5709 ;; Goto right place in buffer if label is not an empty string 6015 ;; Goto right place in buffer if label is not an empty string
5710 (or (string= label "") 6016 (or (string= label "")
5844 6150
5845 6151
5846 ;; Added by Subbu Meiyappan for Header 6152 ;; Added by Subbu Meiyappan for Header
5847 6153
5848 (defun verilog-header () 6154 (defun verilog-header ()
5849 "Insert a standard Verilog file header." 6155 "Insert a standard Verilog file header.
6156 See also `verilog-sk-header' for an alternative format."
5850 (interactive) 6157 (interactive)
5851 (let ((start (point))) 6158 (let ((start (point)))
5852 (insert "\ 6159 (insert "\
5853 //----------------------------------------------------------------------------- 6160 //-----------------------------------------------------------------------------
5854 // Title : <title> 6161 // Title : <title>
5909 ;; verilog-header Uses the verilog-insert-date function 6216 ;; verilog-header Uses the verilog-insert-date function
5910 6217
5911 (defun verilog-insert-date () 6218 (defun verilog-insert-date ()
5912 "Insert date from the system." 6219 "Insert date from the system."
5913 (interactive) 6220 (interactive)
5914 (let ((timpos)) 6221 (if verilog-date-scientific-format
5915 (setq timpos (point)) 6222 (insert (format-time-string "%Y/%m/%d"))
5916 (if verilog-date-scientific-format 6223 (insert (format-time-string "%d.%m.%Y"))))
5917 (shell-command "date \"+@%Y/%m/%d\"" t)
5918 (shell-command "date \"+@%d.%m.%Y\"" t))
5919 (search-forward "@")
5920 (delete-region timpos (point))
5921 (end-of-line))
5922 (delete-char 1))
5923 6224
5924 (defun verilog-insert-year () 6225 (defun verilog-insert-year ()
5925 "Insert year from the system." 6226 "Insert year from the system."
5926 (interactive) 6227 (interactive)
5927 (let ((timpos)) 6228 (insert (format-time-string "%Y")))
5928 (setq timpos (point))
5929 (shell-command "date \"+@%Y\"" t)
5930 (search-forward "@")
5931 (delete-region timpos (point))
5932 (end-of-line))
5933 (delete-char 1))
5934 6229
5935 6230
5936 ;; 6231 ;;
5937 ;; Signal list parsing 6232 ;; Signal list parsing
5938 ;; 6233 ;;
5959 (let ((str "") (args (verilog-sig-multidim sig))) 6254 (let ((str "") (args (verilog-sig-multidim sig)))
5960 (while args 6255 (while args
5961 (setq str (concat str (car args))) 6256 (setq str (concat str (car args)))
5962 (setq args (cdr args))) 6257 (setq args (cdr args)))
5963 str))) 6258 str)))
6259 (defsubst verilog-sig-modport (sig)
6260 (nth 8 sig))
5964 (defsubst verilog-sig-width (sig) 6261 (defsubst verilog-sig-width (sig)
5965 (verilog-make-width-expression (verilog-sig-bits sig))) 6262 (verilog-make-width-expression (verilog-sig-bits sig)))
5966 6263
5967 (defsubst verilog-alw-get-inputs (sigs) 6264 (defsubst verilog-alw-get-inputs (sigs)
5968 (nth 2 sigs)) 6265 (nth 2 sigs))
6024 (let (combo buswarn 6321 (let (combo buswarn
6025 out-list 6322 out-list
6026 sig highbit lowbit ; Temp information about current signal 6323 sig highbit lowbit ; Temp information about current signal
6027 sv-name sv-highbit sv-lowbit ; Details about signal we are forming 6324 sv-name sv-highbit sv-lowbit ; Details about signal we are forming
6028 sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring 6325 sv-comment sv-memory sv-enum sv-signed sv-type sv-multidim sv-busstring
6326 sv-modport
6029 bus) 6327 bus)
6030 ;; Shove signals so duplicated signals will be adjacent 6328 ;; Shove signals so duplicated signals will be adjacent
6031 (setq in-list (sort in-list `verilog-signals-sort-compare)) 6329 (setq in-list (sort in-list `verilog-signals-sort-compare))
6032 (while in-list 6330 (while in-list
6033 (setq sig (car in-list)) 6331 (setq sig (car in-list))
6040 sv-memory (verilog-sig-memory sig) 6338 sv-memory (verilog-sig-memory sig)
6041 sv-enum (verilog-sig-enum sig) 6339 sv-enum (verilog-sig-enum sig)
6042 sv-signed (verilog-sig-signed sig) 6340 sv-signed (verilog-sig-signed sig)
6043 sv-type (verilog-sig-type sig) 6341 sv-type (verilog-sig-type sig)
6044 sv-multidim (verilog-sig-multidim sig) 6342 sv-multidim (verilog-sig-multidim sig)
6343 sv-modport (verilog-sig-modport sig)
6045 combo "" 6344 combo ""
6046 buswarn "")) 6345 buswarn ""))
6047 ;; Extract bus details 6346 ;; Extract bus details
6048 (setq bus (verilog-sig-bits sig)) 6347 (setq bus (verilog-sig-bits sig))
6049 (cond ((and bus 6348 (cond ((and bus
6078 (if (verilog-sig-comment sig) (setq combo ", ...")) 6377 (if (verilog-sig-comment sig) (setq combo ", ..."))
6079 (setq sv-memory (or sv-memory (verilog-sig-memory sig)) 6378 (setq sv-memory (or sv-memory (verilog-sig-memory sig))
6080 sv-enum (or sv-enum (verilog-sig-enum sig)) 6379 sv-enum (or sv-enum (verilog-sig-enum sig))
6081 sv-signed (or sv-signed (verilog-sig-signed sig)) 6380 sv-signed (or sv-signed (verilog-sig-signed sig))
6082 sv-type (or sv-type (verilog-sig-type sig)) 6381 sv-type (or sv-type (verilog-sig-type sig))
6083 sv-multidim (or sv-multidim (verilog-sig-multidim sig)))) 6382 sv-multidim (or sv-multidim (verilog-sig-multidim sig))
6383 sv-modport (or sv-modport (verilog-sig-modport sig))))
6084 ;; Doesn't match next signal, add to queue, zero in prep for next 6384 ;; Doesn't match next signal, add to queue, zero in prep for next
6085 ;; Note sig may also be nil for the last signal in the list 6385 ;; Note sig may also be nil for the last signal in the list
6086 (t 6386 (t
6087 (setq out-list 6387 (setq out-list
6088 (cons 6388 (cons
6090 (or sv-busstring 6390 (or sv-busstring
6091 (if sv-highbit 6391 (if sv-highbit
6092 (concat "[" (int-to-string sv-highbit) ":" 6392 (concat "[" (int-to-string sv-highbit) ":"
6093 (int-to-string sv-lowbit) "]"))) 6393 (int-to-string sv-lowbit) "]")))
6094 (concat sv-comment combo buswarn) 6394 (concat sv-comment combo buswarn)
6095 sv-memory sv-enum sv-signed sv-type sv-multidim) 6395 sv-memory sv-enum sv-signed sv-type sv-multidim sv-modport)
6096 out-list) 6396 out-list)
6097 sv-name nil)))) 6397 sv-name nil))))
6098 ;; 6398 ;;
6099 out-list)) 6399 out-list))
6100 6400
6160 (re-search-backward "[(;]") 6460 (re-search-backward "[(;]")
6161 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil) 6461 (verilog-re-search-backward-quick "\\b[a-zA-Z0-9`_\$]" nil nil)
6162 (skip-chars-backward "a-zA-Z0-9`_$") 6462 (skip-chars-backward "a-zA-Z0-9`_$")
6163 (looking-at "[a-zA-Z0-9`_\$]+") 6463 (looking-at "[a-zA-Z0-9`_\$]+")
6164 ;; Important: don't use match string, this must work with Emacs 19 font-lock on 6464 ;; Important: don't use match string, this must work with Emacs 19 font-lock on
6165 (buffer-substring-no-properties (match-beginning 0) (match-end 0)))) 6465 (verilog-symbol-detick
6466 (buffer-substring-no-properties (match-beginning 0) (match-end 0)) t)))
6166 6467
6167 (defun verilog-read-inst-param-value () 6468 (defun verilog-read-inst-param-value ()
6168 "Return list of parameters and values when point is inside instantiation." 6469 "Return list of parameters and values when point is inside instantiation."
6169 (save-excursion 6470 (save-excursion
6170 (verilog-read-inst-backward-name) 6471 (verilog-read-inst-backward-name)
6212 6513
6213 (defun verilog-read-decls () 6514 (defun verilog-read-decls ()
6214 "Compute signal declaration information for the current module at point. 6515 "Compute signal declaration information for the current module at point.
6215 Return a array of [outputs inouts inputs wire reg assign const]." 6516 Return a array of [outputs inouts inputs wire reg assign const]."
6216 (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max))) 6517 (let ((end-mod-point (or (verilog-get-end-of-defun t) (point-max)))
6217 (functask 0) (paren 0) (sig-paren 0) 6518 (functask 0) (paren 0) (sig-paren 0) (v2kargs-ok t)
6218 sigs-in sigs-out sigs-inout sigs-wire sigs-reg sigs-assign sigs-const sigs-gparam 6519 sigs-in sigs-out sigs-inout sigs-wire sigs-reg sigs-assign sigs-const
6219 vec expect-signal keywd newsig rvalue enum io signed typedefed multidim) 6520 sigs-gparam sigs-intf
6521 vec expect-signal keywd newsig rvalue enum io signed typedefed multidim
6522 modport)
6220 (save-excursion 6523 (save-excursion
6221 (verilog-beg-of-defun) 6524 (verilog-beg-of-defun)
6222 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point)) 6525 (setq sigs-const (verilog-read-auto-constants (point) end-mod-point))
6223 (while (< (point) end-mod-point) 6526 (while (< (point) end-mod-point)
6224 ;;(if dbg (setq dbg (cons (format "Pt %s Vec %s Kwd'%s'\n" (point) vec keywd) dbg))) 6527 ;;(if dbg (setq dbg (cons (format "Pt %s Vec %s Kwd'%s'\n" (point) vec keywd) dbg)))
6233 (setq enum (match-string 1))) 6536 (setq enum (match-string 1)))
6234 (or (search-forward "*/") 6537 (or (search-forward "*/")
6235 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point)))) 6538 (error "%s: Unmatched /* */, at char %d" (verilog-point-text) (point))))
6236 ((looking-at "(\\*") 6539 ((looking-at "(\\*")
6237 (forward-char 2) 6540 (forward-char 2)
6238 (or (looking-at "\\s-*)") ; It's a "always @ (*)" 6541 (or (looking-at "\\s-*)") ; It's an "always @ (*)"
6239 (search-forward "*)") 6542 (search-forward "*)")
6240 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point)))) 6543 (error "%s: Unmatched (* *), at char %d" (verilog-point-text) (point))))
6241 ((eq ?\" (following-char)) 6544 ((eq ?\" (following-char))
6242 (or (re-search-forward "[^\\]\"" nil t) ;; don't forward-char first, since we look for a non backslash first 6545 (or (re-search-forward "[^\\]\"" nil t) ;; don't forward-char first, since we look for a non backslash first
6243 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point)))) 6546 (error "%s: Unmatched quotes, at char %d" (verilog-point-text) (point))))
6244 ((eq ?\; (following-char)) 6547 ((eq ?\; (following-char))
6245 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil) 6548 (setq vec nil io nil expect-signal nil newsig nil paren 0 rvalue nil
6549 v2kargs-ok nil)
6246 (forward-char 1)) 6550 (forward-char 1))
6247 ((eq ?= (following-char)) 6551 ((eq ?= (following-char))
6248 (setq rvalue t newsig nil) 6552 (setq rvalue t newsig nil)
6249 (forward-char 1)) 6553 (forward-char 1))
6250 ((and (or rvalue sig-paren) 6554 ((and (or rvalue sig-paren)
6281 (setq keywd (match-string 1)) 6585 (setq keywd (match-string 1))
6282 (when (string-match "^\\\\" keywd) 6586 (when (string-match "^\\\\" keywd)
6283 (setq keywd (concat keywd " "))) ;; Escaped ID needs space at end 6587 (setq keywd (concat keywd " "))) ;; Escaped ID needs space at end
6284 (cond ((equal keywd "input") 6588 (cond ((equal keywd "input")
6285 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren 6589 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren
6286 expect-signal 'sigs-in io t)) 6590 expect-signal 'sigs-in io t modport nil))
6287 ((equal keywd "output") 6591 ((equal keywd "output")
6288 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren 6592 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren
6289 expect-signal 'sigs-out io t)) 6593 expect-signal 'sigs-out io t modport nil))
6290 ((equal keywd "inout") 6594 ((equal keywd "inout")
6291 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren 6595 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed nil multidim nil sig-paren paren
6292 expect-signal 'sigs-inout io t)) 6596 expect-signal 'sigs-inout io t modport nil))
6293 ((or (equal keywd "wire") 6597 ((equal keywd "parameter")
6294 (equal keywd "tri") 6598 (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
6295 (equal keywd "tri0") 6599 expect-signal 'sigs-gparam io t modport nil))
6296 (equal keywd "tri1")) 6600 ((member keywd '("wire" "tri" "tri0" "tri1" "triand" "trior" "wand" "wor"))
6297 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren 6601 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
6298 expect-signal 'sigs-wire))) 6602 expect-signal 'sigs-wire modport nil)))
6299 ((member keywd (list "reg" "trireg" 6603 ((member keywd '("reg" "trireg"
6300 "byte" "shortint" "int" "longint" "integer" "time" 6604 "byte" "shortint" "int" "longint" "integer" "time"
6301 "bit" "logic")) 6605 "bit" "logic"))
6302 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren 6606 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
6303 expect-signal 'sigs-reg))) 6607 expect-signal 'sigs-reg modport nil)))
6304 ((equal keywd "assign") 6608 ((equal keywd "assign")
6305 (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren 6609 (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
6306 expect-signal 'sigs-assign)) 6610 expect-signal 'sigs-assign modport nil))
6307 ((or (equal keywd "supply0") 6611 ((member keywd '("supply0" "supply1" "supply"
6308 (equal keywd "supply1") 6612 "localparam" "genvar"))
6309 (equal keywd "supply")
6310 (equal keywd "localparam")
6311 (equal keywd "genvar"))
6312 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren 6613 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
6313 expect-signal 'sigs-const))) 6614 expect-signal 'sigs-const modport nil)))
6314 ((or (equal keywd "parameter"))
6315 (unless io (setq vec nil enum nil rvalue nil signed nil typedefed nil multidim nil sig-paren paren
6316 expect-signal 'sigs-gparam)))
6317 ((equal keywd "signed") 6615 ((equal keywd "signed")
6318 (setq signed "signed")) 6616 (setq signed "signed"))
6319 ((or (equal keywd "function") 6617 ((member keywd '("class" "clocking" "covergroup" "function"
6320 (equal keywd "task")) 6618 "property" "randsequence" "sequence" "task"))
6321 (setq functask (1+ functask))) 6619 (setq functask (1+ functask)))
6322 ((or (equal keywd "endfunction") 6620 ((member keywd '("endclass" "endclocking" "endgroup" "endfunction"
6323 (equal keywd "endtask")) 6621 "endproperty" "endsequence" "endtask"))
6324 (setq functask (1- functask))) 6622 (setq functask (1- functask)))
6325 ((or (equal keywd "`ifdef") 6623 ;; Ifdef? Ignore name of define
6326 (equal keywd "`ifndef")) 6624 ((member keywd '("`ifdef" "`ifndef"))
6327 (setq rvalue t)) 6625 (setq rvalue t))
6626 ;; Type?
6328 ((verilog-typedef-name-p keywd) 6627 ((verilog-typedef-name-p keywd)
6329 (setq typedefed keywd)) 6628 (setq typedefed keywd))
6629 ;; Interface with optional modport in v2k arglist?
6630 ;; Skip over parsing modport, and take the interface name as the type
6631 ((and v2kargs-ok
6632 (eq paren 1)
6633 (looking-at "\\s-*\\(\\.\\(\\s-*[a-zA-Z0-9`_$]+\\)\\|\\)\\s-*[a-zA-Z0-9`_$]+"))
6634 (when (match-end 2) (goto-char (match-end 2)))
6635 (setq vec nil enum nil rvalue nil newsig nil signed nil typedefed keywd multidim nil sig-paren paren
6636 expect-signal 'sigs-intf io t modport (match-string 2)))
6637 ;; New signal, maybe?
6330 ((and expect-signal 6638 ((and expect-signal
6331 (eq functask 0) 6639 (eq functask 0)
6332 (not rvalue) 6640 (not rvalue)
6333 (eq paren sig-paren) 6641 (eq paren sig-paren)
6334 (not (member keywd verilog-keywords))) 6642 (not (member keywd verilog-keywords)))
6335 ;; Add new signal to expect-signal's variable 6643 ;; Add new signal to expect-signal's variable
6336 (setq newsig (list keywd vec nil nil enum signed typedefed multidim)) 6644 (setq newsig (list keywd vec nil nil enum signed typedefed multidim modport))
6337 (set expect-signal (cons newsig 6645 (set expect-signal (cons newsig
6338 (symbol-value expect-signal)))))) 6646 (symbol-value expect-signal))))))
6339 (t 6647 (t
6340 (forward-char 1))) 6648 (forward-char 1)))
6341 (skip-syntax-forward " ")) 6649 (skip-syntax-forward " "))
6345 (nreverse sigs-in) 6653 (nreverse sigs-in)
6346 (nreverse sigs-wire) 6654 (nreverse sigs-wire)
6347 (nreverse sigs-reg) 6655 (nreverse sigs-reg)
6348 (nreverse sigs-assign) 6656 (nreverse sigs-assign)
6349 (nreverse sigs-const) 6657 (nreverse sigs-const)
6350 (nreverse sigs-gparam))))) 6658 (nreverse sigs-gparam)
6659 (nreverse sigs-intf)))))
6351 6660
6352 (eval-when-compile 6661 (eval-when-compile
6353 ;; Prevent compile warnings; these are let's, not globals 6662 ;; Prevent compile warnings; these are let's, not globals
6354 ;; Do not remove the eval-when-compile 6663 ;; Do not remove the eval-when-compile
6355 ;; - we want a error when we are debugging this code if they are refed. 6664 ;; - we want a error when we are debugging this code if they are refed.
6356 (defvar sigs-in) 6665 (defvar sigs-in)
6357 (defvar sigs-inout) 6666 (defvar sigs-inout)
6358 (defvar sigs-out)) 6667 (defvar sigs-out)
6668 (defvar sigs-intf))
6359 6669
6360 6670
6361 (defsubst verilog-modi-get-decls (modi) 6671 (defsubst verilog-modi-get-decls (modi)
6362 (verilog-modi-cache-results modi 'verilog-read-decls)) 6672 (verilog-modi-cache-results modi 'verilog-read-decls))
6363 6673
6382 (aref decls 5)) 6692 (aref decls 5))
6383 (defsubst verilog-decls-get-consts (decls) 6693 (defsubst verilog-decls-get-consts (decls)
6384 (aref decls 6)) 6694 (aref decls 6))
6385 (defsubst verilog-decls-get-gparams (decls) 6695 (defsubst verilog-decls-get-gparams (decls)
6386 (aref decls 7)) 6696 (aref decls 7))
6697 (defsubst verilog-decls-get-interfaces (decls)
6698 (aref decls 8))
6387 (defsubst verilog-subdecls-get-outputs (subdecls) 6699 (defsubst verilog-subdecls-get-outputs (subdecls)
6388 (aref subdecls 0)) 6700 (aref subdecls 0))
6389 (defsubst verilog-subdecls-get-inouts (subdecls) 6701 (defsubst verilog-subdecls-get-inouts (subdecls)
6390 (aref subdecls 1)) 6702 (aref subdecls 1))
6391 (defsubst verilog-subdecls-get-inputs (subdecls) 6703 (defsubst verilog-subdecls-get-inputs (subdecls)
6392 (aref subdecls 2)) 6704 (aref subdecls 2))
6705 (defsubst verilog-subdecls-get-interfaces (subdecls)
6706 (aref subdecls 3))
6393 6707
6394 6708
6395 (defun verilog-read-sub-decls-sig (submoddecls comment port sig vec multidim) 6709 (defun verilog-read-sub-decls-sig (submoddecls comment port sig vec multidim)
6396 "For `verilog-read-sub-decls-line', add a signal." 6710 "For `verilog-read-sub-decls-line', add a signal."
6397 (let (portdata) 6711 (let (portdata)
6398 (when sig 6712 (when sig
6399 (setq port (verilog-symbol-detick-denumber port)) 6713 (setq port (verilog-symbol-detick-denumber port))
6400 (setq sig (verilog-symbol-detick-denumber sig)) 6714 (setq sig (verilog-symbol-detick-denumber sig))
6401 (if sig (setq sig (verilog-string-replace-matches "^[---+~!|&]+" "" nil nil sig))) 6715 (if sig (setq sig (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil sig)))
6402 (if vec (setq vec (verilog-symbol-detick-denumber vec))) 6716 (if vec (setq vec (verilog-symbol-detick-denumber vec)))
6403 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim))) 6717 (if multidim (setq multidim (mapcar `verilog-symbol-detick-denumber multidim)))
6404 (unless (or (not sig) 6718 (unless (or (not sig)
6405 (equal sig "")) ;; Ignore .foo(1'b1) assignments 6719 (equal sig "")) ;; Ignore .foo(1'b1) assignments
6406 (cond ((setq portdata (assoc port (verilog-decls-get-inouts submoddecls))) 6720 (cond ((setq portdata (assoc port (verilog-decls-get-inouts submoddecls)))
6419 (setq sigs-in (cons (list sig vec (concat "To " comment) nil nil 6733 (setq sigs-in (cons (list sig vec (concat "To " comment) nil nil
6420 (verilog-sig-signed portdata) 6734 (verilog-sig-signed portdata)
6421 (verilog-sig-type portdata) 6735 (verilog-sig-type portdata)
6422 multidim) 6736 multidim)
6423 sigs-in))) 6737 sigs-in)))
6738 ((setq portdata (assoc port (verilog-decls-get-interfaces submoddecls)))
6739 (setq sigs-intf (cons (list sig vec (concat "To/From " comment) nil nil
6740 (verilog-sig-signed portdata)
6741 (verilog-sig-type portdata)
6742 multidim)
6743 sigs-intf)))
6424 ;; (t -- warning pin isn't defined.) ; Leave for lint tool 6744 ;; (t -- warning pin isn't defined.) ; Leave for lint tool
6425 ))))) 6745 )))))
6746
6747 (defun verilog-read-sub-decls-expr (submoddecls comment port expr)
6748 "For `verilog-read-sub-decls-line', parse a subexpression and add signals."
6749 ;;(message "vrsde: '%s'" expr)
6750 ;; Replace special /*[....]*/ comments inserted by verilog-auto-inst-port
6751 (setq expr (verilog-string-replace-matches "/\\*\\(\\[[^*]+\\]\\)\\*/" "\\1" nil nil expr))
6752 ;; Remove front operators
6753 (setq expr (verilog-string-replace-matches "^\\s-*[---+~!|&]+\\s-*" "" nil nil expr))
6754 ;;
6755 (cond
6756 ;; {..., a, b} requires us to recurse on a,b
6757 ((string-match "^\\s-*{\\([^{}]*\\)}\\s-*$" expr)
6758 (let ((mlst (split-string (match-string 1 expr) ","))
6759 mstr)
6760 (while (setq mstr (pop mlst))
6761 (verilog-read-sub-decls-expr submoddecls comment port mstr))))
6762 (t
6763 (let (sig vec multidim)
6764 (cond ;; Find \signal. Final space is part of escaped signal name
6765 ((string-match "^\\s-*\\(\\\\[^ \t\n\f]+\\s-\\)" expr)
6766 ;;(message "vrsde-s: '%s'" (match-string 1 expr))
6767 (setq sig (match-string 1 expr)
6768 expr (substring expr (match-end 0))))
6769 ;; Find signal
6770 ((string-match "^\\s-*\\([^[({).\\]+\\)" expr)
6771 ;;(message "vrsde-s: '%s'" (match-string 1 expr))
6772 (setq sig (verilog-string-remove-spaces (match-string 1 expr))
6773 expr (substring expr (match-end 0)))))
6774 ;; Find [vector] or [multi][multi][multi][vector]
6775 (while (string-match "^\\s-*\\(\\[[^]]+\\]\\)" expr)
6776 ;;(message "vrsde-v: '%s'" (match-string 1 expr))
6777 (when vec (setq multidim (cons vec multidim)))
6778 (setq vec (match-string 1 expr)
6779 expr (substring expr (match-end 0))))
6780 ;; If found signal, and nothing unrecognized, add the signal
6781 ;;(message "vrsde-rem: '%s'" expr)
6782 (when (and sig (string-match "^\\s-*$" expr))
6783 (verilog-read-sub-decls-sig submoddecls comment port sig vec multidim))))))
6426 6784
6427 (defun verilog-read-sub-decls-line (submoddecls comment) 6785 (defun verilog-read-sub-decls-line (submoddecls comment)
6428 "For `verilog-read-sub-decls', read lines of port defs until none match anymore. 6786 "For `verilog-read-sub-decls', read lines of port defs until none match anymore.
6429 Return the list of signals found, using submodi to look up each port." 6787 Return the list of signals found, using submodi to look up each port."
6430 (let (done port sig vec multidim) 6788 (let (done port)
6431 (save-excursion 6789 (save-excursion
6432 (forward-line 1) 6790 (forward-line 1)
6433 (while (not done) 6791 (while (not done)
6434 ;; Get port name 6792 ;; Get port name
6435 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*") 6793 (cond ((looking-at "\\s-*\\.\\s-*\\([a-zA-Z0-9`_$]*\\)\\s-*(\\s-*")
6441 ((looking-at "\\s-*\\.[^(]*(") 6799 ((looking-at "\\s-*\\.[^(]*(")
6442 (setq port nil) ;; skip this line 6800 (setq port nil) ;; skip this line
6443 (goto-char (match-end 0))) 6801 (goto-char (match-end 0)))
6444 (t 6802 (t
6445 (setq port nil done t))) ;; Unknown, ignore rest of line 6803 (setq port nil done t))) ;; Unknown, ignore rest of line
6446 ;; Get signal name 6804 ;; Get signal name. Point is at the first-non-space after (
6805 ;; We intentionally ignore (non-escaped) signals with .s in them
6806 ;; this prevents AUTOWIRE etc from noticing hierarchical sigs.
6447 (when port 6807 (when port
6448 (setq multidim nil) 6808 (cond ((looking-at "\\([^[({).\\]*\\)\\s-*)")
6449 (cond ((looking-at "\\(\\\\[^ \t\n\f]*\\)\\s-*)") 6809 (verilog-read-sub-decls-sig
6450 (setq sig (concat (match-string 1) " ") ;; escaped id's need trailing space 6810 submoddecls comment port
6451 vec nil)) 6811 (verilog-string-remove-spaces (match-string 1)) ; sig
6452 ; We intentionally ignore (non-escaped) signals with .s in them 6812 nil nil)) ; vec multidim
6453 ; this prevents AUTOWIRE etc from noticing hierarchical sigs. 6813 ;;
6454 ((looking-at "\\([^[({).]*\\)\\s-*)") 6814 ((looking-at "\\([^[({).\\]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)")
6455 (setq sig (verilog-string-remove-spaces (match-string 1)) 6815 (verilog-read-sub-decls-sig
6456 vec nil)) 6816 submoddecls comment port
6457 ((looking-at "\\([^[({).]*\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*)") 6817 (verilog-string-remove-spaces (match-string 1)) ; sig
6458 (setq sig (verilog-string-remove-spaces (match-string 1)) 6818 (match-string 2) nil)) ; vec multidim
6459 vec (match-string 2))) 6819 ;; Fastpath was above looking-at's.
6460 ((looking-at "\\([^[({).]*\\)\\s-*/\\*\\(\\[[^*]+\\]\\)\\*/\\s-*)") 6820 ;; For something more complicated invoke a parser
6461 (setq sig (verilog-string-remove-spaces (match-string 1)) 6821 ((looking-at "[^)]+")
6462 vec nil) 6822 (verilog-read-sub-decls-expr
6463 (let ((parse (match-string 2))) 6823 submoddecls comment port
6464 (while (string-match "^\\(\\[[^]]+\\]\\)\\(.*\\)$" parse) 6824 (buffer-substring
6465 (when vec (setq multidim (cons vec multidim))) 6825 (point) (1- (progn (backward-char 1) ; start at (
6466 (setq vec (match-string 1 parse)) 6826 (forward-sexp 1) (point)))))))) ; expr
6467 (setq parse (match-string 2 parse)))))
6468 ((looking-at "{\\(.*\\)}.*\\s-*)")
6469 (let ((mlst (split-string (match-string 1) ","))
6470 mstr)
6471 (while (setq mstr (pop mlst))
6472 ;;(unless noninteractive (message "sig: %s " mstr))
6473 (cond
6474 ((string-match "\\(['`a-zA-Z0-9_$]+\\)\\s-*$" mstr)
6475 (setq sig (verilog-string-remove-spaces (match-string 1 mstr))
6476 vec nil)
6477 ;;(unless noninteractive (message "concat sig1: %s %s" mstr (match-string 1 mstr)))
6478 )
6479 ((string-match "\\([^[({).]+\\)\\s-*\\(\\[[^]]+\\]\\)\\s-*" mstr)
6480 (setq sig (verilog-string-remove-spaces (match-string 1 mstr))
6481 vec (match-string 2 mstr))
6482 ;;(unless noninteractive (message "concat sig2: '%s' '%s' '%s'" mstr (match-string 1 mstr) (match-string 2 mstr)))
6483 )
6484 (t
6485 (setq sig nil)))
6486 ;; Process signals
6487 (verilog-read-sub-decls-sig submoddecls comment port sig vec multidim))))
6488 (t
6489 (setq sig nil)))
6490 ;; Process signals
6491 (verilog-read-sub-decls-sig submoddecls comment port sig vec multidim))
6492 ;; 6827 ;;
6493 (forward-line 1))))) 6828 (forward-line 1)))))
6494 6829
6495 (defun verilog-read-sub-decls () 6830 (defun verilog-read-sub-decls ()
6496 "Internally parse signals going to modules under this module. 6831 "Internally parse signals going to modules under this module.
6512 .in (in));" 6847 .in (in));"
6513 (save-excursion 6848 (save-excursion
6514 (let ((end-mod-point (verilog-get-end-of-defun t)) 6849 (let ((end-mod-point (verilog-get-end-of-defun t))
6515 st-point end-inst-point 6850 st-point end-inst-point
6516 ;; below 3 modified by verilog-read-sub-decls-line 6851 ;; below 3 modified by verilog-read-sub-decls-line
6517 sigs-out sigs-inout sigs-in) 6852 sigs-out sigs-inout sigs-in sigs-intf)
6518 (verilog-beg-of-defun) 6853 (verilog-beg-of-defun)
6519 (while (verilog-re-search-forward "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t) 6854 (while (verilog-re-search-forward "\\(/\\*AUTOINST\\*/\\|\\.\\*\\)" end-mod-point t)
6520 (save-excursion 6855 (save-excursion
6521 (goto-char (match-beginning 0)) 6856 (goto-char (match-beginning 0))
6522 (unless (verilog-inside-comment-p) 6857 (unless (verilog-inside-comment-p)
6530 ;; This could have used a list created by verilog-auto-inst 6865 ;; This could have used a list created by verilog-auto-inst
6531 ;; However I want it to be runnable even on user's manually added signals 6866 ;; However I want it to be runnable even on user's manually added signals
6532 (verilog-backward-open-paren) 6867 (verilog-backward-open-paren)
6533 (setq end-inst-point (save-excursion (forward-sexp 1) (point)) 6868 (setq end-inst-point (save-excursion (forward-sexp 1) (point))
6534 st-point (point)) 6869 st-point (point))
6870 (while (re-search-forward "\\s *(?\\s *// Interfaces" end-inst-point t)
6871 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
6872 (goto-char st-point)
6535 (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t) 6873 (while (re-search-forward "\\s *(?\\s *// Outputs" end-inst-point t)
6536 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out 6874 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-out
6537 (goto-char st-point) 6875 (goto-char st-point)
6538 (while (re-search-forward "\\s *// Inouts" end-inst-point t) 6876 (while (re-search-forward "\\s *// Inouts" end-inst-point t)
6539 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-inout 6877 (verilog-read-sub-decls-line submoddecls comment)) ;; Modifies sigs-inout
6543 ))))) 6881 )))))
6544 ;; Combine duplicate bits 6882 ;; Combine duplicate bits
6545 ;;(setq rr (vector sigs-out sigs-inout sigs-in)) 6883 ;;(setq rr (vector sigs-out sigs-inout sigs-in))
6546 (vector (verilog-signals-combine-bus (nreverse sigs-out)) 6884 (vector (verilog-signals-combine-bus (nreverse sigs-out))
6547 (verilog-signals-combine-bus (nreverse sigs-inout)) 6885 (verilog-signals-combine-bus (nreverse sigs-inout))
6548 (verilog-signals-combine-bus (nreverse sigs-in)))))) 6886 (verilog-signals-combine-bus (nreverse sigs-in))
6887 (verilog-signals-combine-bus (nreverse sigs-intf))))))
6549 6888
6550 (defun verilog-read-inst-pins () 6889 (defun verilog-read-inst-pins ()
6551 "Return an array of [ pins ] for the current instantiation at point. 6890 "Return an array of [ pins ] for the current instantiation at point.
6552 For example if declare A A (.B(SIG)) then B will be included in the list." 6891 For example if declare A A (.B(SIG)) then B will be included in the list."
6553 (save-excursion 6892 (save-excursion
6675 ((equal keywd ":") ;; Case statement, begin/end label, x?y:z 7014 ((equal keywd ":") ;; Case statement, begin/end label, x?y:z
6676 (cond ((equal "endcase" exit-keywd) ;; case x: y=z; statement next 7015 (cond ((equal "endcase" exit-keywd) ;; case x: y=z; statement next
6677 (setq ignore-next nil rvalue nil)) 7016 (setq ignore-next nil rvalue nil))
6678 ((equal "?" exit-keywd) ;; x?y:z rvalue 7017 ((equal "?" exit-keywd) ;; x?y:z rvalue
6679 ) ;; NOP 7018 ) ;; NOP
7019 ((equal "]" exit-keywd) ;; [x:y] rvalue
7020 ) ;; NOP
6680 (got-sig ;; label: statement 7021 (got-sig ;; label: statement
6681 (setq ignore-next nil rvalue semi-rvalue got-sig nil)) 7022 (setq ignore-next nil rvalue semi-rvalue got-sig nil))
6682 ((not rvalue) ;; begin label 7023 ((not rvalue) ;; begin label
6683 (setq ignore-next t rvalue nil))) 7024 (setq ignore-next t rvalue nil)))
6684 (forward-char 1)) 7025 (forward-char 1))
6685 ((equal keywd "=") 7026 ((equal keywd "=")
6686 (if (eq (char-before) ?< ) 7027 (if (and (eq (char-before) ?< )
7028 (not rvalue))
6687 (setq uses-delayed 1)) 7029 (setq uses-delayed 1))
6688 (setq ignore-next nil rvalue t) 7030 (setq ignore-next nil rvalue t)
6689 (forward-char 1)) 7031 (forward-char 1))
6690 ((equal keywd "?") 7032 ((equal keywd "?")
6691 (forward-char 1) 7033 (forward-char 1)
6879 (set (make-variable-buffer-local mac) 7221 (set (make-variable-buffer-local mac)
6880 (if (equal defvalue "") "1" defvalue))) 7222 (if (equal defvalue "") "1" defvalue)))
6881 (if enumname 7223 (if enumname
6882 (let ((enumvar (intern (concat "venum-" enumname)))) 7224 (let ((enumvar (intern (concat "venum-" enumname))))
6883 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1) 7225 ;;(message "Define %s=%s" defname defvalue) (sleep-for 1)
7226 (unless (boundp enumvar) (set enumvar nil))
6884 (make-variable-buffer-local enumvar) 7227 (make-variable-buffer-local enumvar)
6885 (add-to-list enumvar defname))))) 7228 (add-to-list enumvar defname)))))
6886 7229
6887 (defun verilog-read-defines (&optional filename recurse subcall) 7230 (defun verilog-read-defines (&optional filename recurse subcall)
6888 "Read `defines and parameters for the current file, or optional FILENAME. 7231 "Read `defines and parameters for the current file, or optional FILENAME.
6950 (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue)) 7293 (setq defvalue (verilog-string-replace-matches "\\s-*/[/*].*$" "" nil nil defvalue))
6951 (verilog-set-define defname defvalue origbuf))) 7294 (verilog-set-define defname defvalue origbuf)))
6952 ;; Hack: Read parameters 7295 ;; Hack: Read parameters
6953 (goto-char (point-min)) 7296 (goto-char (point-min))
6954 (while (re-search-forward 7297 (while (re-search-forward
6955 "^\\s-*\\(parameter\\|localparam\\)\\(\\(\\s-*\\[[^]]*\\]\\|\\)\\s-+\\([a-zA-Z0-9_$]+\\)\\s-*=\\s-*\\([^;,]*\\),?\\|\\)\\s-*" nil t) 7298 "^\\s-*\\(parameter\\|localparam\\)\\(\\s-*\\[[^]]*\\]\\)?\\s-+" nil t)
6956 (let ((var (match-string-no-properties 4)) 7299 (let (enumname)
6957 (val (match-string-no-properties 5))
6958 enumname)
6959 ;; The primary way of getting defines is verilog-read-decls 7300 ;; The primary way of getting defines is verilog-read-decls
6960 ;; However, that isn't called yet for included files, so we'll add another scheme 7301 ;; However, that isn't called yet for included files, so we'll add another scheme
6961 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)") 7302 (if (looking-at "[^\n]*synopsys\\s +enum\\s +\\([a-zA-Z0-9_]+\\)")
6962 (setq enumname (match-string-no-properties 1))) 7303 (setq enumname (match-string-no-properties 1)))
6963 (if var
6964 (verilog-set-define var val origbuf enumname))
6965 (forward-comment 999) 7304 (forward-comment 999)
6966 (while (looking-at "\\s-*,?\\s-*\\([a-zA-Z0-9_$]+\\)\\s-*=\\s-*\\([^;,]*\\),?\\s-*") 7305 (while (looking-at "\\s-*,?\\s-*\\([a-zA-Z0-9_$]+\\)\\s-*=\\s-*\\([^;,]*\\),?\\s-*")
6967 (verilog-set-define (match-string-no-properties 1) (match-string-no-properties 2) origbuf enumname) 7306 (verilog-set-define (match-string-no-properties 1) (match-string-no-properties 2) origbuf enumname)
6968 (goto-char (match-end 0)) 7307 (goto-char (match-end 0))
6969 (forward-comment 999))))))) 7308 (forward-comment 999)))))))
7079 (verilog-set-define (match-string 1 arg) (match-string 2 arg))) 7418 (verilog-set-define (match-string 1 arg) (match-string 2 arg)))
7080 ;; 7419 ;;
7081 ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ;; +incdir+dir 7420 ((or (string-match "^\\+incdir\\+\\(.*\\)" arg) ;; +incdir+dir
7082 (string-match "^-I\\(.*\\)" arg)) ;; -Idir 7421 (string-match "^-I\\(.*\\)" arg)) ;; -Idir
7083 (verilog-add-list-unique `verilog-library-directories 7422 (verilog-add-list-unique `verilog-library-directories
7084 (match-string 1 arg))) 7423 (match-string 1 (substitute-in-file-name arg))))
7085 ;; Ignore 7424 ;; Ignore
7086 ((equal "+librescan" arg)) 7425 ((equal "+librescan" arg))
7087 ((string-match "^-U\\(.*\\)" arg)) ;; -Udefine 7426 ((string-match "^-U\\(.*\\)" arg)) ;; -Udefine
7088 ;; Second parameters 7427 ;; Second parameters
7089 ((equal next-param "-f") 7428 ((equal next-param "-f")
7090 (setq next-param nil) 7429 (setq next-param nil)
7091 (verilog-getopt-file arg)) 7430 (verilog-getopt-file (substitute-in-file-name arg)))
7092 ((equal next-param "-v") 7431 ((equal next-param "-v")
7093 (setq next-param nil) 7432 (setq next-param nil)
7094 (verilog-add-list-unique `verilog-library-files arg)) 7433 (verilog-add-list-unique `verilog-library-files
7434 (substitute-in-file-name arg)))
7095 ((equal next-param "-y") 7435 ((equal next-param "-y")
7096 (setq next-param nil) 7436 (setq next-param nil)
7097 (verilog-add-list-unique `verilog-library-directories arg)) 7437 (verilog-add-list-unique `verilog-library-directories
7438 (substitute-in-file-name arg)))
7098 ;; Filename 7439 ;; Filename
7099 ((string-match "^[^-+]" arg) 7440 ((string-match "^[^-+]" arg)
7100 (verilog-add-list-unique `verilog-library-files arg)) 7441 (verilog-add-list-unique `verilog-library-files
7442 (substitute-in-file-name arg)))
7101 ;; Default - ignore; no warning 7443 ;; Default - ignore; no warning
7102 )))) 7444 ))))
7103 ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir")) 7445 ;;(verilog-getopt (list "+libext+.a+.b" "+incdir+foodir" "+define+a+aval" "-f" "otherf" "-v" "library" "-y" "dir"))
7104 7446
7105 (defun verilog-getopt-file (filename) 7447 (defun verilog-getopt-file (filename)
7277 "Return TEXT without any known defines. 7619 "Return TEXT without any known defines.
7278 If the variable vh-{symbol} is defined, substitute that value." 7620 If the variable vh-{symbol} is defined, substitute that value."
7279 (let ((ok t) symbol val) 7621 (let ((ok t) symbol val)
7280 (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text)) 7622 (while (and ok (string-match "`\\([a-zA-Z0-9_]+\\)" text))
7281 (setq symbol (match-string 1 text)) 7623 (setq symbol (match-string 1 text))
7282 (message symbol) 7624 ;;(message symbol)
7283 (cond ((and 7625 (cond ((and
7284 (boundp (intern (concat "vh-" symbol))) 7626 (boundp (intern (concat "vh-" symbol)))
7285 ;; Emacs has a bug where boundp on a buffer-local 7627 ;; Emacs has a bug where boundp on a buffer-local
7286 ;; variable in only one buffer returns t in another. 7628 ;; variable in only one buffer returns t in another.
7287 ;; This can confuse, so check for nil. 7629 ;; This can confuse, so check for nil.
7569 (setq enumlist (cdr enumlist)))) 7911 (setq enumlist (cdr enumlist))))
7570 (nreverse out-list))) 7912 (nreverse out-list)))
7571 7913
7572 (defun verilog-signals-matching-regexp (in-list regexp) 7914 (defun verilog-signals-matching-regexp (in-list regexp)
7573 "Return all signals in IN-LIST matching the given REGEXP, if non-nil." 7915 "Return all signals in IN-LIST matching the given REGEXP, if non-nil."
7574 (if (not regexp) 7916 (if (or (not regexp) (equal regexp ""))
7575 in-list 7917 in-list
7576 (let (out-list) 7918 (let (out-list)
7577 (while in-list 7919 (while in-list
7578 (if (string-match regexp (verilog-sig-name (car in-list))) 7920 (if (string-match regexp (verilog-sig-name (car in-list)))
7579 (setq out-list (cons (car in-list) out-list))) 7921 (setq out-list (cons (car in-list) out-list)))
7580 (setq in-list (cdr in-list))) 7922 (setq in-list (cdr in-list)))
7581 (nreverse out-list)))) 7923 (nreverse out-list))))
7582 7924
7583 (defun verilog-signals-not-matching-regexp (in-list regexp) 7925 (defun verilog-signals-not-matching-regexp (in-list regexp)
7584 "Return all signals in IN-LIST not matching the given REGEXP, if non-nil." 7926 "Return all signals in IN-LIST not matching the given REGEXP, if non-nil."
7585 (if (not regexp) 7927 (if (or (not regexp) (equal regexp ""))
7586 in-list 7928 in-list
7587 (let (out-list) 7929 (let (out-list)
7588 (while in-list 7930 (while in-list
7589 (if (not (string-match regexp (verilog-sig-name (car in-list)))) 7931 (if (not (string-match regexp (verilog-sig-name (car in-list))))
7932 (setq out-list (cons (car in-list) out-list)))
7933 (setq in-list (cdr in-list)))
7934 (nreverse out-list))))
7935
7936 (defun verilog-signals-matching-dir-re (in-list decl-type regexp)
7937 "Return all signals in IN-LIST matching the given directional REGEXP,
7938 if non-nil."
7939 (if (or (not regexp) (equal regexp ""))
7940 in-list
7941 (let (out-list to-match)
7942 (while in-list
7943 ;; Note verilog-insert-one-definition matches on this order
7944 (setq to-match (concat
7945 decl-type
7946 " " (verilog-sig-signed (car in-list))
7947 " " (verilog-sig-multidim (car in-list))
7948 (verilog-sig-bits (car in-list))))
7949 (if (string-match regexp to-match)
7590 (setq out-list (cons (car in-list) out-list))) 7950 (setq out-list (cons (car in-list) out-list)))
7591 (setq in-list (cdr in-list))) 7951 (setq in-list (cdr in-list)))
7592 (nreverse out-list)))) 7952 (nreverse out-list))))
7593 7953
7594 ;; Combined 7954 ;; Combined
7637 7997
7638 (defun verilog-insert-one-definition (sig type indent-pt) 7998 (defun verilog-insert-one-definition (sig type indent-pt)
7639 "Print out a definition for SIG of the given TYPE, 7999 "Print out a definition for SIG of the given TYPE,
7640 with appropriate INDENT-PT indentation." 8000 with appropriate INDENT-PT indentation."
7641 (indent-to indent-pt) 8001 (indent-to indent-pt)
8002 ;; Note verilog-signals-matching-dir-re matches on this order
7642 (insert type) 8003 (insert type)
8004 (when (verilog-sig-modport sig)
8005 (insert "." (verilog-sig-modport sig)))
7643 (when (verilog-sig-signed sig) 8006 (when (verilog-sig-signed sig)
7644 (insert " " (verilog-sig-signed sig))) 8007 (insert " " (verilog-sig-signed sig)))
7645 (when (verilog-sig-multidim sig) 8008 (when (verilog-sig-multidim sig)
7646 (insert " " (verilog-sig-multidim-string sig))) 8009 (insert " " (verilog-sig-multidim-string sig)))
7647 (when (verilog-sig-bits sig) 8010 (when (verilog-sig-bits sig)
7662 (verilog-insert-one-definition 8025 (verilog-insert-one-definition
7663 sig 8026 sig
7664 ;; Want "type x" or "output type x", not "wire type x" 8027 ;; Want "type x" or "output type x", not "wire type x"
7665 (cond ((verilog-sig-type sig) 8028 (cond ((verilog-sig-type sig)
7666 (concat 8029 (concat
7667 (if (not (equal direction "wire")) 8030 (if (not (member direction '("wire" "interface")))
7668 (concat direction " ")) 8031 (concat direction " "))
7669 (verilog-sig-type sig))) 8032 (verilog-sig-type sig)))
7670 (t direction)) 8033 (t direction))
7671 indent-pt) 8034 indent-pt)
7672 (insert (if v2k "," ";")) 8035 (insert (if v2k "," ";"))
7692 (setq need-indent (string-match "\n$" (car stuff)) 8055 (setq need-indent (string-match "\n$" (car stuff))
7693 stuff (cdr stuff))))) 8056 stuff (cdr stuff)))))
7694 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n")) 8057 ;;(let ((indent-pt 10)) (verilog-insert-indent "hello\n" "addon" "there\n"))
7695 8058
7696 (defun verilog-repair-open-comma () 8059 (defun verilog-repair-open-comma ()
7697 "If backwards-from-point is other than a open parenthesis insert comma." 8060 "Insert comma if previous argument is other than a open parenthesis or endif."
8061 ;; We can't just search backward for ) as it might be inside another expression.
8062 ;; Also want "`ifdef X input foo `endif" to just leave things to the human to deal with
7698 (save-excursion 8063 (save-excursion
7699 (verilog-backward-syntactic-ws) 8064 (verilog-backward-syntactic-ws)
7700 (when (save-excursion 8065 (when (and (not (save-excursion ;; Not beginning (, or existing ,
7701 (backward-char 1) 8066 (backward-char 1)
7702 (and (not (looking-at "[(,]")) 8067 (looking-at "[(,]")))
7703 (progn 8068 (not (save-excursion ;; Not `endif, or user define
7704 (verilog-re-search-backward "[(`]" nil t) 8069 (backward-char 1)
7705 (looking-at "(")))) 8070 (skip-chars-backward "[a-zA-Z0-9_`]")
7706 (insert ",")))) 8071 (looking-at "`"))))
8072 (insert ","))))
7707 8073
7708 (defun verilog-repair-close-comma () 8074 (defun verilog-repair-close-comma ()
7709 "If point is at a comma followed by a close parenthesis, fix it. 8075 "If point is at a comma followed by a close parenthesis, fix it.
7710 This repairs those mis-inserted by a AUTOARG." 8076 This repairs those mis-inserted by a AUTOARG."
7711 ;; It would be much nicer if Verilog allowed extra commas like Perl does! 8077 ;; It would be much nicer if Verilog allowed extra commas like Perl does!
7738 (t 8104 (t
7739 (if (string-match "^\\[\\(.*\\)\\]$" range-exp) 8105 (if (string-match "^\\[\\(.*\\)\\]$" range-exp)
7740 (setq range-exp (match-string 1 range-exp))) 8106 (setq range-exp (match-string 1 range-exp)))
7741 (cond ((not range-exp) 8107 (cond ((not range-exp)
7742 "1") 8108 "1")
8109 ;; [#:#] We can compute a numeric result
7743 ((string-match "^\\s *\\([0-9]+\\)\\s *:\\s *\\([0-9]+\\)\\s *$" 8110 ((string-match "^\\s *\\([0-9]+\\)\\s *:\\s *\\([0-9]+\\)\\s *$"
7744 range-exp) 8111 range-exp)
7745 (int-to-string 8112 (int-to-string
7746 (1+ (abs (- (string-to-number (match-string 1 range-exp)) 8113 (1+ (abs (- (string-to-number (match-string 1 range-exp))
7747 (string-to-number (match-string 2 range-exp))))))) 8114 (string-to-number (match-string 2 range-exp)))))))
8115 ;; [PARAM-1:0] can just return PARAM
8116 ((string-match "^\\s *\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s *-\\s *1\\s *:\\s *0\\s *$" range-exp)
8117 (match-string 1 range-exp))
8118 ;; [arbitrary] need math
7748 ((string-match "^\\(.*\\)\\s *:\\s *\\(.*\\)\\s *$" range-exp) 8119 ((string-match "^\\(.*\\)\\s *:\\s *\\(.*\\)\\s *$" range-exp)
7749 (concat "(1+(" (match-string 1 range-exp) ")" 8120 (concat "(1+(" (match-string 1 range-exp) ")"
7750 (if (equal "0" (match-string 2 range-exp)) 8121 (if (equal "0" (match-string 2 range-exp))
7751 "" ;; Don't bother with -(0) 8122 "" ;; Don't bother with -(0)
7752 (concat "-(" (match-string 2 range-exp) ")")) 8123 (concat "-(" (match-string 2 range-exp) ")"))
7761 (while (not (equal last-pass out)) 8132 (while (not (equal last-pass out))
7762 (setq last-pass out) 8133 (setq last-pass out)
7763 (while (string-match "(\\<\\([0-9A-Z-az_]+\\)\\>)" out) 8134 (while (string-match "(\\<\\([0-9A-Z-az_]+\\)\\>)" out)
7764 (setq out (replace-match "\\1" nil nil out))) 8135 (setq out (replace-match "\\1" nil nil out)))
7765 (while (string-match "\\<\\([0-9]+\\)\\>\\s *\\+\\s *\\<\\([0-9]+\\)\\>" out) 8136 (while (string-match "\\<\\([0-9]+\\)\\>\\s *\\+\\s *\\<\\([0-9]+\\)\\>" out)
7766 (setq out (replace-match 8137 (setq out (replace-match
7767 (int-to-string (+ (string-to-number (match-string 1 out)) 8138 (int-to-string (+ (string-to-number (match-string 1 out))
7768 (string-to-number (match-string 2 out)))) 8139 (string-to-number (match-string 2 out))))
7769 nil nil out))) 8140 nil nil out)))
7770 (while (string-match "\\<\\([0-9]+\\)\\>\\s *\\-\\s *\\<\\([0-9]+\\)\\>" out) 8141 (while (string-match "\\<\\([0-9]+\\)\\>\\s *\\-\\s *\\<\\([0-9]+\\)\\>" out)
7771 (setq out (replace-match 8142 (setq out (replace-match
7772 (int-to-string (- (string-to-number (match-string 1 out)) 8143 (int-to-string (- (string-to-number (match-string 1 out))
7773 (string-to-number (match-string 2 out)))) 8144 (string-to-number (match-string 2 out))))
7774 nil nil out)))) 8145 nil nil out))))
7775 out)) 8146 out))
7776 ;;(verilog-simplify-range-expression "1") 8147 ;;(verilog-simplify-range-expression "1")
7913 (concat "/\\*" 8284 (concat "/\\*"
7914 (eval-when-compile 8285 (eval-when-compile
7915 (verilog-regexp-words 8286 (verilog-regexp-words
7916 `("AUTOASCIIENUM" "AUTOCONCATCOMMENT" "AUTODEFINEVALUE" 8287 `("AUTOASCIIENUM" "AUTOCONCATCOMMENT" "AUTODEFINEVALUE"
7917 "AUTOINOUT" "AUTOINOUTCOMP" "AUTOINOUTMODULE" 8288 "AUTOINOUT" "AUTOINOUTCOMP" "AUTOINOUTMODULE"
7918 "AUTOINPUT" "AUTOOUTPUT" "AUTOOUTPUTEVERY" 8289 "AUTOINPUT" "AUTOINSERTLISP" "AUTOOUTPUT" "AUTOOUTPUTEVERY"
7919 "AUTOREG" "AUTOREGINPUT" "AUTORESET" "AUTOTIEOFF" 8290 "AUTOREG" "AUTOREGINPUT" "AUTORESET" "AUTOTIEOFF"
7920 "AUTOUNUSED" "AUTOWIRE"))) 8291 "AUTOUNUSED" "AUTOWIRE")))
7921 "\\(\\|([^)]*)\\|(\"[^\"]*\")\\)" ; Optional parens or quoted parameter 8292 ;; Optional parens or quoted parameter or .* for (((...)))
8293 "\\(\\|([^)]*)\\|(\"[^\"]*\")\\|.*?\\)"
7922 "\\*/") 8294 "\\*/")
7923 'verilog-delete-autos-lined) 8295 'verilog-delete-autos-lined)
7924 ;; Remove those that are in parenthesis 8296 ;; Remove those that are in parenthesis
7925 (verilog-auto-re-search-do 8297 (verilog-auto-re-search-do
7926 (concat "/\\*" 8298 (concat "/\\*"
8104 If FORCE, always reread it." 8476 If FORCE, always reread it."
8105 (make-local-variable 'verilog-auto-last-file-locals) 8477 (make-local-variable 'verilog-auto-last-file-locals)
8106 (let ((curlocal (verilog-auto-read-locals))) 8478 (let ((curlocal (verilog-auto-read-locals)))
8107 (when (or force (not (equal verilog-auto-last-file-locals curlocal))) 8479 (when (or force (not (equal verilog-auto-last-file-locals curlocal)))
8108 (setq verilog-auto-last-file-locals curlocal) 8480 (setq verilog-auto-last-file-locals curlocal)
8109 ;; Note this may cause this function to be recursively invoked. 8481 ;; Note this may cause this function to be recursively invoked,
8482 ;; because hack-local-variables may call (verilog-mode)
8110 ;; The above when statement will prevent it from recursing forever. 8483 ;; The above when statement will prevent it from recursing forever.
8111 (hack-local-variables) 8484 (hack-local-variables)
8112 t))) 8485 t)))
8113 8486
8114 ;; 8487 ;;
8117 8490
8118 (defun verilog-auto-arg-ports (sigs message indent-pt) 8491 (defun verilog-auto-arg-ports (sigs message indent-pt)
8119 "Print a list of ports for a AUTOINST. 8492 "Print a list of ports for a AUTOINST.
8120 Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT." 8493 Takes SIGS list, adds MESSAGE to front and inserts each at INDENT-PT."
8121 (when sigs 8494 (when sigs
8495 (when verilog-auto-arg-sort
8496 (setq sigs (sort (copy-alist sigs) `verilog-signals-sort-compare)))
8122 (insert "\n") 8497 (insert "\n")
8123 (indent-to indent-pt) 8498 (indent-to indent-pt)
8124 (insert message) 8499 (insert message)
8125 (insert "\n") 8500 (insert "\n")
8126 (let ((space "")) 8501 (let ((space ""))
8164 i 8539 i
8165 ); 8540 );
8166 input i; 8541 input i;
8167 output o; 8542 output o;
8168 endmodule 8543 endmodule
8544
8545 The argument declarations may be printed in declaration order to best suit
8546 order based instantiations, or alphabetically, based on the
8547 `verilog-auto-arg-sort' variable.
8169 8548
8170 Any ports declared between the ( and /*AUTOARG*/ are presumed to be 8549 Any ports declared between the ( and /*AUTOARG*/ are presumed to be
8171 predeclared and are not redeclared by AUTOARG. AUTOARG will make a 8550 predeclared and are not redeclared by AUTOARG. AUTOARG will make a
8172 conservative guess on adding a comma for the first signal, if you have 8551 conservative guess on adding a comma for the first signal, if you have
8173 any ifdefs or complicated expressions before the AUTOARG you will need 8552 any ifdefs or complicated expressions before the AUTOARG you will need
8202 (defun verilog-auto-inst-port-map (port-st) 8581 (defun verilog-auto-inst-port-map (port-st)
8203 nil) 8582 nil)
8204 8583
8205 (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning 8584 (defvar vl-cell-type nil "See `verilog-auto-inst'.") ; Prevent compile warning
8206 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning 8585 (defvar vl-cell-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
8586 (defvar vl-modport nil "See `verilog-auto-inst'.") ; Prevent compile warning
8207 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning 8587 (defvar vl-name nil "See `verilog-auto-inst'.") ; Prevent compile warning
8208 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning 8588 (defvar vl-width nil "See `verilog-auto-inst'.") ; Prevent compile warning
8209 (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning 8589 (defvar vl-dir nil "See `verilog-auto-inst'.") ; Prevent compile warning
8210 8590
8211 (defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star par-values) 8591 (defun verilog-auto-inst-port (port-st indent-pt tpl-list tpl-num for-star par-values)
8219 (tpl-ass (or (assoc port (car tpl-list)) 8599 (tpl-ass (or (assoc port (car tpl-list))
8220 (verilog-auto-inst-port-map port-st))) 8600 (verilog-auto-inst-port-map port-st)))
8221 ;; vl-* are documented for user use 8601 ;; vl-* are documented for user use
8222 (vl-name (verilog-sig-name port-st)) 8602 (vl-name (verilog-sig-name port-st))
8223 (vl-width (verilog-sig-width port-st)) 8603 (vl-width (verilog-sig-width port-st))
8604 (vl-modport (verilog-sig-modport port-st))
8224 (vl-bits (if (or verilog-auto-inst-vector 8605 (vl-bits (if (or verilog-auto-inst-vector
8225 (not (assoc port vector-skip-list)) 8606 (not (assoc port vector-skip-list))
8226 (not (equal (verilog-sig-bits port-st) 8607 (not (equal (verilog-sig-bits port-st)
8227 (verilog-sig-bits (assoc port vector-skip-list))))) 8608 (verilog-sig-bits (assoc port vector-skip-list)))))
8228 (or (verilog-sig-bits port-st) "") 8609 (or (verilog-sig-bits port-st) "")
8239 (concat "(" (nth 1 (car check-values)) ")") 8620 (concat "(" (nth 1 (car check-values)) ")")
8240 t t vl-bits) 8621 t t vl-bits)
8241 check-values (cdr check-values))) 8622 check-values (cdr check-values)))
8242 (setq vl-bits (verilog-simplify-range-expression vl-bits))) ; Not in the loop for speed 8623 (setq vl-bits (verilog-simplify-range-expression vl-bits))) ; Not in the loop for speed
8243 ;; Default net value if not found 8624 ;; Default net value if not found
8244 (setq tpl-net (if (verilog-sig-multidim port-st) 8625 (setq tpl-net (concat port
8245 (concat port "/*" (verilog-sig-multidim-string port-st) 8626 (if vl-modport (concat "." vl-modport) "")
8246 vl-bits "*/") 8627 (if (verilog-sig-multidim port-st)
8247 (concat port vl-bits))) 8628 (concat "/*" (verilog-sig-multidim-string port-st)
8629 vl-bits "*/")
8630 (concat vl-bits))))
8248 ;; Find template 8631 ;; Find template
8249 (cond (tpl-ass ; Template of exact port name 8632 (cond (tpl-ass ; Template of exact port name
8250 (setq tpl-net (nth 1 tpl-ass))) 8633 (setq tpl-net (nth 1 tpl-ass)))
8251 ((nth 1 tpl-list) ; Wildcards in template, search them 8634 ((nth 1 tpl-list) ; Wildcards in template, search them
8252 (let ((wildcards (nth 1 tpl-list))) 8635 (let ((wildcards (nth 1 tpl-list)))
8564 8947
8565 vl-name Name portion of the input/output port. 8948 vl-name Name portion of the input/output port.
8566 vl-bits Bus bits portion of the input/output port ('[2:0]'). 8949 vl-bits Bus bits portion of the input/output port ('[2:0]').
8567 vl-width Width of the input/output port ('3' for [2:0]). 8950 vl-width Width of the input/output port ('3' for [2:0]).
8568 May be a (...) expression if bits isn't a constant. 8951 May be a (...) expression if bits isn't a constant.
8569 vl-dir Direction of the pin input/output/inout. 8952 vl-dir Direction of the pin input/output/inout/interface.
8953 vl-modport The modport, if an interface with a modport.
8570 vl-cell-type Module name/type of the cell ('InstModule'). 8954 vl-cell-type Module name/type of the cell ('InstModule').
8571 vl-cell-name Instance name of the cell ('instName'). 8955 vl-cell-name Instance name of the cell ('instName').
8572 8956
8573 Normal Lisp variables may be used in expressions. See 8957 Normal Lisp variables may be used in expressions. See
8574 `verilog-read-defines' which can set vh-{definename} variables for use 8958 `verilog-read-defines' which can set vh-{definename} variables for use
8577 /*AUTO_LISP(setq foo 1)*/ 8961 /*AUTO_LISP(setq foo 1)*/
8578 8962
8579 will evaluate any Lisp expression inside the parenthesis between the 8963 will evaluate any Lisp expression inside the parenthesis between the
8580 beginning of the buffer and the point of the AUTOINST. This allows 8964 beginning of the buffer and the point of the AUTOINST. This allows
8581 functions to be defined or variables to be changed between instantiations. 8965 functions to be defined or variables to be changed between instantiations.
8966 (See also `verilog-auto-insert-lisp' if you want the output from your
8967 lisp function to be inserted.)
8582 8968
8583 Note that when using lisp expressions errors may occur when @ is not a 8969 Note that when using lisp expressions errors may occur when @ is not a
8584 number; you may need to use the standard Emacs Lisp functions 8970 number; you may need to use the standard Emacs Lisp functions
8585 `number-to-string' and `string-to-number'. 8971 `number-to-string' and `string-to-number'.
8586 8972
8627 (match-string 1 inst) 9013 (match-string 1 inst)
8628 "") 9014 "")
8629 tpl-list (aref tpl-info 1))) 9015 tpl-list (aref tpl-info 1)))
8630 ;; Find submodule's signals and dump 9016 ;; Find submodule's signals and dump
8631 (let ((sig-list (verilog-signals-not-in 9017 (let ((sig-list (verilog-signals-not-in
9018 (verilog-decls-get-interfaces submoddecls)
9019 skip-pins))
9020 (vl-dir "interface"))
9021 (when sig-list
9022 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
9023 (indent-to indent-pt)
9024 ;; Note these are searched for in verilog-read-sub-decls.
9025 (insert "// Interfaces\n")
9026 (mapc (lambda (port)
9027 (verilog-auto-inst-port port indent-pt
9028 tpl-list tpl-num for-star par-values))
9029 sig-list)))
9030 (let ((sig-list (verilog-signals-not-in
8632 (verilog-decls-get-outputs submoddecls) 9031 (verilog-decls-get-outputs submoddecls)
8633 skip-pins)) 9032 skip-pins))
8634 (vl-dir "output")) 9033 (vl-dir "output"))
8635 (when sig-list 9034 (when sig-list
8636 (when (not did-first) (verilog-auto-inst-first) (setq did-first t)) 9035 (when (not did-first) (verilog-auto-inst-first) (setq did-first t))
8637 (indent-to indent-pt) 9036 (indent-to indent-pt)
8638 ;; Note these are searched for in verilog-read-sub-decls.
8639 (insert "// Outputs\n") 9037 (insert "// Outputs\n")
8640 (mapc (lambda (port) 9038 (mapc (lambda (port)
8641 (verilog-auto-inst-port port indent-pt 9039 (verilog-auto-inst-port port indent-pt
8642 tpl-list tpl-num for-star par-values)) 9040 tpl-list tpl-num for-star par-values))
8643 sig-list))) 9041 sig-list)))
8955 (when nil ;; Too slow on huge modules, plus makes everyone's module change 9353 (when nil ;; Too slow on huge modules, plus makes everyone's module change
8956 (beginning-of-line) 9354 (beginning-of-line)
8957 (setq pnt (point)) 9355 (setq pnt (point))
8958 (verilog-pretty-declarations quiet) 9356 (verilog-pretty-declarations quiet)
8959 (goto-char pnt) 9357 (goto-char pnt)
8960 (verilog-pretty-expr "//")))))) 9358 (verilog-pretty-expr t "//"))))))
8961 9359
8962 (defun verilog-auto-output (&optional with-params) 9360 (defun verilog-auto-output (&optional with-params)
8963 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto]. 9361 "Expand AUTOOUTPUT statements, as part of \\[verilog-auto].
8964 Make output statements for any output signal from an /*AUTOINST*/ that 9362 Make output statements for any output signal from an /*AUTOINST*/ that
8965 isn't a input to another AUTOINST. This is useful for modules which 9363 isn't a input to another AUTOINST. This is useful for modules which
9291 9689
9292 You may also provide an optional regular expression, in which case only 9690 You may also provide an optional regular expression, in which case only
9293 signals matching the regular expression will be included. For example the 9691 signals matching the regular expression will be included. For example the
9294 same expansion will result from only extracting signals starting with i: 9692 same expansion will result from only extracting signals starting with i:
9295 9693
9296 /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/" 9694 /*AUTOINOUTMODULE(\"ExampMain\",\"^i\")*/
9695
9696 You may also provide an optional second regulat expression, in
9697 which case only signals which have that pin direction and data
9698 type will be included. This matches against everything before
9699 the signal name in the declaration, for example against
9700 \"input\" (single bit), \"output logic\" (direction and type) or
9701 \"output [1:0]\" (direction and implicit type). You also
9702 probably want to skip spaces in your regexp.
9703
9704 For example, the below will result in matching the output \"o\"
9705 against the previous example's module:
9706
9707 /*AUTOINOUTMODULE(\"ExampMain\",\"\",\"^output.*\")*/"
9297 (save-excursion 9708 (save-excursion
9298 (let* ((params (verilog-read-auto-params 1 2)) 9709 (let* ((params (verilog-read-auto-params 1 3))
9299 (submod (nth 0 params)) 9710 (submod (nth 0 params))
9300 (regexp (nth 1 params)) 9711 (regexp (nth 1 params))
9712 (direction-re (nth 2 params))
9301 submodi) 9713 submodi)
9302 ;; Lookup position, etc of co-module 9714 ;; Lookup position, etc of co-module
9303 ;; Note this may raise an error 9715 ;; Note this may raise an error
9304 (when (setq submodi (verilog-modi-lookup submod t)) 9716 (when (setq submodi (verilog-modi-lookup submod t))
9305 (let* ((indent-pt (current-indentation)) 9717 (let* ((indent-pt (current-indentation))
9317 (verilog-decls-get-inputs submoddecls) 9729 (verilog-decls-get-inputs submoddecls)
9318 (verilog-decls-get-outputs submoddecls)) 9730 (verilog-decls-get-outputs submoddecls))
9319 (append (verilog-decls-get-outputs moddecls)))) 9731 (append (verilog-decls-get-outputs moddecls))))
9320 (sig-list-io (verilog-signals-not-in 9732 (sig-list-io (verilog-signals-not-in
9321 (verilog-decls-get-inouts submoddecls) 9733 (verilog-decls-get-inouts submoddecls)
9322 (append (verilog-decls-get-inouts moddecls))))) 9734 (append (verilog-decls-get-inouts moddecls))))
9735 (sig-list-if (verilog-signals-not-in
9736 (verilog-decls-get-interfaces submoddecls)
9737 (append (verilog-decls-get-interfaces moddecls)))))
9323 (forward-line 1) 9738 (forward-line 1)
9324 (when regexp 9739 (setq sig-list-i (verilog-signals-matching-dir-re
9325 (setq sig-list-i (verilog-signals-matching-regexp 9740 (verilog-signals-matching-regexp sig-list-i regexp)
9326 sig-list-i regexp) 9741 "input" direction-re)
9327 sig-list-o (verilog-signals-matching-regexp 9742 sig-list-o (verilog-signals-matching-dir-re
9328 sig-list-o regexp) 9743 (verilog-signals-matching-regexp sig-list-o regexp)
9329 sig-list-io (verilog-signals-matching-regexp 9744 "output" direction-re)
9330 sig-list-io regexp))) 9745 sig-list-io (verilog-signals-matching-dir-re
9746 (verilog-signals-matching-regexp sig-list-io regexp)
9747 "inout" direction-re)
9748 sig-list-if (verilog-signals-matching-dir-re
9749 (verilog-signals-matching-regexp sig-list-if regexp)
9750 "interface" direction-re))
9331 (when v2k (verilog-repair-open-comma)) 9751 (when v2k (verilog-repair-open-comma))
9332 (when (or sig-list-i sig-list-o sig-list-io) 9752 (when (or sig-list-i sig-list-o sig-list-io)
9333 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n") 9753 (verilog-insert-indent "// Beginning of automatic in/out/inouts (from specific module)\n")
9334 ;; Don't sort them so a upper AUTOINST will match the main module 9754 ;; Don't sort them so a upper AUTOINST will match the main module
9335 (verilog-insert-definition sig-list-o "output" indent-pt v2k t) 9755 (verilog-insert-definition sig-list-o "output" indent-pt v2k t)
9336 (verilog-insert-definition sig-list-io "inout" indent-pt v2k t) 9756 (verilog-insert-definition sig-list-io "inout" indent-pt v2k t)
9337 (verilog-insert-definition sig-list-i "input" indent-pt v2k t) 9757 (verilog-insert-definition sig-list-i "input" indent-pt v2k t)
9758 (verilog-insert-definition sig-list-if "interface" indent-pt v2k t)
9338 (verilog-modi-cache-add-inputs modi sig-list-i) 9759 (verilog-modi-cache-add-inputs modi sig-list-i)
9339 (verilog-modi-cache-add-outputs modi sig-list-o) 9760 (verilog-modi-cache-add-outputs modi sig-list-o)
9340 (verilog-modi-cache-add-inouts modi sig-list-io) 9761 (verilog-modi-cache-add-inouts modi sig-list-io)
9341 (verilog-insert-indent "// End of automatics\n")) 9762 (verilog-insert-indent "// End of automatics\n"))
9342 (when v2k (verilog-repair-close-comma))))))) 9763 (when v2k (verilog-repair-close-comma)))))))
9389 signals matching the regular expression will be included. For example the 9810 signals matching the regular expression will be included. For example the
9390 same expansion will result from only extracting signals starting with i: 9811 same expansion will result from only extracting signals starting with i:
9391 9812
9392 /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/" 9813 /*AUTOINOUTCOMP(\"ExampMain\",\"^i\")*/"
9393 (verilog-auto-inout-module t)) 9814 (verilog-auto-inout-module t))
9815
9816 (defun verilog-auto-insert-lisp ()
9817 "Expand AUTOINSERTLISP statements, as part of \\[verilog-auto].
9818 The Lisp code provided is called, and the Lisp code calls
9819 `insert` to insert text into the current file beginning on the
9820 line after the AUTOINSERTLISP.
9821
9822 See also AUTO_LISP, which takes a Lisp expression and evaluates
9823 it during `verilog-auto-inst' but does not insert any text.
9824
9825 An example:
9826
9827 module ExampInsertLisp;
9828 /*AUTOINSERTLISP(my-verilog-insert-hello \"world\")*/
9829 endmodule
9830
9831 // For this example we declare the function in the
9832 // module's file itself. Often you'd define it instead
9833 // in a site-start.el or .emacs file.
9834 /*
9835 Local Variables:
9836 eval:
9837 (defun my-verilog-insert-hello (who)
9838 (insert (concat \"initial $write(\\\"hello \" who \"\\\");\\n\")))
9839 End:
9840 */
9841
9842 Typing \\[verilog-auto] will call my-verilog-insert-hello and
9843 expand the above into:
9844
9845 // Beginning of automatic insert lisp
9846 initial $write(\"hello world\");
9847 // End of automatics
9848
9849 You can also call an external program and insert the returned
9850 text:
9851
9852 /*AUTOINSERTLISP(insert (shell-command-to-string \"echo //hello\"))*/
9853 // Beginning of automatic insert lisp
9854 //hello
9855 // End of automatics"
9856 (save-excursion
9857 ;; Point is at end of /*AUTO...*/
9858 (let* ((indent-pt (current-indentation))
9859 (cmd-end-pt (save-excursion (search-backward ")")
9860 (forward-char)
9861 (point))) ;; Closing paren
9862 (cmd-beg-pt (save-excursion (goto-char cmd-end-pt)
9863 (backward-sexp 1)
9864 (point))) ;; Beginning paren
9865 (cmd (buffer-substring-no-properties cmd-beg-pt cmd-end-pt)))
9866 (forward-line 1)
9867 (let ((pre-eval-pt (point)))
9868 ;;Debug: (insert cmd)
9869 ;; Don't use eval-region as Xemacs has a bug where it goto-char's begin-pt
9870 (eval (read cmd))
9871 ;; If inserted something add the begin/end blocks
9872 (when (not (equal pre-eval-pt (point)))
9873 (when (not (bolp)) (insert "\n")) ;; If user forgot final newline, add it
9874 (save-excursion
9875 (goto-char pre-eval-pt)
9876 (verilog-insert-indent "// Beginning of automatic insert lisp\n"))
9877 (verilog-insert-indent "// End of automatics\n"))))))
9394 9878
9395 (defun verilog-auto-sense-sigs (moddecls presense-sigs) 9879 (defun verilog-auto-sense-sigs (moddecls presense-sigs)
9396 "Return list of signals for current AUTOSENSE block." 9880 "Return list of signals for current AUTOSENSE block."
9397 (let* ((sigss (verilog-read-always-signals)) 9881 (let* ((sigss (verilog-read-always-signals))
9398 (sig-list (verilog-signals-not-params 9882 (sig-list (verilog-signals-not-params
9508 registers set elsewhere in the always block. 9992 registers set elsewhere in the always block.
9509 9993
9510 Limitations: 9994 Limitations:
9511 AUTORESET will not clear memories. 9995 AUTORESET will not clear memories.
9512 9996
9513 AUTORESET uses <= if there are any <= in the block, else it uses =. 9997 AUTORESET uses <= if there are any <= assigmnents in the block,
9998 else it uses =.
9514 9999
9515 /*AUTORESET*/ presumes that any signals mentioned between the previous 10000 /*AUTORESET*/ presumes that any signals mentioned between the previous
9516 begin/case/if statement and the AUTORESET comment are being reset manually 10001 begin/case/if statement and the AUTORESET comment are being reset manually
9517 and should not be automatically reset. This includes omitting any signals 10002 and should not be automatically reset. This includes omitting any signals
9518 used on the right hand side of assignments. 10003 used on the right hand side of assignments.
9768 doesn't care. 10253 doesn't care.
9769 10254
9770 Finally, a AUTOASCIIENUM command is used. 10255 Finally, a AUTOASCIIENUM command is used.
9771 10256
9772 The first parameter is the name of the signal to be decoded. 10257 The first parameter is the name of the signal to be decoded.
10258 If and only if the first parameter width is 2^(number of states
10259 in enum) and does NOT match the width of the enum, the signal
10260 is assumed to be a one hot decode. Otherwise, it's a normal
10261 encoded state vector.
9773 10262
9774 The second parameter is the name to store the ASCII code into. For the 10263 The second parameter is the name to store the ASCII code into. For the
9775 signal foo, I suggest the name _foo__ascii, where the leading _ indicates 10264 signal foo, I suggest the name _foo__ascii, where the leading _ indicates
9776 a signal that is just for simulation, and the magic characters _ascii 10265 a signal that is just for simulation, and the magic characters _ascii
9777 tell viewers like Dinotrace to display in ASCII format. 10266 tell viewers like Dinotrace to display in ASCII format.
9785 parameter [2:0] // synopsys enum state_info 10274 parameter [2:0] // synopsys enum state_info
9786 SM_IDLE = 3'b000, 10275 SM_IDLE = 3'b000,
9787 SM_SEND = 3'b001, 10276 SM_SEND = 3'b001,
9788 SM_WAIT1 = 3'b010; 10277 SM_WAIT1 = 3'b010;
9789 //== State variables 10278 //== State variables
9790 reg [2:0] /* synopsys enum state_info */ 10279 reg [2:0] /* synopsys enum state_info */
9791 state_r; /* synopsys state_vector state_r */ 10280 state_r; /* synopsys state_vector state_r */
9792 reg [2:0] /* synopsys enum state_info */ 10281 reg [2:0] /* synopsys enum state_info */
9793 state_e1; 10282 state_e1;
9794
9795 //== ASCII state decoding
9796 10283
9797 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/ 10284 /*AUTOASCIIENUM(\"state_r\", \"state_ascii_r\", \"SM_\")*/
9798 10285
9799 Typing \\[verilog-auto] will make this into: 10286 Typing \\[verilog-auto] will make this into:
9800 10287
9833 (undecode-sig (or (assoc undecode-name sig-list-all) 10320 (undecode-sig (or (assoc undecode-name sig-list-all)
9834 (error "%s: Signal %s not found in design" (verilog-point-text) undecode-name))) 10321 (error "%s: Signal %s not found in design" (verilog-point-text) undecode-name)))
9835 (undecode-enum (or (verilog-sig-enum undecode-sig) 10322 (undecode-enum (or (verilog-sig-enum undecode-sig)
9836 (error "%s: Signal %s does not have a enum tag" (verilog-point-text) undecode-name))) 10323 (error "%s: Signal %s does not have a enum tag" (verilog-point-text) undecode-name)))
9837 ;; 10324 ;;
9838 (enum-sigs (or (verilog-signals-matching-enum sig-list-consts undecode-enum) 10325 (enum-sigs (verilog-signals-not-in
9839 (error "%s: No state definitions for %s" (verilog-point-text) undecode-enum))) 10326 (or (verilog-signals-matching-enum sig-list-consts undecode-enum)
10327 (error "%s: No state definitions for %s" (verilog-point-text) undecode-enum))
10328 nil))
9840 ;; 10329 ;;
9841 (enum-chars 0) 10330 (one-hot (and ;; width(enum) != width(sig)
10331 (or (not (verilog-sig-bits (car enum-sigs)))
10332 (not (equal (verilog-sig-width (car enum-sigs))
10333 (verilog-sig-width undecode-sig))))
10334 ;; count(enums) == width(sig)
10335 (equal (number-to-string (length enum-sigs))
10336 (verilog-sig-width undecode-sig))))
10337 (enum-chars 0)
9842 (ascii-chars 0)) 10338 (ascii-chars 0))
9843 ;; 10339 ;;
9844 ;; Find number of ascii chars needed 10340 ;; Find number of ascii chars needed
9845 (let ((tmp-sigs enum-sigs)) 10341 (let ((tmp-sigs enum-sigs))
9846 (while tmp-sigs 10342 (while tmp-sigs
9862 (indent-to indent-pt) 10358 (indent-to indent-pt)
9863 (insert "case ({" undecode-name "})\n") 10359 (insert "case ({" undecode-name "})\n")
9864 (setq indent-pt (+ indent-pt verilog-case-indent)) 10360 (setq indent-pt (+ indent-pt verilog-case-indent))
9865 ;; 10361 ;;
9866 (let ((tmp-sigs enum-sigs) 10362 (let ((tmp-sigs enum-sigs)
9867 (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n" (1+ (max 8 enum-chars)) 10363 (chrfmt (format "%%-%ds %s = \"%%-%ds\";\n"
10364 (+ (if one-hot 9 1) (max 8 enum-chars))
9868 ascii-name ascii-chars)) 10365 ascii-name ascii-chars))
9869 (errname (substring "%Error" 0 (min 6 ascii-chars)))) 10366 (errname (substring "%Error" 0 (min 6 ascii-chars))))
9870 (while tmp-sigs 10367 (while tmp-sigs
9871 (verilog-insert-indent 10368 (verilog-insert-indent
9872 (format chrfmt (concat (verilog-sig-name (car tmp-sigs)) ":") 10369 (concat
9873 (verilog-enum-ascii (verilog-sig-name (car tmp-sigs)) 10370 (format chrfmt
9874 elim-regexp))) 10371 (concat (if one-hot "(")
10372 (if one-hot (verilog-sig-width undecode-sig))
10373 ;; We use a shift instead of var[index]
10374 ;; so that a non-one hot value will show as error.
10375 (if one-hot "'b1<<")
10376 (verilog-sig-name (car tmp-sigs))
10377 (if one-hot ")") ":")
10378 (verilog-enum-ascii (verilog-sig-name (car tmp-sigs))
10379 elim-regexp))))
9875 (setq tmp-sigs (cdr tmp-sigs))) 10380 (setq tmp-sigs (cdr tmp-sigs)))
9876 (verilog-insert-indent (format chrfmt "default:" errname))) 10381 (verilog-insert-indent (format chrfmt "default:" errname)))
9877 ;; 10382 ;;
9878 (setq indent-pt (- indent-pt verilog-case-indent)) 10383 (setq indent-pt (- indent-pt verilog-case-indent))
9879 (verilog-insert-indent "endcase\n") 10384 (verilog-insert-indent "endcase\n")
9944 `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding 10449 `verilog-auto-ascii-enum' for AUTOASCIIENUM enumeration decoding
9945 `verilog-auto-inout-comp' for AUTOINOUTCOMP copy complemented i/o 10450 `verilog-auto-inout-comp' for AUTOINOUTCOMP copy complemented i/o
9946 `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere 10451 `verilog-auto-inout-module' for AUTOINOUTMODULE copying i/o from elsewhere
9947 `verilog-auto-inout' for AUTOINOUT making hierarchy inouts 10452 `verilog-auto-inout' for AUTOINOUT making hierarchy inouts
9948 `verilog-auto-input' for AUTOINPUT making hierarchy inputs 10453 `verilog-auto-input' for AUTOINPUT making hierarchy inputs
10454 `verilog-auto-insert-lisp' for AUTOINSERTLISP insert code from lisp function
9949 `verilog-auto-inst' for AUTOINST instantiation pins 10455 `verilog-auto-inst' for AUTOINST instantiation pins
9950 `verilog-auto-star' for AUTOINST .* SystemVerilog pins 10456 `verilog-auto-star' for AUTOINST .* SystemVerilog pins
9951 `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params 10457 `verilog-auto-inst-param' for AUTOINSTPARAM instantiation params
9952 `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs 10458 `verilog-auto-output' for AUTOOUTPUT making hierarchy outputs
9953 `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs 10459 `verilog-auto-output-every' for AUTOOUTPUTEVERY making all outputs
9960 `verilog-auto-wire' for AUTOWIRE instantiation wires 10466 `verilog-auto-wire' for AUTOWIRE instantiation wires
9961 10467
9962 `verilog-read-defines' for reading `define values 10468 `verilog-read-defines' for reading `define values
9963 `verilog-read-includes' for reading `includes 10469 `verilog-read-includes' for reading `includes
9964 10470
9965 If you have bugs with these autos, try contacting the AUTOAUTHOR 10471 If you have bugs with these autos, please file an issue at
9966 Wilson Snyder (wsnyder@wsnyder.org), and/or see http://www.veripool.org." 10472 http://www.veripool.org/verilog-mode or contact the AUTOAUTHOR
10473 Wilson Snyder (wsnyder@wsnyder.org)."
9967 (interactive) 10474 (interactive)
9968 (unless noninteractive (message "Updating AUTOs...")) 10475 (unless noninteractive (message "Updating AUTOs..."))
9969 (if (fboundp 'dinotrace-unannotate-all) 10476 (if (fboundp 'dinotrace-unannotate-all)
9970 (dinotrace-unannotate-all)) 10477 (dinotrace-unannotate-all))
9971 (let ((oldbuf (if (not (buffer-modified-p)) 10478 (let ((oldbuf (if (not (buffer-modified-p))
10004 (when inject 10511 (when inject
10005 (verilog-inject-inst) 10512 (verilog-inject-inst)
10006 (verilog-inject-sense) 10513 (verilog-inject-sense)
10007 (verilog-inject-arg)) 10514 (verilog-inject-arg))
10008 ;; 10515 ;;
10516 ;; Do user inserts first, so their code can insert AUTOs
10517 ;; We may provide a AUTOINSERTLISPLAST if another cleanup pass is needed
10518 (verilog-auto-re-search-do "/\\*AUTOINSERTLISP(.*?)\\*/"
10519 'verilog-auto-insert-lisp)
10520 ;; Expand instances before need the signals the instances input/output
10009 (verilog-auto-re-search-do "/\\*AUTOINSTPARAM\\*/" 'verilog-auto-inst-param) 10521 (verilog-auto-re-search-do "/\\*AUTOINSTPARAM\\*/" 'verilog-auto-inst-param)
10010 (verilog-auto-re-search-do "/\\*AUTOINST\\*/" 'verilog-auto-inst) 10522 (verilog-auto-re-search-do "/\\*AUTOINST\\*/" 'verilog-auto-inst)
10011 (verilog-auto-re-search-do "\\.\\*" 'verilog-auto-star) 10523 (verilog-auto-re-search-do "\\.\\*" 'verilog-auto-star)
10012 ;; Doesn't matter when done, but combine it with a common changer 10524 ;; Doesn't matter when done, but combine it with a common changer
10013 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense) 10525 (verilog-auto-re-search-do "/\\*\\(AUTOSENSE\\|AS\\)\\*/" 'verilog-auto-sense)
10156 (setq verilog-sk-p (point)) 10668 (setq verilog-sk-p (point))
10157 (verilog-sk-prompt-msb) 10669 (verilog-sk-prompt-msb)
10158 (if (> (point) verilog-sk-p) "] " " "))) 10670 (if (> (point) verilog-sk-p) "] " " ")))
10159 10671
10160 (defun verilog-sk-header () 10672 (defun verilog-sk-header ()
10161 "Insert a descriptive header at the top of the file." 10673 "Insert a descriptive header at the top of the file.
10674 See also `verilog-header' for an alternative format."
10162 (interactive "*") 10675 (interactive "*")
10163 (save-excursion 10676 (save-excursion
10164 (goto-char (point-min)) 10677 (goto-char (point-min))
10165 (verilog-sk-header-tmpl))) 10678 (verilog-sk-header-tmpl)))
10166 10679
10170 "// -*- Mode: Verilog -*-" 10683 "// -*- Mode: Verilog -*-"
10171 "\n// Filename : " (buffer-name) 10684 "\n// Filename : " (buffer-name)
10172 "\n// Description : " str 10685 "\n// Description : " str
10173 "\n// Author : " (user-full-name) 10686 "\n// Author : " (user-full-name)
10174 "\n// Created On : " (current-time-string) 10687 "\n// Created On : " (current-time-string)
10175 "\n// Last Modified By: ." 10688 "\n// Last Modified By: " (user-full-name)
10176 "\n// Last Modified On: ." 10689 "\n// Last Modified On: " (current-time-string)
10177 "\n// Update Count : 0" 10690 "\n// Update Count : 0"
10178 "\n// Status : Unknown, Use with caution!" 10691 "\n// Status : Unknown, Use with caution!"
10179 "\n") 10692 "\n")
10180 10693
10181 (define-skeleton verilog-sk-module 10694 (define-skeleton verilog-sk-module
10267 (define-skeleton verilog-sk-case 10780 (define-skeleton verilog-sk-case
10268 "Build skeleton case statement, prompting for the selector expression, 10781 "Build skeleton case statement, prompting for the selector expression,
10269 and the case items." 10782 and the case items."
10270 "[selector expression]: " 10783 "[selector expression]: "
10271 > "case (" str ") " \n 10784 > "case (" str ") " \n
10272 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n ) 10785 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
10273 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)) 10786 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
10274 10787
10275 (define-skeleton verilog-sk-casex 10788 (define-skeleton verilog-sk-casex
10276 "Build skeleton casex statement, prompting for the selector expression, 10789 "Build skeleton casex statement, prompting for the selector expression,
10277 and the case items." 10790 and the case items."
10278 "[selector expression]: " 10791 "[selector expression]: "
10279 > "casex (" str ") " \n 10792 > "casex (" str ") " \n
10280 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n ) 10793 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
10281 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)) 10794 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
10282 10795
10283 (define-skeleton verilog-sk-casez 10796 (define-skeleton verilog-sk-casez
10284 "Build skeleton casez statement, prompting for the selector expression, 10797 "Build skeleton casez statement, prompting for the selector expression,
10285 and the case items." 10798 and the case items."
10286 "[selector expression]: " 10799 "[selector expression]: "
10287 > "casez (" str ") " \n 10800 > "casez (" str ") " \n
10288 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n ) 10801 > ("case selector: " str ": begin" \n > _ \n > (- verilog-indent-level-behavioral) "end" \n > )
10289 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil)) 10802 resume: > (- verilog-case-indent) "endcase" (progn (electric-verilog-terminate-line) nil))
10290 10803
10291 (define-skeleton verilog-sk-if 10804 (define-skeleton verilog-sk-if
10292 "Insert a skeleton if statement." 10805 "Insert a skeleton if statement."
10293 > "if (" '(verilog-sk-prompt-condition) & ")" " begin" \n 10806 > "if (" '(verilog-sk-prompt-condition) & ")" " begin" \n