如何导入 SystemVerilog 宏? [英] How to import SystemVerilog macros?

查看:49
本文介绍了如何导入 SystemVerilog 宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个扩展 ovm_monitorSystemVerilog 监视器,我想知道如何导入我正在使用的 ovm 宏.我正在使用:

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;

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

VCS 编译错误:

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

以下有效,但我认为在 import 语句中使用 * 是不好的做法:

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

import ovm_pkg::*

推荐答案

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

Importing with * is actually the best practice.

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

Importing with * makes all package contents visible but does not do the actual import until used. Importing a function by name immediately imports the function whether used or not (that is the inferior practice).

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

Users of OVM or UVM are instructed to never define any user-defined classes or macros using the "ovm_" prefix since future versions of OVM may add more ovm_classes or `ovm_macros, so importing OVM packages with * is safe.

如果要导入两个带 * 的包,并且两个包都定义了相同的函数名,那么如果您的代码没有使用该函数,则没有问题.如果您的代码确实需要该函数,请为该函数添加 pkg2::function_name 前缀,这也是最佳做法.

If you were to import two packages with * and if both packages had the same function name defined, if your code does not use the function, there is no problem. If your code does require the function, prefix the function with pkg2::function_name, which again is the best practice.

问候 - Cliff Cummings - Verilog &SystemVerilog 大师

Regards - Cliff Cummings - Verilog & SystemVerilog Guru

这篇关于如何导入 SystemVerilog 宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