uvm_factory——我们的工厂(三)

现在让我们回过头来想想factory 是用来干什么,它做了什么?

fantory就是生产uvm_object 和 uvm_component。用factory 生产和用SV直接new有什么区别了?

factory机制的的特点就是根据类的名字来创建类的实例。

uvm_object 在定义时调用 uvm_object_utils 宏,而 uvm_component 在定义时要调用uvm_component_utils宏。

factory所有的操作都通过这两个宏来完成。

 

上节说到了create_object 函数,

  // Function: create_object
  //
  // Creates an object of type ~T~ and returns it as a handle to a
  // <uvm_object>. This is an override of the method in <uvm_object_wrapper>.
  // It is called by the factory after determining the type of object to create.
  // You should not call this method directly. Call <create> instead.

  virtual function uvm_object create_object(string name="");
    T obj;
`ifdef UVM_OBJECT_DO_NOT_NEED_CONSTRUCTOR
    obj = new();
    if (name!="")
      obj.set_name(name);
`else
    if (name=="") obj = new();
    else obj = new(name);
`endif
    return obj;
  endfunction

从这个角度看的话factory机制就是重写的SV的new()方法。

 

转载于:https://www.cnblogs.com/dpc525/p/7868565.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值