gvim tags如何支持systemverilog

本文介绍了如何生成tags文件,用于GVIM中快速跳转SystemVerilog代码。tags文件格式包含特殊行如`_TAG_FILE_SORTED`和`_TAG_FILE_FORMAT`,以及类、任务、函数等标签信息。通过编写脚本或定制ctags配置,可以解析SystemVerilog源文件生成tags,支持类、任务、函数、模块等元素的定位。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值