How to constraint queue using `uvm_do_on_with

Hi am calling a sequence say seq1, from a virtual sequence vseq, using uvm_do_on_with.

This seq1 has a queue, and i couldn constraint this queue with a variable.
I get the below error
** Error: (vsim-3978) Illegal operation on unpacked types.

How to resolve this.
Cant queue data types be constrained via uvm_do_on_with ?

Yes you can constrain queue data types, I do it using a foreach construct in my constraint. The real issue is it is complaining about an illegal operation on unpacked type. If you make a queue of single bits, for example, this is an unpacked queue. That means it must be passed by reference to a function (ref) and operations that work on bit vectors (packed) do not work on unpacked ones.

It would help to show the constraint and the types used in the constraint. You may need to use a foreach to put constraints on individual elements of a queue.

Thanks, I will try to constraint using foreach.

Hi, I have tried using foreach to constraint a queue within uvm_do_on_with as pasted below.

*class virt_seq1 extends base_virt_seq;
rand bit[3:0] wr_data_q1[$];

`uvm_do_on_with(seq1, p_sequencer.seqr_1, {data1 == var1;
foreach(wr_data_q1[i]){
data_q[i] == wr_data_q1[i];} })
endclass

class seq1 …
rand bit[3:0] data_q[$];

endclass*
For above code am getting the error
Index out of bounds in constraint”.

What is the mistake here ?

How do you know that the queues are of the same size? The constraint will fail any time the size doesn’t match.

Also, this kind of direct assignment is something you should be doing after you’ve randomized the sequence_item. I’d recommend changing the code to something like:

class virt_seq1 extends base_virt_seq; rand bit[3:0] wr_data_q1[$]; .... // You might need to construct seq1 first - I can't remember what the macros do ... seq1.randomize(); seq1.data1 = var1; if(seq1.data_q.size() >= wr_data_q1.size()) begin foreach(wr_data_q1[i]) begin seq1.data_q[i] = wr_data_q1[i]; end end else begin foreach(seq1.data_q[i]) begin seq1.data_q[i] = wr_data_q1[i]; end end seq1.start(p_sequencer.seqr_1);

endclass

In reply to mperyer:

Hi, thanks.
Above method works.
Additionally even in uvm_do_on_with macro, if i constraint the queue size before assigning the queue elements, it worked.