VSCode配置verilog环境(代码提示+自动例化+格式化)

本次推荐三个插件。

目录

Verilog-HDL/SystemVerilog/Bluespec SystemVerilog

可实现功能:

插件配置

功能展示

Verilog_Testbench

可实现功能:

 SystemVerilog and Verilog Formatter

可实现功能

自定义参数设置表

插件配置

如何使用?如何格式化?


Verilog-HDL/SystemVerilog/Bluespec SystemVerilog

可实现功能:

  • 语法高亮
  • 自动例化
  • 代码提示和跳转
  • 自动补全

插件配置

如Verilog HDL/SystemVerilog插件欢迎页的说明,支持Ctags功能:

在这里插入图片描述

配置步骤:

  1. 下载最新版ctags,旧版的有些功能不够齐全;windows可选x64版本;
  2. 将ctags.exe的路径设置到系统环境变量中;
  3. 插件设置中配置ctags路径;
  4. 重启VSCode即可;

 可以选择不同的编译器

 包括:

  • iverilog
  • xvlog(vivado)
  • modelsim

功能展示

支持verilog、SV等语法高亮。

shift+ctrl+p输入verilog,可以直接自动例化模块。

鼠标放在信号上,就会有声明显示在悬浮框中。Ctrl+左键,点击信号名,自动跳转到声明处。光标放在信号处,右键选择查看定义(快捷键可自行绑定),可以在此处展开声明处的代码,用于修改声明十分方便,就不用再来回跳转了。


Verilog_Testbench

可实现功能:

  • 自动生成testbench 

 shift+ctrl+p输入testbench,可以直接生成tb。然后在终端复制即可。


SystemVerilog and Verilog Formatter

这款工具由谷歌推出,同时支持Verilog和System Verilog,效果非常好,支持自定义的格式化参数也很丰富。个人认为比verilog format好用。

可实现功能

  • 自动格式化文件
  • 自动格式化选定内容
  • 自定义格式

自定义参数设置表

verible-verilog-format: usage: bazel-bin/verilog/tools/formatter/verible-verilog-format [options] <file> [<file...>]
To pipe from stdin, use '-' as <file>.

  Flags from common/formatting/basic_format_style_init.cc:
    --column_limit (Target line length limit to stay under when formatting.);
      default: 100;
    --indentation_spaces (Each indentation level adds this many spaces.);
      default: 2;
    --line_break_penalty (Penalty added to solution for each introduced line
      break.); default: 2;
    --over_column_limit_penalty (For penalty minimization, this represents the
      baseline penalty value of exceeding the column limit. Additional penalty
      of 1 is incurred for each character over this limit); default: 100;
    --wrap_spaces (Each wrap level adds this many spaces. This applies when the
      first element after an open-group section is wrapped. Otherwise, the
      indentation level is set to the column position of the open-group
      operator.); default: 4;


  Flags from external/com_google_absl/absl/flags/parse.cc:
    --flagfile (comma-separated list of files to load flags from); default: ;
    --fromenv (comma-separated list of flags to set from the environment [use
      'export FLAGS_flag1=value']); default: ;
    --tryfromenv (comma-separated list of flags to try to set from the
      environment if present); default: ;
    --undefok (comma-separated list of flag names that it is okay to specify on
      the command line even if the program does not define a flag with that
      name); default: ;


  Flags from verilog/formatting/format_style_init.cc:
    --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;
    --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;
    --distribution_items_alignment (Aligh distribution items:
      {align,flush-left,preserve,infer}); default: infer;
    --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;
    --module_net_variable_alignment (Format net/variable declarations:
      {align,flush-left,preserve,infer}); default: 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;
    --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;


  Flags from verilog/parser/verilog_parser.cc:
    --verilog_trace_parser (Trace verilog parser); default: false;


  Flags from verilog/tools/formatter/verilog_format.cc:
    --failsafe_success (If true, always exit with 0 status, even if there were
      input errors or internal errors. In all error conditions, the original
      text is always preserved. This is useful in deploying services where
      fail-safe behaviors should be considered a success.); default: true;
    --inplace (If true, overwrite the input file on successful conditions.);
      default: false;
    --lines (Specific lines to format, 1-based, comma-separated, inclusive N-M
      ranges, N is short for N-N. By default, left unspecified, all lines are
      enabled for formatting. (repeatable, cumulative)); default: ;
    --max_search_states (Limits the number of search states explored during line
      wrap optimization.); default: 100000;
    --show_equally_optimal_wrappings (If true, print when multiple optimal
      solutions are found (stderr), but continue to operate normally.);
      default: false;
    --show_inter_token_info (If true, along with show_token_partition_tree,
      include inter-token information such as spacing and break penalties.);
      default: false;
    --show_largest_token_partitions (If > 0, print token partitioning and then
      exit without formatting output.); default: 0;
    --show_token_partition_tree (If true, print diagnostics after token
      partitioning and then exit without formatting output.); default: false;
    --stdin_name (When using '-' to read from stdin, this gives an alternate
      name for diagnostic purposes. Otherwise this is ignored.);
      default: "<stdin>";
    --verbose (Be more verbose.); default: false;
    --verify_convergence (If true, and not incrementally formatting with
      --lines, verify that re-formatting the formatted output yields no further
      changes, i.e. formatting is convergent.); default: true;

