Add Yosys linter for Verilog files. (#3713)

* Add yosys for verilog files.

* Add handler test for yosys.

* fix typo in yosys handler test

* fix array order in yosys handler test

* add yosys linter to filetype defaults test

* fix duplicate tag

* add 'yosys' to 'ale-supported-languages-and-tools.txt'
This commit is contained in:
Nathan Sharp 2021-07-12 06:39:53 -06:00 committed by GitHub
parent 9a9fd24b17
commit c8f669249a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 98 additions and 2 deletions

View File

@ -0,0 +1,42 @@
" Author: Nathan Sharp <nwsharp+eda@live.com>
" Description: Yosys for Verilog files
call ale#Set('verilog_yosys_executable', 'yosys')
call ale#Set('verilog_yosys_options', '-Q -T -p ''read_verilog %s''')
function! ale_linters#verilog#yosys#GetCommand(buffer) abort
return '%e ' . ale#Var(a:buffer, 'verilog_yosys_options') . ' 2>&1'
endfunction
function! ale_linters#verilog#yosys#Handle(buffer, lines) abort
let l:output = []
let l:path = fnamemodify(bufname(a:buffer), ':p')
for l:match in ale#util#GetMatches(a:lines, '^\([^:]\+\):\(\d\+\): \(WARNING\|ERROR\): \(.\+\)$')
call add(l:output, {
\ 'lnum': str2nr(l:match[2]),
\ 'text': l:match[4],
\ 'type': l:match[3][0],
\ 'filename': l:match[1],
\})
endfor
for l:match in ale#util#GetMatches(a:lines, '^\(Warning\|ERROR\): \(.\+\)$')
call add(l:output, {
\ 'lnum': 1,
\ 'text': l:match[2],
\ 'type': l:match[1][0],
\})
endfor
return l:output
endfunction
call ale#linter#Define('verilog', {
\ 'name': 'yosys',
\ 'output_stream': 'stdout',
\ 'executable': {b -> ale#Var(b, 'verilog_yosys_executable')},
\ 'command': function('ale_linters#verilog#yosys#GetCommand'),
\ 'callback': 'ale_linters#verilog#yosys#Handle',
\ 'lint_file': 1,
\})

View File

@ -550,6 +550,7 @@ Notes:
* `verilator` * `verilator`
* `vlog` * `vlog`
* `xvlog` * `xvlog`
* `yosys`
* VHDL * VHDL
* `ghdl` * `ghdl`
* `vcom` * `vcom`

View File

@ -3,7 +3,7 @@ ALE Verilog/SystemVerilog Integration *ale-verilog-options*
=============================================================================== ===============================================================================
ALE can use five different linters for Verilog HDL: ALE can use six different linters for Verilog HDL:
HDL Checker HDL Checker
Using `hdl_checker --lsp` Using `hdl_checker --lsp`
@ -20,6 +20,9 @@ ALE can use five different linters for Verilog HDL:
Vivado Vivado
Using `xvlog` Using `xvlog`
Yosys
Using `ysoys -Q -T -p 'read_verilog'`
By default, both 'verilog' and 'systemverilog' filetypes are checked. By default, both 'verilog' and 'systemverilog' filetypes are checked.
You can limit 'systemverilog' files to be checked using only 'verilator' by You can limit 'systemverilog' files to be checked using only 'verilator' by
@ -114,5 +117,26 @@ g:ale_verilog_xvlog_options *g:ale_verilog_xvlog_options*
This variable can be changed to modify the flags/options passed to 'xvlog'. This variable can be changed to modify the flags/options passed to 'xvlog'.
===============================================================================
yosys *ale-verilog-yosys*
g:ale_verilog_yosys_executable *g:ale_verilog_yosys_executable*
*b:ale_verilog_yosys_executable*
Type: |String|
Default: `'yosys'`
This variable can be changed to the path to the 'yosys' executable.
g:ale_verilog_yosys_options *g:ale_verilog_yosys_options*
*b:ale_verilog_yosys_options*
Type: |String|
Default: `'-Q -T -p ''read_verilog %s'''`
This variable can be changed to modify the flags/options passed to 'yosys'.
By default, Yosys is an interative program. To obtain linting functionality,
the `'read_verilog'` command is used.
=============================================================================== ===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -3067,6 +3067,7 @@ documented in additional help files.
verilator.............................|ale-verilog-verilator| verilator.............................|ale-verilog-verilator|
vlog..................................|ale-verilog-vlog| vlog..................................|ale-verilog-vlog|
xvlog.................................|ale-verilog-xvlog| xvlog.................................|ale-verilog-xvlog|
yosys.................................|ale-verilog-yosys|
vhdl....................................|ale-vhdl-options| vhdl....................................|ale-vhdl-options|
ghdl..................................|ale-vhdl-ghdl| ghdl..................................|ale-vhdl-ghdl|
hdl-checker...........................|ale-vhdl-hdl-checker| hdl-checker...........................|ale-vhdl-hdl-checker|

View File

@ -559,6 +559,7 @@ formatting.
* [verilator](http://www.veripool.org/projects/verilator/wiki/Intro) * [verilator](http://www.veripool.org/projects/verilator/wiki/Intro)
* [vlog](https://www.mentor.com/products/fv/questa/) * [vlog](https://www.mentor.com/products/fv/questa/)
* [xvlog](https://www.xilinx.com/products/design-tools/vivado.html) * [xvlog](https://www.xilinx.com/products/design-tools/vivado.html)
* [yosys](http://www.clifford.at/yosys/)
* VHDL * VHDL
* [ghdl](https://github.com/ghdl/ghdl) * [ghdl](https://github.com/ghdl/ghdl)
* [vcom](https://www.mentor.com/products/fv/questa/) * [vcom](https://www.mentor.com/products/fv/questa/)

View File

@ -0,0 +1,27 @@
Before:
runtime ale_linters/verilog/yosys.vim
After:
call ale#linter#Reset()
Execute(The yosys handler should parse lines correctly):
AssertEqual
\ [
\ {
\ 'lnum': 3,
\ 'type': 'E',
\ 'text': 'syntax error, unexpected TOK_ID',
\ 'filename': 'file.v'
\ },
\ {
\ 'lnum': 1,
\ 'type': 'E',
\ 'text': 'internal error',
\ },
\ ],
\ ale_linters#verilog#yosys#Handle(bufnr(''), [
\ '1. Executing Verilog-2005 frontend: file.v',
\ 'ERROR: internal error',
\ 'file.v:3: ERROR: syntax error, unexpected TOK_ID',
\ ])

View File

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