Skip navigation.
Home

SystemVerilog Queue

SystemVerilog introduced a new data type for a queue. The syntax for creating a queue is the same as for a dynamic array except that inside the brackets there is a $. The queue data type supports a number of functions such as queue.push_back(), queue.push_front(), queue.pop_front() and queue_.pop_back(). The names are self explanatory -- they simply push or pop items from the front or back of the queue. This snippet demonstrates how to push the contents of a file into a queue and how to read it back out and print it out while accessed like an array.

module systemverilog_queue;
int file,value,cnt=0,value_queue[$];           // queue and variables.
initial begin
  file = $fopen("hexdata.dat","r");            // open file.
  while ($fscanf(file,"%x",value) != -1)       // attempt to read a value from file.
    value_queue.push_back(value);
  foreach(value_queue[ii])                     // display the values.
    $display("value_queue[%d]=%x",ii,value_queue[ii]);
  $stop;
end
endmodule