我使用Verilator將在SystemVerilog中編寫的算法合併到可操作通過stdin
和stdout
傳遞的I/O流的可執行實用程序中。不幸的是,當我使用SystemVerilog $display()
函數時,輸出爲stdout
。我希望它去stderr
,以便stdout
未因我的其他目的而受到污染。
我該如何做到這一點?
我使用Verilator將在SystemVerilog中編寫的算法合併到可操作通過stdin
和stdout
傳遞的I/O流的可執行實用程序中。不幸的是,當我使用SystemVerilog $display()
函數時,輸出爲stdout
。我希望它去stderr
,以便stdout
未因我的其他目的而受到污染。
我該如何做到這一點?
感謝@toolic您指出的$fdisplay()
的存在,可正是如此使用...
$fdisplay(STDERR,"hello world"); // also supports formatted arguments
IEEE標準2000至12年規定,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(我還沒有得到這個工作到目前爲止)。
STDERR在VCS SystemVerilog中並不存在。我在wikipedia上發現文件描述符的數字/整數通常是'STDOUT == 1'和'STDERR == 2' ...使用'$ fdisplay(1,「Hello World」)'在這裏工作得很好。 – nmz787
可能的工作方式是使用'$ fdisplay'寫入文件。它看起來也可以用來指向'STDERR'。請參閱IEEE Std 1800-2012。 – toolic