跳转至

输入查询内容

    本页内容

    抽象组件的工厂注册与 type_name 使用

    影响范围

    抽象组件使用 factory,或把 type_name 用在特殊变量上下文。

    具体差异

    五个已是抽象类的基类在 2.0 新增 abstract factory 注册;type_name 改为无参静态函数,返回字符串保持。SV 允许省略无参函数的调用括号,string s = uvm_agent::type_name; 两版 VCS 实测均可用。变量引用/重定义等特殊上下文应单独检查。is_active 改用 uvm_resource_enum_read,枚举、字符串与整数回退须按实际资源类型核对。

    修改方案

    普通 get_type_name() 或无参 type_name 读取可保留。若需要可写字符串或 ref 实参,先复制类型名到自己的 string 变量,停止将目标 type_name 当变量写入或重复声明;同源例子见 M09-006。通过抽象基类 factory 创建时,先设置具体类 override,再检查实际对象类型。

    兼容措施与范围:现有入口无需兼容开关;这不表示两版行为相同,仍按本条条件和验证方法核对。

    迁移后验证

    编译相关声明;factory 创建抽象类型前配置具体 override,检查实例类型与所需虚方法行为。

    记录本条结果M10-003 · 状态与证据

    已有实测与复现

    补充查阅

    扫描定位与记录结果

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

    • C27 · 启发式:type_name 被当作可写变量。 排除自有变量、形参及普通下标读取;受影响成员写入和注册宏与同名声明冲突仍提示,未解析完整类型系统。
    uv run tools/uvm_migration_scan.py <SoC代码目录> --rules C27
    

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

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

    源码与标准依据

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

    VCS 内置 UVM-1.2uvm_agent.svh:117uvm_env.svh:45uvm_test.svh:74uvm_monitor.svh:46uvm_scoreboard.svh:48(均为 const static string type_name + get_type_name() 手写覆盖)

    VCS 内置 uvm-ieee-2020-2.0uvm_agent.svh:45uvm_env.svh:36uvm_test.svh:65uvm_monitor.svh:37uvm_scoreboard.svh:39(均改为 `uvm_component_abstract_utils(<类名>)

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

    src/vcs-uvm-1.2/comps/uvm_agent.svh
      endfunction
    
      const static string type_name = "uvm_agent";
    
      virtual function string get_type_name ();
        return type_name;
      endfunction
    
      // Function: get_is_active
      //
      // Returns UVM_ACTIVE is the agent is acting as an active agent and 
      // UVM_PASSIVE if it is acting as a passive agent. The default implementation
      // is to just return the is_active flag, but the component developer may
      // override this behavior if a more complex algorithm is needed to determine
      // the active/passive nature of the agent.
    
      virtual function uvm_active_passive_enum get_is_active();
        return is_active;
    

    完整源码 · SHA256:a325bfd47a9773fdaa20817d312ee62181c5f2687880b3afac962dedf45e3c78

    src/vcs-uvm-1.2/comps/uvm_env.svh
        super.new(name,parent);
      endfunction
    
      const static string type_name = "uvm_env";
    
      virtual function string get_type_name ();
        return type_name;
      endfunction
    
    endclass
    

    完整源码 · SHA256:6902259d460655d21aec17f7c18ded6451f60f247f41201ad1ec86240702e877

    src/vcs-uvm-1.2/comps/uvm_test.svh
        super.new(name,parent);
      endfunction
    
      const static string type_name = "uvm_test";
    
      virtual function string get_type_name ();
        return type_name;
      endfunction
    
    endclass
    

    完整源码 · SHA256:0f87cf5bd62e3b4e59bc809c5cf0ea9b5ce56c3e22bf179534f187badd046803

    src/vcs-uvm-1.2/comps/uvm_monitor.svh
        super.new(name, parent);
      endfunction
    
      const static string type_name = "uvm_monitor";
    
      virtual function string get_type_name ();
        return type_name;
      endfunction
    
    endclass
    

    完整源码 · SHA256:afd2e42834830e7bf3fa988c6fc48aeb7d2d051a08e85f1854a2067aa1a979c8

    src/vcs-uvm-1.2/comps/uvm_scoreboard.svh
        super.new(name, parent);
      endfunction
    
      const static string type_name = "uvm_scoreboard";
    
      virtual function string get_type_name ();
        return type_name;
      endfunction
    
    endclass
    

    完整源码 · SHA256:7a9c94a2c7930d64b53a6a9887f81b2e44dc18321d0c6f2a569dd47b95f29c99

    src/vcs-uvm-ieee-2020-2.0/comps/uvm_agent.svh
      uvm_active_passive_enum is_active = UVM_ACTIVE;
    
      // TODO: Make ~is_active~ a field via field utils
      `uvm_component_abstract_utils(uvm_agent)
    
      // Function -- NODOCS -- new
      //
      // Creates and initializes an instance of this class using the normal
      // constructor arguments for <uvm_component>: ~name~ is the name of the
      // instance, and ~parent~ is the handle to the hierarchical parent, if any.
      //
      // The int configuration parameter is_active is used to identify whether this
      // agent should be acting in active or passive mode. This parameter can
      // be set by doing:
      //
      //| uvm_config_int::set(this, "<relative_path_to_agent>, "is_active", UVM_ACTIVE);
    
      // @uvm-ieee 1800.2-2020 auto 13.4.2.1
      function new (string name, uvm_component parent);
    

    完整源码 · SHA256:a54d61262f2d71a3ddb787488edabaf2dc99944ad4243f137def8d818f99a700

    src/vcs-uvm-ieee-2020-2.0/comps/uvm_env.svh
    // @uvm-ieee 1800.2-2020 auto 13.3.1
    virtual class uvm_env extends uvm_component;
    
      `uvm_component_abstract_utils(uvm_env)
    
      // Function -- NODOCS -- new
      //
      // Creates and initializes an instance of this class using the normal
      // constructor arguments for <uvm_component>: ~name~ is the name of the
      // instance, and ~parent~ is the handle to the hierarchical parent, if any.
    
      // @uvm-ieee 1800.2-2020 auto 13.3.2
      function new (string name="env", uvm_component parent=null);
        super.new(name,parent);
      endfunction
    
    endclass
    

    完整源码 · SHA256:4b718c245e759b53d287c08383f212bda462abc7feb76c33f3211bc8d482e475

    src/vcs-uvm-ieee-2020-2.0/comps/uvm_test.svh
    // @uvm-ieee 1800.2-2020 auto 13.2.1
    virtual class uvm_test extends uvm_component;
    
      `uvm_component_abstract_utils(uvm_test)
    
      // Function -- NODOCS -- new
      //
      // Creates and initializes an instance of this class using the normal
      // constructor arguments for <uvm_component>: ~name~ is the name of the
      // instance, and ~parent~ is the handle to the hierarchical parent, if any.
    
      // @uvm-ieee 1800.2-2020 auto 13.2.2
      function new (string name, uvm_component parent);
        super.new(name,parent);
      endfunction
    
    endclass
    

    完整源码 · SHA256:f561e0e17e3bceb1a552738012bdff8665e200a4f77cf3677acb44913d5215c2

    src/vcs-uvm-ieee-2020-2.0/comps/uvm_monitor.svh
    // @uvm-ieee 1800.2-2020 auto 13.5.1
    virtual class uvm_monitor extends uvm_component;
    
      `uvm_component_abstract_utils(uvm_monitor)
    
      // Function -- NODOCS -- new
      //
      // Creates and initializes an instance of this class using the normal
      // constructor arguments for <uvm_component>: ~name~ is the name of the
      // instance, and ~parent~ is the handle to the hierarchical parent, if any.
    
      // @uvm-ieee 1800.2-2020 auto 13.5.2
      function new (string name, uvm_component parent);
        super.new(name, parent);
      endfunction
    
    endclass
    

    完整源码 · SHA256:4fb3bee83f18821a204e09479b092ee9d74827d6102e9b241f06abec22624df9

    src/vcs-uvm-ieee-2020-2.0/comps/uvm_scoreboard.svh
    // @uvm-ieee 1800.2-2020 auto 13.6.1
    virtual class uvm_scoreboard extends uvm_component;
    
      `uvm_component_abstract_utils(uvm_scoreboard)
    
      // Function -- NODOCS -- new
      //
      // Creates and initializes an instance of this class using the normal
      // constructor arguments for <uvm_component>: ~name~ is the name of the
      // instance, and ~parent~ is the handle to the hierarchical parent, if any.
    
      function new (string name, uvm_component parent);
        super.new(name, parent);
      endfunction
    
    endclass
    

    完整源码 · SHA256:788fc96b8e8c7ce14fa47cbb8ec080c242485a5c971a5ae29527f6b4d564df3a

    术语解释 · 兼容配置

    注册宏的 type_name 改为函数形式(M09-006)

    返回Component / VCS 集成 · 迁移清单

    版本适用范围