2013-05-03 456 views
1

问题 - 我需要获取命令行选项来为系统verilog中的约束添加条件。将字符串变量传递给系统verilog中的plusargs

我从函数调用调用$value$pluargs("string=%d",val),我需要使用传递给函数的参数作为'字符串'名称。

function(string name); 
$value$plusargs("<name>=%d", val) 
endfunction 

我不知道该怎么做。说$value$plusargs("%s=%d",name,val)会导致“参数太多”的错误。

任何建议将非常感激!谢谢!

回答

4

您可以使用字符串连接:

module tb; 
    int val = 5; 

    initial begin 
     $monitor("val=", val); 
     foo("bar"); 
    end 

    function void foo (string name); 
     $value$plusargs({name, "=%d"}, val); 
    endfunction 
endmodule 
0

您可以使用$测试$ plusargs确定命令行开关是否提供或不提供。

该系统函数在提供的 字符串中搜索plusargs列表。在 提供的命令中搜索命令行上的正文。

如果提供的字符串中的所有字符都返回1'b1的结果。如果命令行中没有plusarg与提供的字符串匹配,则返回1'b0的结果。我修改了一下这个功能。

function void foo (string name); 
    if($test$plusargs("name")) 
    begin 
    // Use the below 
    $value$plusargs({name, "=%d"}, val); 
    end 
endfunction 
+0

这没有正确使用名称参数(除了注释行)。 – ScottJ 2016-01-22 19:25:34

+1

@ScottJ我编辑了答案。感谢指针。 – sharvil111 2016-01-23 02:32:17