VMM 中 factory 所用的 copy 和 allocate 方法的区别

在VMM1.1 以及之前,其factory机制的实现是通过以下两种方法实现的

1) copy : 如下

class xxx
   base_transaction      factory;
   ....
   factory=new();
   ....
   base_transaction      tr;   
   $cast(tr, factory.copy())
endclass

in test: 
initial begin
    env.xxx.factory = real_print
end

描述起来就是: 工厂里面已经有现成的模子(实例),我们所做的就是用新的模子 替换原有的模子。(替换的模子的基本功能确定,即基类确定)


2) allocate

class xxx
     base_transaction     tr;
      virtual function new(base_transaction factory);
                 tr= factory.allocate();
      endfunction      
endclass
when instance xxx:
        xxx     inst;
        inst =new(real_print); // real_print is instance of extended xxx class.

描述起来就是: 工厂里面没有模子,模子需要 外部获得。(但是基本功能确定,即基类确定)


我们在Designware  AHB slave VIP 就使用了第二种方法,第二种方法不需要暴露类中的transaction 实例,但是必须暴露参数。


由此,我们在定义 base_transaction的扩展类时,必须实现copy 和 allocate函数。要 提醒大家的是,即使扩展类没有加入新的类成员,只是加了些constraint,但是依然要 加入

`vmm_data_member_begin( xxxxx)
`vmm_data_member_end(xxxx) 


   这样才在扩展类加入了copy 和 allocate 函数的实现


你可能感兴趣的:(SystemVerilog,扩展,function,class)