factory 机制是实现(功能):通过一个字符串来创建此字符串所代表的的类的一个实例。

//------------------------------------------------------------------------------
//
// Group: Usage
//
// Using the factory involves three basic operations
//
// 1 - Registering objects and components types with the factory
// 2 - Designing components to use the factory to create objects or components
// 3 - Configuring the factory with type and instance overrides, both within and
// outside components

factory 的使用方法:

在object 和component 实例化时用`uvm_object_utils(packet)和`uvm_component_utils(comp)进行注册,然后,使用driver0 = B_driver::type_id::create("driver0",this);

最后,根据需要将type和instance overrides.

首先来看`uvm_object_utils(T)的宏定义, uvm_object_utils 又是用uvm_object_utils_begin(T) 实现的:

`define uvm_object_utils(T) \
`uvm_object_utils_begin(T) \
`uvm_object_utils_end

uvm_object_utils_begin(T) 由如下几个宏实现。

`define uvm_object_utils_begin(T) \
`m_uvm_object_registry_internal(T,T) \
`m_uvm_object_create_func(T) \
`m_uvm_get_type_name_func(T) \
`uvm_field_utils_begin(T)

首先来看m_uvm_object_reistry_internal(T),这里最重要的是uvm_ object_registry#(T, `"S`").

// m_uvm_object_registry_internal
// ------------------------------ //This is needed due to an issue in of passing down strings
//created by args to lower level macros.
`define m_uvm_object_registry_internal(T,S) \
typedef uvm_object_registry#(T,`"S`") type_id; \
static function type_id get_type(); \
return type_id::get(); \
endfunction \
virtual function uvm_object_wrapper get_object_type(); \
return type_id::get(); \
endfunction

接着,再看`m_uvm_object_create_func(T), 本质就new uvm_object 的类。

//-----------------------------------------------------------------------------
// INTERNAL MACROS - in support of *_utils macros -- do not use directly
//----------------------------------------------------------------------------- // m_uvm_object_create_func
// ------------------------ `define m_uvm_object_create_func(T) \
function uvm_object create (string name=""); \
T tmp; \
`ifdef UVM_OBJECT_DO_NOT_NEED_CONSTRUCTOR \
tmp = new(); \
if (name!="") \
tmp.set_name(name); \
`else \
if (name=="") tmp = new(); \
else tmp = new(name); \
`endif \
return tmp; \
endfunction

再往下看 m_uvm_get_type_name_func(T),得到type的名字。

// m_uvm_get_type_name_func
// ---------------------- `define m_uvm_get_type_name_func(T) \
const static string type_name = `"T`"; \
virtual function string get_type_name (); \
return type_name; \
endfunction

看完了uvm_object_utils_begin(T) ,我们把目光转向uvm_object_registry#(T,S) type_id; 为什么会有这么一个class,它到底干了些什么?

uvm_object_registry这个类的定义在src/base/uvm_registry.svh里面,这个文件里面定义了uvm_object_registry和uvm_component_registry两个类, 下一节我们先看是前者

uvm_object_registry。uvm_object_registry和uvm_component_registry都继承自uvm_object_wrapper(在uvm_factory.svh中)。

