bac*_*chu 4 verilog system-verilog command-line-arguments
如何在systemverilog中将值数组作为参数获取,我的要求是我需要从命令行获取未定义大小的命令数组,以及如何将这些参数提供给数组/队列
例如:
+CMDS=READ,WRITE,READ_N_WRITE :它应该被带到一个数组?
$value$plusargs不支持数组,它支持字符串.参见IEEE Std1800-2012§21.6 "命令行输入".在SystemVerilog中解析字符串只是有点麻烦但仍然非常可行,尤其是当分隔符表示为单个字符时.这是一个使用SystemVerilog队列的通用字符串解析器,用于重新编码IEEE Std1800-2012§7.10 "Queue"和§6.16.8 " Substr "中substr定义的索引和字符串方法
function void parse(output string out [], input byte separator, input string in);
int index [$]; // queue
foreach(in[i]) begin // find commas
if (in[i]==separator) begin
index.push_back(i-1); // index before comma
index.push_back(i+1); // index after comma
end
end
index.push_front(0); // first index
index.push_back(in.len()-1); // last index
out = new[index.size()/2];
foreach (out[i]) begin
out[i] = in.substr(index[2*i],index[2*i+1]);
/*$display("cmd[%0d] == in.substr(%0d,%0d) == \"%s\"",
i, index[2*i],index[2*i+1], out[i]); */
end
endfunction : parse
Run Code Online (Sandbox Code Playgroud)
然后结合它$value$plusargs来解析输入:
string cmd[];
string plusarg_string;
if ( $value$plusargs("CMDS=%s",plusarg_string) ) begin
parse(cmd, ",", plusarg_string);
end
foreach(cmd[i])
$display("CMD[%0d]:'%s'",i,cmd[i]);
Run Code Online (Sandbox Code Playgroud)
完整的工作示例:http://www.edaplayground.com/s/6/570