static屬性一般是在編譯的時(shí)候就已經(jīng)分配了內(nèi)存,并被這個(gè)類的所有實(shí)例共享,
也就是在仿真時(shí)刻0之前就已經(jīng)完成了靜態(tài)屬性的內(nèi)存分配。
但是,參數(shù)化類中的靜態(tài)屬性可能有所區(qū)別。參數(shù)化類中的靜態(tài)屬性(參數(shù)化)是在參數(shù)初始化的時(shí)候才會(huì)分配。
// Class with parameters class with_param #(type T = int); static T static_with_p; endclass // Class without Parameters class without_param; static int static_wo_p; endclass module top; initial begin $display("static_wo_p = %0d", without_param :: static_wo_p); $display("static_with_p = %0d", with_param :: static_with_p); end endmodule: top
在上面的兩個(gè)class中,一個(gè)包含parameter (with_param),還有一個(gè)不包含parameter(without_param).
在各自class中,我們都聲明了靜態(tài)屬性。在訪問靜態(tài)屬性“static_wo_p”時(shí)沒有問題,而在訪問靜態(tài)屬性
“static_with_p”時(shí),編譯器會(huì)報(bào)錯(cuò)(Error或者Warning):
Warning-[PCSRMIO] Class scope used outside of class testbench.sv, 59 "with_param::static_with_p" An unspecialized class scope '::' reference was seen. To access a static member of the default specialization outside the class 'with_param', use 'with_param#( )::' instead. This will be an error in a future release.
需要修改成下面這樣的寫法才能編譯通過。
$display("static_with_p = %0d", with_param # ( ) :: static_with_p);
下面這個(gè)例子更能夠展示參數(shù)化類中的靜態(tài)屬性和非參數(shù)類中的靜態(tài)屬性的區(qū)別:
class with_param #(type T = int); static T counter = 2; function new; counter++; endfunction: new endclass: with_param class with_param_extend extends with_param #(real); endclass: with_param_extend typedef with_param #(byte) s_byte; s_byte S1 = new( ); s_byte S2 = new( ); with_param S3 = new( ); with_param #(bit[2:0]) S4 = new( ); with_param_extend S5 = new( ); initial begin $display ("Counter value of S1 instance = %0d", with_param #(byte)::counter); $display ("Counter value of S2 instance = %0d", s_byte:: counter); $display ("Counter value of S3 instance = %0d", with_param #()::counter); $display ("Counter value of S4 instance = %0d", with_param #(bit[2:0])::counter); $ d i s p l a y ( " C o u n t e r value of S5 instance =%0d",with_param_extend::counter); end
仿真log:
Counter value of S1 instance = 4 Counter value of S2 instance = 4 Counter value of S3 instance = 3 Counter value of S4 instance = 3 Counter value of S5 instance = 3.000000 V C S S i m u l a t i o n R e p o r t
上面的例子中S1、S2、S3、S4、S5中的參數(shù)T分別被覆蓋成byte、byte、int、bit[2:0]、real,所以只有S1(s_byte)和S2(s_byte)中的靜態(tài)屬性counter彼此共享。
參數(shù)類的擴(kuò)展類
class class1 #(type T = int); …. endclass class class2 #(type P = real) extends class1; class class3 #(type P = real) extends class1 #(integer); class class4 #(type P = real) extends class1 #(P);
上面是一個(gè)參數(shù)化類的擴(kuò)展類示例,class1是一個(gè)參數(shù)化類,參數(shù)T默認(rèn)為"int"。
class2增加了一個(gè)參數(shù)P,此時(shí)參數(shù)T為默認(rèn)的"int"
class3增加了一個(gè)參數(shù)P,此時(shí)參數(shù)T覆蓋成"integer"
class4增加了一個(gè)參數(shù)P,此時(shí)參數(shù)T也覆蓋成為P
-
屬性
+關(guān)注
關(guān)注
0文章
23瀏覽量
8577 -
static
+關(guān)注
關(guān)注
0文章
33瀏覽量
10407
原文標(biāo)題:參數(shù)化Class中的靜態(tài)屬性
文章出處:【微信號(hào):芯片驗(yàn)證工程師,微信公眾號(hào):芯片驗(yàn)證工程師】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評(píng)論請先 登錄
相關(guān)推薦
如何使SOLIDWORKS參數(shù)化設(shè)計(jì)軟件提升效率
如何使用ADC_PRO來測試ADC的INL與DNL等靜態(tài)特性參數(shù)?
請問靜態(tài)變量如何放到flash中?
FPGA設(shè)計(jì)中,對SPI進(jìn)行參數(shù)化結(jié)構(gòu)設(shè)計(jì)
![](https://file1.elecfans.com/web2/M00/DE/4B/wKgZomYu39WAJchbAAkYJ18y9JI146.png)
FPGA設(shè)計(jì)中,對SPI進(jìn)行參數(shù)化結(jié)構(gòu)設(shè)計(jì)
如何調(diào)整S7-1500中S7-GRAPH FB的保持性屬性
![如何調(diào)整S7-1500<b class='flag-5'>中</b>S7-GRAPH FB的保持性<b class='flag-5'>屬性</b>](https://file1.elecfans.com/web2/M00/C6/CA/wKgZomYMrp6AYd3YAABszeAxJK4086.png)
評(píng)論