如何在systemverilog中获取值数组作为plusargs? [英] how to get array of values as plusargs in systemverilog?
问题描述
如何在systemverilog中获取值数组作为参数,我的要求是我需要从命令行获取未定义大小的命令数组,以及如何将这些参数获取到数组/队列中
How to get the array of values as arguments in systemverilog, my requirement is I need get an array of commands of undefined size from the command line ,and how to get these arguments to an array/Queue
例如:
+ CMDS = READ,WRITE,READ_N_WRITE
:应该
推荐答案
$ value $ plusargs
支持数组,它确实支持字符串。参见 IEEE Std 1800-2012 § 21.6命令行输入。在SystemVerilog中解析字符串只是有点麻烦,但仍然非常可行,尤其是当分隔符表示为单个字符时。这是一个使用SystemVerilog队列的通用字符串解析器,用于重新编码在
$value$plusargs
does not support arrays, it does support strings. See IEEE Std 1800-2012 § 21.6 "Command line input". Parsing a string in SystemVerilog is only a little cumbersome but still very doable, especially when the separator is represented as a single character. Here is a generic string parser using a SystemVerilog queue for recoding the indexes and string method substr
defined in IEEE Std 1800-2012 § 7.10 "Queue" and § 6.16.8 "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
然后将其与<$ c组合$ c> $ value $ plusargs 来解析输入:
Then combine it with $value$plusargs
to parse the input:
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]);
完整的示例: http://www.edaplayground.com/s/6/570
这篇关于如何在systemverilog中获取值数组作为plusargs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!