Inline constraints with uvm_do_on_with macro

In reply to cgales:

I’d suggest doing it slightly differently so that you can constrain all fields of ‘req’, not just the ones you export to the sequence:


class mem_sequence extends uvm_sequence #(mem_seq_item)
  rand mem_seq_item req;

  function void pre_randomize();
    req = mem_seq_item::type_id::create("req");
  endfunction
 
  task body();
    start_item(req);
    finish_item(req);
  endtask: body
  
  `uvm_object_utils(mem_sequence)
endclass

This way, ‘req’ gets randomized together with the sequence, so any inline constraints you apply when randomizing the sequence won’t get discarded by a second call to ‘req.randomize()’. Now, the code you showed us in the beginning should work:


class base_sequence extends uvm sequence ;
  mem_sequence seq1;
  
  function new(string name="base_sequence");
    super.new(name);
  endfunction
  
  virtual task body;
    `uvm_do_on_with(seq1, p_sequencer.seqr1,{ 
      req.x inside [0,1,3,4];
      req.y inside [2,6];
    }) 
  endtask

  'uvm_object_utils(base_sequence)
endclass