[Verilog] $test$plusargs・$value$plusargs でシミュレーションにコマンドライン引数を渡す

シミュレーターにコマンドライン引数を渡して、条件分岐などを行う方法。システムタスク $test$plusargs(string)、$value$plusargs(user_string, variable) を使う。

文字列の指定

simv +FOO のように渡す場合。

gistfile1.v
if ($test$plusargs("FOO")) begin
    $display("FOO");
end

$test$plusargs は前方一致で判断するので、+FOO でも +FOOO、+FOOOO などでも上記条件は成立する。

任意の値の指定

simv +FOO=100 のように渡す場合。

gistfile1.v
integer foo;
if ($value$plusargs("FOO=%d", foo)) begin
    $display("FOO = %0d", foo);
end

%d 部分は、受け取りたい(変換したい)型に合せて指定する。

format string説明
%ddecimal conversion
%ooctal conversion
%hhexadecimal conversion
%bbinary conversion
%ereal exponential conversion
%freal decimal conversion
%greal decimal or exponential conversion
%sstring