1

I am developing a SystemVerilog monitor that extends ovm_monitor and I'd like to know how to import the ovm macros that I am using. I am using:

`ovm_component_utils_begin
`ovm_field_string
`ovm_component_utils_end

I tried the following at the top of my file, both of which do not compile:

import ovm_pkg::ovm_monitor;
import ovm_pkg::ovm_macros;

and

import ovm_pkg::ovm_monitor;
`include "ovm_macros.svh"

VCS compile error:

Error-[SE] Syntax error
  Following verilog source has syntax error :
  "my_monitor.svh", 58 (expanding macro): token is '#'
  `ovm_component_utils_begin(my_monitor)
                                        ^

The following works, but I consider it bad practice to use * in the import statement:

import ovm_pkg::*
4

4 回答 4

3

使用 * 导入实际上是最佳实践。

使用 * 导入会使所有包内容可见,但在使用之前不会进行实际导入。按名称导入函数会立即导入该函数,无论是否使用(这是次要的做法)。

OVM 或 UVM 的用户被指示永远不要使用“ovm_”前缀定义任何用户定义的类或宏,因为未来版本的 OVM 可能会添加更多 ovm_classes 或 `ovm_macros,因此使用 * 导入 OVM 包是安全的。

如果您要使用 * 导入两个包,并且如果两个包都定义了相同的函数名,那么如果您的代码不使用该函数,则没有问题。如果您的代码确实需要该函数,请在该函数前面加上 pkg2::function_name,这也是最佳实践。

问候 - Cliff Cummings - Verilog 和 SystemVerilog 大师

于 2012-06-27T21:40:17.657 回答
1

这应该是对 Adam12 回复的评论,但我无法添加评论。

@Victor Lyuboslavsky,如果您不想使用import ovm_pkg::*,则必须查看宏扩展或宏生成的扩展代码,以及import必要的标识符,例如ovm_component_registry, ovm_objectOVM_CHECK_FIELDS基于 Adam12 的回答)。

但是,将来ovm_component_utils_*orovm_field_*宏可能会更改为包含更多 OVM 标识符,您必须将代码修改为import这些额外的标识符。

于 2013-05-17T10:03:25.427 回答
1

似乎缺少 ovm_component_registry 的类定义等。我不是 OVM 的真正用户,但它对嵌套包含和宏的广泛使用意味着您可能需要查看预处理的输出。

class top extends blah;



   typedef ovm_component_registry #(top,"top") type_id; 
           ^
   static function type_id get_type(); 
     return type_id::get(); 
   endfunction  

   const static string type_name = "top"; 
   virtual function string get_type_name (); 
     return type_name; 
   endfunction  

   static bit m_fields_checked = 0; 
   function void m_field_automation (ovm_object tmp_data__=null, 
                                     int what__=0, 
                                     string str__=""); 
   begin 
     top local_data__; /* Used for copy and compare */ 
     string string_aa_key; /* Used for associative array lookups */ 
     /* Check the fields if not already checked */ 
     if(what__ == OVM_CHECK_FIELDS) begin 
       if(! top::m_fields_checked) 
         top::m_fields_checked=1; 
       else 
         return; 
     end 
     /* Type is verified by ovm_object::compare() */ 
     super.m_field_automation(tmp_data__, what__, str__); 
     if(tmp_data__ != null) 
       /* Allow objects in same hierarchy to be copied/compared */ 
       if(!$cast(local_data__, tmp_data__)) return; 
     if(what__ == OVM_CHECK_FIELDS) begin 
       m_field_array.delete(); 
     end 

     end 
   endfunction(top)


endclass
于 2012-03-02T18:25:21.457 回答
0

不幸的是,导入 ovm_pkg::* 的选择并不多。OVM 并没有在内部用包名完全限定它的所有名称,因此几乎不可能在没有它的情况下编译代码。

于 2012-03-01T02:28:39.990 回答