zoukankan      html  css  js  c++  java
  • 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中)。

  • 相关阅读:
    (转)原始图像数据和PDF中的图像数据
    itextSharp 附pdf文件解析
    (转)pdf文件结构
    【iCore1S 双核心板_ARM】例程九:DAC实验——输出直流电压
    【iCore4 双核心板_FPGA】例程七:状态机实验——状态机使用
    【iCore4 双核心板_FPGA】例程六:触发器实验——触发器的使用
    【iCore4 双核心板_ARM】例程八:定时器PWM实验——呼吸灯
    【iCore4 双核心板_ARM】例程七:WWDG看门狗实验——复位ARM
    【iCore1S 双核心板_FPGA】例程七:基础逻辑门实验——逻辑门使用
    【iCore1S 双核心板_FPGA】例程六:状态机实验——状态机使用
  • 原文地址:https://www.cnblogs.com/dpc525/p/7865521.html
Copyright © 2011-2022 走看看