uvm_in_order_comparator(T, comp_type, convert, pair_type)源码分析

1、参数说明

uvm_in_order_comparator(T, comp_type, convert, pair_type)
//T:用于指定被比较的transaction的类型
//comp_type:用于比较两个transactin stream的类。它必须提供静态方法“function bit comp(T a, T b)”,如果a和b相同,则返回TRUE
//convert:将正在比较的transaction转换为字符串的类。它必须提供静态方法" function string convert2string(T a) "
//pair_type:将一对transaction作为单个uvm_object类型处理。

class uvm_in_order_comparator 
  #( type T = int ,
     type comp_type = uvm_built_in_comp #( T ) , //默认使用uvm提供的内建数据类型的comp
     type convert = uvm_built_in_converter #( T ) ,  //默认使用uvm提供的内建数据类型的convert 
     type pair_type = uvm_built_in_pair #( T ) )//默认使用uvm提供的内建数据类型的pair_type 
    extends uvm_component

2、成员变量

  local uvm_tlm_analysis_fifo #(T) m_before_fifo;
  local uvm_tlm_analysis_fifo #(T) m_after_fifo;
  int m_matches, m_mismatches; //在new 函数中初始化为0

before_export

m_before_fifo连接,用于接收其中一路transaction stream

 uvm_analysis_export #(T) before_export;

after_export

m_after_fifo连接,用于接收另外一路transaction stream

 uvm_analysis_export #(T) after_export;

pair_ap

用于将一对transaction发送出去

uvm_analysis_port   #(pair_type) pair_ap;

3、成员方法

3.1、run phase

run phase中调用comp函数完成比较。

  virtual task run_phase(uvm_phase phase);
    pair_type pair;
    T b;
    T a;
    string s;
    super.run_phase(phase); 
    forever begin
      m_before_fifo.get(b); //从mailbox上获取数据
      m_after_fifo.get(a);
   
      if(!comp_type::comp(b, a)) begin //返回0,不匹配
        $sformat(s, "%s differs from %s", convert::convert2string(a),
                                          convert::convert2string(b));
        uvm_report_warning("Comparator Mismatch", s);
        m_mismatches++;
      end
      else begin //返回1,表示匹配
        s = convert::convert2string(b);
        uvm_report_info("Comparator Match", s);
        m_matches++;
      end
      // we make the assumption here that a transaction "sent for
      // analysis" is safe from being edited by another process.
      // Hence, it is safe not to clone a and b.   
      pair = new("after/before");
      pair.first = a;
      pair.second = b; //从此处可以看出,如果用户遥自定义pair,
      					//则内部必须实现first和second两个变量用于存放transaction对
      pair_ap.write(pair);
    end
  endtask

3.2、flush

m_matchesm_mismatches清零。

  virtual function void flush();
    m_matches = 0;
    m_mismatches = 0;
  endfunction

4、comparator的扩展

4.1、uvm_in_order_built_in_comparator

如果是比较内建的数据类型(int 、bit 、string ...),则可以使用该比较器。

class uvm_in_order_built_in_comparator #(type T=int) //使用该比较器时,只传入内建数据类型
  extends uvm_in_order_comparator #(T);
  typedef uvm_in_order_built_in_comparator #(T) this_type;
  `uvm_component_param_utils(this_type)
  const static string type_name = "uvm_in_order_built_in_comparator #(T)";
  function new(string name, uvm_component parent);
    super.new(name, parent);
  endfunction
 
  virtual function string get_type_name ();
    return type_name;
  endfunction
endclass

4.2、uvm_in_order_class_comparator

如果传入的数据类型是object,则使用该比较器。

class uvm_in_order_class_comparator #( type T = int )
  extends uvm_in_order_comparator #( T , 
                                     uvm_class_comp #( T ) , 
                                     uvm_class_converter #( T ) , //默认使用uvm提供与class相关的comp,convert,pair
                                     uvm_class_pair #( T, T ) );//在使用该类时,只传入transaction的类型

  typedef uvm_in_order_class_comparator #(T) this_type;
  `uvm_component_param_utils(this_type)

  const static string type_name = "uvm_in_order_class_comparator #(T)";

  function new( string name  , uvm_component parent);
    super.new( name, parent );
  endfunction
  
  virtual function string get_type_name ();
    return type_name;
  endfunction

endclass
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值