This post is about one of UVM utility uvm_pool
which is wrapper around Systemverilog associative array. UVM defines singletons from uvm_pool as well.
Starting with some internal inside uvm_pool, pool
assoc array is delatred as protected as there couple of setters and getter defines anyway.
typedef uvm_pool #(KEY,T) this_type;
static protected this_type m_global_pool;
protected T pool[KEY];
get
and set
are defined as follows. Easy enough!
virtual function T get (KEY key);
if (!pool.exists(key)) begin
T default_value;
pool[key] = default_value;
end
return pool[key];
endfunction
virtual function void add (KEY key, T item);
pool[key] = item;
endfunction
For the singleton, these methods can be used. Again easy enough! Not that global pool is created once the first time get_global_pool
is called.
static function this_type get_global_pool ();
if (m_global_pool==null)
m_global_pool = new("pool");
return m_global_pool;
endfunction
static function T get_global (KEY key);
this_type gpool;
gpool = get_global_pool();
return gpool.get(key);
endfunction
UVM also declares specialization with string type which is again singleton.
class uvm_object_string_pool #(type T=uvm_object) extends uvm_pool #(string,T);