SystemVerilog program 能不能定义在 module里?
时间:10-02
整理:3721RD
点击:
初学SV, 根据RLM 尝试着把program定义在module里。结果编译失败。如果把program定义移动到module外,编译成功。根据LRM "Program blocks can be nested within modules or interfaces." ,program可以定义在module里,错在了哪里?
- Error-[SE] Syntax error
- Following verilog source has syntax error :
- "sv_program.sv", 8: token is 'program'
- program automatic test();
- ^
- System verilogkeyword 'program' is not expected to be used in this
- context.
- `timescale 1ns/100ps
- module top;
- reg clk;
- program automatic test();
- initial begin
- for(int j=0; j!=3; j++) begin
- int k = j;
- fork
- $write("j = %0d\n",j);
- $write("k = %0d\n",k);
- join_none
- end
- end
- endprogram
- initial begin
- $display("Hello World");
- end
- test t();
- endmodule
用Mentor的工具compile没有问题。但是VCS 会报错。
他们是同级别的!
module和program是同一级别的,把program的定义从module里面拎出来,在module里面例化一个test就ok了,就像例化一个子模块一样。
可以的
`define DIS "hello,world,%d,%h",'h8,5'd15
module test2;
reg clk;
program automatic test;
class cov;
rand bit[4:0] port;
endclass
cov cov1;
covergroupportcov;
coverpoint cov1.port{
bins port[]={[0]};
bins other[]=default;
}
endgroup
portcov portcovsample;
initial begin
portcovsample=new();
cov1=new();
repeat(1000) begin
assert(cov1.randomize());
$display("port is %d",cov1.port);
portcovsample.sample();
end
end
initial begin
$display(`DIS);
repeat(1000) begin
#10;
$display("good");
$stop;
end
end
endprogram
endmodule
学习了