代码之家  ›  专栏  ›  技术社区  ›  sara8d

函数的一般类型输入

  •  0
  • sara8d  · 技术社区  · 8 年前

    我有一个UVM项目。我的test_base中有以下代码:

    class test_base extends uvm_test;
       //factory registration
       `uvm_component_utils(test_base)
    
       //internal decleration
       girobo2_env grb_env_i;
    
       //configuration objects:
       grb2_env_config    m_env_cfg;
       axi_agent_config   m_axi_agent_cfg;
    
       .........
    
       //build_phase
       //Create axi_agent agent configuration object
       m_axi_agent_cfg = axi_agent_config::type_id::create("m_axi_agent_cfg");
       if(!uvm_config_db #(virtual axi_interface)::get(this, "", "axi_vif", m_axi_agent_cfg.axi_vif) 
          `uvm_error("RESOURCE_ERROR", "axi_interface virtual interface not found")
       m_env_cfg.m_axi_agent_cfg = m_axi_agent_cfg; 
       // Call function to configure the axi  agent
       configure_axi_agent(m_axi_agent_cfg);
    
       //--------------------------------------------------------------------
       // configure_my_agent
       //--------------------------------------------------------------------
       // Convenience function to configure the agent
       // This can be overloaded by extensions to this base class
       virtual function void configure_axi_agent (axi_agent_config cfg);
          cfg.is_active = UVM_PASSIVE;    
       endfunction: configure_my_agent
    endclass: test_base
    

    是否有定义输入类型的选项 configure_my_agent 函数通用(如c++中的模板)。

    2 回复  |  直到 8 年前
        1
  •  1
  •   noobuntu    8 年前

    您可以将输入类型设置为 configure_my_agent 泛型 uvm_object .然后,你可以通过任何 uvm_object 并适当地铸造它。

    virtual function void configure_my_agent (uvm_object base_cfg);
    
      if (base_cfg.get_type_name == "grb2_env_config") begin
        axi_agent_config cfg;
        $cast(cfg, base_cfg);
        cfg.is_active = UVM_PASSIVE;
      end
      else if (base_cfg.get_type_name == "grb2_env_config") begin
        grb2_env_config cfg;
        $cast(cfg, base_cfg);
        cfg.is_active = UVM_PASSIVE;
      end
      else if ...... // All other config type names 
    
    endfunction: configure_my_agent
    

    注: 就我个人而言,我不喜欢这种方法。 is_active 是典型的 UVM_ACTIVE_PASSIVE_ENUM 并且应该直接从构建阶段中每个代理的基本测试设置。然后,在代理的build_phase中,查找这个变量并决定代理是主动的还是被动的。请注意,要使其工作,您应该注册 is_active 变量在代理的“uvm_component_utils”中(uvm组件在其build_phase期间自动查找注册的类变量)。

        2
  •  0
  •   dave_59    8 年前

    静态方法 axi_agent_config::type_id::get_type() 返回代理单例对象的句柄,该对象表示 axi_agent_config .您可以调用虚拟 uvm_object 方法 get_object_type() 返回代理单例对象的句柄,该对象表示 真实的 传递给的对象 cfg .所以你可以写

    if (axi_agent_config::type_id::get_type() == cfg.get_object_type() )
       // then you have a matching base class object
    else if (axi_extended_agent_cdg::type_id::get_type() == cfg.get_object_type() )
       // then you have a matching extended object