如何迭代所有传递给SV中的任务或函数的参数?

时间:2019-04-12 02:57:47

标签: verilog system-verilog

是否可以遍历我传递给系统Verilog任务或函数的所有参数,例如c中的argv和Perl中的@ARGV?因为我不知道要传递多少参数。

test("name2", 1,2,3);    // might pass more argument than this
task test(string signal, int tog1, int tog2, int tog3);
        $display("The value are: %s, %d and %d", signal, tog1, tog3) ;    //any way to just iterate through this?

endtask

2 个答案:

答案 0 :(得分:2)

SystemVerilog没有此功能。在编译时检查任务和函数调用参数是否匹配原型。

我能想到的两种选择:

  1. 如果所有参数都是相同的数据类型(如您的示例中所示),则可以使单个参数成为动态数组。您可以查询函数内部数组的大小。
  2. 您可以为不想传递的参数声明默认值。

    任务测试(字符串信号=“”,int tog1 = -1,int tog2 = -1,int tog3 = -1); ... test(“ name2”,1,2); /参数tog3将为-1

答案 1 :(得分:2)

首先argv@ARGV迭代传递给程序而不是函数的参数。 Verilog使用plusargs实现了类似的功能。换句话说,您可以传递以+开头的参数,并使用plusargs函数进行扫描。例如,如果您将仿真图像命名为

%> simv +HELLO

在Vreilog中,您可以使用类似以下的内容

initial begin
  if ($test$plusargs("HELLO")) $display("Hello argument found.");
  ...
end

该标准定义了2个功能:

$test$plusargs ( string )
$value$plusargs ( user_string, variable )

第二,c不允许您遍历,除非您将varargsvariadic函数一起使用。 perl确实允许,将args视为数组。 verilog 没有没有任何语言功能。

但是,verilog定义了一组pli函数以与c互操作。 vpi界面具有允许您遍历任务和函数的参数(在“ c”中)的功能。