systemverilog 当前时间写入文件
systemverilog 当前时间写入文件
使用SV系统函数$system(" [terminal_command_line]")
$system的本质是调用 C system()函数。 C system()函数执行传递给它的参数,效果同终端执行的一样。 $system 可以作为任务或函数调用。 当作为函数调用时,它返回调用 system() 的返回值,数据类型为 int。 如果调用 $system 时没有字符串参数,则 C system() 函数将使用 NULL 字符串调用。
如下面例子,将design.v
文件名改为adder.v
:
module top;
initial $system("mv design.v adder.v");
endmodule
显示当前系统时间:
initial begin
$system("date");
end
当前时间写入文件
基于VCS-MX2018, 低版本VCS貌似不支持$system("")
module top;
integer fd;
function string get_localtime();
int fdt,flag;
string current_time;
$system("date > localtime"); // temp file
fdt = $fopen("localtime", "r");
flag = $fgets(current_time, fdt);
$fclose(fdt);
$system("rm localtime"); // delete file
return current_time;
endfunction
initial begin
$fopen(fd,"time.txt","w+");
$fdisplay(fd,"%s",get_localtime());
$fdisplay(fd,"write current to time.txt");
$fclose(fd);
end
endmodule
其他办法 DPI-C
#include <time.h>
wallclock() {
time_t t;
t = time(NULL);
return (ctime(&t));
//return time(NULL);
}
import "DPI-C" function string wallclock();
module try;
//int unsigned t;
string t;
initial begin
t = wallclock();
$write("time=%0s\n", t);
end
endmodule