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 withtype_id::create()for components likefifo_envand its children. - Recognize that
type_id::create()requires prioruvm_component_utils()oruvm_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).
| Pattern | Syntax | When to Use |
|---|---|---|
| Direct allocation | agent = new("agent", this); | Only for sequence items (not components) |
| Factory allocation | agent = 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
- Open this chapter in RtlStudio; files appear in Explore.
- Open
student/tb/tb_top.svin the editor. - In
fifo_base_test::build_phase(), replace the directnew()call forfifo_envwithfifo_env::type_id::create("env", this);. - Open
student/env/fifo_env.svin the editor. - In
fifo_env::build_phase(), replace directnew()calls forfifo_agentandfifo_scoreboardwithfifo_agent::type_id::create(...)andfifo_scoreboard::type_id::create(...)respectively. - Run Simulation and verify the Log panel shows
INFO: === Factory ===,INFO: fifo full=0 empty=1, andINFO: 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
- Open the UVM workspace in the IDE. The DUT and the testbench compile together in the browser.
- Run the SystemVerilog simulation with Verilator and read the phase and scoreboard lines in the log.
- When the check is on pins rather than a print, open the VCD next to that log.
- 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.