我们正在学习SV流程,样品执行书。。
功能:函数返回数组。
Code1:
/*书上提供的样例。存在错误,不可执行
function void init(ref int f[5], int start);//主要是函数定义时没有声明automatic属性
foreach(f)
f = i + start;
endfunction
initial begin
int fa[5];
fa = init(fa,5);
foreach(fa)
$display("fa[%0d] = %0d", i, fa);
end
*/
#-----------------------------------------------------------------------------------
Code2:
//下面这段代码在modelsim下可成功执行。
(在定义function时加上了automatic)
module enum_name;
int fa[5];
initial begin
// fa = init(fa, 5);
init(fa, 5);
foreach(fa)
$display("fa[%0d] = %0d", i, fa);
end
function automatic void init(ref int f[5], input int start);
foreach(f)//初始化数组
f = i + start;
endfunction
endmodule
#-----------------------------------------------------------------------------------
Question:
在LRM中第16章,解说program结果时有例如以下结构:
Code3:
module test(...)
int shared;
// variable shared by programs p1 and p1
program p1;
...
endprogram
program p2;
...
endprogram //
p1 and p2 are implicitly instantiated once in module test
endmodule
想问一下,Code2中的function怎么能够包在program...endprogram里面,形成Code3形式的代码结构。
当中,Code4是我尝试改的,但在ModelSim中编译能够通过,但执行时报错。
Code4:
module enum_name;
int fa[5];
initial begin
// fa = init(fa, 5);
test.init(fa, 5); //相应报错信息中提示的第61行内容
foreach(fa)
$display("fa[%0d] = %0d", i, fa);
end
//------------------------------------------------------------;
program automatic test;
function automatic void init(ref int f[5], input int start);
foreach(f)//初始化数组
f = i + start;
endfunction
endprogram
endmodule
执行时报错内容:
# Compile of enum_name.sv was successful with warnings.
vsim -gui work.enum_name
# vsim -gui work.enum_name
# Loading sv_std.std
# Loading work.enum_name
# ** Error: (vsim-3927) D:/ModelSim/SysVerilog/enum/enum_name.sv(61) Accessing program item ‘/enum_name/test/init‘ from a non-program design unit enum_name is illegal.
#
# Region: /enum_name
# ** Error: (vsim-3927) D:/ModelSim/SysVerilog/enum/enum_name.sv(61) Accessing program item ‘/enum_name/test/init‘ from a non-program design unit enum_name is illegal.
#
# Region: /enum_name
# ** Error: (vsim-3927) D:/ModelSim/SysVerilog/enum/enum_name.sv(61) Accessing program item ‘/enum_name/test/init‘ from a non-program design unit enum_name is illegal.
#
# Region: /enum_name
# Error loading design
版权声明:本文博主原创文章,博客,未经同意不得转载。