- 区别
- local — 限制只在本class中使用,子类以及外部类中不可调用
- protected — 限制只在本class以及子类中使用,外部类不可调用
- 举例
- protected demo
class father_protected;
protected logic [7:0] sig_prote = 'haa;
function display();
$display("father_protected sig_prote = 0x%0h",sig_prote);
endfunction
endclass
class son_protected extends father_protected;
function display();
sig_prote = 'hbb;
$display("son_protected sig_prote = 0x%0h",sig_prote);
endfunction
endclass
module tb;
father_protected f_prote;
son_protected s_prote;
initial begin
f_prote = new();
s_prote = new();
f_prote.display();
s_prote.display();
#10;
$finish;
end
endmodule
上述打印结果
father_protected sig_prote = 0xaa
son_protected sig_prote = 0xbb
但是当在tb中增加对信号的操作时,如下:
f_prote.sig_prote = 'hff;
在编译时会产生compile error
- local demo
代码整体同上,将protected替换成local
编译过程中将出现compile error,如下: