Start for free Book a free session

Subprogram bodies in packages

A package declaration is the interface of a package. It can declare functions and procedures, but it cannot contain their bodies (LRM 4.7), those belong in the package body (LRM 4.8). Sigasi reports mislocated and missing bodies as errors. Without a body, a simulator or synthesis tool cannot execute a call to the subprogram.

Function declarations in a package cannot have a function body

A function in a package declaration can only contain the declaration, which ends after the return type (rule 21). Move the body to the package body.

VHDL
package pkg is
  function is_even(n : integer) return boolean is -- body in the package declaration
  begin
    return n mod 2 = 0;
  end function is_even;
end package pkg;

package pkg is
  function is_even(n : integer) return boolean;   -- declaration only
end package pkg;

package body pkg is
  function is_even(n : integer) return boolean is -- the body belongs here
  begin
    return n mod 2 = 0;
  end function is_even;
end package body pkg;

Procedure declarations in a package cannot have a procedure body

The same applies to procedures (rule 40). A procedure in a package declaration ends after its parameter list, or after its name when it has none, and its body goes in the package body.

VHDL
package pkg is
  procedure clear(signal q : out bit) is -- body in the package declaration
  begin
    q <= '0';
  end procedure clear;
end package pkg;

package pkg is
  procedure clear(signal q : out bit);   -- declaration only
end package pkg;

package body pkg is
  procedure clear(signal q : out bit) is -- the body belongs here
  begin
    q <= '0';
  end procedure clear;
end package body pkg;

Function declarations in a package body must have a function body

A function declared inside a package body, which is typically done so that it can be called before its body appears, must have its body in that same package body (rule 22). The specification of the body must conform lexically to the declaration (LRM 4.3, 4.10).

VHDL
package body pkg is
  function is_even(n : integer) return boolean; -- no body follows
end package body pkg;

package body pkg is
  function is_even(n : integer) return boolean; -- declaration, with the body below
  function is_even(n : integer) return boolean is
  begin
    return n mod 2 = 0;
  end function is_even;
end package body pkg;

Procedure declarations in a package body must have a procedure body

The same applies to procedures declared inside a package body (rule 41). The specification of the body must lexically conform to the declaration (LRM 4.3, 4.10). Sigasi matches a declaration with a body by name and by the class, mode, and type of each parameter.

VHDL
package body pkg is
  procedure clear(signal q : out bit); -- no body follows
end package body pkg;

package body pkg is
  procedure clear(signal q : out bit); -- declaration, with the body below
  procedure clear(signal q : out bit) is
  begin
    q <= '0';
  end procedure clear;
end package body pkg;