Skip to content

Commit

Permalink
Merge pull request #1 from HonkW93/dev
Browse files Browse the repository at this point in the history
Dev update
  • Loading branch information
HonkW93 authored May 9, 2021
2 parents 06d2eb5 + 9c1713c commit 913e8b4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 20 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

一款基于Vimscript的自动化verilog脚本。由[automatic for Verilog & RtlTree](https://www.vim.org/scripts/script.php?script_id=4067)修改而来,原作者zhangguo。

[![Release-Version](https://img.shields.io/badge/Release-1.0.4-blue.svg)](https://github.com/HonkW93/automatic-verilog/releases)-[![Vim-Version](https://img.shields.io/badge/Vim-8.2-green.svg)](https://www.vim.org/download.php)
[![Release-Version](https://img.shields.io/badge/Release-1.0.5-blue.svg)](https://github.com/HonkW93/automatic-verilog/releases)-[![Vim-Version](https://img.shields.io/badge/Vim-7.4-green.svg)](https://www.vim.org/download.php)

## 安装

Expand All @@ -45,6 +45,7 @@
- [x] 支持行尾自动添加端口类型`input/output/inout` (参考`vim automatic-verilog`
- [x] 支持新增端口自动添加`//INST_NEW`(参考`vim automatic-verilog`
- [x] 支持删除端口自动添加`//INST_DEL`(参考`vim automatic-verilog`
- [x] 支持例化文件名与模块名不同的模块
- [ ] 支持`` `ifdef```` `endif``
- [ ] 进行中...

Expand Down Expand Up @@ -93,6 +94,11 @@
[Vimcript-AutoMatic | HonkW](https://blog.honk.wang/posts/AutoMatic/)


## 更新

[Update](https://blog.honk.wang/posts/AutoMatic/#更新日志release)


## 开源协议

[GPL V3.0](/LICENSE)
70 changes: 51 additions & 19 deletions automatic.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
" Vim Plugin for Verilog Code Automactic Generation
" Author: HonkW
" Website: https://honk.wang
" Last Modified: 2021/04/30 20:13
" Last Modified: 2021/05/08 23:41
"------------------------------------------------------------------------------
" Modification History:
" Date By Version Change Description")
"------------------------------------------------------------------------------
" 2021/3/26 HonkW 1.0.0 First copy from zhangguo's vimscript
" 2021/4/5 HonkW 1.0.1 Finish AutoInst & AutoPara
" 2021/4/5 HonkW 1.0.1 Finish AutoInst & Autopara
" 2021/4/19 HonkW 1.0.2 Finish GetReg
" 2021/4/24 HonkW 1.0.3 Add read .sv file
" 2021/4/30 HonkW 1.0.4 Bug fixed & Add " ',' feature for AutoPara
" 2021/5/8 HonkW 1.0.5 Compatible with vim 7.4
" For vim version 7.x or above
"-----------------------------------------------------------------------------
"Update 记录脚本更新{{{1
Expand Down Expand Up @@ -171,10 +172,10 @@ amenu &Verilog.Code.Template.LoadTemplate<TAB> :call Lo

"Auto
amenu &Verilog.AutoInst.AutoInst(1)<TAB>All :call AutoInst(1)<CR>
amenu &Verilog.AutoInst.AutoInst(0)<TAB>CurrentLine :call AutoInst(0)<CR>
amenu &Verilog.AutoInst.AutoInst(0)<TAB>One :call AutoInst(0)<CR>

amenu &Verilog.AutoPara.AutoPara(1)<TAB>All :call AutoPara(1)<CR>
amenu &Verilog.AutoPara.AutoPara(0)<TAB>CurrentLine :call AutoPara(0)<CR>
amenu &Verilog.AutoPara.AutoPara(0)<TAB>One :call AutoPara(0)<CR>

"}}}3

Expand All @@ -190,6 +191,11 @@ imap <F2> <C-R>=strftime("%x")<CR>
map <C-F8> :call Invert()<ESC>
"}}}3

"Auto {{{3
map <S-F3> :call AutoInst(0)<ESC>
map <S-F4> :call AutoPara(0)<ESC>
"}}}3

"Code Snippet 代码段{{{3
"Add Always 添加always块
map ;al :call AlBpp()<CR>i
Expand Down Expand Up @@ -1129,7 +1135,7 @@ function s:GetIO(lines,mode)
endif
"record first null line
" [type, sequence, io_dir, width1, width2, signal_name, last_port, line ]
let value = ['keep',seq, '', 'c0', 'c0', '', 0, '']
let value = ['keep',seq, '', 'c0', 'c0', 'NULL', 0, '']
call extend(io_seqs, {seq : value})
let seq = seq + 1
" `ifdef `ifndef & single comment line
Expand Down Expand Up @@ -1176,6 +1182,9 @@ function s:GetIO(lines,mode)
let line = substitute(line,type,'','')
let line = substitute(line,'\[.*:.*\]','','')
let name = matchstr(line,'\w\+')
if name == ''
let name = 'NULL'
endif

" [type,sequence,io_dir, width1, width2, signal_name, last_port, line ]
let value = [type,seq, io_dir, width1, width2, name, 0, '']
Expand All @@ -1201,8 +1210,7 @@ function s:GetIO(lines,mode)
let type = value[0]
if type !~ 'keep'
let value[7] = 1
call remove(io_seqs,seq)
call extend(io_seqs,{seq:value})
call extend(io_seqs,{seq : value})
break
end
endif
Expand Down Expand Up @@ -1465,6 +1473,8 @@ endfunction
" line after kill
"---------------------------------------------------
function s:KillAutoInst()
let orig_idx = line('.')
let orig_col = col('.')
let idx = line('.')
let line = getline(idx)
if line =~ '/\*\<autoinst\>'
Expand All @@ -1481,21 +1491,25 @@ function s:KillAutoInst()
let line = getline(idx)
"end of inst
if line =~ ');\s*$'
call deletebufline('%',idx)
"call deletebufline('%',idx)
execute ':'.idx.'d'
break
"abnormal end
"abnormal end
elseif line =~ 'endmodule' || idx == line('$')
echohl ErrorMsg | echo "Error running KillAutoInst! Kill abnormally till the end!"| echohl None
break
"middle
"middle
else
call deletebufline('%',idx)
"call deletebufline('%',idx)
execute ':'.idx.'d'
endif
endwhile
endif
else
echohl ErrorMsg | echo "Error running KillAutoInst! Kill line not match /*autoinst*/ !"| echohl None
endif
"cursor back
call cursor(orig_idx,orig_col)
endfunction
"}}}3

Expand Down Expand Up @@ -1532,7 +1546,7 @@ function s:DrawIO(io_seqs,io_list,config)
"guarantee spaces width
let max_lbracket_len = 0
let max_rbracket_len = 0
for seq in sort(keys(a:io_seqs),'N')
for seq in sort(keys(a:io_seqs),'n')
let value = a:io_seqs[seq]
let type = value[0]
if type != 'keep'
Expand All @@ -1552,7 +1566,7 @@ function s:DrawIO(io_seqs,io_list,config)
let last_port_flag = 0
let io_list = copy(a:io_list)
let config = copy(a:config)
for seq in sort(keys(a:io_seqs),'N')
for seq in sort(keys(a:io_seqs),'n')
let value = a:io_seqs[seq]
let type = value[0]
let line = value[7]
Expand Down Expand Up @@ -2008,6 +2022,8 @@ endfunction
" kill untill inst_name
"---------------------------------------------------
function s:KillAutoPara(inst_name)
let orig_idx = line('.')
let orig_col = col('.')
let idx = line('.')
let line = getline(idx)
if line =~ '/\*\<autoinstparam\>'
Expand All @@ -2034,13 +2050,16 @@ function s:KillAutoPara(inst_name)
break
"middle
else
call deletebufline('%',idx)
"call deletebufline('%',idx)
execute ':'.idx.'d'
endif
endwhile
endif
else
echohl ErrorMsg | echo "Error running KillAutoPara! Kill line not match /*autoinstparam*/ !"| echohl None
endif
"cursor back
call cursor(orig_idx,orig_col)
endfunction
"}}}3

Expand Down Expand Up @@ -2089,7 +2108,7 @@ function s:DrawPara(para_seqs,para_list,config)
"guarantee spaces width
let max_lbracket_len = 0
let max_rbracket_len = 0
for seq in sort(keys(a:para_seqs),'N')
for seq in sort(keys(a:para_seqs),'n')
let value = a:para_seqs[seq]
let p_name = value[2]
let p_value = value[3]
Expand Down Expand Up @@ -2118,7 +2137,7 @@ function s:DrawPara(para_seqs,para_list,config)
let para_list_empty = 0
endif

for seq in sort(keys(a:para_seqs),'N')
for seq in sort(keys(a:para_seqs),'n')
let value = a:para_seqs[seq]
"Format parameter sequences
" [type, sequence, parameter_name, parameter_value ,last_parameter]
Expand Down Expand Up @@ -3004,21 +3023,34 @@ endfunction
" files : files-directory dictionary(.v or .sv file)
"---------------------------------------------------
function s:GetFileDirDic(dir,rec,files)
let filelist = readdir(a:dir,{n -> n =~ '.v$\|.sv$'})
"let filelist = readdir(a:dir,{n -> n =~ '.v$\|.sv$'})
let filedirlist = glob(a:dir.'/'.'*',0,1)
let idx = 0
while idx <len(filedirlist)
let file = fnamemodify(filedirlist[idx],':t')
let filedirlist[idx] = file
let idx = idx + 1
endwhile

let filelist = filter(copy(filedirlist),'v:val =~ ".v$" || v:val =~ ".sv$"')

for file in filelist
if has_key(a:files,file)
echohl ErrorMsg | echo "Same file ".file." exist in both ".a:dir." and ".a:files[file]."! Only use one as directory"| echohl None
endif
call extend (a:files,{file : a:dir})
endfor

if a:rec
for item in readdir(a:dir)
"for item in readdir(a:dir)
for item in filedirlist
if isdirectory(a:dir.'/'.item)
call s:GetFileDirDic(a:dir.'/'.item,1,a:files)
endif
endfor
endif
return a:files

endfunction

"}}}3
Expand Down Expand Up @@ -3049,7 +3081,7 @@ function s:GetModuleFileDict(files)
endif
endfor
if module == ''
call extend(modules,{'' : file})
call extend(modules,{'NULL' : file})
else
call extend(modules,{module : file})
endif
Expand Down

0 comments on commit 913e8b4

Please sign in to comment.