SV中local vs protected

  1. 区别
  • local — 限制只在本class中使用,子类以及外部类中不可调用
  • protected — 限制只在本class以及子类中使用,外部类不可调用
  1. 举例
  • 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,如下:
    在这里插入图片描述
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值