隊列同樣可以保存類對象,這在驗證環(huán)境中是非常有用的,下面是一個例子:
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}}
該示例聲明了一個名為“animals”的類,字符串“name”初始化為“UN”。
聲明了兩個“animals”類型的對象" f "和“f2”。
創(chuàng)建“animals”類型的對象隊列“alist”。
分別實例化兩個對象“f”和“f2”,然后push到隊列中。
-
Verilog
+關(guān)注
關(guān)注
29文章
1367瀏覽量
112258 -
System
+關(guān)注
關(guān)注
0文章
166瀏覽量
37807 -
隊列
+關(guān)注
關(guān)注
1文章
46瀏覽量
11082
原文標題:SystemVerilog中的類隊列
文章出處:【微信號:芯片驗證工程師,微信公眾號:芯片驗證工程師】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
SystemVerilog 3.1a語言參考手冊
SystemC 和SystemVerilog的比較
System Verilog與verilog的對比
使用Verilog/SystemVerilog硬件描述語言練習(xí)數(shù)字硬件設(shè)計
FPGA學(xué)習(xí)-SystemVerilog語言簡介
從Verilog PLI到SystemVerilog DPI的演變過程

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

verilog/systemverilog中隱藏的初始化說明

verilog-2005和systemverilog-2017標準規(guī)范

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

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

評論