stdout - 将 SystemVerilog $display 发送到 stderr

标签 stdout verilog system-verilog stderr verilator

我正在使用Verilator将用 SystemVerilog 编写的算法合并到可执行实用程序中,该实用程序操作通过 stdinstdout 传递的 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/

相关文章:

Python:彩色打印和风格打印

constraints - 软约束不适用于位变量

verilog - 陷入 while 循环 verilog

verilog - 总是 @* block 与单个非阻塞分配 - 好,坏或不相关?

verilog - 仿真结果与综合原理图不匹配

system-verilog - 系统verilog : scope of text substitution macro

c - 在 C 中将文件内容打印到标准输出低级 I/O

javascript - 从 Pyramid View 的 subprocess.Popen 动态输出 stdout 到网页

python - 解析命令调用的输出

Verilog:部分选择或索引部分选择无法应用于内存