Home

Awesome

MELPA MELPA Stable Build Status Build Status Build Status

verilog-ext.el - SystemVerilog Extensions for Emacs

This package provides useful extensions on top of verilog-mode and verilog-ts-mode.

Requirements

Tree-sitter is optional but recommended and only required if using verilog-ts-mode for some of the features above.

For more info, see the wiki.

Installation

MELPA

verilog-ext is available on MELPA.

straight.el

To install it via straight with use-package:

(straight-use-package 'use-package)
(use-package verilog-ext)

Basic config

The most basic configuration just requires choosing which features you want to load, setup the minor-mode and add it as a hook for verilog-mode. By default all features are enabled:

;; Can also be set through `M-x RET customize-group RET verilog-ext':
;; Comment out/remove the ones you do not need
(setq verilog-ext-feature-list
      '(font-lock
        xref
        capf
        hierarchy
        eglot
        lsp
        lsp-bridge
        lspce
        flycheck
        beautify
        navigation
        template
        formatter
        compilation
        imenu
        which-func
        hideshow
        typedefs
        time-stamp
        block-end-comments
        ports))
(require 'verilog-ext)
(verilog-ext-mode-setup)
(add-hook 'verilog-mode-hook #'verilog-ext-mode)

If installed and loaded via use-package:

(use-package verilog-ext
  :hook ((verilog-mode . verilog-ext-mode))
  :init
  ;; Can also be set through `M-x RET customize-group RET verilog-ext':
  ;; Comment out/remove the ones you do not need
  (setq verilog-ext-feature-list
        '(font-lock
          xref
          capf
          hierarchy
          eglot
          lsp
          lsp-bridge
          lspce
          flycheck
          beautify
          navigation
          template
          formatter
          compilation
          imenu
          which-func
          hideshow
          typedefs
          time-stamp
          block-end-comments
          ports))
  :config
  (verilog-ext-mode-setup))

Keybindings

Enabling of verilog-ext-mode minor-mode creates the following keybindings:

Features

Tree-sitter

Some of the features that verilog-ext provides are based either on builtin verilog-mode Emacs lisp parsing or on tree-sitter verilog-ts-mode. These features are hierarchy extraction and project tags collection for completion and navigation of definitions and references.

Using tree-sitter as a backend is recommended as it is much faster, efficient and accurate than internal Emacs lisp parsing.

For information about installation of verilog-ts-mode check its repo.

Project management

The package provides the variable verilog-ext-project-alist to select which files belong to a specific project:

(setq verilog-ext-project-alist
      `(("ucontroller" ; Project name
         :root "/home/gonz/Repos/larumbe/ucontroller" ; supports remote dirs via Tramp
         :files ("src/my_block.sv"
                 "src/*.v") ; Multiple files can be specified through the glob pattern
         :dirs ("src/tb"
                "-r src/rtl" ; -r to add directories recursively
                "src/syn/*_block"
                "src/**/netlists") ; add all dirs that begin with "src" and end with "netlists"
         :ignore-dirs ("src/ignored_ip")
         :ignore-files ("src/some_ip/ignored_sim_netlist.v")
         :compile-cmd "make tb_top" ; command used to compile current project
         ;; `vhier' related properties
         :command-file "commands.f" ; vhier command file
         :lib-search-path nil)))    ; list of dirs to look for include directories or libraries

The different properties for each project entry determine which files will be used for some features of the package, such as completion, xref navigation, hierarchy extraction and compilation.

Syntax highlighting

<img src="https://user-images.githubusercontent.com/51021955/208774894-a0f3159e-0f41-45db-be28-8a8706ad49ec.gif" width=80%>

For configuration information, see the wiki.

Find definitions and references

verilog-ext provides an xref backend to navigate definitions and references of current project.

<img src="https://github.com/gmlarumbe/verilog-ext/assets/51021955/d196a676-6d28-4bfa-9cee-2662d592b3fb" width=80%>

For configuration information, see the wiki.

Auto-completion

Complete with tags from current project. Supports dot and scope completion for module signals, class attributes and methods.

<img src="https://github.com/gmlarumbe/verilog-ext/assets/51021955/7e0e6e49-8d5d-4be0-bb61-290c950e8623" width=80%>

For configuration information, see the wiki.

Hierarchy extraction

Hierarchy extraction of module at current buffer.

<img src="https://github.com/gmlarumbe/verilog-ext/assets/51021955/94e009c3-e61c-496a-bacf-02e7d022157a" width=80%>

