uvm_factory——我们的工厂(一)
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——我们的工厂(一)的更多相关文章
- uvm_factory——我们的工厂(二)
上节我们说到uvm_object_registry #(T),uvm_object_reistry 又继承自uvm_object_wrapper,所以首先,让我们先看看它爹是啥样子的: //----- ...
- uvm_factory——我们的工厂(三)
现在让我们回过头来想想factory 是用来干什么,它做了什么? fantory就是生产uvm_object 和 uvm_component.用factory 生产和用SV直接new有什么区别了? f ...
- C++ 可配置的类工厂
项目中常用到工厂模式,工厂模式可以把创建对象的具体细节封装到Create函数中,减少重复代码,增强可读和可维护性.传统的工厂实现如下: class Widget { public: virtual i ...
- 工厂方法模式——创建型模式02
1. 简单工厂模式 在介绍工厂方法模式之前,先介绍一下简单工厂模式.虽然简单工厂模式不属于GoF 23种设计模式,但通常将它作为学习其他工厂模式的入门,并且在实际开发中使用的也较为频繁. (1 ...
- 23种设计模式--工厂模式-Factory Pattern
一.工厂模式的介绍 工厂模式让我们相到的就是工厂,那么生活中的工厂是生产产品的,在代码中的工厂是生产实例的,在直白一点就是生产实例的类,代码中我们常用new关键字,那么这个new出来的实例 ...
- 缓存工厂之Redis缓存
这几天没有按照计划分享技术博文,主要是去医院了,这里一想到在医院经历的种种,我真的有话要说:医院里的医务人员曾经被吹捧为美丽+和蔼+可亲的天使,在经受5天左右相互接触后不得不让感慨:遇见的有些人员在挂 ...
- javascript工厂模式和构造函数模式创建对象
一.工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程(本书后面还将讨论其他设计模式及其在JavaScript 中的实现).考虑到在ECMAScript 中无法创 ...
- 设计模式C#合集--抽象工厂模式
抽象工厂,名字就告诉你是抽象的了.上代码. public interface BMW { public void Drive(); } public class BMW730 : BMW { publ ...
- 设计模式C#合集--工厂方法模式
简单工厂,代码: public interface ISpeak { public void Say(); } public class Hello : ISpeak { public void Sa ...
随机推荐
- android开发中怎么通过Log函数输出当前行号和当前函数名
public class Debug { public static int line(Exception e) { StackTraceElement[] trace = e.getStackTra ...
- Lecture0 -- Introduction&&Linear Regression with One Variable
Introduction What is machine learning? Tom Mitchell provides a more modern definition: "A compu ...
- glance image-create --name "linux-core-mini-01" --file /cirros-0.3.4-x86_64-disk.img --disk-format qcow2 --container-format bare --progress --visibility public
glance image-create --name "linux-core-mini-01" --file /cirros-0.3.4-x86_64-disk.img --dis ...
- 深度学习之softmax回归
前言 以下内容是个人学习之后的感悟,转载请注明出处~ softmax回归 首先,我们看一下sigmod激活函数,如下图,它经常用于逻辑回归,将一个real value映射到(0, ...
- 8、html的body内标签之fieldset标签和label标签
一.label标签 <label> 标签为 input 元素定义标签(label). label 元素不会向用户呈现任何特殊的样式.不过,它为鼠标用户改善了可用性,因为如果用户点击 lab ...
- CPython里的GIL
GIL不是Python特性,是CPython解释器特性,因为CPython有垃圾回收机制. GIL 本质是互斥锁,保护解释器安全. 保证线程安全,垃圾回收线程不会和其他线程一起运行. 多个线程不能实现 ...
- Flutter实战视频-移动电商-55.购物车_底部结算栏UI制作
55.购物车_底部结算栏UI制作 主要做下面结算这一栏目 cart_bottom.dart页面 先设置下内边距 拆分成三个子元素 全选 因为有一个文本框和一个全选的text文本,所以这里也用了Row布 ...
- PLSQL配置教程
下载一个PLSQL安装包 网盘下载地址↓ 链接: https://pan.baidu.com/s/1q-uwAfeLOPxzBBx6V1pYLg 提取码: hei9 PLSQL文件夹一定要放在D:\i ...
- ORM取数据很简单!是吗?
简介 几乎任何系统都以某种方式与外部数据存储一起运行.大多数情况下,外部数据存储是一个关系数据库,并且在实现时通常将数据提取任务委托给某些 ORM. 尽管 ORM 包含很多 routine 代码,但是 ...
- unity3d easytouch教程
http://www.taikr.com/group/6/thread/1987 说一说easytouch的简单使用方法,和移动平台上的rpg游戏一样,我们肯定也不陌生,我们经常玩游戏的时候用的都是虚 ...