标签:init fas nbsp ilo fun mod queue 操作 class
systemverilog中的队列操作十分简单,只需要调用函数即可。/* Exercise platform: Questa Sim 10.1b */ module queue; int q[$] ; function void sep(); for( int i = 0 ; i < 10 ; i++ ) $write(" *** "); $display(); endfunction:sep function void print(int q[$]); sep(); foreach(q[i]) $display("queue[%2d] = %d",i,q[i]); sep(); endfunction:print initial begin for(int i = 0 ; i < 10 ; i++ ) q.insert(i,i); print(q); $display(" push back 10 "); q.push_back(10); // 还有 push_front 方法 print(q); $display(" pop back 10 "); q.pop_back(); // 还有 pop_front 方法 print(q); $display(" Delete pos 0 "); q.delete(0); // 删除索引为0的队列成员 print(q); q = {}; // 清除队列,犹如c++中的析构函数 end endmodule:queue
仿真结果: # Loading work.queue(fast) >>>run # *** *** *** *** *** *** *** *** *** *** # queue[ 0] = 0 # queue[ 1] = 1 # queue[ 2] = 2 # queue[ 3] = 3 # queue[ 4] = 4 # queue[ 5] = 5 # queue[ 6] = 6 # queue[ 7] = 7 # queue[ 8] = 8 # queue[ 9] = 9 # *** *** *** *** *** *** *** *** *** *** # push back 10 # *** *** *** *** *** *** *** *** *** *** # queue[ 0] = 0 # queue[ 1] = 1 # queue[ 2] = 2 # queue[ 3] = 3 # queue[ 4] = 4 # queue[ 5] = 5 # queue[ 6] = 6 # queue[ 7] = 7 # queue[ 8] = 8 # queue[ 9] = 9 # queue[10] = 10 # *** *** *** *** *** *** *** *** *** *** # pop back 10 # *** *** *** *** *** *** *** *** *** *** # queue[ 0] = 0 # queue[ 1] = 1 # queue[ 2] = 2 # queue[ 3] = 3 # queue[ 4] = 4 # queue[ 5] = 5 # queue[ 6] = 6 # queue[ 7] = 7 # queue[ 8] = 8 # queue[ 9] = 9 # *** *** *** *** *** *** *** *** *** *** # Delete pos 0 # *** *** *** *** *** *** *** *** *** *** # queue[ 0] = 1 # queue[ 1] = 2 # queue[ 2] = 3 # queue[ 3] = 4 # queue[ 4] = 5 # queue[ 5] = 6 # queue[ 6] = 7 # queue[ 7] = 8 # queue[ 8] = 9 # *** *** *** *** *** *** *** *** *** ***
标签:init fas nbsp ilo fun mod queue 操作 class
原文地址:http://blog.51cto.com/13824643/2142133