我正在使用Verilator将用 SystemVerilog 编写的算法合并到可执行实用程序中,该实用程序操作通过 stdin
和 stdout
传递的 I/O 流。不幸的是,当我使用 SystemVerilog $display()
函数时,输出会转到 stdout
。我希望它转到 stderr
,以便 stdout
在我的其他目的中保持不受污染。
我怎样才能做到这一点?
最佳答案
感谢@toolic指出$fdisplay()
的存在,因此可以使用它......
$fdisplay(STDERR,"hello world"); // also supports formatted arguments
IEEE Std 1800-2012 规定 STDERR
应该预先打开,但 Verilator 似乎并不知道。解决此问题的方法是:
integer STDERR = 32'h8000_0002;
或者,您可以创建一个日志文件句柄以与 $fdisplay()
一起使用,如下所示...
integer logfile;
initial begin
$system("echo 'initial at ['$(date)']'>>temp.log");
logfile = $fopen("temp.log","a"); // or open with "w" to start fresh
end
如果您可以创建一个类似于 $display
但使用您选择的文件描述符(无需每次都指定)的自定义包装器,那就太好了。不幸的是,that doesn't seem to be possible within the language itself -- 但也许你可以用 DPI 来做到这一点,参见DPI Display Functions (到目前为止我还没有让它发挥作用)。
关于stdout - 将 SystemVerilog $display 发送到 stderr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33160500/