<- Click here to Toggle

Home » Resources » Hierarchy

Hierarchy

Verilog HDL has a simple organization. All data, functions and tasks are in modules except for system tasks and functions, which are global, and can be defined in the PLI. A Verilog module can contain instances of other modules. Any uninstantiated module is at the top level. This does not apply to libraries, which therefore have a different status and a different procedure for analyzing them.

A hierarchical name can be used to specify any named object from anywhere in the instance hierarchy. The module hierarchy is often arbitrary and a lot of effort is spent in maintaining port lists.

SystemVerilog adds many enhancements for representing design hierarchy:

Packages:

SystemVerilog packages provide an additional mechanism for sharing

interfaces and program Packages are explicitly named scopes appearing at the outermost level of the source text. Types, variables, tasks, functions, sequences, and properties may be declared within a package. Such declarations may be referenced within modules, macromodules, interfaces, programs, and other packages by either import or fully resolved name.

Above can be shared across SystemVerilog modules, macromodule interfaces and programs. Few rules that should be followed with packages are.

Accessing data, functions or types in packages there are two ways.

package ComplexPkg;
typedef struct {
float i, r; } Complex;
function Complex add(Complex a, b);
add.r = a.r + b.r;
add.i = a.i + b.i;
endfunction
function Complex mul(Complex a, b); mul.r = (a.r * b.r) - (a.i * b.i);
mul.i = (a.r * b.i) + (a.i * b.r);
endfunction
endpackage : ComplexPkg

Referencing data in packages

Packages must exist in order for the items they define to be recognized by the scopes in which they are imported. One way to use declarations made in a package is to reference them using the scope resolution operator “::”.

ComplexPkg::Complex cout = ComplexPkg::mul(a, b);

An alternate method for utilizing package declarations is via the import statement.

Compilation unit support

SystemVerilog supports separate compilation using compiled units. The following terms and definitions are provided:

Top-level instance:

The name $root is added to unambiguously refer to a top level instance, or to an instance path starting from the root of the instantiation tree. $root is the root of the instantiation tree.

For example:
$root.A.B // item B within top instance A
$root.A.B.C // item C within instance B within instance A