隊(duì)列同樣可以保存類對(duì)象,這在驗(yàn)證環(huán)境中是非常有用的,下面是一個(gè)例子:
class animals; string sname; int i1; function new (string name="UN"); sname = name; i1++; endfunction endclass module tb; // queue of class type 'animals' animals alist [$]; initial begin animals f, f2; //declare two variables of type animals // Create a new class object 'f' and push into the queue f = new ("lion"); alist.push_front (f); // Create another class object 'f2'and push into the queue f2 = new ("tiger"); alist.push_back (f2); // Iterate through queue and access each class object foreach (alist[i]) begin $display ("alist[%0d] = %s", i, alist[i].sname); $display ("alist[%0d] = %p", i, alist[i]); end // Simply display the whole queue $display ("alist = %p", alist); end endmodule
仿真log:
# KERNEL: alist[0] = lion # KERNEL: alist[0] = '{sname:"lion", i1:1} # KERNEL: alist[1] = tiger # KERNEL: alist[1] = '{sname:"tiger", i1:1} # KERNEL: alist = '{'{sname:"lion", i1:1}, '{sname:"tiger", i1:1}}
該示例聲明了一個(gè)名為“animals”的類,字符串“name”初始化為“UN”。
聲明了兩個(gè)“animals”類型的對(duì)象" f "和“f2”。
創(chuàng)建“animals”類型的對(duì)象隊(duì)列“alist”。
分別實(shí)例化兩個(gè)對(duì)象“f”和“f2”,然后push到隊(duì)列中。
-
Verilog
+關(guān)注
關(guān)注
29文章
1367瀏覽量
112228 -
System
+關(guān)注
關(guān)注
0文章
166瀏覽量
37782 -
隊(duì)列
+關(guān)注
關(guān)注
1文章
46瀏覽量
11081
原文標(biāo)題:SystemVerilog中的類隊(duì)列
文章出處:【微信號(hào):芯片驗(yàn)證工程師,微信公眾號(hào):芯片驗(yàn)證工程師】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
例說(shuō)Verilog HDL和VHDL區(qū)別

SystemVerilog 3.1a語(yǔ)言參考手冊(cè)
SystemC 和SystemVerilog的比較
System Verilog與verilog的對(duì)比
使用Verilog/SystemVerilog硬件描述語(yǔ)言練習(xí)數(shù)字硬件設(shè)計(jì)
SystemVerilog中的Shallow Copy
FPGA學(xué)習(xí)-SystemVerilog語(yǔ)言簡(jiǎn)介
從Verilog PLI到SystemVerilog DPI的演變過(guò)程

如何實(shí)現(xiàn)全面的SystemVerilog語(yǔ)法覆蓋

verilog/systemverilog中隱藏的初始化說(shuō)明

verilog-2005和systemverilog-2017標(biāo)準(zhǔn)規(guī)范

SystemVerilog在硬件設(shè)計(jì)部分有哪些優(yōu)勢(shì)

SystemVerilog相比于Verilog的優(yōu)勢(shì)

評(píng)論