Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get array of values as plusargs in 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

Eg:

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

like image 490
bachu Avatar asked Dec 11 '13 12:12

bachu


2 Answers

$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

like image 93
Greg Avatar answered Nov 15 '22 11:11

Greg


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
like image 22
toolic Avatar answered Nov 15 '22 11:11

toolic