You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

UVM技术问题:get_type_name()为什么未被定义为静态方法?

问题原因分析

为什么get_type_name()没有被定义为静态方法

这个是SystemVerilog语言约束和UVM设计需求共同决定的:

  • SystemVerilog语法明确不允许将静态方法声明为virtual(虚方法),而UVM的类型标识机制需要支持多态特性:当用基类句柄指向子类实例时,调用get_type_name()需要返回实例实际所属子类的类型名,而非基类名,该需求必须依赖虚方法才能实现
  • 如果强行将get_type_name()定义为静态方法,调用时只会返回调用语句中指定的声明类型的名称,完全失去多态能力,不符合UVM面向对象的设计框架

正确的替代实现方式

你不需要直接访问内部的const static string成员,UVM提供了规范的静态访问类型名的方式:
每个通过uvm_object_utils系列宏注册的类,都会自动生成一个静态方法get_type(),该方法返回对应类的类型注册器(uvm_object_wrapper)实例,调用该实例的get_type_name()方法即可拿到类型名字符串。
你只需要将报错的代码行修改为如下写法即可:

MyTransaction::get_type().get_type_name()

修正后的完整代码示例

virtual class SomeThing extends uvm_pkg::uvm_object;
  `uvm_object_utils(SomeThing)
  ...
endclass

class MyThing extends SomeThing#(MyTransaction);
  `uvm_object_param_utils(MyThing)

  function new(string name = "MyThing");
    super.new(name);
    `uvm_info(get_name(), {"Created a ", get_type_name(),
                           " using transactions of type: ",
                           MyTransaction::get_type().get_type_name()},
              UVM_LOW)
  endfunction
  ...
endclass: MyThing

内容的提问来源于stack exchange,提问作者Lance E.T. Compte

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 12:15:06