1 tags文件的格式
在gvim中敲:help tag可以查看tag的介绍,里面讲了tags的文件格式。
The first lines in the tags file can contain lines that start with
!_TAG_
These are sorted to the first lines, only rare tags that start with "!" can
sort to before them. Vim recognizes two items. The first one is the line
that indicates if the file was sorted. When this line is found, Vim uses
binary searching for the tags file:
!_TAG_FILE_SORTED<Tab>1<Tab>{anything}
第一行可以为:
!_TAG_FILE_SORTED<Tab>1<Tab>I am a tags file.
第二行可以为:
!_TAG_FILE_FORMAT<Tab>1<Tab>/exxtend format; --format=1 will not append;" to lines/
正文的内容格式:
1. {tagname} {TAB} {tagfile} {TAB} {tagaddress}
2. {tagfile}:{tagname} {TAB} {tagfile} {TAB} {tagaddress}
3. {tagname} {TAB} {tagfile} {TAB} {tagaddress} {term} {field} ..
比如:
myclass /home/xxx/test.sv call setpos('.',[0,10,9]) " kind:C
m_data /home/xxx/test.sv call setpos('.',[0,20,4]) " kind:D
MAX_DATA_WIDTH /home/xxx/test.sv call setpos('.',[0,3,4]) " kind:D
new /home/xxx/test.sv call setpos('.',[0,30,4]) " kind:F
其中,[0, 10, 9]表示第10行,第9列。
关键的信息应该就是tagname, tagfile,和pos信息。kind我暂时还没弄清楚作用是什么…但好像是可以自己分类的,Class,Moudle,Define,Function等等
2 用脚本生产tags文件
tags文件可以用ctag之类的工具生成,但是这些工具都不支持systemverilog。我想了下,可以编写脚本来解析源文件,然后生成tags文件,反正tags文件的格式也比较简单。源文件可以在工作目录下直接遍历,也可以从VCS compile log中找到源文件路径然后解析之。这对于脚本达人来说,并非难事……
3 定制ctag使其支持systemverilog的语法
可参考 https://verificationacademy.com/forums/systemverilog/ctags-systemverilog
在home目录下的.ctags文件加入以下配置:
--exclude=.SOS
--exclude=.git
--exclude=nobackup
--exclude=nobkp
--exclude=*.log
--langdef=systemverilog
--langmap=systemverilog:.v.vg.sv.svh.tv.vinc
--regex-systemverilog=/^\s*(\b(static|local|virtual|protected)\b)*\s*\bclass\b\s*(\b\w+\b)/\3/c,class/
--regex-systemverilog=/^\s*(\b(static|local|virtual|protected)\b)*\s*\btask\b\s*(\b(static|automatic)\b)?\s*(\w+::)?\s*(\b\w+\b)/\6/t,task/
--regex-systemverilog=/^\s*(\b(static|local|virtual|protected)\b)*\s*\bfunction\b\s*(\b(\w+)\b)?\s*(\w+::)?\s*(\b\w+\b)/\6/f,function/
--regex-systemverilog=/^\s*\bmodule\b\s*(\b\w+\b)/\1/m,module/
--regex-systemverilog=/^\s*\bprogram\b\s*(\b\w+\b)/\1/p,program/
--regex-systemverilog=/^\s*\binterface\b\s*(\b\w+\b)/\1/i,interface/
--regex-systemverilog=/^\s*\btypedef\b\s+.*\s+(\b\w+\b)\s*;/\1/e,typedef/
--regex-systemverilog=/^\s*`define\b\s*(\w+)/`\1/d,define/
--regex-systemverilog=/}\s*(\b\w+\b)\s*;/\1/e,typedef/
--regex-systemverilog=/^\s*(\b(static|local|private|rand)\b)*\s*(\b(shortint|int|longint)\b)\s*(\bunsigned\b)?(\s*\[.+\])*\s*(\b\w+\b)/\7/v,variable/
--regex-systemverilog=/^\s*(\b(static|local|private|rand)\b)*\s*(\b(byte|bit|logic|reg|integer|time)\b)(\s*\[.+\])*\s*(\b\w+\b)/\6/v,variable/
--regex-systemverilog=/^\s*(\b(static|local|private)\b)*\s*(\b(real|shortreal|chandle|string|event)\b)(\s*\[.+\])*\s*(\b\w+\b)/\6/v,variable/
--regex-systemverilog=/(\b(input|output|inout)\b)?\s*(\[.+\])*\s*(\b(wire|reg|logic)\b)\s*(\[.+\])*\s*(#(\(.+\)|\S+)\))?\s*(\b\w+\b)/\9/v,variable/
--regex-systemverilog=/(\b(parameter|localparam)\b).+(\b\w+\b)\s*=/\3/a,parameter/
用ctags生产tags的命令:
在工程根目录敲:ctags -R --languages=systemverilog ./
或者: ctags -L filelist --languages=systemverilog