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