System verilog 如何编写关于返回数据的函数
好的,我需要帮助。我遇到了有关数组数据事务的问题。请帮助我! 代码如下。 数据包是数据类,有三个队列,R、G、B,在模块“test”中,arith函数返回的_数据是无数据。为什么? 问题:虽然“into-arith”函数,但输出tr_out没有数据System verilog 如何编写关于返回数据的函数,system-verilog,System Verilog,好的,我需要帮助。我遇到了有关数组数据事务的问题。请帮助我! 代码如下。 数据包是数据类,有三个队列,R、G、B,在模块“test”中,arith函数返回的_数据是无数据。为什么? 问题:虽然“into-arith”函数,但输出tr_out没有数据 class packet # (int bit_depth =16);//packet class bit [bit_depth-1:0] R[$]; bit [bit_depth-1:0] G[$]; bit [bit_depth-1
class packet # (int bit_depth =16);//packet class
bit [bit_depth-1:0] R[$];
bit [bit_depth-1:0] G[$];
bit [bit_depth-1:0] B[$];
endclass
//数据包是数据类
module test #(active_num=1920); //
packet in_tr [4];
initial begin
foreach(in_tr[i]) begin
in_tr[i] = new();
end
foreach(in_tr[j]) begin
for(int i=0;i<1920;i++) begin
in_tr[j].R.push_back(i);
end
end
process_in_tr;
end
task process_in_tr();
packet tr_out[4];
foreach(tr_out[i])begin
tr_out[i] = new();
end
tr_out[4] = into_arith(in_tr);
foreach(tr_out[j]) begin
foreach(tr_out[j].R[i]) begin
$display("%h",tr_out[j].R[i]);
end
end
endtask
function packet[4] into_arith(ref packet in_tr[4]);
packet tr_tmp[4];
foreach(tr_tmp[i]) begin
tr_tmp[i] = new();
end
for(int m=0;m<4;m++) begin
foreach(in_tr[m].R[i]) begin
tr_tmp[m].R.push_back(in_tr[m].R[i]);
tr_tmp[m].G.push_back(in_tr[m].G[i]);
tr_tmp[m].B.push_back(in_tr[m].B[i]);
end
end
return tr_tmp[4];
endfunction
endmodule
模块测试#(活动_num=1920)//
_tr[4]中的数据包;
初始开始
foreach(in_tr[i])开始
in_tr[i]=new();
结束
foreach(in_tr[j])开始
对于(inti=0;i我无法在Questa中编译此事件,存在许多语法错误
这三个主要问题是:
函数声明出错。返回聚合类型时必须使用typedef(在本例中为数据包#())的未打包数组)
赋值tr_out[4]=into_arith(in_tr);
是非法的。您试图将一个包含4个元素的未打包数组分配给数组的第5个元素,而该元素甚至不存在
返回tr_tmp[4];
也是非法的。您试图返回数组中不存在的第5个元素,作为需要4个元素数组的函数的返回值
请参阅下面我的所有更正:
class packet # (int bit_depth =16);//packet class
bit [bit_depth-1:0] R[$];
bit [bit_depth-1:0] G[$];
bit [bit_depth-1:0] B[$];
endclass
//packet is data class
module test #(active_num=1920); //
typedef packet#() packet4_t[4];
packet4_t in_tr;
initial begin
foreach(in_tr[j]) begin
in_tr[j] = new();
for(int i=0;i<1920;i++)
in_tr[j].R.push_back(i);
end
process_in_tr;
end
task process_in_tr();
packet4_t tr_out;
tr_out = into_arith(in_tr);
foreach(tr_out[j]) begin
foreach(tr_out[j].R[i]) begin
$display("%h",tr_out[j].R[i]);
end
end
endtask
function automatic packet4_t into_arith(ref packet4_t in_tr);
packet4_t tr_tmp;
foreach(tr_tmp[i]) begin
tr_tmp[i] = new();
tr_tmp[m].R = in_tr[m].R;
tr_tmp[m].G = in_tr[m].G;
tr_tmp[m].B = in_tr[m].B;
/* assigments above are the same as the foreach loop below
foreach(in_tr[m].R[i]) begin
tr_tmp[m].R.push_back(in_tr[m].R[i]);
tr_tmp[m].G.push_back(in_tr[m].G[i]);
tr_tmp[m].B.push_back(in_tr[m].B[i]);
end */
end
return tr_tmp;
endfunction
endmodule
class-packet#(int-bit_-depth=16);//packet-class
位[bit_depth-1:0]R[$];
位[bit_depth-1:0]G[$];
位[bit_depth-1:0]B[$];
末级
//数据包是数据类
模块测试(活动数量=1920)//
typedef packet#()packet4_t[4];
包装4英寸;
初始开始
foreach(in_tr[j])开始
in_tr[j]=new();
对于(int i=0;i