verilog两者都会导致编译错误,所以没有区别:-) 。在System Verilog范围内存在差异。
import pkg::* before模块声明将把包的所有定义拉到全局范围内。这意味着在此文件中或在命令行上跟随您的文件的其他文件中定义的所有模块都将知道此导入。例如
import pkg::abc_t;
modle top;
abc_t a;
...
endmodule
module child;
abc_t b;
...
endmodule
在模块内导入只会将包内容拉入此模块范围:
modle top;
import pkg::abc_t;
abc_t a;
...
endmodule
module child;
abc_t b; << error, not visible, needs import first
...
endmodule
到目前为止一切顺利,但是如果模块端口使用包怎么办?在第一种情况下没有问题:
import pkg::*;
module top(input abc_t abc);
但是在全局范围内导入通常是一件坏事,这可能会导致大型项目出现问题。解决方案是在模块头中使用导入。
module top
import pkg::*;
(input abc_t abc);
现在您已经在模块范围内导入了包,并让端口声明也看到了这个导入。