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. Objective-C 中nil/Nil/NULL/NSNull

    转自:http://nshipster.cn/nil/ 理解"不存在"的概念不仅仅是一个哲学的问题,也是一个实际的问题.我们是有形宇宙的居民,而原因在于逻辑宇宙的存在不确定性.作为 ...

  2. C# ActiveX 中static变量缓存的问题

    最近在忙活一个绘图程序,按照要求需要以ActiveX的方式发布在网站中,这个绘图程序的大概功能就是从数据库获取数据,成图.发布后用户反映,数据变化后,图形没有发生变化,好像有缓存,如果把浏览器全部关闭 ...

  3. zz 堆空间与栈空间

    http://blog.sina.com.cn/s/blog_7321be1101013aua.htmlhttp://soft.chinabyte.com/os/51/12324551.shtmlht ...

  4. UVa 12333 Revenge of Fibonacci (字典树+大数)

    题意:给定一个长度小于40的序列,问你那是Fib数列的哪一项的前缀. 析:首先用大数把Fib数列的前100000-1项算出来,注意,一定不能是100000,要不然会WA的,然后每个数取前40位,不足4 ...

  5. java 中判断字符串相等

    今天写Java代码时遇到一个问题,就是关于判断两个字符串是否相等的问题.(刚尝试用SSH框架) 在大多编程中,通常比较两个字符串是否相同的表达式是“==”,但在java中不能这么写.在java中,用的 ...

  6. 跟我学: 使用 fireasy 搭建 asp.net core 项目系列之二 —— 准备

    ==== 目录 ==== 跟我学: 使用 fireasy 搭建 asp.net core 项目系列之一 —— 开篇 跟我学: 使用 fireasy 搭建 asp.net core 项目系列之二 —— ...

  7. Swift3.0 轮播图

    使用三个UIButton实现无限轮播:https://github.com/LXfeiYu/LXCarouselImages.git 喜欢的朋友给个星!!! 功能: 1.可以选择开启和关闭定时器 2. ...

  8. Weekly Contest 78-------->810. Chalkboard XOR Game

    We are given non-negative integers nums[i] which are written on a chalkboard.  Alice and Bob take tu ...

  9. unity关于StartCoroutine的简单线程使用

    StartCoroutine在unity3d的帮助中叫做协程,意思就是启动一个辅助的线程. 在C#中直接有Thread这个线程,但是在unity中有些元素是不能操作的.这个时候可以使用协程来完成. 使 ...

  10. jzoj5986. 【WC2019模拟2019.1.4】立体几何题 (权值线段树)

    传送门 题面 题解 不难看出每个点的大小为行列限制中较小的那一个(因为数据保证有解) 对于行的每个限制,能取到的个数是列里限制大于等于它的数的个数,同理,对于列是行里大于它的个数(这里没有等于,为了避 ...