]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/verilog/verilator.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / ale_linters / verilog / verilator.vim
1 " Author: Masahiro H https://github.com/mshr-h
2 " Description: verilator for verilog files
3
4 " Set this option to change Verilator lint options
5 if !exists('g:ale_verilog_verilator_options')
6     let g:ale_verilog_verilator_options = ''
7 endif
8
9 function! ale_linters#verilog#verilator#GetCommand(buffer) abort
10     " the path to the current file is systematically added to the search path
11     return 'verilator --lint-only -Wall -Wno-DECLFILENAME '
12     \   . '-I%s:h '
13     \   . ale#Var(a:buffer, 'verilog_verilator_options') .' '
14     \   . '%t'
15 endfunction
16
17 function! ale_linters#verilog#verilator#Handle(buffer, lines) abort
18     " Look for lines like the following.
19     "
20     " %Error: addr_gen.v:3: syntax error, unexpected IDENTIFIER
21     " %Warning-WIDTH: addr_gen.v:26: Operator ASSIGNDLY expects 12 bits on the Assign RHS, but Assign RHS's CONST '20'h0' generates 20 bits.
22     " %Warning-UNUSED: test.v:3: Signal is not used: a
23     " %Warning-UNDRIVEN: test.v:3: Signal is not driven: clk
24     " %Warning-UNUSED: test.v:4: Signal is not used: dout
25     " %Warning-BLKSEQ: test.v:10: Blocking assignments (=) in sequential (flop or latch) block; suggest delayed assignments (<=).
26     " Since version 4.032 (04/2020) verilator linter messages also contain the column number,
27     " and look like:
28     " %Error: /tmp/test.sv:3:1: syntax error, unexpected endmodule, expecting ';'
29     "
30     " to stay compatible with old versions of the tool, the column number is
31     " optional in the researched pattern
32     let l:pattern = '^%\(Warning\|Error\)[^:]*:\s*\([^:]\+\):\(\d\+\):\(\d\+\)\?:\? \(.\+\)$'
33     let l:output = []
34
35     for l:match in ale#util#GetMatches(a:lines, l:pattern)
36         let l:item = {
37         \   'lnum': str2nr(l:match[3]),
38         \   'text': l:match[5],
39         \   'type': l:match[1] is# 'Error' ? 'E' : 'W',
40         \   'filename': l:match[2],
41         \}
42
43         if !empty(l:match[4])
44             let l:item.col = str2nr(l:match[4])
45         endif
46
47         call add(l:output, l:item)
48     endfor
49
50     return l:output
51 endfunction
52
53 call ale#linter#Define('verilog', {
54 \   'name': 'verilator',
55 \   'output_stream': 'stderr',
56 \   'executable': 'verilator',
57 \   'command': function('ale_linters#verilog#verilator#GetCommand'),
58 \   'callback': 'ale_linters#verilog#verilator#Handle',
59 \   'read_buffer': 0,
60 \})