uvm_factory——我们的工厂(一)的更多相关文章

  1. uvm_factory——我们的工厂(二)

    上节我们说到uvm_object_registry #(T),uvm_object_reistry 又继承自uvm_object_wrapper,所以首先,让我们先看看它爹是啥样子的: //----- ...

  2. uvm_factory——我们的工厂(三)

    现在让我们回过头来想想factory 是用来干什么,它做了什么? fantory就是生产uvm_object 和 uvm_component.用factory 生产和用SV直接new有什么区别了? f ...

  3. C++ 可配置的类工厂

    项目中常用到工厂模式,工厂模式可以把创建对象的具体细节封装到Create函数中,减少重复代码,增强可读和可维护性.传统的工厂实现如下: class Widget { public: virtual i ...

  4. 工厂方法模式——创建型模式02

    1. 简单工厂模式     在介绍工厂方法模式之前,先介绍一下简单工厂模式.虽然简单工厂模式不属于GoF 23种设计模式,但通常将它作为学习其他工厂模式的入门,并且在实际开发中使用的也较为频繁. (1 ...

  5. 23种设计模式--工厂模式-Factory Pattern

    一.工厂模式的介绍       工厂模式让我们相到的就是工厂,那么生活中的工厂是生产产品的,在代码中的工厂是生产实例的,在直白一点就是生产实例的类,代码中我们常用new关键字,那么这个new出来的实例 ...

  6. 缓存工厂之Redis缓存

    这几天没有按照计划分享技术博文,主要是去医院了,这里一想到在医院经历的种种,我真的有话要说:医院里的医务人员曾经被吹捧为美丽+和蔼+可亲的天使,在经受5天左右相互接触后不得不让感慨:遇见的有些人员在挂 ...

  7. javascript工厂模式和构造函数模式创建对象

    一.工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程(本书后面还将讨论其他设计模式及其在JavaScript 中的实现).考虑到在ECMAScript 中无法创 ...

  8. 设计模式C#合集--抽象工厂模式

    抽象工厂,名字就告诉你是抽象的了.上代码. public interface BMW { public void Drive(); } public class BMW730 : BMW { publ ...

  9. 设计模式C#合集--工厂方法模式

    简单工厂,代码: public interface ISpeak { public void Say(); } public class Hello : ISpeak { public void Sa ...

随机推荐

  1. tty初探 — uart驱动框架分析

    写在前面: 我们没有讲UART驱动,不过我们认为,只要系统学习了第2期,应该具备分析UART驱动的能力,小编做答疑几年以来,陆陆续续有不少人问到UART驱动怎么写,所以今天就分享一篇深度长文(1700 ...

  2. KVM虚拟机内无agent情况下的监控方法

    KVM虚拟机内无agent情况下的监控(ceilometer实现) 今天看到大家在群里讨论KVM虚拟机的监控问题,而且是要求VM内无agent情况下的监控.这方面确实没有深入研究,但尚有些openst ...

  3. mysql创建用户及授权

    创建本地账号 create user 'egon1'@'localhost' identified by '123'; # mysql -uegon1 -p123 创建远程账号 create user ...

  4. python常用第三方库(转载)

    Python标准库与第三方库详解(转载) 转载地址: http://www.codeweblog.com/python%e6%a0%87%e5%87%86%e5%ba%93%e4%b8%8e%e7%a ...

  5. Flutter实战视频-移动电商-58.购物车_删除商品功能制作

    58.购物车_删除商品功能制作 主要做购物车后面的删除按钮 删除的方法写在provide里面 provide/cart.dart文件 传入goodsId,循环对比,找到后进行移除 //删除单个购物车商 ...

  6. css 属性相关

    css属性相关 宽和高 width属性可以为元素设置宽度, height属性可以为元素设置好高度 块级标签才能设置宽度,内联标签的宽度由内容来决定. 字体属性 文字字体 font-family 可以把 ...

  7. PLSQL导入导出oracle表 表空间

    PLSQL导入导出表的正确步骤 原来总是直接 tools->import talbes->Oracle Import结果发现有的时候会出错:有的表不能正确导入, baidu+googel解 ...

  8. jQuery 刷新页面

    window.location.reload();

  9. C++设计模式之工厂方法模式

    来自:http://blog.csdn.net/pangshaohua/article/details/38912555 参考写的一个工厂demo 1.定义"背景风格的抽象类".& ...

  10. Unity中HideInInspector和SerializeField

    http://blog.sina.com.cn/s/blog_697b1b8c0102uxvn.html Unity会自动为Public变量做序列化,序列化的意思是说再次读取Unity时序列化的变量是 ...