如何将字符串变量(不是字符串文字)传递给 SytemVerilog 中的 $dumpfile 系统任务?

How to pass a string variable(Not a string literal) to $dumpfile system task in SytemVerilog?

我正在 运行 模拟,将不同的参数作为 plus args 传递给测试台。我想为这些运行中的每一个转储单独的 VCD。我尝试声明一个字符串变量并使用传递的参数构造文件名,并将其传递给 $dumpfile。

    string file_name;
    file_name = "tx_dsp.vcd"
    $dumpfile(file_name);

但我在 IES 中收到以下错误:

Passing string variable to this system task/function is currently not supported

作为解决方法,我从命令行定义了文件名并将其用作 $dumpfile 的参数。这行得通,但如果测试参数是从测试台内部随机生成的,则行不通。

这是模拟器或SystemVerilog的行为吗?有什么解决办法吗?

谢谢。

根据the SystemVerilog LRM,应该是可以的。在 21.7.1.1 中,它表示如下:

dumpfile_task ::=
$dumpfile ( filename ) ;

The filename is an expression that is a string literal, string data type, or an integral data type containing a character string that names the file to be opened. The filename is optional and defaults to the string literal "dump.vcd" if not specified.

您在示例中使用了 字符串数据类型 (上述文档的第 6.16 节)。一个优点是字符串的长度是动态的,不会发生截断。

另一方面,字符串文字(LRM 中的第 5.9 节)的行为类似于压缩数组。如果您的编译器不支持 $dumpvars 中的字符串数据类型,您可以尝试将 file_name 定义为字符串文字:

reg[N*8:0] file_name;
file_name = "tx_dsp.vcd"
$dumpfile(file_name);

此处,N是您的字符串中的最大字符数。

另请查看 LRM 中的第 11.10 节。本节介绍对字符串文字的操作。