8. General - Introduction to Object-Oriented Programming
​
Classes are the foundation of object-oriented programming (OOP) in SystemVerilog. While modules and interfaces describe hardware structure, classes are used primarily in verification environments to create flexible, reusable, and maintainable testbench code.
​
Think of a class as a cookie cutter, and objects as the cookies. You design the cookie cutter once (the class), and then you can make many cookies (objects) from it. Each cookie has the same shape but can have different decorations (property values).
​
What is Object-Oriented Programming?
​
OOP is a programming paradigm that organizes code around "objects" rather than just functions and variables. Each object combines data (properties) and the functions that work with that data (methods).
​
Why Classes Matter in Verification?
​
-
Organization - Group related data and behavior together
​
-
Reusability - Write code once, use it many times
​
-
Modularity - Break complex testbenches into manageable pieces
​
-
Abstraction - Hide complex details, show only what's needed
​
-
Inheritance - Build new functionality on top of existing code
​
-
Polymorphism - Write flexible code that works with different types
​
Real-World Verification Scenario
​
Imagine you're verifying a PCIe controller. You need to:
​
-
Generate hundreds of different transactions
​
-
Send them to the DUT (Device Under Test)
​
-
Collect responses
​
-
Check if responses are correct
​
-
Track which scenarios were tested
​
Without classes, you would have:
Verilog
With classes, you have:
Verilog
Classes vs Modules vs Structures
​
Understanding the differences:
​
Modules
​
-
Describe hardware (synthesizable)
​
-
Cannot be created dynamically
​
-
Used for RTL design
​
-
Example: Adders, counters, state machines
​
Structures (struct)
​
-
Group related data
​
-
Limited functionality
​
-
Can be synthesized
​
-
Example: Register fields, packet headers
​
Classes
​
-
Verification only (not synthesizable)
​
-
Can be created dynamically with new()
​
-
Support inheritance and polymorphism
​
-
Example: Transactions, drivers, monitors, scoreboards
​
Simple First Example
Verilog
Classes in UVM
​
The Universal Verification Methodology (UVM) is built entirely on SystemVerilog classes. When you learn classes, you're learning the foundation of modern verification.
​
-
uvm_component - Base class for all testbench components
​
-
uvm_transaction - Base class for all transactions
​
-
uvm_driver - Sends transactions to DUT
​
-
uvm_monitor - Observes DUT activity
​
-
uvm_scoreboard - Checks correctness
​
Note: Classes are ONLY for verification (testbenches). They cannot be synthesized into hardware. Use modules and always blocks for RTL design.
​
Tip: Start with simple classes and gradually add features. Don't try to use all OOP features at once!
