Object-Oriented Programming
Object-oriented Programming(OOP) language model for software design that revolves around objects or data instead of logic and functions. It focuses on what the developers want to manipulate rather than how they manipulate them. This approach is well suited for large, complex, and actively updated and maintained.
OOP for Verification
Typically, a testbench creates a transaction i.e., generates the necessary input for the DUT based on the defined rules, transmits it to the DUT, receives the response from the DUT, verifies the response against the golden reference, and generates a report. Grouping all the processes together helps in creating and maintaining large testbenches. However, while verifying a large design the process of detecting a bug in the testbench becomes tedious and complex. Also, when verifying a bus transaction, multiple arrays are required to store data and addresses. For N transactions, N*(multiple arrays) is required. Moreover, these arrays are static, meaning they are allocated at the compile time with a fixed array size, if the verification requires any additional arrays during run time, changes are needed to be made in the source code manually. To overcome these drawbacks, concepts from OOP is applied in SystemVerilog to improve the design’s modularity and reusability.
The testbench is divided into blocks and with the help of OOP they communicate with each other. The generator creates transactions and passes them to the next level, The driver sends the transactions to the design. The monitors accept the response. The scoreboard checks the response against the golden reference.
Advantages of OOP
- Modularity: The testbench can be divided into blocks with the help of classes and maintained independently of the source code for other classes.
- Reusability: Multiple objects can be constructed once a class is written.
- Extensibility: New functionality can be added to an existing class without modifying the underlying code.
- Maintainability: Easy and simple to maintain and modify because of OOP’s modular structure.
Nomenclature
- Class: is a basic building block containing routines and variables. This is analogous to a module in Verilog.
- Handle: is a pointer to the object. It acts as a pointer or link to the actual object stored in memory.
- Object: is an instance of a class. Similar to instantiating a module in Verilog.
- Property: is a variable that holds data. In Verilog, this is a signal such as a register or wire.
- Method: is the procedural code that manipulates variables, contained in tasks and functions. Similar to initial and always blocks, in Verilog.
- Prototype: the header of a routine that shows the name, type, and argument list plus return type.
In Verilog, you build complex designs by creating modules and instantiating them hierarchically. In OOP you create classes and construct them (create objects) to create a similar hierarchy.
Note: Modules are instantiated during compilation while classes are constructed at run time.