Package body
package_body
package body package _simple_name is package_body_declarative_part end [ package body ] [ package _simple_name ] ;
Further definitions
simple_name
package_body_declarative_part
Examples
The objects from the library pck_0 are integrated. In the package body the constant cint , which has to be declared in the package header, is declared as integer and initialized with the result value from function call f(6) (deferred constant).
USE work.pck_0.all; PACKAGE BODY pck IS CONSTANT cint : integer := f(6); END pck ;
Definition of the package body pck_1 in which the two functions G and F are declared.
In the function G the value of the equation A XOR B is returned as a result (as Bit).
In the function F a variable V is declared as Bit which then receives the value from S1 NAND S2 . The function F delivers the bit-value from the function call G(V, S2) as a result value.
PACKAGE BODY pck_1 IS FUNCTION G ( A, B : Bit ) RETURN Bit IS BEGIN RETURN NOT ( A XOR B ); END ; FUNCTION F ( S1, S2 : Bit ) RETURN Bit IS VARIABLE V : Bit; BEGIN V := S1 NAND S2; RETURN G(V, S2); END ; END pck_1 ;
Definition of the package body tristate in which the two functions BitVal and TriVal are declared.
In the function BitVal a constant Bits is declared and initialized with the value “0100”. As a result, the value of the bit in the position Tri'Pos ( Value ) of Bits is returned.
In the function TriVal a variable V of the type Tri is declared and initialized with the value Z .
In LOOP either the value of Source(i) is transferred to V or E is returned as a result value, depending on the individual value of Source(i) and V . In the first case V is returned as a result value afterwards.
PACKAGE BODY tristate IS FUNCTION BitVal ( Value : Tri ) RETURN Bit IS CONSTANT Bits : Bit_Vector := "0100"; BEGIN RETURN Bits(Tri'Pos(Value)) END ; FUNCTION TriVal ( Value : Bit ) RETURN Tri IS VARIABLE V : Tri := 'Z'; BEGIN FOR i IN Sources'Range LOOP IF Sources(i) /= 'Z' THEN IF V = 'Z' THEN V := Sources(i); ELSE RETURN 'E'; END IF ; END IF ; END LOOP ; RETURN V ; END ; END tristate ;