SystemVerilog Queues

hi, I have a queue of SystemVerilog language Using ModelSim SE 6.5 Tools, but it is a final error.
my SystemVerilog code is below:

//////////////////////////////////////////////////////////
  initial begin
    int j=1,
      q2[$] = {3, 4},
      q[$] = {0, 2 ,5};
    q.insert(1, j);
    q.insert(3, q2);
    q.delete(1);
    
    q.push_front(6);
    j=q.pop_back;
    q.push_back(8);
    j = q.pop_front;
    foreach(q[i])
      $display(q[i]);
    q.delete();
  end
/////////////////////////////////////////////////////////////////
ERROR Information:
# ** Fatal: Illegal unpacked assignment to packed LHS.
#    Time: 400 ms  Iteration: 0  Process: /tb_traffic_light/#INITIAL#133(#ublk#0#134) File: XXXXXXX.sv
# Fatal error in Module tb_traffic_light at tb_traffic_light.sv line 139
//////////////////////////////////////////////////////////////////////

ERROR Line 139 : q.insert(3, q2);
why ? q queue does not insert q2 queue ?

Thanks
Neddy
China

The insert method of a queue can only insert one element at a time.

You will have to either insert one element at a time

q.insert(3,q2[0]); q.insert(4,q2[1]);

or use the array concatenation syntax

q = {q[0],q2,q[1:$]};

insert()

This method inserts an element in a queue. i dont think this method insert whole array!..

In reply to Vinay Jain:

Maybe ModelSim does not support it …

In reply to Neddy:

Neddy, SystemVerilog does not support it

7.10.2.2 Insert()
The prototype of the insert() method is as follows:
function void insert(input int index, input element_t item);
The insert() method inserts the given item at the specified index position.

The second argument to the insert method is expecting an element type, not an array type. (Unless you have a multidimensional queue of arrays, of course).
You are getting an error message because you are trying to pass a queue (an unpacked array of ints) to an int (a packed array of bits).

hi Neddy,

 i guess this is tool limitation coz as per systemverilog lrm, it should be supported. 

if you see the lrm , there is something like

typedef int que[$];

now if you create data type from that ie que q1; and use with insert keyword, i am pretty much sure that you will get the same Error Message.

code will be something like this ::
module m;
typedef int qq[$];
qq q1;
int q2 = {1,2,3};
initial
q1.insert(1,q1);
endmodule


suvendu
suvendusaha25@gmail.com

Hi Dave I have been trying queue Methods On 2 Dimensional Queues
eg:

int q2[$][$];
  for ( int i1 = 0 ; i1 < 2; i1++ ) begin
     for ( int i2 = 0 ; i2 < 4; i2++ ) begin
       q2[i1].insert(i2,(i1+i2*10));
     end
   end

$display("%p",q2);

Now this Gives Works and gives Output : '{ '{ 0 , 10 , 20 , 30 } , '{ 1 , 11 , 21 , 31 } }

Now I am confused how to write into a 3 Dimensional Queue Using Queue Methods.

Could u please guide how it can be done ?

In reply to Have_A_Doubt:
I think its confusing because the code you posted should not have worked. (But does in a few implementations)

It is helpful to think of SystemVerilog having arrays of arrays instead gf multi-dimensional arrays. That means you have to create an element for each queue dimension before you can start adding elements to the next dimension. That means your code should have been written as

 for ( int i1 = 0 ; i1 < 2; i1++ ) begin
     q2.insert(i1,{}); // equivalent to q2.push_back({}) in this example
     for ( int i2 = 0 ; i2 < 4; i2++ ) begin
       q2[i1].insert(i2,(i1+i2*10)); // q2[i1].push_back(i1+i2*1)
     end
   end

Now adding more dimensions is straightforward.

module top;

   int q3[$][$][$];
  
   initial begin
      for ( int i1 = 0 ; i1 < 2; i1++ ) begin
	 q3.push_back( {} );
	 for ( int i2 = 0 ; i2 < 4; i2++ ) begin
	    q3[i1].push_back( {} );
    	    for ( int i3 = 0 ; i3 < 6; i3++ ) begin
	       q3[i1][i2].push_back( i1+i2*10+i3*100 );
	    end
	 end
      end
      $display("%p",q3);

   end
endmodule

1 Like