VHDL 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

vhdl:
  indentation: 2
  keyword-case: keep

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.

keyword-case is lowercase, uppercase, or keep. A missing or unknown value leaves keywords as they are written. Comments, strings, and character literals are never changed by this setting.

vhdl:
  keyword-case: uppercase
entity foo is
  -- KEEP End
  constant c : string := "IF";
end entity;

becomes

ENTITY foo IS
  -- KEEP End
  CONSTANT c : string := "IF";
END ENTITY;

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.

architecture rtl of foo is
signal x : std_logic;
begin
process (clk) is
begin
if rising_edge(clk) then
x <= not x;
elsif reset = '1' then
x <= '0';
else
x <= x;
end if;
end process;
end architecture;

becomes

architecture rtl of foo is
  signal x : std_logic;
begin
  process (clk) is
  begin
    if rising_edge(clk) then
      x <= not x;
    elsif reset = '1' then
      x <= '0';
    else
      x <= x;
    end if;
  end process;
end architecture;

One item per line

Each library clause, use clause, context reference, declaration, and statement is placed on its own line. A list written on one line is split.

library ieee; use ieee.std_logic_1164.all;
x <= y; z <= w;

becomes

library ieee;
use ieee.std_logic_1164.all;
x <= y;
z <= w;

if, case, loop, and their branches follow the same rule: the header, each branch label, and the end clause are not left on the same line as the statements they contain.

Design units

These constructs share one layout: entity, architecture, package, context, configuration declaration, and component declaration.

The header is one line. begin and end are on their own lines. An optional end keyword and end name stay on the end line.

architecture
rtl
of
foo
is
  signal x : std_logic;
begin x <= y; end
architecture
rtl
;

becomes

architecture rtl of foo is
  signal x : std_logic;
begin
  x <= y;
end architecture rtl;
entity e -- the entity
is begin
end
entity
;

becomes

entity e is -- the entity
begin
end entity;

Library, use, and context clauses

Each library, use, and context clause is one line. Names in one clause stay on that line, separated by commas. A second clause written on the same line is split off.

library
ieee
,
std
;
library work; library extras;
use ieee.std_logic_1164.std_ulogic; context work.ctx;

becomes

library ieee, std;
library work;
library extras;
use ieee.std_logic_1164.std_ulogic;
context work.ctx;

Declarations

A declaration that fits is one line: the keyword, the name, and the rest of the declaration. An alias is one line. A group declaration keeps the name and : together, and keeps the closing parenthesis with the semicolon.

A record is a declaration whose elements are indented and aligned:

type rec is record a : integer; b : integer; end record;

becomes

type rec is record
  a : integer;
  b : integer;
end record;

Successive declarations of one kind share a : column. A blank line, another kind of item, or another region ends the group. Subtype declarations also line up on is, the type, and what follows the type. Full type declarations and group templates line up on is.

signal a : bit; -- short
signal bb : integer; -- longer type

becomes

signal a  : bit;     -- short
signal bb : integer; -- longer type
subtype a      is integer                      range 1 to 3;   -- short
subtype b      is mytype                       range 25 to 31; -- short
subtype longer is std_logic_vector(7 downto 0);                -- vector
type a      is (x, y);               -- short
type longer is array(0 to 3) of bit; -- array
group a      is (signal);    -- short
group longer is (signal <>); -- box

Attributes

An attribute declaration stays on one line: attribute, the name, :, the type, and ;. Successive declarations share the : column of other declarations of one kind.

attribute a : bit; -- first
attribute length : integer; -- second

becomes

attribute a      : bit;     -- first
attribute length : integer; -- second

An attribute specification stays on one line: attribute, the designator, of, the entity name, :, the class, is, the expression, and ;. Successive specifications line up on of, the entity name, the class, and is. A blank line or another kind of item ends the group. Trailing comments start one space after the longest line. A comma in the entity name list stays on that line.

attribute a of e : signal is true; -- one
attribute longer of name : component is "yes"; -- two

becomes

attribute a      of e    : signal    is true;  -- one
attribute longer of name : component is "yes"; -- two

Generics, ports, and parameters

generic, port, function parameters, and procedure parameters use the same list layout.

The opening parenthesis stays on the keyword line. Each item is on its own line. The closing parenthesis is on its own line, indented with the keyword.

Names, colon (:), mode, bype and trailing comments are vertically alinged.

entity foo is
  port (
    clk_i   : in  std_ulogic;
    res_o   : out std_ulogic_vector(31 downto 0); -- My comment
    valid_o :     std_ulogic                      -- My other comment
  );
end entity foo;

Processes

The label, postponed, process, the sensitivity list, and is form one header. begin and end are on their own lines. An optional postponed and the process label stay on the end line. Declarations between the header and begin stay in the declarative part and are indented.

process ( clk , reset ) is begin null; end process;

becomes

process (clk, reset) is
begin
  null;
end process;

Statements

If

The label and if start the header. A condition that wraps is indented under the expression, and then stays with the last token of that condition. elsif and else are at the if level. end if and an optional label are one line.

lab : if a and b
then
x <= y;
elsif c
then
z <= w;
else x <= z;
end
if
lab
;

becomes

lab : if a and b then
  x <= y;
elsif c then
  z <= w;
else
  x <= z;
end if lab;

Case

The case header is one line. Each when starts its alternative. A choice that is already wrapped stays wrapped, and => is placed on the last choice token. end case and an optional label are one line.

lab
:
case
x
is
when lab :
'0' |
'1'
=>
null;
when others =>
null;
end
case
lab
;

becomes

lab : case x is
  when lab :
    '0' |
    '1' =>
    null;
  when others =>
    null;
end case lab;

Loop

The loop header and end loop, including an optional label, are each one line. The body is indented.

lab: while a=b
loop
  x <= y;
end loop lab;

for i in 0 to 7
loop
  null;
end loop;

becomes

lab : while a = b loop
  x <= y;
end loop lab;

for i in 0 to 7 loop
  null;
end loop;

Assertion

assert stays with its condition. report and severity each start on a new line, indented under the assertion. A label stays on the assert line.

check : assert ready report "late" severity warning;

becomes

check : assert ready
  report "late"
  severity warning;

Assignment

Simple, conditional, and force signal assignments in one group align on <=. A conditional assignment that is already a single line stays on that line. When it is wrapped, the waveforms align, when and else align, and else remains the last token of its line. A final when without else is aligned the same way. A label stays on the assignment line.

s <= a when b else
cc when d else e;

becomes

s <= a  when b else
     cc when d else
     e;

Instantiation and maps

The instance label and the instantiated unit are one line, for a direct name and for the entity, component, and configuration forms.

u : entity work.e(rtl);
v : component work.foo;
w : configuration work.cfg;
x : work.bar;

generic map and port map use the same layout. The opening parenthesis stays on the map line, each association is on its own line, and => aligns. A map written on one line is expanded. A port map that was written on the same line as the closing of the generic map is split onto its own lines.

u : entity work.e generic map(a => x, bb => y);

becomes

u : entity work.e
  generic map (
    a  => x,
    bb => y
  );

Generate statements

A for generate header is one line: the label, for, the range, and generate. end generate and an optional label are one line. Declarations in the generate body stay in the declarative part, and begin is on its own line.

An if generate keeps each label with its condition: if, elsif, and else labels stay with that branch, and end generate with its label is one line. The branches are indented like an if statement.