Verilog and SystemVerilog formatting
The formatter reads <workspace>/.linty/formatting.yml and formats the source file according to the rules below.
Note:
A file that does not parse is left unchanged.
After formatting, the original and formatted parse trees are compared. If they differ, the file is left unchanged.
Contents
Configuration
verilog:
indentation: 2
indentation is the number of spaces in one level. If the file is missing, the key is missing, or the value is zero or not a positive integer, the indentation is 2.
vhdl:
indentation: 4
verilog:
indentation: 4
module m;
initial begin
a = 1;
end
endmodule
becomes
module m;
initial begin
a = 1;
end
endmodule
Trailing spaces
Spaces at the end of a line are removed.
Tabs
Tabs are replaced with spaces.
Line endings
CRLF and CR line endings are written as LF.
Newline at the end of a file
A non-empty file ends with a newline.
Indentation
Each line is indented to the current level. A line whose first word closes a region is indented one level less. A word that opens or closes a region changes the level of the following lines.
class c;
extern function int f();
pure virtual function int g();
int x;
endclass
module m;
int a;
initial begin
disable fork;
wait fork;
a = 2;
end
endmodule
becomes
class c;
extern function int f();
pure virtual function int g();
int x;
endclass
module m;
int a;
initial begin
disable fork;
wait fork;
a = 2;
end
endmodule
Lists
A comma that separates list items is followed by a single space. A comma inside a string or a comment is left as written.
module m;
initial begin
int x = {parity,data};
m2 u(.a(a),.b(b));
end
endmodule
becomes
module m;
initial begin
int x = {parity, data};
m2 u(.a(a), .b(b));
end
endmodule
Operators
A binary operator has a single space or a line break on each side. A packed or unpacked dimension in a declaration may stay compact, as in [WIDTH-1:0], or use a single space. A unary operator is left as written, and so are ? and :.
module m;
initial a=((addr&mask)== My_addr);
endmodule
becomes
module m;
initial a = ((addr & mask) == My_addr);
endmodule
Line continuation
A multi-line macro ends each continued line with a backslash. Those backslashes form one column, exactly one space past the longest line of the macro.
`define REALLY_LONG_MACRO(arg1, arg2, arg3) \
do_something(arg1); \
do_something_else(arg2); \
final_action(arg3);
becomes
`define REALLY_LONG_MACRO(arg1, arg2, arg3) \
do_something(arg1); \
do_something_else(arg2); \
final_action(arg3);
Macro calls
A macro call keeps the opening parenthesis against the macro name. Whitespace between them, including a line break, is removed. The same rule applies to a call nested in another call’s arguments and to a call written in a `define body.
`uvm_error (ID, "you fail");
`ASSERT (name, a & b, clk, rst);
becomes
`uvm_error(ID, "you fail");
`ASSERT(name, a & b, clk, rst);
Block labels
A block label is read together with the colon that attaches it. The name may follow the keyword, as in begin : foo and end : foo, or it may come first, as in my_buses : begin. One space stays on each side of the colon.
module foobar;
initial begin:foo
end:foo
endmodule: foobar
becomes
module foobar;
initial begin : foo
end : foo
endmodule : foobar
Design units
Headers of modules, interfaces, programs, packages, and classes are placed on one line with a single space between each token.
module
automatic
bar;
endmodule
becomes
module automatic bar;
endmodule
A line comment or a block comment between those words is moved above the header.
module
automatic
// blabla
bar;
endmodule
becomes
// blabla
module automatic bar;
endmodule
ANSI port lists
An ANSI port list starts on the line after the opening parenthesis. The closing parenthesis is the first character of the next line after the last port, written );. Direction, type, name, and a trailing comment each share one column. A packed dimension stays with the type. An unpacked dimension or an initializer stays with the name. A port that omits the direction still leaves that column blank so the type and the name line up with the ports above it. One space separates the columns. A trailing comment starts at least one space after the name.
module foo(input logic clk, // clock
output logic [7:0] data, // samples
output logic ready // ready
);
endmodule
becomes
module foo (
input logic clk, // clock
output logic [7:0] data, // samples
output logic ready // ready
);
endmodule
Comments
Line comments (
//) and block comments (/* */) keep their text. A block comment is indented with the surrounding code, and leading spaces are removed from each of its lines.becomes