RTL Studio Open IDE

2.7 · SYSTEMVERILOG CLASS

Inheritance (extends)

Use extends to inherit and extend class definitions for verification reuse.

Watch on YouTube

What you practice

Inheritance (extends) (2.7). Use extends to inherit and extend class definitions for verification reuse. It is in Advanced OOP — Part 2 · Verification & OOP of the SystemVerilog Masterclass. Software-side verification: dynamic data structures, classes, and the first UVM master keys.

The same IDE is the SystemVerilog simulator. Slang lints the file, Verilator runs it, and the waveform viewer sits next to the source.

What you will learn

Today you will learn how to reuse and extend existing SystemVerilog class definitions using the extends keyword, enabling object-oriented design patterns without modifying original source code.

Learning objectives

  • Understand how to define a child class that inherits from a base class using extends.
  • Learn how to call the parent class constructor and methods using super.
  • Practice extending a Transaction class to add new fields and behavior.
  • Verify inheritance works correctly by running a testbench that instantiates both base and extended classes.

Theory

In SystemVerilog, classes support inheritance: a child class can reuse and extend a parent class’s properties and methods.

KeywordRole
extendsDeclares that a class inherits from another class
superRefers to the parent class (e.g., super.new(), super.display())

Inheritance promotes code reuse and polymorphism. The child class (BadTransaction) inherits all non-private members of the parent (Transaction) and may override or add new functionality.

Practice

Open this chapter in RtlStudio. Files appear automatically in Explore.

  1. Open student/tb/tb.sv in the editor.
  2. Locate the BadTransaction class definition.
  3. Replace __TODO__ with Transaction so BadTransaction properly inherits from Transaction.
  4. Run Simulation from the left sidebar.
  5. Check the Log panel for INFO: messages confirming inheritance behavior.

Summary

You practiced extending a base Transaction class to create a BadTransaction child class using the extends keyword. You added an error injection field to the child class, demonstrating how inheritance enables reuse and expansion without altering the original class. This approach supports modular and maintainable testbench design by promoting code reuse. Key takeaway: Inheritance allows safe customization of existing functionality through class extension.

Run it in the Verilog IDE

  1. Open the lesson in the IDE. The SystemVerilog for this topic is already in the editor.
  2. Lint with Slang before you simulate. It covers both Verilog and SystemVerilog in this IDE.
  3. Run Verilator and inspect the VCD. Interfaces, classes, and assertions count only if the simulator agrees.
  4. Run Yosys when the lesson is synthesizable RTL, and keep testbench-only constructs out of that module.

The lesson is done when the simulation matches Inheritance (extends). Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.