From 3975e1af9d297a439665241b42b701e3ca93d6f6 Mon Sep 17 00:00:00 2001 From: Vijayvithal Jahagirdar Date: Wed, 2 Apr 2025 12:14:41 +0530 Subject: [PATCH] feat: Added support for ALE Linter. --- README.md | 10 +++++++++ ale_linters/bsv/ale.vim | 18 +++++++++++++++++ snippets/bsv.snippets | 45 +++++++++++++++++++++++++++++++++++++++-- syntax/bsv.vim | 1 + 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 ale_linters/bsv/ale.vim diff --git a/README.md b/README.md index 54310c8..50f2114 100644 --- a/README.md +++ b/README.md @@ -54,3 +54,13 @@ endfunction autocmd FileType bsv call BSVSetPath(expand(':p:h')) ``` + +# Support for linting via ALE. + +Linting is done via `bsc -u ` + +If additional options need to be passed set `g:ale_bsv_bsc_options` e.g. + +``` +let g:ale_bsv_bsc_options='-p /commonlib/bo:+ -verilog' +``` diff --git a/ale_linters/bsv/ale.vim b/ale_linters/bsv/ale.vim new file mode 100644 index 0000000..2cb9e26 --- /dev/null +++ b/ale_linters/bsv/ale.vim @@ -0,0 +1,18 @@ +" Author: Vijayvithal +" Description: Linter for bluespec system verilog + +call ale#Set('bsv_executable', 'bsc') + +function! GetCommand(buffer, output) abort + let bsc_options = g:ale_bsv_bsc_options ?? '' + return 'bsc -u' . bsc_options .'%s' +endfunction + +call ale#linter#Define('bsv', { +\ 'name': 'bsv', +\ 'output_stream': 'stderr', +\ 'executable': {b -> ale#Var(b, 'bsv_executable')}, +\ 'command': {function('GetCommand') +\ 'callback': 'ale#handlers#c#HandleGCCFormatWithIncludes', +\}) +" 'callback': function('HandleBSCLint') diff --git a/snippets/bsv.snippets b/snippets/bsv.snippets index 3f648bd..7ba3763 100644 --- a/snippets/bsv.snippets +++ b/snippets/bsv.snippets @@ -1,3 +1,10 @@ +snippet struct + typedef struct { ${1:Bit#}; + } deriving(Bits,Eq); +snippet enum + typedef enum { ${1:Bit#}; + } deriving(Bits,Eq); + snippet import import ${1:Standard}::*; ${2} @@ -22,8 +29,33 @@ snippet function ${3} endfunction snippet module - module ${1:modulename} (${2}); - ${3} + interface Ifc_$1; + method Action soft_reset(); + method Bool reset_done(); + endinterface + import StmtFSM::*; + (*synthesize*) + module mk${1:modulename} (Ifc_$1); + Reg#(Bool) rst_done <- mkRegA(False); + ${2} + let reset=action + rst_done <=True; + endaction; + Stmt stmt_$1=seq + if (!rst_done)seq + reset; + endseq + endseq; + FSM fsm_$1 <- mkFSM(stmt_$1); + rule rl_$1_fsm (fsm_$1.done() && (!rst_done)); + fsm_$1.start(); + endrule + method Action soft_reset(); + rst_done <=False; + endmethod + method Bool reset_done(); + return rst_done; + endmethod endmodule snippet rule rule ${1:rulename}; @@ -63,3 +95,12 @@ snippet package package ${1}; ${2} endpackage +snippet fsm + import StmtFSM::*; + Stmt ${1}_stmt=seq + endseq; + FSM $1 mkFSM($1_stmt); + rule $1_rl ($1.done()) + $1.start(); + endrule + diff --git a/syntax/bsv.vim b/syntax/bsv.vim index d061de2..7623375 100644 --- a/syntax/bsv.vim +++ b/syntax/bsv.vim @@ -141,3 +141,4 @@ syntax match bsvNiceOperator "<=" conceal cchar=⇐ highlight link bsvNiceOperator Operator highlight! link Conceal Operator setlocal conceallevel=1 +highlight Conceal ctermfg=Green