Verible 是一套 SystemVerilog / verilog 开发工具,包括解析器、样式检查器、格式化程序和语言服务器。这里为主要分享关于格式化工具verible-verilog-format的使用。用来格式化verilog代码,实现代码风格统一。
verible 项目托管于github,项目地址:https://github.com/chipsalliance/verible
verible可以自行编译安装,也可以下载已经编译好的可执行文件。下载路径见github release。下载完成后,将下载到的压缩包解压,在文件夹的子目录verible-bin/中就可以找到 verible-verilog-format 了。
使用命令调用:
verible-verilog-format -- [options] filename.v
举例:以原位替换的方式,按照默认规则进行verilog代码格式化, inplace及为原位替换选项。
verible-verilog-format --inplace testbench.v
其他可用配置参数可以参考,以为为部分选项的,全部选项见:https://chipsalliance.github.io/verible/verilog_format.html:
--column_limit
(Target line length limit to stay under when formatting.);default: 100;
行代码长度限制,默认最长100个字符。 使用示例: --column_limit=200 设置最长字符数为200个
--indentation_spaces
(Each indentation level adds this many spaces.);default: 2;
代码层级缩进深度,默认为2字符 使用示例:--indentation_spaces=4 设置代码层级缩进为4字符
--assignment_statement_alignment
(Format various assignments:{align,flush-left,preserve,infer}); default: infer;
赋值语句对齐方式:{对齐、左对齐、保留、推断} 默认值:推断;
--case_items_alignment
(Format case items:{align,flush-left,preserve,infer}); default: infer;
case语句格式化对齐方式:{对齐、左对齐、保留、推断} 默认值:推断;
--class_member_variable_alignment
(Format class member variables:{align,flush-left,preserve,infer}); default: infer;
类成员变量格式化对齐方式:{对齐、左对齐、保留、推断} 默认值:推断;
--compact_indexing_and_selections
(Use compact binary expressions inside indexing / bit selection operators); default: true;
使用紧凑的二进制表达式索引/位选择运算符; 默认值:true;
--distribution_items_alignment
(Aligh distribution items: {align,flush-left,preserve,infer}); default: infer;
distribution对齐方式:{对齐、左对齐、保留、推断}); 默认值:推断;
--enum_assignment_statement_alignment
(Format assignments with enums: {align,flush-left,preserve,infer}); default: infer;
枚举对齐方式:{对齐、左对齐、保留、推断}); 默认值:推断;
--expand_coverpoints
(If true, always expand coverpoints.); default: false;
--formal_parameters_alignment
(Format formal parameters: {align,flush-left,preserve,infer}); default: infer;
格式形参对齐方式:{对齐、左对齐、保留、推断} 默认值:推断;
--formal_parameters_indentation
(Indent formal parameters: {indent,wrap});default: wrap;
形参缩进方式{indent,wrap};默认:换行;
--module_net_variable_alignment
(Format net/variable declarations: {align,flush-left,preserve,infer}); default: infer;
wire声明对齐方式:{align,flush-left,preserve,infer}); 默认值:推断;
--named_parameter_alignment
(Format named actual parameters: {align,flush-left,preserve,infer}); default: infer;
命名参数对齐方式:{对齐、左对齐、保留、推断} 默认值:推断;
--named_parameter_indentation
(Indent named parameter assignments:{indent,wrap}); default: wrap;
命名参数缩进方式:{缩进,换行}); 默认:换行;
--named_port_alignment
(Format named port connections:{align,flush-left,preserve,infer}); default: infer;
端口名称对齐方式:{对齐、左对齐、保留、推断}); 默认值:推断;
--named_port_indentation
(Indent named port connections: {indent,wrap});default: wrap;
端口名称缩进方式:{缩进,换行}); 默认:换行;
--port_declarations_alignment
(Format port declarations:{align,flush-left,preserve,infer}); default: infer;
端口声明格式:{对齐、左对齐、保留、推断} 默认值:推断;
--port_declarations_indentation
(Indent port declarations: {indent,wrap});default: wrap;
端口声明缩进方式:{缩进,换行}); 默认:换行;
--port_declarations_right_align_packed_dimensions
(If true, packed dimensions in contexts with enabled alignment are aligned to the right.); default: false;
对齐的上下文中的尺寸将向右对齐。默认值:false;
--port_declarations_right_align_unpacked_dimensions
(If true, unpacked dimensions in contexts with enabled alignment are aligned to the right.); default: false;
--struct_union_members_alignment
(Format struct/union members: {align,flush-left,preserve,infer}); default: infer;
结构体,联合成员变量对齐方式: 默认:推断
--try_wrap_long_lines (If true, let the formatter attempt to optimize line
wrapping decisions where wrapping is needed, else leave them unformatted.
This is a short-term measure to reduce risk-of-harm.); default: false;
--wrap_end_else_clauses
(Split end and else keywords into separate lines); default: false;
将 end 和 else 关键字分成单独的行;默认值:false;
--inplace (If true, overwrite the input file on successful conditions.);default: false;
原位替换为格式化后结果,默认:false
为了方便使用,使用python写了一个基于filelist.f进行批量处理的脚本, 可以根据filelist进行代码批量格式化,有需要的可以自取:
https://github.com/wherelse/verilog-formatter
https://circuitcove.com/tools-verible/
https://chipsalliance.github.io/verible/verilog_format.html
本网站文章版权均为本人所有,未经同意不得私自搬运复制,欢迎注明引用出处的合理转载,图片转载请留言。文章内容仅用于技术研究和探索,不得用于违法目的。