uvm_factory——我们的工厂(二)
上节我们说到uvm_object_registry #(T),uvm_object_reistry 又继承自uvm_object_wrapper,所以首先,让我们先看看它爹是啥样子的:
//------------------------------------------------------------------------------
//
// CLASS: uvm_object_wrapper
//
// The uvm_object_wrapper provides an abstract interface for creating object and
// component proxies. Instances of these lightweight proxies, representing every
// <uvm_object>-based and <uvm_component>-based object available in the test
// environment, are registered with the <uvm_factory>. When the factory is
// called upon to create an object or component, it finds and delegates the
// request to the appropriate proxy.
//
//------------------------------------------------------------------------------ virtual class uvm_object_wrapper; // Function: create_object
//
// Creates a new object with the optional ~name~.
// An object proxy (e.g., <uvm_object_registry #(T,Tname)>) implements this
// method to create an object of a specific type, T. virtual function uvm_object create_object (string name="");
return null;
endfunction // Function: create_component
//
// Creates a new component, passing to its constructor the given ~name~ and
// ~parent~. A component proxy (e.g. <uvm_component_registry #(T,Tname)>)
// implements this method to create a component of a specific type, T. virtual function uvm_component create_component (string name,
uvm_component parent);
return null;
endfunction // Function: get_type_name
//
// Derived classes implement this method to return the type name of the object
// created by <create_component> or <create_object>. The factory uses this
// name when matching against the requested type in name-based lookups. pure virtual function string get_type_name(); endclass
从代码注释来看,都是虚类,这只是轻量级的代理proxy, 它只负责搭台,具体实现让子类去实现,也就是所在uvm中create class,无非就两种uvm_object 和uvm_componet. 它只有这两个儿子,古人云:儿孙自有儿孙福,莫为儿孙做远忧。所以,具体的实现还是让我们进一步去看uvm_object_registry(uvm_register.svh中).
首先来看用法:
// Group: Usage
//
// This section describes usage for the uvm_*_registry classes.
//
// The wrapper classes are used to register lightweight proxies of objects and
// components.
//
// To register a particular component type, you need only typedef a
// specialization of its proxy class, which is typically done inside the class.
//
// For example, to register a UVM component of type ~mycomp~
//
//| class mycomp extends uvm_component;
//| typedef uvm_component_registry #(mycomp,"mycomp") type_id;
//| endclass
//
// However, because of differences between simulators, it is necessary to use a
// macro to ensure vendor interoperability with factory registration. To
// register a UVM component of type ~mycomp~ in a vendor-independent way, you
// would write instead:
//
//| class mycomp extends uvm_component;
//| `uvm_component_utils(mycomp);
//| ...
//| endclass
//
// The <`uvm_component_utils> macro is for non-parameterized classes. In this
// example, the typedef underlying the macro specifies the ~Tname~
// parameter as "mycomp", and ~mycomp~'s get_type_name() is defined to return
// the same. With ~Tname~ defined, you can use the factory's name-based methods to
// set overrides and create objects and components of non-parameterized types.
//
// For parameterized types, the type name changes with each specialization, so
// you cannot specify a ~Tname~ inside a parameterized class and get the behavior
// you want; the same type name string would be registered for all
// specializations of the class! (The factory would produce warnings for each
// specialization beyond the first.) To avoid the warnings and simulator
// interoperability issues with parameterized classes, you must register
// parameterized classes with a different macro.
//
// For example, to register a UVM component of type driver #(T), you
// would write:
//
//| class driver #(type T=int) extends uvm_component;
//| `uvm_component_param_utils(driver #(T));
//| ...
//| endclass
//
// The <`uvm_component_param_utils> and <`uvm_object_param_utils> macros are used
// to register parameterized classes with the factory. Unlike the non-param
// versions, these macros do not specify the ~Tname~ parameter in the underlying
// uvm_component_registry typedef, and they do not define the get_type_name
// method for the user class. Consequently, you will not be able to use the
// factory's name-based methods for parameterized classes.
//
// The primary purpose for adding the factory's type-based methods was to
// accommodate registration of parameterized types and eliminate the many sources
// of errors associated with string-based factory usage. Thus, use of name-based
// lookup in <uvm_factory> is no longer recommended.
uvm_object_register的定义如下:
class uvm_object_registry #(type T=uvm_object, string Tname="<unknown>")
extends uvm_object_wrapper;
typedef uvm_object_registry #(T,Tname) this_type; // 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 const static string type_name = Tname;
type::id::create()
// Function: create
//
// Returns an instance of the object type, ~T~, represented by this proxy,
// subject to any factory overrides based on the context provided by the
// ~parent~'s full name. The ~contxt~ argument, if supplied, supersedes the
// ~parent~'s context. The new instance will have the given leaf ~name~,
// if provided. static function T create (string name="", uvm_component parent=null,
string contxt="");
uvm_object obj;
uvm_coreservice_t cs = uvm_coreservice_t::get();
uvm_factory factory=cs.get_factory(); if (contxt == "" && parent != null)
contxt = parent.get_full_name();
obj = factory.create_object_by_type(get(),contxt,name);
if (!$cast(create, obj)) begin
string msg;
msg = {"Factory did not return an object of type '",type_name,
"'. A component of type '",obj == null ? "null" : obj.get_type_name(),
"' was returned instead. Name=",name," Parent=",
parent==null?"null":parent.get_type_name()," contxt=",contxt};
uvm_report_fatal("FCTTYP", msg, UVM_NONE);
end
endfunction
create() 调用factory.create_object_by_type()函数,该函数又调用create_object()
// create_object_by_type
// --------------------- function uvm_object uvm_default_factory::create_object_by_type (uvm_object_wrapper requested_type,
string parent_inst_path="",
string name=""); string full_inst_path; if (parent_inst_path == "")
full_inst_path = name;
else if (name != "")
full_inst_path = {parent_inst_path,".",name};
else
full_inst_path = parent_inst_path; m_override_info.delete(); requested_type = find_override_by_type(requested_type, full_inst_path); return requested_type.create_object(name); endfunction
所以tpye::id::create()本质上就是调用该class的new()函数。
uvm_factory——我们的工厂(二)的更多相关文章
- uvm_factory——我们的工厂(一)
factory 机制是实现(功能):通过一个字符串来创建此字符串所代表的的类的一个实例. //----------------------------------------------------- ...
- 简单工厂(二)——coding
public abstract class Video { public abstract void produce(); } public class JavaVideo extends Video ...
- uvm_factory——我们的工厂(三)
现在让我们回过头来想想factory 是用来干什么,它做了什么? fantory就是生产uvm_object 和 uvm_component.用factory 生产和用SV直接new有什么区别了? f ...
- c# 设计模式 之:简单工厂、工厂方法、抽象工厂之小结、区别
很多时候,我发现这三种设计模式难以区分,常常会张冠李戴闹了笑话.很有必要深入总结一下三种设计模式的特点.相同之处和不同之处. 1 本质 三个设计模式名字中都含有“工厂”二字,其含义是使用工厂(一个或一 ...
- 面向程序猿的设计模式 ——GoF《设计模式》读书总结(壹)抽象工厂&生成器
第一部分:创建型模式 创建型模式抽象了实例化过程. 它们帮助一个系统独立于怎样创建.组合和表示它的那些对象.(把一些小的对象组装成大对象,这个工作由专门的类对象来做) 一个类创建型模式使用继承改变被实 ...
- Python——工厂模式
目录 前言 一.简单工厂 二.工厂方法 抽象工厂 结论 参考 前言 工厂模式,顾名思义就是我们可以通过一个指定的"工厂"获得需要的"产品". 在设计模式中主要用 ...
- MM 后台配置(转)
本文转自:https://www.cnblogs.com/yanglikun/p/4124797.html 一.全局配置 1.一般配置 SPRO->SAP NETWEAVER -> GEN ...
- MM/PP/SD/FICO 模块常用事物码(T-code)、SAP快捷键
MM/PP/SD/FICO MM常用T-CODE MM01 创建一般物料 Create Material – GeneralMM02 修改一般物料 Change MaterialMM03 显示一般物料 ...
- ABAP权限检查,TCode与权限对象进行关联
一.确认权限对象,和关联字段: Tcode:SU21 维护权限对象例如"M_MSEG_WMB",它关联字段为'WERKS'M_MSEG_WMB 物料凭证:工厂 二.在ABAP代码中 ...
随机推荐
- JAVA 内部类 (二)
一.为什么要使用内部类 为什么要使用内部类?在<Think in java>中有这样一句话:使用内部类最吸引人的原因是:每个内部类都能独立地继承一个(接口的)实现,所以无论外围类是否已经继 ...
- Qt工程pro文件的简单配置(尤其是第三方头文件和库)
Qt开发中,pro文件是对正工程所有源码.编译.资源.目录等的全方位配置的唯一方式,pro文件的编写非常重要,以下对几个重要项进行说明(win和linux,mac平台通用配置) 注释 以”#”开始的行 ...
- sublime 设置像IDE一样的 ctrl+鼠标左键 跳转到定义方法
鼠标点击菜单栏的Preferences,选择Browse Packages ,进入文件加之后,选择User 点击进入User,在User里面添加文件名为 Default (Windows).subli ...
- junit4 Assert静态方法及API
junit中的assert方法全部放在Assert类中. 1.assertTrue/False([String message,]boolean condition); 用来查看变量是是否为fa ...
- python之继承、抽象类、派生、多态、组合、封装
1.继承概念的实现方式主要有2类:实现继承.接口继承. Ø 实现继承是指使用基类的属性和方法而无需额外编码的能力: Ø 接口继承是指仅使用属性和方法的名称.子类必须提供 ...
- csvreader 来操作csv文件
http://www.cnitblog.com/rd416/archive/2010/07/08/47248.html
- LeetCode: 500 Keyboard Row (easy)
题目: Given a List of words, return the words that can be typed using letters of alphabet on only one ...
- Tomcat 容器的安全认证和鉴权
大量的 Web 应用都有安全相关的需求,正因如此,Servlet 规范建议容器要有满足这些需求的机制和基础设施,所以容器要对以下安全特性予以支持: 身份验证:验证授权用户的用户名和密码 资源访问控制: ...
- F#周报2019年第20期
新闻 2019年理事会活动 "实用的F#挑战"意见截止日期接近,不要忘记提交博客文章或者其它作品 接口中的默认实现 .NET Core 3.0里的性能增强 使用Try .NET创建 ...
- POJ1699【AC自动机+状压DP_感言】
萌新感言: 我的天呐! 因为是AC自动机的专题所以没有管别的...硬着头皮吃那份题解(代码)..[请戳简单美丽可爱的代码(没开玩笑)] 首先讲AC自动机: tag存的是以这个节点为后缀的字符串个数(已 ...