在systemverilog中,有时我们难免会给不同的单元(module、package、interface等等)起相同的名字(identifier),为了让这些相同的名字不冲突,systemverilog给它们定义了不同的Name spaces(命名空间)。
在谈及Name spaces前,我们先了解compilation unit(中文即编译空间),指的是我们将一个或者多个systemverilog源代码编译时的集合。在vcsmx中,如果你采用的是Two-step Flow,那么你看到的是一个整体的compilation unit。如果你采用的是Three-step Flow,那么你就会看见多个compilation units。我们可以显示地使用$unit来访问编译空间。
systemverilog根据Name spaces和compilation unit的关系,将Name spaces分为以下3类8种:
- Globals
Definitions name space——非嵌套定义的module, primitive, program, and
interface identifiers。
Package name space——在所有compilation units中定义的package identifiers。
- Global to the compilation unit
Compilation-unit scope name space——在module, interface, package,
checker, program, and primitive外部定义的functions, tasks, checkers, parameters, named events, net declarations, variable declarations, and user-defined types。
text macro name space——text macro names。
- Local
Module name space——在module, interface, package, program, checker, and primitive内部定义的identifier。
Block name space——在named blocks, functions, tasks, parameters, named
events, variable type of declaration, and user-defined types内部定义的identifier。
Port name space——在module, interface, primitive, and program内部定义的port identifier。
Attribute name space——在(* *)之间定义的属性名。
Example
`define candy // This candy is in the text macro name space.
function void candy; // This candy is in the compilation-unit scope name space.
endfunction
module candy( // This candy is in the definitions name space.
input candy ); // This candy is in the port name space.
initial begin
(* candy *) // This candy is in the attribute name space.
bit candy; // This candy is in the block name space.
end
endmodule
package candy; // This candy is in the package name space.
function void candy; // This candy is in the module name space.
endfunction
endpackage
参考:
1、Keisuke ShimizuHidden Gems of SystemVerilog – 2. Name spaces by Keisuke Shimizu
2、IEEE Std 1800™-2012 3.12 Compilation and elaboration
3、IEEE Std 1800™-2012 3.13 Name spaces