跳转至

输入查询内容

    本页内容

    自定义 factory 子类需要补充虚方法

    影响范围

    直接 extends uvm_factory 并实现自定义工厂;继承默认工厂的代码先核对已有实现。

    具体差异

    is_type_name_registered / is_type_registered / set_type_alias / set_inst_alias 在 uvm_factory 基类上为 pure virtual,直接 extends uvm_factory 的自定义 factory 在 2.0 下编译报错,必须实现这 4 个方法。新能力:类型别名(把未注册字符串映射到已注册类型)与按实例别名。

    修改方案

    直接继承 uvm_factory 时补 is_type_name_registered、is_type_registered、set_type_alias 和 set_inst_alias;四个方法必须使用同一注册/别名状态。能沿用默认工厂算法时,可继承 uvm_default_factory 并保留业务 override,具体签名与选择条件见下方代码。

    保留自定义工厂算法时,在已有 extends uvm_factory 的类中补齐下面四个方法。若原实现统一委托给同一个 uvm_default_factory delegate,可以继续转发到该对象:

    virtual function bit is_type_name_registered(string type_name);
      return delegate.is_type_name_registered(type_name);
    endfunction
    virtual function bit is_type_registered(uvm_object_wrapper obj);
      return delegate.is_type_registered(obj);
    endfunction
    virtual function void set_type_alias(string alias_type_name,
                                         uvm_object_wrapper original_type);
      delegate.set_type_alias(alias_type_name, original_type);
    endfunction
    virtual function void set_inst_alias(string alias_type_name,
                                         uvm_object_wrapper original_type,
                                         string full_inst_path);
      delegate.set_inst_alias(alias_type_name, original_type, full_inst_path);
    endfunction
    

    这里的 delegate 必须也是原 register、override、create 等方法使用的对象;不要单独新建一个空工厂来处理这四个接口。自行维护注册表的实现,应将查询及别名解析接入自己的同一份状态,不能用空函数或固定返回值绕过抽象方法检查。

    如果原需求允许沿用默认工厂算法,可将基类从 uvm_factory 改为 uvm_default_factory,保留业务需要的 override;该方式沿用默认实现,不要求再写上述四个转发方法。已有 C12 编译实验覆盖了这条路径。

    安装实例使用 uvm_factory::set(custom_factory)。应在业务注册/创建之前统一安排;替换工厂不会自动迁移旧实例中的 override 与别名。

    兼容措施与范围:兼容开关不会补齐自定义 factory 的纯虚方法;派生实现仍须完整且共享同一注册状态。

    迁移后验证

    编译派生工厂,按 type/name 和实例 override 各创建对象,断言实际类型;采用 alias 时验证别名和未注册名称处理。

    记录本条结果M01-004 · 状态与证据

    已有实测与复现

    补充查阅

    扫描定位与记录结果

    有扫描规则,覆盖部分可识别写法。脚本检查名称、参数和部分 FLAG 表达式,并对少数直接声明关联使用点;未做完整类型解析或预处理,行为结果仍需验证。

    uv run tools/uvm_migration_scan.py <SoC代码目录> --rules C12
    

    核对命中对象及生效分支后,在条目清单记录修改与验证证据;扫描规则记录用于整理命中位置。

    扫描器下载、输入范围与报告说明

    源码与标准依据

    核查方式:源码与实测核对。实测仅覆盖本条所列场景。

    VCS 内置 UVM-1.2uvm_factory.svh:118 起(pure virtual 列表,无这些成员)

    VCS 内置 uvm-ieee-2020-2.0uvm_factory.svh:230is_type_name_registered)、uvm_factory.svh:237is_type_registered)、uvm_factory.svh:287set_type_alias)、uvm_factory.svh:296set_inst_alias);另新增静态 uvm_factory::set(uvm_factory f)uvm_factory.svh:96

    标准依据:IEEE 1800.2-2020 §8.3.1.7.3 / §8.3.1.7.4

    标为“源码标注”或未注明原文核对的条款仅作定位;具体库行为以源码和实测为准。

    引用代码(高亮为引用行);上方行号链接可直接定位。

    src/vcs-uvm-1.2/base/uvm_factory.svh
      // If the proxy object's ~get_type_name~ method returns the empty string,
      // name-based lookup is effectively disabled.
    
      pure virtual function void register (uvm_object_wrapper obj);
    
    
      // Group: Type & Instance Overrides
    
      // Function: set_inst_override_by_type
    
      pure virtual function
          void set_inst_override_by_type (uvm_object_wrapper original_type,
                                          uvm_object_wrapper override_type,
                                          string full_inst_path);
    
      // Function: set_inst_override_by_name
      //
      // Configures the factory to create an object of the override's type whenever
      // a request is made to create an object of the original type using a context
    

    完整源码 · SHA256:5903939ccda4118b353b3a0dd274267e00f30a584a16c3ac8e5afe48d70e4316

    src/vcs-uvm-ieee-2020-2.0/base/uvm_factory.svh
      endfunction   
    
      // @uvm-ieee 1800.2-2020 auto 8.3.1.2.2
      static function void set(uvm_factory f);
            uvm_coreservice_t s;
            s = uvm_coreservice_t::get();
            s.set_factory(f);
      endfunction   
    
      // Group -- NODOCS -- Registering Types
    
      // Function -- NODOCS -- register
      //
      // Registers the given proxy object, ~obj~, with the factory. The proxy object
      // is a lightweight substitute for the component or object it represents. When
      // the factory needs to create an object of a given type, it calls the proxy's
      // create_object or create_component method to do so.
      //
      // When doing name-based operations, the factory calls the proxy's
    

    src/vcs-uvm-ieee-2020-2.0/base/uvm_factory.svh
         pure virtual
            // @uvm-ieee 1800.2-2020 auto 8.3.1.7.3
            function bit is_type_name_registered  (string type_name);
    
    
       // Function -- NODOCS -- is_type_registered 
    
         pure virtual 
            // @uvm-ieee 1800.2-2020 auto 8.3.1.7.4
            function bit is_type_registered     (uvm_object_wrapper obj); 
    
    
      //
      // Creates and returns a component or object of the requested type, which may
      // be specified by type or by name. A requested component must be derived
      // from the <uvm_component> base class, and a requested object must be derived
      // from the <uvm_object> base class.
      //
      // When requesting by type, the ~requested_type~ is a handle to the type's
      // proxy object. Preregistration is not required.
      //
      // When requesting by name, the ~request_type_name~ is a string representing
      // the requested type, which must have been registered with the factory with
      // that name prior to the request. If the factory does not recognize the
      // ~requested_type_name~, an error is produced and a ~null~ handle returned.
    

    src/vcs-uvm-ieee-2020-2.0/base/uvm_factory.svh
      // Function -- NODOCS -- set_type_alias
      pure virtual function
          // @uvm-ieee 1800.2-2020 auto 8.3.1.6.1
          void set_type_alias(string alias_type_name, 
                              uvm_object_wrapper original_type); 
    
      //Intended to allow overrides by type to use the alias_type_name as an additional name to refer to
      //original_type  
    
      // Function -- NODOCS -- set_inst_alias
      pure virtual function
          // @uvm-ieee 1800.2-2020 auto 8.3.1.6.2
          void set_inst_alias(string alias_type_name,
                              uvm_object_wrapper original_type, string full_inst_path);
    
      //Intended to allow overrides by name to use the alias_type_name as an additional name to refer to
      //original_type in the context referred to by full_inst_path.  
    
    
      // Group -- NODOCS -- Debug
    
      // Function -- NODOCS -- debug_create_by_type
    
      pure virtual function
          void debug_create_by_type (uvm_object_wrapper requested_type,
                                     string parent_inst_path="",
                                     string name="");
    

    完整源码 · SHA256:dcaf0974ce7ebac754b3176e73a94a46cfae709f8a249e007c9dfcf3677d2f61

    术语解释 · 兼容配置

    返回Object / Factory · 迁移清单

    版本适用范围