Wednesday, March 16, 2011

SV package not allowed to access items declared in Compilation unit scope

By SV packages, we can group all related functions, tasks and classes at one place and import them any where in your environment and use them.

package CHK_PACK;

// Class declartions

// functions
function void check_pack ();
$display ("check_pack:: In CHK_PACK package\n");
endfunction
// Tasks

endpackage

Import this package in the $root space like.
import CHK_PACK::*;

The functions, tasks and classes in this package can be directly used like.

import CHK_PACK::*;

module tb();

initial begin
check_pack();
end

endmodule

NOTE:
1) New objects that are created in the Compilation unit scope cannot be created in these packages. If they are done, the simulator gives the following error.

> SV package not allowed to access items declared in Compilation unit scope