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