How to get an array of values ​​as a plusarg in the system form?

How to get an array of values ​​as arguments in systemverilog, my requirement is: I need to get an array of commands of size undefined from the command line and how to get these arguments in an array / queue

For example:

+CMDS=READ,WRITE,READ_N_WRITE: should it be taken into an array?

+4
source share
2 answers

$value$plusargs , . . IEEE Std 1800-2012 & sect; 21.6 " ". SystemVerilog , , . , SystemVerilog string substr, IEEE Std 1800-2012 & sect; 7.10 "" & sect; 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

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

: http://www.edaplayground.com/s/6/570

+4

IEEE Std 1800-2012 ( 21.6 " " ) $value$plusargs , . Verilog, , , (. 6.16 " String" ).

:

  • : +CMD1=READ +CMD2=WRITE
  • $readmemh,
  • $fopen
+2

All Articles