Virtual_seq on virtual_seqr

HI :
in the UVM cookbook session SEQ/VIRTUAL : virtual seq that run on vir seqr
the example shows:
**
class v_seq extends uvm_sequence #(uvm_sequence_item);

vir_seqr v_sqr;
bus_sqr bus;
gpio_sqr gpio;
task body();
if ( ! $cast(v_sqr, m_sequencer) begin
`uvm_error(get_full_name, " virtual sequencer pointer cast failed");
bus = v_sqr.bus;
gpio= v_sqr.gpio;

endtask

endclass

I was wondering if i can use macro `uvm_declare_p_sequencer(…) instead. i am not sure what the cons for doing so. To me, it makes more sense to do connection only in TB components side.

  class virtual_seq extends uvm_sequence #(uvm_seq_item);
        `uvm_object_utils(virtual_seq)
        **`uvm_declare_p_sequencer(virtual_sqr)**             ....
         task body();
          ...
          bus_seq.start(**p_sequencer**.bus);
          gpio_seq.start(**p_sequencer**.gpio);
         ...
         endtask

There’s no real difference between the code on the cookbook page and the code in the p_sequencer macro:

define uvm_declare_p_sequencer(SEQUENCER) \ SEQUENCER p_sequencer;\ virtual function void m_set_p_sequencer();\ super.m_set_p_sequencer(); \ if( !$cast(p_sequencer, m_sequencer)) \ uvm_fatal(“DCLPSQ”,
$sformatf(“%m %s Error casting p_sequencer, please verify that this sequence/sequence item is intended to execute on this type of sequencer”, get_full_name()))
endfunction

The more explicit code in the cookbook example is designed to allow users to see what is going on, whereas using the p_sequencer macro hides the code and would require an explanation of the macro and the p_sequencer.

The code shown on the page is also for a virtual sequence base class. Other virtual sequences would inherit from this and simply call super.body() in order to get the sub-sequencer handles assigned.

In reply to mperyer:

For the above $cast to work, m_sequencer which is the generic handle for uvm_sequencer should have been cast earlier to sequencer handle of type virtual_sequencer. Where is this getting done? Is it automatically getting assigned when I construct the object for virtual_sequencer? How does it work?

In reply to malathi@aceic.com:

Exactly, m_sequencer gets a static cast in set_sequencer() that is called when the virtual sequence is started.