First Example:
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
Second Example:
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
Third Example:
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
Fourth Example:
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
Fifth Example:
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
Sixth Example:
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
Seventh Example:
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my_pkg1; | |
int unsigned a = 1; | |
endpackage : my_pkg1 | |
module top1(); | |
import my_pkg1 :: *; | |
initial begin | |
$display("my_pkg1::a = %0d", a); | |
end | |
endmodule : top1 | |
//Output: | |
// my_pkg1::a = 1 |
--------------------------------------------------------------------------------------------------------------------------------
Second Example:
--------------------------------------------------------------------------------------------------------------------------------
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my_pkg1; | |
int unsigned a = 1; | |
endpackage : my_pkg1 | |
package my_pkg2; | |
import my_pkg1 :: *; | |
int unsigned b = 2; | |
endpackage : my_pkg2 | |
module top2(); | |
//import my_pkg1 :: *; | |
import my_pkg2 :: *; | |
initial begin | |
$display("top : my_pkg1::a = %0d, my_pkg2::b = %0d", a, b); | |
end | |
endmodule : top2 | |
//Output: | |
// Identifier 'a' has not been declared yet. If this error is not expected, please check if you have set `default_nettype to none. |
--------------------------------------------------------------------------------------------------------------------------------
Third Example:
--------------------------------------------------------------------------------------------------------------------------------
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my_pkg1; | |
int unsigned a = 1; | |
endpackage : my_pkg1 | |
package my_pkg2; | |
import my_pkg1 :: *; | |
int unsigned b = 2; | |
endpackage : my_pkg2 | |
module top3(); | |
import my_pkg1 :: *; | |
import my_pkg2 :: *; | |
initial begin | |
$display("top : my_pkg1::a = %0d, my_pkg2::b = %0d", a, b); | |
end | |
endmodule : top3 | |
//Output: | |
// top : my_pkg1::a = 1, my_pkg2::b = 2 |
--------------------------------------------------------------------------------------------------------------------------------
Fourth Example:
--------------------------------------------------------------------------------------------------------------------------------
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my_pkg1; | |
int unsigned a = 1; | |
endpackage : my_pkg1 | |
package my_pkg2; | |
import my_pkg1 :: *; | |
int unsigned b = 2; | |
function void pkg2_print(); | |
$display("my_pkg2 : pkg2_print : my_pkg1::a = %0d, my_pkg2::b = %0d", a, b); | |
endfunction : pkg2_print | |
endpackage : my_pkg2 | |
module top4(); | |
import my_pkg2 :: *; | |
initial begin | |
void '(pkg2_print()); | |
end | |
endmodule : top4 | |
//Output: | |
// my_pkg2 : pkg2_print : my_pkg1::a = 1, my_pkg2::b = 2 |
--------------------------------------------------------------------------------------------------------------------------------
Fifth Example:
--------------------------------------------------------------------------------------------------------------------------------
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my_pkg1; | |
int unsigned a = 1; | |
endpackage : my_pkg1 | |
package my_pkg2; | |
import my_pkg1 :: *; | |
int unsigned b = 2; | |
function void pkg2_print(); | |
$display("my_pkg2 : pkg2_print : my_pkg1::a = %0d, my_pkg2::b = %0d", a, b); | |
endfunction : pkg2_print | |
endpackage : my_pkg2 | |
package my_pkg3; | |
//import my_pkg1 :: *; | |
import my_pkg2 :: *; | |
int unsigned c = 3; | |
function void pkg3_print(); | |
$display("my_pkg3 : pkg3_print : my_pkg1::a = %0d, my_pkg2::b = %0d, my_pkg3::c = %0d", a, b, c); | |
endfunction : pkg3_print | |
endpackage : my_pkg3 | |
module top5(); | |
import my_pkg3 :: *; | |
initial begin | |
void '(pkg3_print()); | |
end | |
endmodule : top5 | |
//Output: | |
// Identifier 'a' has not been declared yet. If this error is not expected, please check if you have set `default_nettype to none |
--------------------------------------------------------------------------------------------------------------------------------
Sixth Example:
--------------------------------------------------------------------------------------------------------------------------------
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my_pkg1; | |
int unsigned a = 1; | |
endpackage : my_pkg1 | |
package my_pkg2; | |
import my_pkg1 :: *; | |
int unsigned b = 2; | |
function void pkg2_print(); | |
$display("my_pkg2 : pkg2_print : my_pkg1::a = %0d, my_pkg2::b = %0d", a, b); | |
endfunction : pkg2_print | |
endpackage : my_pkg2 | |
package my_pkg3; | |
import my_pkg1 :: *; | |
import my_pkg2 :: *; | |
int unsigned c = 3; | |
function void pkg3_print(); | |
$display("my_pkg3 : pkg3_print : my_pkg1::a = %0d, my_pkg2::b = %0d, my_pkg3::c = %0d", a, b, c); | |
endfunction : pkg3_print | |
endpackage : my_pkg3 | |
module top6(); | |
import my_pkg3 :: *; | |
initial begin | |
void '(pkg3_print()); | |
end | |
endmodule : top6 | |
//Output: | |
// my_pkg3 : pkg3_print : my_pkg1::a = 1, my_pkg2::b = 2, my_pkg3::c = 3 |
--------------------------------------------------------------------------------------------------------------------------------
Seventh Example:
--------------------------------------------------------------------------------------------------------------------------------
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my_pkg1; | |
int unsigned a = 1; | |
endpackage : my_pkg1 | |
package my_pkg2; | |
import my_pkg1 :: *; | |
int unsigned b = 2; | |
function void pkg2_print(); | |
$display("my_pkg2 : pkg2_print : my_pkg1::a = %0d, my_pkg2::b = %0d", a, b); | |
endfunction : pkg2_print | |
endpackage : my_pkg2 | |
package my_pkg3; | |
//import my_pkg1 :: *; | |
import my_pkg2 :: *; | |
int unsigned c = 3; | |
function void pkg3_print(); | |
$display("my_pkg3 : pkg3_print : my_pkg3::c = %0d", c); | |
$display("calling my_pkg2 :: pkg2_print"); | |
pkg2_print(); | |
endfunction : pkg3_print | |
endpackage : my_pkg3 | |
module top7(); | |
import my_pkg3 :: *; | |
initial begin | |
void '(pkg3_print()); | |
end | |
endmodule : top7 | |
//Output: | |
// my_pkg3 : pkg3_print : my_pkg3::c = 3 | |
// calling my_pkg2 :: pkg2_print | |
// my_pkg2 : pkg2_print : my_pkg1::a = 1, my_pkg2::b = 2 |
--------------------------------------------------------------------------------------------------------------------------------
Eighth Example: (package and module having variable with same name)
--------------------------------------------------------------------------------------------------------------------------------
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my_pkg1; | |
int unsigned a = 1; | |
endpackage : my_pkg1 | |
module top(); | |
int unsigned a = 2; | |
import my_pkg1 :: *; | |
initial begin | |
$display ("a=%0d", a); | |
$display ("my_pkg1::a=%0d", my_pkg1::a); | |
end | |
endmodule : top | |
//Output: | |
// a=2 | |
// my_pkg1::a=1 |
--------------------------------------------------------------------------------------------------------------------------------
Ninth Example: (package and module having variable with same name)
--------------------------------------------------------------------------------------------------------------------------------
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package my_pkg1; | |
int unsigned a = 1; | |
endpackage : my_pkg1 | |
module top(); | |
// Not importing my_pkg1 here | |
int unsigned a = 2; | |
initial begin | |
$display ("a=%0d", a); | |
$display ("my_pkg1::a=%0d", my_pkg1::a); | |
end | |
endmodule : top | |
//Output: | |
// a=2 | |
// my_pkg1::a=1 |
--------------------------------------------------------------------------------------------------------------------------------
thank you very much sagar,your examples are very very helpful in understanding the concepts
ReplyDeleteVery helpful for beginner
ReplyDeleteYour blog is providing simple and effective information. This is very helpful
ReplyDeleteFree Source Code
Free Source code For Academic
Academic Project Download
Academic Project Free Download
Freelancer In India
can package be used to store header files in SV testbench , If yes then how to solve the issue of file not found error arising ??
ReplyDeleteVery informative and simplified explanation for beginers
ReplyDelete