sv和UVM参数化类的相关介绍不多,但实际使用起来与普通类有微小的差异,无论是声明,注册还是转换,踩坑同时留做记录
1. 定义参数化的类
注册时要专门的宏定义注册
class m_agent#(int T=0)extends uvm_agent;
driver drv;
monitor mon;
sequencer sqr;
`uvm_component_param_utils(m_agent#(T)) //注册
endclass
2. 声明例化
声明和例化时都需要传参,否则报错或传参失败
class env extends uvm_env;
m_agent#(0) agt0; //声明时传参
m_agent#(1) agt1;
m_agent#(2) agt2;
m_agent#(3) agt3;
function void build_phase(uvm_phase phase);
super.build_phase(phase);
agt0 = m_agent#(0)::type_id::create("agt0",this);//例化时传参
agt1 = m_agent#(1)::type_id::create("agt0",this);
agt2 = m_agent#(2)::type_id::create("agt0",this);
agt3 = m_agent#(3)::type_id::create("agt0",this);
endfunction
endclass
定义时参数化类需要默认参数,否则编译时会报no override or default value错误
不同类型的参数化类不能强制转换!
UVM的factory是不能重载parameterized class的!原文链接如下