comparison lisp/progmodes/verilog-mode.el @ 80171:97019d686b43

* progmodes/verilog-mode.el (verilog-xemacs-menu): Remove XEmacs conditional. (verilog-font-grouping-keywords-face): Make the begin..end keywords standout more than other verilog keywords. (verilog-type-font-keywords): Move the begin..end out of this list to facilitate making them to (potentially) stand out more. (verilog-backward-token): Fix indent of bare always{_*}?, initial, function & task blocks. (verilog-behavioral-block-beg-re): Fix indent of bare always{_*}?, initial, function & task blocks. (verilog-forward-sexp): Handle the new "disable fork" statement of IEEE-1800 Verilog. (verilog-beg-block-re-ordered): Handle the new "disable fork" statement of IEEE-1800 Verilog. (verilog-calc-1): Handle the new "disable fork" statement of IEEE-1800 Verilog. (verilog-disable-fork-re): Add const to help handle the new "disable fork" statement of IEEE-1800 Verilog. (verilog-declaration-core-re): Add port directions by themselves, with no qualification, as base item of a declaration. (verilog-pretty-declarations): Add new flag to ask it to refrain from printing to the message buffer. (verilog-pretty-expr): Add a QUIET flag to ask it to refrain from printing to the message buffer. Improve handling of the many types of expression line up. (verilog-just-one-space): Remove printing of an empty message. (verilog-get-lineup-indent): Rework to support the better handling of expression lineup for verilog-pretty-expr. (verilog-auto-wire): Pass the quiet flag to verilog-pretty-expr.
author Dan Nicolaescu <dann@ics.uci.edu>
date Thu, 21 Feb 2008 05:15:31 +0000
parents 411da0873a97
children 7d8f87158250
comparison
equal deleted inserted replaced
80170:3e4f6980296d 80171:97019d686b43
113 ;; (This section is required to appease checkdoc.) 113 ;; (This section is required to appease checkdoc.)
114 114
115 ;;; Code: 115 ;;; Code:
116 116
117 ;; This variable will always hold the version number of the mode 117 ;; This variable will always hold the version number of the mode
118 (defconst verilog-mode-version "389" 118 (defconst verilog-mode-version "399"
119 "Version of this Verilog mode.") 119 "Version of this Verilog mode.")
120 (defconst verilog-mode-release-date "2008-02-01-GNU" 120 (defconst verilog-mode-release-date "2008-02-19-GNU"
121 "Release date of this Verilog mode.") 121 "Release date of this Verilog mode.")
122 (defconst verilog-mode-release-emacs t 122 (defconst verilog-mode-release-emacs t
123 "If non-nil, this version of Verilog mode was released with Emacs itself.") 123 "If non-nil, this version of Verilog mode was released with Emacs itself.")
124 124
125 (defun verilog-version () 125 (defun verilog-version ()
990 (verilog-set-compile-command)) 990 (verilog-set-compile-command))
991 :style radio 991 :style radio
992 :selected (equal verilog-tool `verilog-compiler)] 992 :selected (equal verilog-tool `verilog-compiler)]
993 ) 993 )
994 ("Move" 994 ("Move"
995 ,(if (featurep 'xemacs) 995 ["Beginning of function" verilog-beg-of-defun t]
996 (progn 996 ["End of function" verilog-end-of-defun t]
997 ["Beginning of function" verilog-beg-of-defun t] 997 ["Mark function" verilog-mark-defun t]
998 ["End of function" verilog-end-of-defun t]
999 ["Mark function" verilog-mark-defun t])
1000 ["Beginning of function" beginning-of-defun t]
1001 ["End of function" end-of-defun t]
1002 ["Mark function" mark-defun t])
1003
1004 ["Goto function/module" verilog-goto-defun t] 998 ["Goto function/module" verilog-goto-defun t]
1005 ["Move to beginning of block" electric-verilog-backward-sexp t] 999 ["Move to beginning of block" electric-verilog-backward-sexp t]
1006 ["Move to end of block" electric-verilog-forward-sexp t] 1000 ["Move to end of block" electric-verilog-forward-sexp t]
1007 ) 1001 )
1008 ("Comments" 1002 ("Comments"
1449 ;; verilog-forward-sexp and verilog-calc-indent 1443 ;; verilog-forward-sexp and verilog-calc-indent
1450 1444
1451 (defconst verilog-beg-block-re-ordered 1445 (defconst verilog-beg-block-re-ordered
1452 ( concat "\\<" 1446 ( concat "\\<"
1453 "\\(begin\\)" ;1 1447 "\\(begin\\)" ;1
1454 "\\|\\(randcase\\|\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)" ; 2 1448 "\\|\\(randcase\\|\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?\\)" ; 2,3
1455 ;; "\\|\\(randcase\\|case[xz]?\\)" ; 2 1449 "\\|\\(\\(disable\\s-+\\)?fork\\)" ;4
1456 "\\|\\(fork\\)" ;3 1450 "\\|\\(class\\)" ;5
1457 "\\|\\(class\\)" ;4 1451 "\\|\\(table\\)" ;6
1458 "\\|\\(table\\)" ;5 1452 "\\|\\(specify\\)" ;7
1459 "\\|\\(specify\\)" ;6 1453 "\\|\\(function\\)" ;8
1460 "\\|\\(function\\)" ;7 1454 "\\|\\(task\\)" ;9
1461 "\\|\\(task\\)" ;8 1455 "\\|\\(generate\\)" ;10
1462 "\\|\\(generate\\)" ;9 1456 "\\|\\(covergroup\\)" ;11
1463 "\\|\\(covergroup\\)" ;10 1457 "\\|\\(property\\)" ;12
1464 "\\|\\(property\\)" ;11 1458 "\\|\\(\\(rand\\)?sequence\\)" ;13
1465 "\\|\\(\\(rand\\)?sequence\\)" ;12 1459 "\\|\\(clocking\\)" ;14
1466 "\\|\\(clocking\\)" ;13
1467 "\\>")) 1460 "\\>"))
1468 1461
1469 (defconst verilog-end-block-ordered-rry 1462 (defconst verilog-end-block-ordered-rry
1470 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" 1463 [ "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)\\|\\(\\<endcase\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)"
1471 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)" 1464 "\\(\\<randcase\\>\\|\\<case[xz]?\\>\\)\\|\\(\\<endcase\\>\\)"
1572 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig")))) 1565 (eval-when-compile (verilog-regexp-words `("endmodule" "endclass" "endprogram" "endinterface" "endpackage" "endprimitive" "endconfig"))))
1573 (defconst verilog-zero-indent-re 1566 (defconst verilog-zero-indent-re
1574 (concat verilog-defun-re "\\|" verilog-end-defun-re)) 1567 (concat verilog-defun-re "\\|" verilog-end-defun-re))
1575 1568
1576 (defconst verilog-behavioral-block-beg-re 1569 (defconst verilog-behavioral-block-beg-re
1577 (concat "\\(\\<initial\\>\\|\\<final\\>\\|\\<always\\>\\|\\<always_comb\\>\\|\\<always_ff\\>\\|" 1570 (eval-when-compile (verilog-regexp-words `("initial" "final" "always" "always_comb" "always_latch" "always_ff"
1578 "\\<always_latch\\>\\|\\<function\\>\\|\\<task\\>\\)")) 1571 "function" "task"))))
1579 1572
1580 (defconst verilog-indent-re 1573 (defconst verilog-indent-re
1581 (eval-when-compile 1574 (eval-when-compile
1582 (verilog-regexp-words 1575 (verilog-regexp-words
1583 `( 1576 `(
1638 (eval-when-compile 1631 (eval-when-compile
1639 (verilog-regexp-words 1632 (verilog-regexp-words
1640 `( 1633 `(
1641 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass" 1634 "endmodule" "endprimitive" "endinterface" "endpackage" "endprogram" "endclass"
1642 )))) 1635 ))))
1636 (defconst verilog-disable-fork-re "disable\\s-+fork")
1643 (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?") 1637 (defconst verilog-extended-case-re "\\(unique\\s-+\\|priority\\s-+\\)?case[xz]?")
1644 (defconst verilog-extended-complete-re 1638 (defconst verilog-extended-complete-re
1645 (concat "\\(\\<extern\\s-+\\|\\<virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)" 1639 (concat "\\(\\<extern\\s-+\\|\\<virtual\\s-+\\|\\<protected\\s-+\\)*\\(\\<function\\>\\|\\<task\\>\\)"
1646 "\\|\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)" 1640 "\\|\\(\\<typedef\\>\\s-+\\)*\\(\\<struct\\>\\|\\<union\\>\\|\\<class\\>\\)"
1647 "\\|" verilog-extended-case-re )) 1641 "\\|" verilog-extended-case-re ))
1813 (:foreground "orange1" :bold t )) 1807 (:foreground "orange1" :bold t ))
1814 (t (:italic t))) 1808 (t (:italic t)))
1815 "Font lock mode face used to highlight AMS keywords." 1809 "Font lock mode face used to highlight AMS keywords."
1816 :group 'font-lock-highlighting-faces) 1810 :group 'font-lock-highlighting-faces)
1817 1811
1812 (defvar verilog-font-grouping-keywords-face
1813 'verilog-font-lock-grouping-keywords-face
1814 "Font to use for Verilog Grouping Keywords (such as begin..end).")
1815 (defface verilog-font-lock-grouping-keywords-face
1816 '((((class color)
1817 (background light))
1818 (:foreground "red4" :bold t ))
1819 (((class color)
1820 (background dark))
1821 (:foreground "red4" :bold t ))
1822 (t (:italic t)))
1823 "Font lock mode face used to highlight verilog grouping keywords."
1824 :group 'font-lock-highlighting-faces)
1825
1818 (let* ((verilog-type-font-keywords 1826 (let* ((verilog-type-font-keywords
1819 (eval-when-compile 1827 (eval-when-compile
1820 (verilog-regexp-opt 1828 (verilog-regexp-opt
1821 '( 1829 '(
1822 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam" 1830 "and" "bit" "buf" "bufif0" "bufif1" "cmos" "defparam"
1877 1885
1878 (verilog-font-keywords 1886 (verilog-font-keywords
1879 (eval-when-compile 1887 (eval-when-compile
1880 (verilog-regexp-opt 1888 (verilog-regexp-opt
1881 '( 1889 '(
1882 "assign" "begin" "case" "casex" "casez" "randcase" "deassign" 1890 "assign" "case" "casex" "casez" "randcase" "deassign"
1883 "default" "disable" "else" "end" "endcase" "endfunction" 1891 "default" "disable" "else" "endcase" "endfunction"
1884 "endgenerate" "endinterface" "endmodule" "endprimitive" 1892 "endgenerate" "endinterface" "endmodule" "endprimitive"
1885 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break" 1893 "endspecify" "endtable" "endtask" "final" "for" "force" "return" "break"
1886 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial" 1894 "continue" "forever" "fork" "function" "generate" "if" "iff" "initial"
1887 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge" 1895 "interface" "join" "join_any" "join_none" "macromodule" "module" "negedge"
1888 "package" "endpackage" "always" "always_comb" "always_ff" 1896 "package" "endpackage" "always" "always_comb" "always_ff"
1889 "always_latch" "posedge" "primitive" "priority" "release" 1897 "always_latch" "posedge" "primitive" "priority" "release"
1890 "repeat" "specify" "table" "task" "unique" "wait" "while" 1898 "repeat" "specify" "table" "task" "unique" "wait" "while"
1891 "class" "program" "endclass" "endprogram" 1899 "class" "program" "endclass" "endprogram"
1892 ) nil )))) 1900 ) nil )))
1901
1902 (verilog-font-grouping-keywords
1903 (eval-when-compile
1904 (verilog-regexp-opt
1905 '( "begin" "end" ) nil ))))
1893 1906
1894 (setq verilog-font-lock-keywords 1907 (setq verilog-font-lock-keywords
1895 (list 1908 (list
1896 ;; Fontify all builtin keywords 1909 ;; Fontify all builtin keywords
1897 (concat "\\<\\(" verilog-font-keywords "\\|" 1910 (concat "\\<\\(" verilog-font-keywords "\\|"
1898 ;; And user/system tasks and functions 1911 ;; And user/system tasks and functions
1899 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*" 1912 "\\$[a-zA-Z][a-zA-Z0-9_\\$]*"
1900 "\\)\\>") 1913 "\\)\\>")
1901 ;; Fontify all types 1914 ;; Fontify all types
1902 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>") 1915 (cons (concat "\\(\\<" verilog-font-grouping-keywords "\\)\\>")
1916 'verilog-font-lock-ams-face)
1917 (cons (concat "\\<\\(" verilog-type-font-keywords "\\)\\>")
1903 'font-lock-type-face) 1918 'font-lock-type-face)
1904 ;; Fontify IEEE-P1800 keywords appropriately 1919 ;; Fontify IEEE-P1800 keywords appropriately
1905 (if verilog-highlight-p1800-keywords 1920 (if verilog-highlight-p1800-keywords
1906 (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>") 1921 (cons (concat "\\<\\(" verilog-p1800-keywords "\\)\\>")
1907 'verilog-font-lock-p1800-face) 1922 'verilog-font-lock-p1800-face)
2064 (if (not (looking-at "\\<")) 2079 (if (not (looking-at "\\<"))
2065 (forward-word -1)) 2080 (forward-word -1))
2066 (cond 2081 (cond
2067 ((verilog-skip-forward-comment-or-string) 2082 ((verilog-skip-forward-comment-or-string)
2068 (verilog-forward-syntactic-ws)) 2083 (verilog-forward-syntactic-ws))
2069 ((looking-at verilog-beg-block-re-ordered);; begin|case|fork|class|table|specify|function|task|generate|covergroup|property|sequence|clocking 2084 ((looking-at verilog-beg-block-re-ordered) ;; begin|(case)|xx|(fork)|class|table|specify|function|task|generate|covergroup|property|sequence|clocking
2070 (cond 2085 (cond
2071 ((match-end 1) ; end 2086 ((match-end 1) ; end
2072 ;; Search forward for matching begin 2087 ;; Search forward for matching begin
2073 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" )) 2088 (setq reg "\\(\\<begin\\>\\)\\|\\(\\<end\\>\\)" ))
2074 ((match-end 2) ; endcase 2089 ((match-end 2) ; endcase
2075 ;; Search forward for matching case 2090 ;; Search forward for matching case
2076 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )) 2091 (setq reg "\\(\\<randcase\\>\\|\\(\\<unique\\>\\s-+\\|\\<priority\\>\\s-+\\)?\\<case[xz]?\\>[^:]\\)\\|\\(\\<endcase\\>\\)" )
2077 ((match-end 3) ; join 2092 (setq md 3) ;; ender is third item in regexp
2078 ;; Search forward for matching fork 2093 )
2079 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" )) 2094 ((match-end 4) ; join
2080 ((match-end 4) ; endclass 2095 ;; might be "disable fork"
2096 (if (or
2097 (looking-at verilog-disable-fork-re)
2098 (and (looking-at "fork")
2099 (progn
2100 (forward-word -1)
2101 (looking-at verilog-disable-fork-re))))
2102 (progn
2103 (goto-char (match-end 0))
2104 (forward-word)
2105 (setq reg nil))
2106 (progn
2107 ;; Search forward for matching fork
2108 (setq reg "\\(\\<fork\\>\\)\\|\\(\\<join\\(_any\\|_none\\)?\\>\\)" ))))
2109 ((match-end 5) ; endclass
2081 ;; Search forward for matching class 2110 ;; Search forward for matching class
2082 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" )) 2111 (setq reg "\\(\\<class\\>\\)\\|\\(\\<endclass\\>\\)" ))
2083 ((match-end 5) ; endtable 2112 ((match-end 6) ; endtable
2084 ;; Search forward for matching table 2113 ;; Search forward for matching table
2085 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" )) 2114 (setq reg "\\(\\<table\\>\\)\\|\\(\\<endtable\\>\\)" ))
2086 ((match-end 6) ; endspecify 2115 ((match-end 7) ; endspecify
2087 ;; Search forward for matching specify 2116 ;; Search forward for matching specify
2088 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" )) 2117 (setq reg "\\(\\<specify\\>\\)\\|\\(\\<endspecify\\>\\)" ))
2089 ((match-end 7) ; endfunction 2118 ((match-end 8) ; endfunction
2090 ;; Search forward for matching function 2119 ;; Search forward for matching function
2091 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" )) 2120 (setq reg "\\(\\<function\\>\\)\\|\\(\\<endfunction\\>\\)" ))
2092 ((match-end 8) ; endtask 2121 ((match-end 9) ; endtask
2093 ;; Search forward for matching task 2122 ;; Search forward for matching task
2094 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" )) 2123 (setq reg "\\(\\<task\\>\\)\\|\\(\\<endtask\\>\\)" ))
2095 ((match-end 9) ; endgenerate 2124 ((match-end 10) ; endgenerate
2096 ;; Search forward for matching generate 2125 ;; Search forward for matching generate
2097 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" )) 2126 (setq reg "\\(\\<generate\\>\\)\\|\\(\\<endgenerate\\>\\)" ))
2098 ((match-end 10) ; endgroup 2127 ((match-end 11) ; endgroup
2099 ;; Search forward for matching covergroup 2128 ;; Search forward for matching covergroup
2100 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" )) 2129 (setq reg "\\(\\<covergroup\\>\\)\\|\\(\\<endgroup\\>\\)" ))
2101 ((match-end 11) ; endproperty 2130 ((match-end 12) ; endproperty
2102 ;; Search forward for matching property 2131 ;; Search forward for matching property
2103 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" )) 2132 (setq reg "\\(\\<property\\>\\)\\|\\(\\<endproperty\\>\\)" ))
2104 ((match-end 12) ; endsequence 2133 ((match-end 13) ; endsequence
2105 ;; Search forward for matching sequence 2134 ;; Search forward for matching sequence
2106 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" ) 2135 (setq reg "\\(\\<\\(rand\\)?sequence\\>\\)\\|\\(\\<endsequence\\>\\)" )
2107 (setq md 3)) ; 3 to get to endsequence in the reg above 2136 (setq md 3)) ; 3 to get to endsequence in the reg above
2108 ((match-end 13) ; endclocking 2137 ((match-end 14) ; endclocking
2109 ;; Search forward for matching clocking 2138 ;; Search forward for matching clocking
2110 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" ))) 2139 (setq reg "\\(\\<clocking\\>\\)\\|\\(\\<endclocking\\>\\)" )))
2111 (if (forward-word 1) 2140 (if (and reg
2141 (forward-word 1))
2112 (catch 'skip 2142 (catch 'skip
2113 (let ((nest 1)) 2143 (let ((nest 1))
2114 (while (verilog-re-search-forward reg nil 'move) 2144 (while (verilog-re-search-forward reg nil 'move)
2115 (cond 2145 (cond
2116 ((match-end md) ; the closer in reg, so we are climbing out 2146 ((match-end md) ; the closer in reg, so we are climbing out
3932 (verilog-beg-of-statement) 3962 (verilog-beg-of-statement)
3933 (if (looking-at verilog-extended-case-re) 3963 (if (looking-at verilog-extended-case-re)
3934 (throw 'nesting 'case) 3964 (throw 'nesting 'case)
3935 (goto-char here))) 3965 (goto-char here)))
3936 (throw 'nesting 'case)) 3966 (throw 'nesting 'case))
3967
3968 ((match-end 4) ; *sigh* could be "disable fork"
3969 (let ((here (point)))
3970 (verilog-beg-of-statement)
3971 (if (looking-at verilog-disable-fork-re)
3972 t ; is disable fork, this is a normal statement
3973 (progn ; or is fork, starts a new block
3974 (goto-char here)
3975 (throw 'nesting 'block)))))
3976
3937 3977
3938 ;; need to consider typedef struct here... 3978 ;; need to consider typedef struct here...
3939 ((looking-at "\\<class\\|struct\\|function\\|task\\|property\\>") 3979 ((looking-at "\\<class\\|struct\\|function\\|task\\|property\\>")
3940 ; *sigh* These words have an optional prefix: 3980 ; *sigh* These words have an optional prefix:
3941 ; extern {virtual|protected}? function a(); 3981 ; extern {virtual|protected}? function a();
4166 (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete 4206 (;-- any of begin|initial|while are complete statements; 'begin : foo' is also complete
4167 t 4207 t
4168 (forward-word -1) 4208 (forward-word -1)
4169 (cond 4209 (cond
4170 ((looking-at "\\<else\\>") 4210 ((looking-at "\\<else\\>")
4211 t)
4212 ((looking-at verilog-behavioral-block-beg-re)
4171 t) 4213 t)
4172 ((looking-at verilog-indent-re) 4214 ((looking-at verilog-indent-re)
4173 nil) 4215 nil)
4174 (t 4216 (t
4175 (let 4217 (let