UVM是否支持嵌套/内部类?

时间:2014-02-03 23:00:26

标签: inner-classes nested-class system-verilog uvm

我们的验证环境的代码指南是每个文件一个类。

有时只有uvm_object需要另外一个uvm_component,因此,遵循面向对象的理论,我们应该使用嵌套/内部类。

SystemVerilog完全支持嵌套类。但是,他们是否受到UVM的支持?

是否可以编译如下内容:

class inception_level_1 extends uvm_test;

  `uvm_component_utils(inception_level_1)

  function new(string name = "inception_level_1", uvm_component parent = null);
    super.new(name, parent);
  endfunction

  class inception_level_2 extends uvm_object;

    int a;

    `uvm_object_utils_begin(inception_level_2)
      `uvm_field_int(a, UVM_DEFAULT)
    `uvm_object_utils_end

    function new(string name = "inception_level_2");
      super.new(name);
    endfunction

  endclass

endclass

目前上面的代码给出了编译错误:

** Error: testbench.sv(20): (vlog-2889) Illegal to access non-static method 'uvm_report_warning' outside its class scope.

此处的完整代码示例:http://www.edaplayground.com/x/3r8

3 个答案:

答案 0 :(得分:5)

SystemVerilog有包,这是从其他包“隐藏”类声明的首选机制。

使用字段宏或尝试引用内部类中的标识符的任何其他内容都会遇到问题,这些标识符在全局uvm_pkg和外部类中使用相同的名称定义。所有uvm_report_...方法都在两者中定义,因为uvm_componentuvm_report_object扩展而uvm_report_...在全局uvm_pkg中。

使用嵌套类的工厂时也会遇到问题。只有外部类能够按类型提供覆盖,但是按名称的字符串覆盖是全局的。因此,即使嵌套了内部类,除了外部类之外的作用域也能够通过字符串名称提供它。

答案 1 :(得分:2)

我更改了代码以删除字段宏,然后运行。因此,如果您可以放弃现场自动化宏,似乎支持这一点:http://www.edaplayground.com/x/i5

class inception_level_1 extends uvm_test;

  `uvm_component_utils(inception_level_1)

  function new(string name = "inception_level_1", uvm_component parent = null);
    super.new(name, parent);
  endfunction

  class inception_level_2 extends uvm_object;

    int a;

    `uvm_object_utils(inception_level_2)

    function new(string name = "inception_level_2");
      super.new(name);
    endfunction

  endclass

endclass

答案 2 :(得分:1)

一般来说它确实有用。但是,在某些情况下,UVM使用与类中类方案冲突的快捷方式。例子是

  • 基于字符串的工厂(inception_level_2只能注册一次,尽管foo:inception_level_2和bla :: inception_level_2将是不同的类)
  • 名称查找冲突(此处为uvm_report_warning,应该转到uvm_pkg :: uvm_report_warning,而不是封闭类uvm_component :: uvm_report_warning) ......等等。
相关问题