系统函数$test $plusargs与 $value $plusargs总结
systemVerilog可以采用define与parameter等方式定义变量,但是需要在编译前完成变量的定义,编译之后不能修改,如果在仿真时需要修改变量,则只能重新定义变量、重新编译。由此引出$test $plusargs 和 $value $plusargs的功能:可以在仿真时从命令框读取参数,从而实现在不重新编译的情况下完成变量的重新赋值。
- $test $ plusargs
在仿真时,$test $plusargs 会在命令框内搜索制定字符,如果存在相应字符,则返回“1”,如果不存在相应字符,则返回“0”。示例如下:
module tb
initial begin
if($test$plusargs("test0"))
$display("test0 is here");
else
$display("test0 is not here");
end
endmodule
当命令框中输入:sim +test0时,$ test $ plusargs会判断是否存在“test0”,显然存在,返回“1”,打印“test0 is here”。
当命令框中输入:sim +test1时,$ test $ plusargs搜索不到“test0”,故返回“0”,将打印“test0 is not here”。
虽然$test $plusargs解决了重新编译的问题,但是不推荐大量使用该语句,因为这会使编译变得更加复杂。
- $ value $ plusargs
在仿真时,$ value $ plusargs可以将外部参数传递到内部信号,完成对内部信号的赋值。示例如下:
module tb
initial begin
string t;
if($value$plusagrs("my_string=%s",t))
$display("now %s is here",t);
end
endmodule
当命令框内输入:sim +my_string=test1时,$ value $ plusargs搜识别到“my_string”,并将test1赋值给字符串t,那么将打印“now test1 is here”。
如果传递参数没有被识别,或者没有传递参数,那么仿真器会利用系统函数$error()来报告错误。