Subprograms in Package Declarations
Another kind of declaration that may be included in a package declaration is a subprogram declaration—either a procedure or a function declaration. An important aspect of declaring a subprogram in a package declaration is that we only write the
header of the subprogram, that is, the part that includes the name and the interface list defining the parameters (and result type for functions). We leave out the body of the subprogram. For example, suppose we have a package declaration that defines
a bit-vector subtype:
subtype word32 is bit_vector(31 downto 0);
We can include in the package a procedure to do addition on word32 values that represent signed integers. The procedure declaration in the package declaration is procedure add ( a, b : in word32;
result : out word32; overflow : out boolean );
Note that we do not include the keyword is or any of the local declarations or statements needed to perform the addition; these are deferred to the package body.
Each package declaration that includes subprogram declarations must have a corresponding package body to fill in the missing details. However, if a package declaration only includes other kinds of declarations, such as types, signals or fully specified
constants, no package body is necessary. The syntax rule for a package body is similar
to that for the interface, but with the inclusion of the keyword body:
package_body ⇐
package body identifier is
{ package_body_declarative_item }
end [ package body ] [ identifier ] ;
The items declared in a package body must include the full declarations of all subprograms
defined in the corresponding package declaration. These full declarations
must include the subprogram headers exactly as they are written in the package declaration.
A package body may also include declarations of additional types, subtypes,
constants and subprograms. These items are used to implement the subprograms defined
in the package declaration. Note that the items declared in the package declaration
cannot be declared again in the body (apart from subprograms and deferred
constants, as described above), since they are automatically visible in the body
谢谢你们的翻译。。可不要拿网络上的翻译器翻。。我是说需要计算机专业人士或是英语学的好帮我翻,再次谢谢你们。
参考资料:金山快译