how to get array of values as plusargs in systemverilog?

孤人 提交于 2019-12-10 16:42:53

问题


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

Eg:

+CMDS=READ,WRITE,READ_N_WRITE : It should be taken to an array ?


回答1:


$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

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]);

Full working example: http://www.edaplayground.com/s/6/570




回答2:


According to the IEEE Std 1800-2012 (Section 21.6 "Command line input"), the $value$plusargs system function accepts a string, not an array. You would have to parse the string inside Verilog, which would probably be very cumbersome (refer to Section 6.16 "String data type" for string operators).

Other options might be:

  1. Use several plusargs: +CMD1=READ +CMD2=WRITE
  2. Read data in from a file via $readmemh, although that is limited to numeric data
  3. Read data in from a file via $fopen


来源:https://stackoverflow.com/questions/20519349/how-to-get-array-of-values-as-plusargs-in-systemverilog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!