factory机制有对域的自动化的声明,声明之后对于pkg中的一些函数无需定义即可直接使用,包括copy(),compare(),print(),增加代码的可重用性。
typedef enum {WRITE, READ, IDLE} op_t; //枚举类型声明
class trans extends uvm_object;
bit[31:0] addr;
bit[31:0] data;
op_t op;
string name;
`uvm_object_utils_begin(trans)
//域的自动化的声明
`uvm_field_int(addr, UVM_ALL_ON)//包含变量名称和对数据的操作
`uvm_field_int(data, UVM_DEFAULT)
`uvm_field_enum(op_t, op, UVM_ALL_ON)
`uvm_field_string(name, UVM_ALL_ON)
`uvm_object_utils_end
function new(string name = "trans");
super.new(name);
`uvm_info("CREATE", $sformatf("trans type [%s] created", name), UVM_LOW)
endfunction
function bit do_compare(uvm_object rhs, uvm_comparer comparer);//回调函数,自定义想要比较的类型
trans t;
do_compare = 1;
void'($cast(t, rhs));
if(addr != t.a