Skip to content

Formatter macro policy

The formatter cannot expand macros, so it treats them conservatively. Tell it what your macros are in lazyverilog.toml:

toml
[format.macros]
object_like_expr = ["MY_WIDTH"]
function_like_expr = ["MY_CLAMP"]
statement_like = ["uvm_info", "DV_CHECK_EQ"]
declaration_like = ["uvm_component_utils"]
control_flow_like = ["MY_IF"]
block_begin_like = ["uvm_object_utils_begin"]
block_end_like = ["uvm_object_utils_end"]
whitespace_sensitive = ["DV_SPINWAIT"]

Names work with or without the leading backtick. Put a macro in one role only. whitespace_sensitive is an extra safety flag that can go with any role.

Roles

RoleUse forEffect
object_like_exprA macro with no arguments that stands for a value: `MY_WIDTHFormatted like an ordinary operand
function_like_exprA macro call that yields a value: `MIN(a, b)An expression item that can sit in argument lists
statement_likeA complete statement: `uvm_info(...)Line break after it
declaration_likeDeclaration-level macros: `uvm_object_utils(T)Line break after it
control_flow_likeA macro used like if: `MY_IF(en)No alignment inside; no forced break. Use statement_like if it should end the line
block_begin_likeOpens a block: `uvm_object_utils_beginLine break, then indents what follows
block_end_likeCloses that blockUn-indents, then line break
whitespace_sensitiveArguments whose exact spacing mattersArguments are left exactly as written
systemverilog
class my_item extends uvm_object;
  `uvm_object_utils_begin(my_item)
    `uvm_field_int(addr, UVM_DEFAULT)
    `uvm_field_int(data, UVM_DEFAULT)
  `uvm_object_utils_end
endclass

Always true

  • `ifdef, `else, `endif, and single-line `define stay on their own lines.
  • Multiline `define bodies are left verbatim.
  • Text between // verilog_format: off and // verilog_format: on is left verbatim.

Choosing a role

  • Substitutes a value: object_like_expr or function_like_expr.
  • A complete action: statement_like.
  • Appears where a declaration would: declaration_like.
  • Changes indentation: block_begin_like and block_end_like.
  • Formatting its arguments could change the meaning: whitespace_sensitive, or wrap the region in // verilog_format: off / on.

Released under the MIT License. Themed with Catppuccin.