如何在 SystemVerilog 中存储 $system("...") 调用的返回值?

Cha*_*ton 2 system-verilog

如果我模拟以下模块:

module test;

    longint seconds;
    initial begin
        seconds = $system("date +%s");
        $display("Seconds: %0d", seconds);
        $finish;
    end

endmodule
Run Code Online (Sandbox Code Playgroud)

从两者的输出ncsimvsim为:

1571172006
Seconds: 0
Run Code Online (Sandbox Code Playgroud)

所以我可以看到$system调用正在以秒为单位打印时间1571172006,但是变量seconds的值为 ,0所以我没有保存该值。

有没有办法让我保存那个值?(最好不要使用 DPI)

提前致谢。

edaplayground 链接

dav*_*_59 5

我不知道你为什么不想使用 DPI。比马修的方法简单得多。

module test;
  import "DPI-C" function longint date();
    longint seconds;
    initial begin
      seconds = date();
        $display("Seconds: %0d", seconds);
        $finish;
    end

endmodule

#include <time.h>
long int date() {
  return time(NULL);
}
Run Code Online (Sandbox Code Playgroud)

https://www.edaplayground.com/x/5NTw