Try --helpfull to get a list of all flags or --help=substring shows help for
flags which include specified substring in either in the name, or description or
path.

插件配置

如果是windows,systemverilogFormatter.veribleBuild设置为win64

systemverilogFormatter.commandLineArguments可以自定义格式化参数,下面放上我自己用的参数,可以实现大部分常用代码段实现对齐。

--indentation_spaces=4 --named_port_alignment=align  --ort_declarations_alignment=align --module_net_variable_alignment=align

如何使用?如何格式化?

和vscode内置格式化一样,直接shift+ctrl+f就可以格式化文件,ctrl+k可以格式化选定内容。

值得注意的是,由于这个插件也是在完善中,还是存在部分问题的。

比如else不会换行。

比如,存在语法问题,或者不能识别语法的时候,格式化会使用不了。这里我将最后一个端口加上","就不能格式化了。

  • 21
    点赞
  • 156
    收藏
    觉得还不错? 一键收藏
  • 11
    评论
### 回答1: 首先,需要在VS Code中安装Verilog插件。在插件市场中搜索“Verilog”即可找到。 接下来,需要安装Vivado软件,并将其添加到系统环境变量中。在Windows系统中,可以在“控制面板”中找到“系统”选项,然后点击“高级系统设置”,在弹出的窗口中点击“环境变量”,找到“Path”选项,点击“编辑”,然后在末尾添加Vivado软件的安装路径。 然后,在VS Code中打开Verilog文件,点击右下角的“选择解释器”按钮,选择“verilog.vivado”作为解释器。接下来,可以使用VS Code中的调试功能来调试Verilog代码。 需要注意的是,Verilog++是一种较为新的Verilog语言扩展,目前还没有被广泛支持。因此,在配置Verilog++时需要特别注意。 ### 回答2: Visual Studio Code(VSCode)是一款广受欢迎的轻量级开发工具和代码编辑器,它支持多种编程语言,包括Verilog。这个配置过程并不复杂,具体步骤如下: 第一步:安装Visual Studio Code 在VSCode官方网站(https://code.visualstudio.com/)下载VSCode并安装。 第二步:安装Verilog插件 在VSCode中打开“扩展”视图,搜索“Verilog HDL Language”插件并安装。 第三步:设置编译器 在VSCode的“Settings”视图中搜索“Verilog”,找到“Verilog: Simulation>Compiler Path”选项,将其设置为Xilinx Vivado工具中的vlog.exe路径。 第四步:创建项目并编写代码VSCode中创建一个新文件夹,并创建包含Verilog代码的文件。在文件中编写代码并保存。 第五步:创建Vivado工程 在Vivado中创建一个新工程,选择刚才创建的文件夹作为项目路径,并设置好工程选项。 第六步:生成RTL 在Vivado中将Verilog代码添加到工程中,并生成RTL。 第七步:使用VSCode进行仿真 在VSCode中打开终端,进入项目路径,运行仿真代码。这将使用Vivado中生成的RTL执行仿真操作。 通过以上步骤,您现在已经可以在VSCode配置Verilog开发环境,并使用Vivado进行仿真。祝您愉快的编程旅程! ### 回答3: 在vscode配置Verilog与Vivado的过程需要按照以下步骤进行: 1. 首先,需要安装vscode和Vivado软件。Vivado是Xilinx公司的FPGA设计工具,用于开发Verilog代码。 2. 安装Verilog系统Verilog插件。在vscode的插件市场中可以找到这个插件,安装后即可在vscode中使用相应的Verilog语言支持。 3. 在Vivado软件中创建项目。在Vivado中创建项目之前,需要先设置好设计的元件库和仿真IP库,根据设计需求设置好各项参数。 4. 在Vivado中导出设计文件。在设计完成后,在Vivado的菜单栏中选择"File"->"Export"->"Export HDL",在弹出的窗口中选择要导出的文件格式和路径,然后点击"Export"按钮,即可将设计文件导出到指定的路径中。 5. 在vscode中打开设计文件。在vscode的文件窗口中选择要打开的设计文件,双击即可打开文件。 6. 在vscode中编写代码。编写代码时需要注意代码的格式和语法,可以参考其他已有的Verilog代码参考。 7. 在vscode中进行调试和仿真。在vscode的插件中,选择"Debug"->"Prepare for Debugging",然后再点击"Start Debugging"按钮,即可在vscode中进行仿真和调试。 总的来说,通过vscode和Vivado配合使用,可以更方便地进行Verilog代码的编写、仿真和调试,提高设计效率和质量。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值