SystemVerilog:コマンドラインからの指定($plusargs)
Plus args in System Verilog is Plus point!!
UVMでのテスト指定とかでみたことはあったけど、自分で指定出来るですね。
SystemVerilogでは、2種類の定義が可能です。
- $test$plusargs ( string )
- $value$plusargs ( user_string, variable )
$test$plusargs
引き数の文字を指定できます。
- サンプルコード
module testbench (); initial begin if ($test$plusargs("HELLO")) $display("Hello argument found."); if ($test$plusargs("HE")) $display("The HE subset string is detected."); if ($test$plusargs("H")) $display("Argument starting with H found."); if ($test$plusargs("HELLO_HERE")) $display("Long argument."); if ($test$plusargs("HI")) $display("Simple greeting."); if ($test$plusargs("LO")) $display("Does not match."); $finish(1); end endmodule: testbench
- 実行結果
# vsim +HELLO -L work -do {run -all; quit} -c testbench # Loading sv_std.std # Loading work.testbench # run -all # Hello argument found. # The HE subset string is detected. # Argument starting with H found. # ** Note: $finish : sample.sv(10) # Time: 0 ps Iteration: 0 Instance: /testbench
おっ!前文字から一致したものを見るのか。。。
注意しないと!
$value$plusargs
文字+値を取得することができます。
- サンプルコード
module testbench (); int a; initial begin if ($value$plusargs("HOGE=%d", a)) $display("HOGE value was %d", a); else $display("+HOGE= not found"); $finish(1); end endmodule: testbench
- 実行結果
# vsim +HOGE=10 -L work -do {run -all; quit} -c testbench # Loading sv_std.std # Loading work.testbench # run -all # HOGE value was 10 # ** Note: $finish : sample2.sv(11) # Time: 0 ps Iteration: 0 Instance: /testbench
variableで取得する型指定は以下の通りです。
指定 | 説明 |
---|---|
%d | decimal conversion |
%o | octal conversion |
%h, %x | hexadecimal conversion |
%b | binary conversion |
%e | real exponential conversion |
%f | real decimal conversion |
%g | real decimal or exponential conversion |
%s | string (no conversion) |
今まで、実行シェルスクリプトとかでやっていた処理が
ここまで簡単に出来るようになっているとは。。。