For configuration information, see the wiki.

Language Server Protocol

Auto-configure various SystemVerilog language servers for lsp-bridge, lsp-mode, eglot and lspce:

For configuration instructions, see the wiki

Linting

Support via flycheck for the following linters:

For configuration and usage instructions, see the wiki

Beautify instances

Indent blocks and align parameters and ports of RTL instances.

<img src="https://user-images.githubusercontent.com/51021955/208781782-dbf45c3e-df3f-405a-aacc-1d190ab87ae9.gif" width=80%>

Interactive functions:

Batch-mode functions:

Navigation

Features:

<img src="https://user-images.githubusercontent.com/51021955/208782492-b2ff09b3-f662-4d22-a46c-64eb69f9f7b9.gif" width=80%>

For detailed info see the wiki.

Templates

Select among snippets that cover most frequently used SystemVerilog constructs:

<img src="https://user-images.githubusercontent.com/51021955/209577453-730014b7-d261-4884-9eb2-baa8eaa02a66.gif" width=80%>

Insert instances in current module from file:

<img src="https://user-images.githubusercontent.com/51021955/209577185-ad6b688d-158d-476f-94f5-e1d0eeb0fbd8.gif" width=80%>

Create basic testbench environment from DUT file:

<img src="https://user-images.githubusercontent.com/51021955/209578258-1db8eb6b-37ce-4be0-8cd6-ec380116d0cd.gif" width=80%>

UVM Agent template:

<img src="https://github.com/gmlarumbe/verilog-ext/assets/51021955/255e4b4b-afb7-4720-8b21-55796ae887eb" width=80%>

Functions:

Code formatter

Code-formatter setup via apheleia and verible-verilog-format.

<img src="https://user-images.githubusercontent.com/51021955/220176079-f31ba086-7e64-434f-bb23-9c08e3f3ed6d.gif" width=80%>

See configuration in the wiki.

Compilation

Provides functions to perform compilations with syntax highlighting and jump to error, buffer preprocessing and makefile development:

<img src="https://github.com/gmlarumbe/verilog-ext/assets/51021955/1a78cc1b-da3e-4219-baaf-cb1fb11d335c" width=80%>

See configuration in the wiki.

Imenu

Support detection of instances and methods inside classes.

Instances:

<img src="https://user-images.githubusercontent.com/51021955/208779722-9b760d8d-796b-48cb-ad35-f95f1ec48786.gif" width=80%>

Methods:

<img src="https://user-images.githubusercontent.com/51021955/208780855-52166bf0-5897-48d1-83e8-698d0b1d6269.gif" width=80%>

Find more information here.

Which-func

Enhanced which-func support: show current block/instance at point in the mode-line

<img src="https://user-images.githubusercontent.com/51021955/220174496-b35c99fd-2eb8-424b-9eca-49b9a1d6aa54.gif" width=80%>

Code folding

Code folding via hideshow: <kbd>C-<tab></kbd>

<img src="https://user-images.githubusercontent.com/51021955/220174477-06beb019-3b2f-4329-8897-88e739ed5ea7.gif" width=80%>

Typedefs

Add support for syntax-higlighting and alignment via verilog-pretty-declarations of user defined types and classes.

<img src="https://github.com/gmlarumbe/verilog-ext/assets/51021955/5e654ba5-6eaa-4699-865c-628cadeda75a" width=80%>

For configuration see wiki

Time-stamp

Automatic update of header timestamp after file saving.

For configuration see wiki

Block-end comments

Auto convert block comments to names after file saving.

Port connections

Toggle connections of ports under instance at point

<img src="https://user-images.githubusercontent.com/51021955/220176192-d823ba19-099f-4484-abc7-8269fd92928b.gif" width=80%>

Misc

Wrapper functions to stop cursor at underscores without breaking indentation

Contributing

Contributions are welcome! Just stick to common Elisp conventions and run the ERT suite after testing your changes and before submitting a new PR.

For new functionality add new ERT tests if possible.

Consider sponsoring to help maintaining the project and for the development of new features. Thank you!

ERT Tests

Setup

To run the whole ERT test suite change directory to the verilog-ext root and make sure test-hdl Git submodule has been loaded:

git submodule update --init

Targets

Then run the default target:

$ make

To run a subset of tests (e.g. navigation):

$ make TESTS=navigation

To regenerate all the expected outputs for the tests:

$ make gen

To regenerate the expected outputs for a group of tests (e.g. navigation):

$ make gen TESTS=navigation

Other packages