I am trying to execute a sequence within the run_phase()
task of a uvm_test
derived class. I raise an objection at the start of the task; declare, create, and execute a sequence on a sequencer; drop the objection.
task run_phase(uvm_phase phase);
phase.raise_objections(this);
uvm_sequence seq;
seq = uvm_sequence::type_id::create("seq");
seq.start(m_env.m_sequencer);
phase.drop_objections(this);
endtask: run_phase
This gives me the error
expecting an '=' or '<=' sign in an assignment
referring to the statement uvm_sequence seq
.
I know now that I can't declare a variable midway through a task unless I assign a value when I declare it. However, if I use begin/end
statements, I can declare the sequence after I raise the objection, as such
task run_phase(uvm_phase phase);
phase.raise_objections(this);
begin
uvm_sequence seq;
seq = uvm_sequence::type_id::create("seq");
seq.start(m_env.m_sequencer);
end
phase.drop_objections(this);
endtask: run_phase
This code compiles fine. What is it about the begin/end
block that allows me to declare a variable mid-task?