Slang linter for Verilog. (#4713)

This commit is contained in:
AlvinRolling 2024-02-22 10:18:04 +08:00 committed by GitHub
parent 1c5b84f375
commit 52c6146751
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 112 additions and 4 deletions

View File

@ -0,0 +1,53 @@
" Author: Alvin Rolling <alvinrolling@gmail.com>
" Description: slang for verilog files
" Set this option to change Slang lint options
if !exists('g:ale_verilog_slang_options')
let g:ale_verilog_slang_options = ''
endif
" --lint-only
function! ale_linters#verilog#slang#GetCommand(buffer) abort
return 'slang -Weverything '
\ . '-I%s:h '
\ . ale#Var(a:buffer, 'verilog_slang_options') .' '
\ . '%t'
endfunction
function! s:RemoveUnicodeQuotes(text) abort
let l:text = a:text
let l:text = substitute(l:text, '[`´]', '''', 'g')
let l:text = substitute(l:text, '[“”]', '"', 'g')
return l:text
endfunction
function! ale_linters#verilog#slang#Handle(buffer, lines) abort
let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+)?:?(\d+)?:? ([^:]+): (.+)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
let l:item = {
\ 'lnum': str2nr(l:match[2]),
\ 'type': (l:match[4] is# 'error') ? 'E' : 'W',
\ 'text': s:RemoveUnicodeQuotes(l:match[5]),
\}
if !empty(l:match[3])
let l:item.col = str2nr(l:match[3])
endif
call add(l:output, l:item)
endfor
return l:output
endfunction
call ale#linter#Define('verilog', {
\ 'name': 'slang',
\ 'output_stream': 'stderr',
\ 'executable': 'slang',
\ 'command': function('ale_linters#verilog#slang#GetCommand'),
\ 'callback': 'ale_linters#verilog#slang#Handle',
\ 'read_buffer': 0,
\})

View File

@ -677,6 +677,7 @@ Notes:
* Verilog
* `hdl-checker`
* `iverilog`
* slang
* `verilator`
* `vlog`
* `xvlog`

View File

@ -3,7 +3,7 @@ ALE Verilog/SystemVerilog Integration *ale-verilog-options*
===============================================================================
ALE can use six different linters for Verilog HDL:
ALE can use seven different linters for Verilog HDL:
HDL Checker
Using `hdl_checker --lsp`
@ -11,6 +11,9 @@ ALE can use six different linters for Verilog HDL:
iverilog:
Using `iverilog -t null -Wall`
slang:
Using `slang -Weverything`
verilator
Using `verilator --lint-only -Wall`
@ -21,7 +24,7 @@ ALE can use six different linters for Verilog HDL:
Using `xvlog`
Yosys
Using `ysoys -Q -T -p 'read_verilog'`
Using `yosys -Q -T -p 'read_verilog'`
By default, both 'verilog' and 'systemverilog' filetypes are checked.
@ -64,6 +67,15 @@ iverilog *ale-verilog-iverilog*
No additional options
===============================================================================
slang *ale-verilog-slang*
g:ale_verilog_slang_option *g:ale_verilog_slang_options*
*b:ale_verilog_slang_options*
Type: String
Default: ''
This variable can be changed to modify 'slang' command arguments.
===============================================================================
verilator *ale-verilog-verilator*
@ -73,7 +85,7 @@ g:ale_verilog_verilator_options *g:ale_verilog_verilator_options*
Type: |String|
Default: `''`
This variable can be changed to modify 'verilator' command arguments
This variable can be changed to modify 'verilator' command arguments.
For example `'-sv --default-language "1800-2012"'` if you want to enable
SystemVerilog parsing and select the 2012 version of the language.

View File

@ -3461,6 +3461,7 @@ documented in additional help files.
verilog/systemverilog...................|ale-verilog-options|
hdl-checker...........................|ale-verilog-hdl-checker|
iverilog..............................|ale-verilog-iverilog|
slang.................................|ale-verilog-slang|
verilator.............................|ale-verilog-verilator|
vlog..................................|ale-verilog-vlog|
xvlog.................................|ale-verilog-xvlog|

View File

@ -686,6 +686,7 @@ formatting.
* Verilog
* [hdl-checker](https://pypi.org/project/hdl-checker)
* [iverilog](https://github.com/steveicarus/iverilog)
* [slang](https://github.com/MikePopoloski/slang)
* [verilator](http://www.veripool.org/projects/verilator/wiki/Intro)
* [vlog](https://www.mentor.com/products/fv/questa/)
* [xvlog](https://www.xilinx.com/products/design-tools/vivado.html)

View File

@ -0,0 +1,26 @@
Before:
runtime ale_linters/verilog/slang.vim
After:
call ale#linter#Reset()
Execute(The slang handler should parse lines correctly):
AssertEqual
\ [
\ {
\ 'lnum': 11,
\ 'col': 1,
\ 'type': 'W',
\ 'text': 'extra '';'' has no effect [-Wempty-member]',
\ },
\ {
\ 'lnum': 24,
\ 'col': 12,
\ 'type': 'E',
\ 'text': 'cannot mix continuous and procedural assignments to variable ''data_o''',
\ },
\ ],
\ ale_linters#verilog#slang#Handle(bufnr(''), [
\ 'foo.sv:11:1: warning: extra '';'' has no effect [-Wempty-member]',
\ 'foo.sv:24:12: error: cannot mix continuous and procedural assignments to variable ''data_o''',
\ ])

View File

@ -0,0 +1,14 @@
Before:
call ale#assert#SetUpLinterTest('verilog', 'slang')
After:
call ale#assert#TearDownLinterTest()
Execute(The default slang command should be correct):
AssertLinter 'slang', 'slang -Weverything -I%s:h %t'
Execute(slang options should be configurable):
" Additional args for the linter
let g:ale_verilog_slang_options = '--define-macro DWIDTH=12'
AssertLinter 'slang', 'slang -Weverything -I%s:h --define-macro DWIDTH=12 %t'

View File

@ -119,7 +119,7 @@ Execute(The defaults for the zsh filetype should be correct):
Execute(The defaults for the verilog filetype should be correct):
" This filetype isn't configured with default, so we can test loading all
" available linters with this.
AssertEqual ['hdl_checker', 'iverilog', 'verilator', 'vlog', 'xvlog', 'yosys'], GetLinterNames('verilog')
AssertEqual ['hdl_checker', 'iverilog', 'slang', 'verilator', 'vlog', 'xvlog', 'yosys'], GetLinterNames('verilog')
let g:ale_linters_explicit = 1