├── LICENSE ├── README.md ├── ftdetect └── systemverilog.vim ├── ftplugin └── systemverilog.vim ├── indent └── systemverilog.vim └── syntax └── systemverilog.vim /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SystemVerilog 2 | ============ 3 | Author: WeiChung Wu 4 | 5 | Support SystemVerilog: indent, syntax highlight, matchit 6 | 7 | ##About 8 | 9 | The **syntax** file is modified from **Vera** syntax highlighting. 10 | The **indent** file is modified from **Verilog** indent file. 11 | 12 | 13 | * * * 14 | Installation 15 | ---------------- 16 | 17 | ###With [Pathogen](https://github.com/tpope/vim-pathogen) 18 | 19 | Check out from github 20 | 21 | cd ~/.vim/bundle 22 | git clone git://github.com/WeiChungWu/vim-SystemVerilog.git 23 | 24 | ###Manual install details 25 | Copy all files into your personal vim directory, keeping the directory structure. 26 | 27 | * Ex. 28 | copy `ftdetect/systemverilog.vim` to `~/.vim/ftdetect` 29 | copy `ftplugin/systemverilog.vim` to `~/.vim/ftplugin` 30 | copy `indent/systemverilog.vim` to `~/.vim/indent` 31 | copy `syntax/systemverilog.vim` to `~/.vim/syntax` 32 | -------------------------------------------------------------------------------- /ftdetect/systemverilog.vim: -------------------------------------------------------------------------------- 1 | au BufNewFile,BufRead *.sv,*.svi,*.svh set filetype=systemverilog 2 | -------------------------------------------------------------------------------- /ftplugin/systemverilog.vim: -------------------------------------------------------------------------------- 1 | " Vim filetype plugin file 2 | " Language: SystemVerilog 3 | " Maintainer: WeiChung Wu 4 | " Last Change: Thu Jan 13 13:05:54 CST 2011 5 | 6 | " Only do this when not done yet for this buffer 7 | if exists("b:did_ftplugin") 8 | finish 9 | endif 10 | 11 | " Don't load another plugin for this buffer 12 | let b:did_ftplugin = 1 13 | 14 | " Undo the plugin effect 15 | let b:undo_ftplugin = "setlocal fo< com< tw<" 16 | \ . "| unlet! b:browsefilter b:match_ignorecase b:match_words" 17 | 18 | " Set 'formatoptions' to break comment lines but not other lines, 19 | " and insert the comment leader when hitting or using "o". 20 | setlocal fo-=t fo+=croqlm1 21 | 22 | " Set 'comments' to format dashed lists in comments. 23 | setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:// 24 | 25 | " Format comments to be up to 78 characters long 26 | "if &textwidth == 0 27 | " setlocal tw=78 28 | "endif 29 | 30 | set cpo-=C 31 | 32 | " Win32 can filter files in the browse dialog 33 | "if has("gui_win32") && !exists("b:browsefilter") 34 | " let b:browsefilter = "Verilog Source Files (*.v)\t*.v\n" . 35 | " \ "All Files (*.*)\t*.*\n" 36 | "endif 37 | 38 | " Let the matchit plugin know what items can be matched. 39 | if exists("loaded_matchit") 40 | let b:match_ignorecase=0 41 | let b:match_words= 42 | \ '\:\,' . 43 | \ '\:\,' . 44 | \ '`if\%[n]def\>:`els\%(if\|e\)\>:`endif\>,' . 45 | \ '\\|\:\,' . 46 | \ '\%(disable\s\+\)\@:\<\%(join_none\|join_any\|join\)\>,' . 47 | \ '\:\,' . 48 | \ '\:\:\,' . 49 | \ '\:\,' . 50 | \ '\:\,' . 51 | \ '\:\,' . 52 | \ '\:\,' . 53 | \ '\:\,' . 54 | \ '\:\,' . 55 | \ '\:\,' . 56 | \ '\:\,' . 57 | \ '\:\,' . 58 | \ '\:\,' . 59 | \ '\:\,' . 60 | \ '`uvm_object\%(_param\)\=_utils_begin\>:`uvm_object_utils_end\>,' . 61 | \ '`uvm_component\%(_param\)\=_utils_begin\>:`uvm_component_utils_end\>' 62 | endif 63 | -------------------------------------------------------------------------------- /indent/systemverilog.vim: -------------------------------------------------------------------------------- 1 | " Language: SystemVerilog 2 | " Maintainer: WeiChung Wu 3 | " Last Change: Thu Aug 22 18:53:42 CST 2011 4 | " 5 | " Credits: 6 | " Originally created by 7 | " Chih-Tsun Huang 8 | " http://larc.ee.nthu.edu.tw/~cthuang/vim/indent/verilog.vim 9 | " 10 | " Buffer Variables: 11 | " b:sv_indent_modules : indenting after the declaration 12 | " of module blocks 13 | " b:sv_indent_width : indenting width 14 | " b:sv_indent_verbose : verbose to each indenting 15 | " 16 | " Revision Comments: 17 | " 18 | 19 | " Only load this indent file when no other was loaded. 20 | if exists("b:did_indent") 21 | finish 22 | endif 23 | let b:did_indent = 1 24 | 25 | setlocal indentexpr=GetSystemVerilogIndent() 26 | setlocal indentkeys=!^F,o,O,0),0},=begin,=end,=join,=endcase,=join_any,=join_none 27 | setlocal indentkeys+==endmodule,=endfunction,=endtask,=endspecify 28 | setlocal indentkeys+==endclass,=endpackage,=endsequence,=endclocking 29 | setlocal indentkeys+==endinterface,=endgroup,=endprogram,=endproperty 30 | setlocal indentkeys+==endgenerate 31 | setlocal indentkeys+==`else,=`endif 32 | 33 | " Only define the function once. 34 | if exists("*GetSystemVerilogIndent") 35 | finish 36 | endif 37 | 38 | set cpo-=C 39 | 40 | " Check if the column is a comment 41 | function s:IsSVColComment(lnum, cnum) 42 | let rc = synIDattr(synID(a:lnum, a:cnum, 0), "name") =~? 'comment\|string' 43 | return rc 44 | endfunction 45 | 46 | " Check if the line is a fully comment, or part of comment 47 | function s:IsSVLineComment(lnum) 48 | let line = getline(a:lnum) 49 | let rc = (line =~ '^\s*\/\/' || 50 | \ ( s:IsSVColComment(a:lnum, match(line,'\S')+1) && 51 | \ ((line !~ '\*\/\s*\S') || 52 | \ (line =~ '\*\/\s*\S' && s:IsSVColComment(a:lnum, matchend(line,'\*\/\s*\S'))) 53 | \ ) 54 | \ )) ? 1: 0 55 | return rc 56 | endfunction 57 | 58 | function s:PrevNonBlankNonComment(lnum) 59 | let lnum = prevnonblank(a:lnum) 60 | while lnum > 0 61 | if 0 == s:IsSVLineComment(lnum) 62 | break 63 | endif 64 | let lnum = prevnonblank(lnum - 1) 65 | endwhile 66 | return lnum 67 | endfunction 68 | 69 | function s:RemoveSVComment(line) 70 | let myline = substitute(a:line,'\%(\/\/.*\|\/\*.*\*\/\s*\)',"","g") 71 | let myline = substitute(myline,'\%(^.*\*\/\|\/\*.*$\)',"","g") 72 | let myline = substitute(myline,'^\s*',"","") 73 | "let myline = substitute(myline,'\s*\/\s*$',"","") "remove \ 74 | return myline 75 | endfunction 76 | 77 | function s:GetSVBlockStart(keyword, curr_lnum, mode) 78 | let lnum = a:curr_lnum 79 | let pmid = '' 80 | if a:keyword =~ '\' 81 | let pend = '\' 82 | let pstart = '\' 83 | elseif a:keyword =~ '`\@' 84 | let pend = '\' 85 | let pstart = '\' 86 | elseif a:keyword =~ 'join' 87 | let pend = '\<\%(join\|join_any\|join_none\)\>' 88 | let pstart = '\%(disable\s\+\)\@' 89 | elseif a:keyword =~ ')' 90 | let pend = ')' 91 | let pstart = '(' 92 | elseif a:keyword =~ '}' 93 | let pend = '}' 94 | let pstart = '{' 95 | elseif a:keyword =~ '\' 96 | let pend = '\' 97 | let pstart = '\<\%(case\%[zx]\|randcase\)\>' 98 | elseif a:keyword =~ '\' 99 | let pend = '\' 100 | let pstart = '\' 101 | elseif a:keyword =~ '\' 102 | let pend = '\' 103 | let pstart = '\' 104 | elseif a:keyword =~ '`else' 105 | let pend = '`else' 106 | let pstart = '`if\%[n]def' 107 | elseif a:keyword =~ '`endif' 108 | let pend = '`endif' 109 | let pstart = '`if\%[n]def' 110 | let pmid = '`else' 111 | elseif a:keyword =~ '`uvm_object_utils_end\>' 112 | let pend = '`uvm_object_utils_end\>' 113 | let pstart = '`uvm_object\%(_param\)\=_utils_begin\>' 114 | elseif a:keyword =~ '`uvm_component_utils_end\>' 115 | let pend = '`uvm_component_utils_end\>' 116 | let pstart = '`uvm_component\%(_param\)\=_utils_begin\>' 117 | else 118 | let pend = '\<' . a:keyword . '\>' 119 | "let pstart = '\<' . substitute(a:keyword,'^end','','') . '\>' 120 | let pstart = '\<' . strpart(a:keyword,3) . '\>' 121 | endif 122 | let skip = "s:IsSVColComment(line('.'),col('.'))" 123 | call cursor(lnum, 1) 124 | let m_lnum = searchpair(pstart, pmid, pend, 'bW', skip) 125 | let ind = m_lnum > 0 && m_lnum < lnum ? 126 | \ indent(m_lnum) : indent(lnum) 127 | let result = a:mode=='line' ? m_lnum : 128 | \ a:mode=='indent' ? ind : 0 129 | if exists('b:sv_indent_verbose') 130 | echo pend . ' ' . pstart . ' m:' . m_lnum . ' c:' . lnum . ' i:' . ind . "\n" 131 | endif 132 | return result 133 | endfunction 134 | 135 | function GetSystemVerilogIndent() 136 | 137 | if exists('b:sv_indent_width') 138 | let offset = b:sv_indent_width 139 | else 140 | let offset = &sw 141 | endif 142 | if exists('b:sv_indent_modules') 143 | let indent_modules = offset 144 | else 145 | let indent_modules = 0 146 | endif 147 | 148 | " Find a non-blank, non-comment line above the current line. 149 | let lnum = s:PrevNonBlankNonComment(v:lnum - 1) 150 | 151 | " At the start of the file use zero indent. 152 | if lnum == 0 153 | return 0 154 | endif 155 | 156 | let lnum2 = s:PrevNonBlankNonComment(lnum - 1) 157 | let curr_line = s:RemoveSVComment(getline(v:lnum)) 158 | let last_line = s:RemoveSVComment(getline(lnum)) 159 | let last_line2 = s:RemoveSVComment(getline(lnum2)) 160 | let ind = indent(lnum) 161 | let offset_comment1 = 1 162 | " Define the condition of an open statement 163 | " Exclude the match of //, /* or */ 164 | let sv_openstat = '\%(\\|\%([*/]\)\@<+-/%^&|!=?:]\%([*/]\)\@!\)' 165 | " Define the condition when the statement ends with a one-line comment 166 | let sv_comment = '\%(\/\/.*\|\/\*.*\*\/\s*\)' 167 | let sv_block1_statement = '\%(`\@\)\|' . 168 | \ '\%(^\s*\<\%(for\|case\%[zx]\|do\|foreach\|randcase\|randsequence' . 169 | \ '\|initial\|forever\|fork\|final\|specify' . 170 | \ '\|always\|always_comb\|always_ff\|always_latch\)\>\)' 171 | let sv_block2_statement = '^\s*\%(' . 172 | \ '\%(\<\%(clocking\|interface\|package\|generate' . 173 | \ '\|property\|program\|sequence\)\>\)\|' . 174 | \ '\%(\%(\\s*\)\=\\)\|' . 175 | \ '\%(\%(\<\S\+\s\+\)*\<\%(function\|task\)\>\)\|' . 176 | \ '\%(\%(\w\+\s*:\)\=\s*\\)' . 177 | \ '\)' 178 | let sv_oneline_statement = '\<\%(' . 179 | \ '`\@' 181 | let sv_end_statement = '\%(\<\%(' . 182 | \ 'endclocking\|endinterface\|endpackage\|' . 183 | \ 'endproperty\|endprogram\|endsequence\|' . 184 | \ 'endclass\|endfunction\|endtask\|endgroup\|endgenerate' . 185 | \ '\)\>\)' 186 | let sv_end_match = '\<\%(' . 187 | \ 'end\|else\|' . 188 | \ 'end\%(case\|task\|function\|clocking\|interface\|program\|' . 189 | \ 'module\|class\|specify\|package\|sequence\|group\|property\|generate\)\|' . 190 | \ 'join\|join_any\|join_none\)\>\|' . 191 | \ '[})]\|' . 192 | \ '`\<\%(else\|endif\)\>\|' . 193 | \ '`\<\%(uvm_\%(object\|component\)_utils_end\)\>' 194 | 195 | 196 | if exists('b:sv_indent_verbose') 197 | let vverb_str = 'INDENT VERBOSE:' 198 | let vverb = 1 199 | else 200 | let vverb = 0 201 | endif 202 | 203 | if last_line2 =~ sv_openstat . '\s*' . sv_comment . '*$' 204 | if vverb 205 | echo "last_line2 is open statement!\n" 206 | endif 207 | endif 208 | 209 | " Indent comment accoding to last line 210 | " End of multiple-line comment TODO 211 | if last_line =~ '\*/\s*$' && last_line !~ '/\*.\{-}\*/' 212 | let ind = ind - offset_comment1 213 | if vverb 214 | echo vverb_str "De-indent after a multiple-line comment.\n" 215 | endif 216 | 217 | " bypass single comment 218 | elseif last_line =~ '^\s*' . sv_comment 219 | if vverb | echo vverb_str "Skip Indent after a comment.\n" | endif 220 | 221 | endif 222 | 223 | " Indent accoding to last line 224 | " Indent after if/else/for/case/always/initial/specify/fork blocks 225 | if last_line =~ sv_block1_statement 226 | if last_line !~ '\%([;}]\|\<\%(end\|endcase\|endspecify\)\>\)\s*$' 227 | let ind = ind + offset 228 | if vverb | echo vverb_str "Indent after a if/else/for block statement.\n" | endif 229 | else 230 | if vverb | echo vverb_str "Fail Indent after a if/else/for block statement.\n" | endif 231 | endif 232 | 233 | " Indent after function/task/class/package/sequence/clocking/ 234 | " interface/covergroup/property/program blocks 235 | elseif last_line =~ sv_block2_statement 236 | if last_line !~ sv_end_statement . '\s*$' && 237 | \ last_line !~ '^\s*\.*;\s*$' 238 | let ind = ind + offset 239 | if vverb 240 | echo vverb_str "Indent after function/task/class block statement.\n" 241 | endif 242 | else 243 | if vverb | echo vverb_str "Fail Indent after a function/task/class block statement.\n" | endif 244 | endif 245 | 246 | " Indent after multiple-line function/task stand-alone ');' 247 | elseif last_line =~ '^\s*)\s*;\s*$' 248 | let m_lnum = s:GetSVBlockStart(')', lnum, 'line') 249 | if s:RemoveSVComment(getline(m_lnum)) =~ '\%(\%(\<\S\+\s\+\)*\<\%(function\|task\)\>\)' && 250 | \ s:RemoveSVComment(getline(m_lnum)) !~ '^\s*\<\%(extern\|import\)\>' 251 | let ind = ind + offset 252 | if vverb 253 | echo vverb_str "Indent after a multiple-line function/task\n" 254 | endif 255 | endif 256 | 257 | " Indent after module blocks 258 | elseif last_line =~ '^\s*\%(\\s*\)\=\' 259 | let ind = ind + indent_modules 260 | if vverb && indent_modules 261 | echo vverb_str "Indent after module statement.\n" 262 | endif 263 | if last_line =~ '[(,]\s*$' 264 | let ind = ind + offset 265 | if vverb 266 | echo vverb_str "Indent after a multiple-line module statement.\n" 267 | endif 268 | endif 269 | 270 | " Indent after a 'begin' statement 271 | elseif last_line =~ '\%(\\)\%(\s*:\s*\S\+\)*\s*$' && 272 | \ ( last_line2 !~ sv_openstat . '\s*$' || 273 | \ last_line2 =~ '^\s*[^=!]\+\s*:\s*$' ) 274 | let ind = ind + offset 275 | if vverb | echo vverb_str "Indent after begin statement.\n" | endif 276 | 277 | " Indent after a '{' or a '(' 278 | elseif last_line =~ '[{(]\s*$' && 279 | \ ( last_line2 !~ sv_openstat . '\s*$' || 280 | \ last_line2 =~ '^\s*[^=!]\+\s*:\s*$' ) 281 | let ind = ind + offset 282 | if vverb | echo vverb_str "Indent after {( statement.\n" | endif 283 | 284 | " Indent after a '`uvm_*_utils_begin' 285 | elseif last_line =~ '`uvm_\%(object\|component\)_utils_begin\>' && 286 | \ ( last_line2 !~ sv_openstat . '\s*$' || 287 | \ last_line2 =~ '^\s*[^=!]\+\s*:\s*$' ) 288 | let ind = ind + offset 289 | if vverb | echo vverb_str "Indent after uvm_utils_begin statement.\n" | endif 290 | 291 | " De-indent for the end of one-line block 292 | elseif ( last_line !~ '\<\%(begin\|else\)\>' && 293 | \ last_line =~ ';\s*$' ) && 294 | \ ( last_line2 =~ sv_oneline_statement . '.*$' && 295 | \ last_line2 !~ sv_openstat . '\s*$' && 296 | \ last_line2 !~ ';\s*$' && 297 | \ last_line2 !~ '\' ) 298 | let ind = ind - offset 299 | if vverb 300 | echo vverb_str "De-indent after the end of one-line statement.\n" 301 | endif 302 | 303 | " Multiple-line statement (including case statement) 304 | " Open statement 305 | " Ident the first open line 306 | elseif last_line =~ sv_openstat . '\s*$' && 307 | \ last_line2 !~ sv_openstat . '\s*$' 308 | let ind = ind + offset 309 | if vverb | echo vverb_str "Indent after an open statement.\n" | endif 310 | 311 | " Indent for `ifdef `else block 312 | elseif last_line =~ '^\s*`\<\%(ifdef\|else\)\>' 313 | let ind = ind + offset 314 | if vverb 315 | echo vverb_str "Indent after a `ifdef or `else statement.\n" 316 | endif 317 | 318 | endif 319 | 320 | " Re-indent current line 321 | 322 | " bypass single comment 323 | if s:IsSVLineComment(v:lnum) 324 | if getline(v:lnum) =~ '^\s*' . sv_comment && 325 | \ last_line !~ sv_openstat . '\s*$' && last_line =~ ';\s*$' && 326 | \ last_line2 =~ sv_openstat . '\s*$' && last_line2 !~ '[{]\s*$' 327 | let ind = ind - offset 328 | if vverb | echo vverb_str "De-indent Comment the end of a multiple statement.\n" | endif 329 | else 330 | if vverb | echo vverb_str "Skip De-Indent comment line.\n" | endif 331 | endif 332 | 333 | " De-indent on the end of the block 334 | " join/end/endcase/endfunction/endtask/endspecify 335 | " m_lnum : line of BlockStart 336 | " m_lnum2: previous line number of m_lnum 337 | elseif curr_line =~ '^\s*\%(' . sv_end_match . '\)' && 338 | \ ( curr_line !~ '^\s*\' || last_line !~ '^\s*\%(\\|}[^;]\)' ) 339 | let block_end = matchstr(curr_line, sv_end_match) 340 | let ind = s:GetSVBlockStart(block_end, v:lnum, 'indent') 341 | let m_lnum = s:GetSVBlockStart(block_end, v:lnum, 'line') 342 | let m_lnum2 = s:PrevNonBlankNonComment(m_lnum-1) 343 | if s:RemoveSVComment(getline(m_lnum2)) =~ sv_openstat . '\s*$' && 344 | \ s:RemoveSVComment(getline(m_lnum2)) !~ '[:{]\s*$' 345 | let ind = ind - offset 346 | if vverb | echo vverb_str "De-indent the end of a block(multiple statement).\n" | endif 347 | else 348 | if vverb | echo vverb_str "De-indent the end of a block.\n" | endif 349 | endif 350 | 351 | elseif curr_line =~ '^\s*\' 352 | let ind = ind - indent_modules 353 | if vverb && indent_modules 354 | echo vverb_str "De-indent the end of a module.\n" 355 | endif 356 | 357 | " De-indent on a stand-alone 'begin' 358 | elseif curr_line =~ '^\s*\' && 359 | \ last_line !~ '\' 360 | call cursor(v:lnum,1) 361 | let m_lnum = search('^\s*\%(\<\%(end\|if\|else\|for\|foreach\|' . 362 | \ 'always\|initial\|final\|fork\|repeat\|while\)\>\|'. 363 | \ '\%(\S\+::\)\=\%(\S\+\):\)' , 'bnW') 364 | let sb_lnum = search('\%(' . sv_block2_statement . '\)' 365 | \ , 'bnW', m_lnum) 366 | let ind = m_lnum>0 && m_lnum\|' . 377 | \ '\%(`\0 && m_lnum' 385 | let ind = indent(lnum) 386 | if vverb 387 | echo vverb_str "Indent after a `ifdef or `else statement.\n" 388 | endif 389 | 390 | " De-indent after the end of multiple-line statement 391 | " excluding function/task/expression = 392 | elseif curr_line =~ '\S\+\s*$' 393 | if last_line !~ sv_openstat . '\s*$' && last_line =~ ';\s*$' && 394 | \ last_line2 =~ sv_openstat . '\s*$' && last_line2 !~ '[{]\s*$' 395 | if last_line !~ ')\s*;\s*$' 396 | let ind = ind - offset 397 | if vverb | echo vverb_str "De-indent the end of a multiple statement.\n" | endif 398 | else 399 | let m_lnum = s:GetSVBlockStart(')', lnum, 'line') 400 | if s:RemoveSVComment(getline(m_lnum)) !~ '\%(\%(\<\S\+\s\+\)*\<\%(function\|task\)\>\)\|' . 401 | \ '\%(\".\{-}\)\@' && 415 | \ last_line2 =~ '^\s*\' && 416 | \ curr_line !~ '^\s*\%(' . sv_end_match . '\)' 417 | let ind = ind - offset 418 | if vverb | echo vverb_str "De-indent after uvm macro.\n" | endif 419 | endif 420 | endif 421 | 422 | " Return the indention 423 | return ind 424 | endfunction 425 | 426 | " vim:sw=2 427 | -------------------------------------------------------------------------------- /syntax/systemverilog.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: SystemVerilog 3 | " Maintainer: WeiChung Wu 4 | " Last Change: 2011 Aug 04 5 | " 6 | " Credits: 7 | " Originally created by 8 | " Dave Eggum (opine at bluebottle dOt com) 9 | 10 | " NOTE: extra white space at the end of the line will be highlighted if you 11 | " add this line to your colorscheme: 12 | 13 | " highlight SpaceError guibg=#204050 14 | 15 | " (change the value for guibg to any color you like) 16 | 17 | " For version 5.x: Clear all syntax items 18 | " For version 6.x: Quit when a syntax file was already loaded 19 | if version < 600 20 | syntax clear 21 | elseif exists("b:current_syntax") 22 | finish 23 | endif 24 | 25 | " A bunch of useful SV keywords 26 | syn keyword svStatement always always_comb always_ff always_latch assert 27 | syn keyword svStatement break return continue fork join disable force release assign alias 28 | syn keyword svStatement join_any join_none frokjoin binsof intersect wait wait_order 29 | 30 | syn keyword svLabel bind constraint covergroup coverpoint 31 | syn keyword svLabel class CLOCK clocking default function generate interface modport 32 | syn keyword svLabel package program property randseq sequence specify 33 | syn keyword svLabel task 34 | syn keyword svLabel begin initial module forever final import 35 | syn keyword svLabel end endclass endfunction endgenerate endtask endprogram endmodule 36 | syn keyword svLabel endinterface endpackage endproperty endclocking endgroup 37 | 38 | syn keyword svConditional if iff else case casex casez endcase randcase 39 | syn keyword svConditional unique priority randsequence endsequence 40 | syn keyword svRepeat repeat while for do foreach 41 | syn keyword svModifier after all any around assoc_size async 42 | syn keyword svModifier before big_endian bit_normal bit_reverse export 43 | syn keyword svModifier extends extern hdl_node hdl_task implements interconnect little_endian local 44 | syn keyword svModifier negedge nettype none packed protected posedge public rules 45 | syn keyword svModifier shadow soft solve static super this typedef unpacked var 46 | syn keyword svModifier vca virtual virtuals wildcard with 47 | syn keyword svModifier ref const pure automatic 48 | 49 | syn keyword svType reg string enum struct event bit semaphore 50 | syn keyword svType rand randc integer parameter localparam specparam defparam 51 | syn keyword svType logic int mailbox input output inout unsigned signed time wire 52 | syn keyword svType shortint longint byte real 53 | 54 | "syn keyword svDeprecated call_func call_task close_conn get_bind get_bind_id 55 | "syn keyword svDeprecated get_conn_err mailbox_receive mailbox_send make_client 56 | "syn keyword svDeprecated make_server simwave_plot up_connections 57 | 58 | " predefined tasks and functions 59 | "syn keyword svTask alloc assoc_index cast_assign cm_coverage 60 | "syn keyword svTask cm_get_coverage cm_get_limit delay error error_mode 61 | "syn keyword svTask exit fclose feof ferror fflush flag fopen fprintf 62 | "syn keyword svTask freadb freadh freadstr get_cycle get_env get_memsize 63 | "syn keyword svTask get_plus_arg getstate get_systime get_time get_time_unit 64 | "syn keyword svTask initstate lock_file mailbox_get mailbox_put os_command 65 | "syn keyword svTask printf prodget prodset psprintf query query_str query_x 66 | "syn keyword svTask rand48 random region_enter region_exit rewind 67 | "syn keyword svTask semaphore_get semaphore_put setstate signal_connect 68 | "syn keyword svTask sprintf srandom sscanf stop suspend_thread sync 69 | "syn keyword svTask trace trigger unit_delay unlock_file urand48 70 | "syn keyword svTask urandom urandom_range 71 | "syn keyword svTask vsv_call_func vsv_call_task vsv_get_conn_err 72 | "syn keyword svTask vsv_make_client vsv_make_server vsv_up_connections 73 | "syn keyword svTask vsv_wait_for_done vsv_wait_for_input wait_child wait_var 74 | " " ChungWu modify 75 | "syn keyword svTask wait cast display displayb displayh write 76 | syn match svTask "\$[a-zA-Z0-9_]\+\>" 77 | 78 | syn cluster svOperGroup contains=svOperator,svOperParen,svNumber,svString,svOperOk,svType 79 | " syn match svOperator "++\|--\|&\|\~&\||\|\~|\|^\|\~^\|\~\|><" 80 | " syn match svOperator "*\|/\|%\|+\|-\|<<\|>>\|<\|<=\|>\|>=\|!in" 81 | " syn match svOperator "=?=\|!?=\|==\|!=\|===\|!==\|&\~\|^\~\||\~" 82 | " syn match svOperator "&&\|||\|=\|+=\|-=\|*=\|/=\|%=\|<<=\|>>=\|&=" 83 | " syn match svOperator "|=\|^=\|\~&=\|\~|=\|\~^=" 84 | 85 | syn match svOperator "[&|\~>" 170 | " "hex number 171 | " syn match svNumber display contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>" 172 | " syn match svNumber "\(\<[0-9]\+\|\)'[bdoh][0-9a-fxzA-FXZ_]\+\>" 173 | syn match svNumber "\<\(\<[0-9]\+\)\?\('[bdoh]\)\?[0-9a-fxz_]\+\>" 174 | " syn match svNumber "\<[+-]\=[0-9]\+\>" 175 | " Flag the first zero of an octal number as something special 176 | syn match svOctal display contained "0\o\+\(u\=l\{0,2}\|ll\=u\)\>" contains=svOctalZero 177 | syn match svOctalZero display contained "\<0" 178 | syn match svFloat display contained "\d\+f" 179 | "floating point number, with dot, optional exponent 180 | syn match svFloat display contained "\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\=" 181 | "floating point number, starting with a dot, optional exponent 182 | syn match svFloat display contained "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>" 183 | "floating point number, without dot, with exponent 184 | syn match svFloat display contained "\d\+e[-+]\=\d\+[fl]\=\>" 185 | "hexadecimal floating point number, optional leading digits, with dot, with exponent 186 | syn match svFloat display contained "0x\x*\.\x\+p[-+]\=\d\+[fl]\=\>" 187 | "hexadecimal floating point number, with leading digits, optional dot, with exponent 188 | syn match svFloat display contained "0x\x\+\.\=p[-+]\=\d\+[fl]\=\>" 189 | 190 | " flag an octal number with wrong digits 191 | syn match svOctalError display contained "0\o*[89]\d*" 192 | syn case match 193 | 194 | let sv_comment_strings = 1 195 | 196 | if exists("sv_comment_strings") 197 | " A comment can contain svString, svCharacter and svNumber. 198 | " But a "*/" inside a svString in a svComment DOES end the comment! So we 199 | " need to use a special type of svString: svCommentString, which also ends on 200 | " "*/", and sees a "*" at the start of the line as comment again. 201 | " Unfortunately this doesn't work very well for // type of comments :-( 202 | syntax match svCommentSkip contained "^\s*\*\($\|\s\+\)" 203 | syntax region svCommentString contained start=+L\=\\\@" 247 | syn match svUvmMacro "`\(u\|o\)vm_\w\+" 248 | 249 | syn match svClass "\zs\w\+\ze::" 250 | syn match svClass "\zs\w\+\ze\s\+\w\+\s*[=;,)\[]" contains=svConstant,svUserConstant 251 | syn match svClass "\zs\w\+\ze\s\+\w\+\s*$" contains=svConstant,svUserConstant 252 | syn match svClass "\zs\w\+\ze\s*#(" contains=svConstant,svUserConstant 253 | syn match svUserMethod "\zs\w\+\ze\s*(" contains=svConstant,svUserConstant 254 | syn match svObject "\zs\w\+\ze\.\w" 255 | syn match svObject "\zs\w\+\ze\.\$\w" 256 | 257 | " Accept ` for # (Verilog) 258 | syn region svPreCondit start="^\s*\(`\|#\)\s*\(if\|ifdef\|ifndef\|elsif\)\>" skip="\\$" end="$" end="//"me=s-1 contains=svComment,svCppString,svCharacter,svCppParen,svParenError,svNumbers,svCommentError,svSpaceError 259 | syn match svPreCondit display "^\s*\(`\|#\)\s*\(else\|endif\)\>" 260 | if !exists("sv_no_if0") 261 | syn region svCppOut start="^\s*\(`\|#\)\s*if\s\+0\+\>" end=".\@=\|$" contains=svCppOut2 262 | syn region svCppOut2 contained start="0" end="^\s*\(`\|#\)\s*\(endif\>\|else\>\|elsif\>\)" contains=svSpaceError,svCppSkip 263 | syn region svCppSkip contained start="^\s*\(`\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(`\|#\)\s*endif\>" contains=svSpaceError,svCppSkip 264 | endif 265 | syn region svIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+ 266 | syn match svIncluded display contained "<[^>]*>" 267 | syn match svInclude display "^\s*\(`\|#\)\s*include\>\s*["<]" contains=svIncluded 268 | "syn match svLineSkip "\\$" 269 | syn cluster svPreProcGroup contains=svPreCondit,svIncluded,svInclude,svDefine,svErrInParen,svErrInBracket,svUserLabel,svSpecial,svOctalZero,svCppOut,svCppOut2,svCppSkip,svFormat,svNumber,svFloat,svOctal,svOctalError,svNumbersCom,svString,svCommentSkip,svCommentString,svComment2String,@svCommentGroup,svCommentStartError,svParen,svBracket,svMulti 270 | syn region svDefine start="^\s*\(`\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$" end="//"me=s-1 contains=ALLBUT,@svPreProcGroup,@Spell 271 | syn region svPreProc start="^\s*\(`\|#\)\s*\(pragma\>\|line\>\|warning\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@svPreProcGroup,@Spell 272 | 273 | " Highlight User Labels 274 | syn cluster svMultiGroup contains=svIncluded,svSpecial,svCommentSkip,svCommentString,svComment2String,@svCommentGroup,svCommentStartError,svUserCont,svUserLabel,svBitField,svOctalZero,svCppOut,svCppOut2,svCppSkip,svFormat,svNumber,svFloat,svOctal,svOctalError,svNumbersCom,svCppParen,svCppBracket,svCppString 275 | syn region svMulti transparent start='?' skip='::' end=':' contains=ALLBUT,@svMultiGroup,@Spell 276 | " syn region svMulti transparent start='?' skip='::' end=':' contains=ALL 277 | " The above causes svCppOut2 to catch on: 278 | " i = (isTrue) ? 0 : 1; 279 | " which ends up commenting the rest of the file 280 | 281 | " Avoid matching foo::bar() by requiring that the next char is not ':' 282 | syn cluster svLabelGroup contains=svUserLabel 283 | syn match svUserCont display "^\s*\I\i*\s*:$" contains=@svLabelGroup 284 | syn match svUserCont display ";\s*\I\i*\s*:$" contains=@svLabelGroup 285 | syn match svUserCont display "^\s*\I\i*\s*:[^:]"me=e-1 contains=@svLabelGroup 286 | syn match svUserCont display ";\s*\I\i*\s*:[^:]"me=e-1 contains=@svLabelGroup 287 | 288 | syn match svUserLabel display "\I\i*" contained 289 | 290 | " Avoid recognizing most bitfields as labels 291 | syn match svBitField display "^\s*\I\i*\s*:\s*[1-9]"me=e-1 292 | syn match svBitField display ";\s*\I\i*\s*:\s*[1-9]"me=e-1 293 | 294 | if exists("sv_minlines") 295 | let b:sv_minlines = sv_minlines 296 | else 297 | if !exists("sv_no_if0") 298 | let b:sv_minlines = 50 " #if 0 constructs can be long 299 | else 300 | let b:sv_minlines = 15 " mostly for () constructs 301 | endif 302 | endif 303 | exec "syn sync ccomment svComment minlines=" . b:sv_minlines 304 | 305 | " Define the default highlighting. 306 | " For version 5.7 and earlier: only when not done already 307 | " For version 5.8 and later: only when an item doesn't have highlighting yet 308 | if version >= 508 || !exists("did_systemverilog_syn_inits") 309 | if version < 508 310 | let did_systemverilog_syn_inits = 1 311 | command -nargs=+ HiLink hi link 312 | else 313 | command -nargs=+ HiLink hi def link 314 | endif 315 | 316 | HiLink svClass Identifier 317 | HiLink svObject Identifier 318 | HiLink svUserMethod Function 319 | HiLink svUvmMacro Function 320 | HiLink svTask Keyword 321 | HiLink svModifier Tag 322 | HiLink svDeprecated svError 323 | HiLink svMethods Statement 324 | " HiLink svInterface Label 325 | " HiLink svInterface Function 326 | 327 | HiLink svFormat svSpecial 328 | HiLink svCppString svString 329 | HiLink svCommentL svComment 330 | HiLink svCommentStart svComment 331 | HiLink svLabel Label 332 | HiLink svUserLabel Label 333 | HiLink svConditional Conditional 334 | HiLink svRepeat Repeat 335 | HiLink svCharacter Character 336 | HiLink svSpecialCharacter svSpecial 337 | HiLink svNumber Number 338 | HiLink svOctal Number 339 | HiLink svOctalZero PreProc " link this to Error if you want 340 | HiLink svFloat Float 341 | HiLink svOctalError svError 342 | HiLink svParenError svError 343 | HiLink svErrInParen svError 344 | HiLink svErrInBracket svError 345 | HiLink svCommentError svError 346 | HiLink svCommentStartError svError 347 | HiLink svSpaceError SpaceError 348 | HiLink svSpecialError svError 349 | HiLink svOperator Operator 350 | HiLink svStructure Structure 351 | HiLink svInclude Include 352 | HiLink svPreProc PreProc 353 | HiLink svDefine Macro 354 | HiLink svIncluded svString 355 | HiLink svError Error 356 | HiLink svStatement Statement 357 | HiLink svPreCondit PreCondit 358 | HiLink svType Type 359 | " HiLink svConstant Constant 360 | HiLink svConstant Keyword 361 | HiLink svUserConstant Constant 362 | HiLink svCommentString svString 363 | HiLink svComment2String svString 364 | HiLink svCommentSkip svComment 365 | HiLink svString String 366 | HiLink svComment Comment 367 | HiLink svSpecial SpecialChar 368 | HiLink svTodo Todo 369 | HiLink svCppSkip svCppOut 370 | HiLink svCppOut2 svCppOut 371 | HiLink svCppOut Comment 372 | 373 | delcommand HiLink 374 | endif 375 | 376 | let b:current_syntax = "systemverilog" 377 | 378 | " vim: ts=8 379 | --------------------------------------------------------------------------------