1. 程式人生 > 其它 >用uvm_cmdline_processor來獲取模擬引數

用uvm_cmdline_processor來獲取模擬引數

uvm_cmdline_processor有下列函式:

1. function int get_arg_matches (string match, ref string args[$]);

// This function loads a queue with all of the arguments that
// match the input expression and returns the number of items
// that matched. If the input expression is bracketed
// with //, then it is taken as an extended regular expression
// otherwise, it is taken as the beginning of an argument to match.
// For example:
//
//| string myargs[$]
//| initial begin
//| void'(uvm_cmdline_proc.get_arg_matches("+foo",myargs)); //matches +foo, +foobar
//| //doesn't match +barfoo
//| void'(uvm_cmdline_proc.get_arg_matches("/foo/",myargs)); //matches +foo, +foobar,
//| //foo.sv, barfoo, etc.
//| void'(uvm_cmdline_proc.get_arg_matches("/^foo.*\.sv",myargs)); //matches foo.sv
//| //and foo123.sv,
//| //not barfoo.sv.

function int get_arg_matches (string match, ref string args[$]);

`ifndef UVM_CMDLINE_NO_DPI
chandle exp_h = null;
int len = match.len();
args.delete();
if((match.len() > 2) && (match[0] == "/") && (match[match.len()-1] == "/")) begin
match = match.substr(1,match.len()-2);
exp_h = uvm_dpi_regcomp(match);
if(exp_h == null) begin
uvm_report_error("UVM_CMDLINE_PROC", {"Unable to compile the regular expression: ", match}, UVM_NONE);
return 0;
end
end
foreach (m_argv[i]) begin
if(exp_h != null) begin
if(!uvm_dpi_regexec(exp_h, m_argv[i]))
args.push_back(m_argv[i]);
end
else if((m_argv[i].len() >= len) && (m_argv[i].substr(0,len - 1) == match))
args.push_back(m_argv[i]);
end

if(exp_h != null)
uvm_dpi_regfree(exp_h);
`endif

return args.size();
endfunction

2.

// Group: Argument Values

// Function: get_arg_value
//
// This function finds the first argument which matches the ~match~ arg and
// returns the suffix of the argument. This is similar to the $value$plusargs
// system task, but does not take a formating string. The return value is
// the number of command line arguments that match the ~match~ string, and
// ~value~ is the value of the first match.

function int get_arg_value (string match, ref string value);
int chars = match.len();
get_arg_value = 0;
foreach (m_argv[i]) begin
if(m_argv[i].len() >= chars) begin
if(m_argv[i].substr(0,chars-1) == match) begin
get_arg_value++;
if(get_arg_value == 1)
value = m_argv[i].substr(chars,m_argv[i].len()-1);
end
end
end
endfunction

3.

// Function: get_arg_values
//
// This function finds all the arguments which matches the ~match~ arg and
// returns the suffix of the arguments in a list of values. The return
// value is the number of matches that were found (it is the same as
// values.size() ).
// For example if '+foo=1,yes,on +foo=5,no,off' was provided on the command
// line and the following code was executed:
//
//| string foo_values[$]
//| initial begin
//| void'(uvm_cmdline_proc.get_arg_values("+foo=",foo_values));
//|
//
// The foo_values queue would contain two entries. These entries are shown
// here:
//
// 0 - "1,yes,on"
// 1 - "5,no,off"
//
// Splitting the resultant string is left to user but using the
// uvm_split_string() function is recommended.

function int get_arg_values (string match, ref string values[$]);
int chars = match.len();

values.delete();
foreach (m_argv[i]) begin
if(m_argv[i].len() >= chars) begin
if(m_argv[i].substr(0,chars-1) == match)
values.push_back(m_argv[i].substr(chars,m_argv[i].len()-1));
end
end
return values.size();
endfunction

$value$plusargs相當於uvm_cmdline_processor::get_arg_value,如果給同一個引數設定了多個值,則只能獲得設定的第一個值。而get_arg_values可以獲得所有的值。

在UVM環境中,可以通過全域性變數uvm_cmdline_proc或者直接通過uvm_cmdline_processor::get_inst()來呼叫get_arg_value等函式。