如何在系统verilog中返回关联数组

Rog*_*rer 1 verification verilog system-verilog

你好想知道关联数组如何作为返回值传递

代码:

function abc()
begin
int value[string][string];
value = def();
end

function int def()
begin
int new_value[string][string];
//logic to populate the array
return new_value;
end
Run Code Online (Sandbox Code Playgroud)

我看到以下错误:目标的类型是 int。而source的类型是int$[string][string]。

如何处理这个问题并无缝地传递关联数组?

dav*_*_59 6

对于返回聚合类型的函数,您需要typedef首先声明 a,然后将其用作返回值。

typedef int AA_t[string][string];
function AA_t def();
  AA_t new_value; 
  //logic to populate the array
  return new_value;
endfunction
Run Code Online (Sandbox Code Playgroud)

一旦你拥有了它,typedef你就可以在任何地方使用它。