RTL Studio Open IDE

4.3 · UVM CLASS

UVM factory: type_id::create()

Allocate components with type_id::create() instead of new() for flexible substitution.

Watch on YouTube

What you practice

UVM factory: type_id::create() (4.3). Allocate components with type_id::create() instead of new() for flexible substitution. It is in Factory — Part 4 · Advanced UVM of the UVM Masterclass. Factory, config objects, virtual sequences, and pipelined drivers for large SoC verification.

The UVM bench compiles in that same browser SystemVerilog simulator. You edit the test in the IDE, run Verilator, and read the log beside the waveform.

What you will learn

You will learn how to allocate UVM components via the factory pattern using type_id::create() instead of direct new() calls, enabling flexible component substitution and test customization.

Learning objectives

  • Understand why the UVM factory pattern improves testbench flexibility.
  • Replace direct new() calls with type_id::create() for components like fifo_env and its children.
  • Recognize that type_id::create() requires prior uvm_component_utils() or uvm_object_utils() registration.
  • Keep new()/randomize() for sequence items, as they are not UVM components.

Theory

The UVM factory is a registry that allows components and objects to be instantiated indirectly via string-based type names. This decouples testbench construction from concrete types, enabling runtime overrides (e.g., swapping a scoreboard with a custom variant). Components must register with uvm_component_utils() (for components) or uvm_object_utils() (for objects) to participate in the factory. The factory method type_id::create() is the standard way to instantiate registered types. It returns a base-class handle (e.g., fifo_agent) but constructs the actual registered type (e.g., fifo_agent or a derived class if overridden).

PatternSyntaxWhen to Use
Direct allocationagent = new("agent", this);Only for sequence items (not components)
Factory allocationagent = fifo_agent::type_id::create("agent", this);For all UVM components

The factory lookup uses the type name registered via uvm_component_utils(). If no override is registered, type_id::create() behaves like new(), but the indirection is essential for test flexibility.

Practice

  1. Open this chapter in RtlStudio; files appear in Explore.
  2. Open student/tb/tb_top.sv in the editor.
  3. In fifo_base_test::build_phase(), replace the direct new() call for fifo_env with fifo_env::type_id::create("env", this);.
  4. Open student/env/fifo_env.sv in the editor.
  5. In fifo_env::build_phase(), replace direct new() calls for fifo_agent and fifo_scoreboard with fifo_agent::type_id::create(...) and fifo_scoreboard::type_id::create(...) respectively.
  6. Run Simulation and verify the Log panel shows INFO: === Factory ===, INFO: fifo full=0 empty=1, and INFO: PASS.

Summary

You practiced using the UVM factory’s type_id::create() method to instantiate key components like fifo_agent and fifo_scoreboard instead of calling new() directly. This approach promotes flexibility and configurability by decoupling object creation from specific class types. The refactored build_phase in fifo_env and fifo_base_test now relies on the factory mechanism for component instantiation. You kept direct use of new() and randomize() only for sequence_item, as appropriate for leaf-level objects. The key takeaway is that the factory pattern enables easy component substitution and test customization without modifying core build logic.

Run it in the Verilog IDE

  1. Open the UVM workspace in the IDE. The DUT and the testbench compile together in the browser.
  2. Run the SystemVerilog simulation with Verilator and read the phase and scoreboard lines in the log.
  3. When the check is on pins rather than a print, open the VCD next to that log.
  4. Edit the sequence, driver, or scoreboard in the IDE and rerun. You stay in the same simulator.

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