0% found this document useful (0 votes)
34 views3 pages

UVM File Inclusion: Import vs Include

In SystemVerilog, the `include directive inserts the contents of an external file directly into the current file, primarily for sharing common definitions and macros. The import statement, on the other hand, brings in names from external files or namespaces into the current scope, facilitating modular design and organization of code. While `include acts like a copy-paste operation, import allows for direct usage of imported items without prefixes, enhancing code management.

Uploaded by

rafee31122
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views3 pages

UVM File Inclusion: Import vs Include

In SystemVerilog, the `include directive inserts the contents of an external file directly into the current file, primarily for sharing common definitions and macros. The import statement, on the other hand, brings in names from external files or namespaces into the current scope, facilitating modular design and organization of code. While `include acts like a copy-paste operation, import allows for direct usage of imported items without prefixes, enhancing code management.

Uploaded by

rafee31122
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

@shraddha_pawankar Date:24/03/2024

When import is used and when `include is used?


In SystemVerilog, both import and include are used for including external files, but they
serve different purposes.

1. `include directive:
 The include directive is used to insert the contents of an external file directly into
the current file at the location where the directive is placed.
 It is mainly used for including common definitions, declarations, or macros that are
required across multiple files.
 The included file is treated as if its content was directly written in place of the
include directive.
 The syntax for include directive is: `include "filename"

In SystemVerilog, the include directive is like copying and pasting code from one file
into another.
When you use include "filename", it takes the contents of the file named "filename"
and adds it directly into the current file where the include statement is placed.
This is handy for reusing common code, like definitions or macros, across multiple
files.

Copy and Paste: Using include is like copying content from one file and pasting it
directly into another file.
Whatever is in the included file gets inserted into the current file at the spot where
you put the include statement.

Sharing Common Stuff: It's great for sharing common stuff like definitions or macros
across multiple files. Instead of rewriting the same things in each file, you can include
a single file that holds all those common bits.

Direct Integration: When you include a file, it's as if the content of that file is directly
written into the current file at the point of the include statement. So, the compiler
sees it all as one big file during compilation.

1|Page
@shraddha_pawankar Date:24/03/2024

2. import statement:
 The import statement is used to bring in names (such as modules, packages, or individual
identifiers) from an external file or a namespace into the current scope.

 It is primarily used for modularizing designs and organizing code hierarchically.

 The imported items can be used directly in the current file without any prefix.

 The syntax for import statement depends on what you are importing. For example, to
import a module,

The syntax is: import module_name::*;

Bringing Stuff In: The import statement in UVM is like inviting certain things from another
place (like a file or a namespace) into the current space where you're working.

Organizing Your Work: It helps you organize your UVM code in a structured way, making it
easier to manage and understand by breaking it into smaller parts.

No Need for Prefix: Once you import something, you can use it directly without needing to
add any extra stuff before it. It's like having your tools right in front of you on the
workbench, ready to use.

Sharing Resources: Packages are like containers where you can store and share different
things like parameters, data, functions, and more. They provide a structured way to organize
and share these resources.

Access Control: You can decide what parts of a package you want to use by importing it into
your current code using the import keyword followed by :: and the specific items you want
to bring in. This way, you only get access to what you need, keeping things tidy and
controlled.

No Hierarchy: Unlike modules or primitives, items inside a package can't refer to each other
using hierarchical references. They're like separate compartments that sit at the same level
as top-level modules or primitives.

2|Page
@shraddha_pawankar Date:24/03/2024

Syntax :
// To import package
1) import <package_name> :: *; // All package items are imported

Importing Everything: When you use import <package_name> :: *;, it's like opening
up the entire package and bringing everything inside it into your current workspace.
You get access to all the items stored in that package.

2) import <package_name> :: <method_name>; // Only <method_name> is


imported

Importing Specific Things: If you only want to bring in a particular thing from the
package, like a method or function, you can use import <package_name> ::
<method_name>;.
This means you're only taking that specific item from the package and leaving the
rest behind.

3|Page

You might also like