uvm_queue类构建一个动态队列,该队列将按需分配并通过引用传递。
uvm_queue类声明:
class uvm_queue #( type T = int ) extends uvm_object
1 uvm_queue class hierarchy
2 uvm_queue class Methods
3 UVM Queue Example
在下面的示例中,组件A用于向队列中添加元素,组件B用于从同一队列中删除元素。
组件A和组件B代码:
class componentA extends uvm_component;`uvm_component_utils(componentA)uvm_queue#(string) qA;function new(string name = "componentA", uvm_component parent = null);super.new(name, parent);endfunctiontask run_phase(uvm_phase phase);super.run_phase(phase);qA = uvm_queue#(string)::get_global_queue();qA.push_front("Rock");qA.push_back("Scissor");qA.insert(1, "Paper");endtask
endclassclass componentB extends uvm_component;`uvm_component_utils(componentB)uvm_queue#(string) qB;string s_name;function new(string name = "componentB", uvm_component parent = null);super.new(name, parent);endfunctiontask run_phase(uvm_phase phase);super.run_phase(phase);s_name = uvm_queue#(string)::get_global(1);`uvm_info(get_name(), $sformatf("get_global: item = %s", s_name), UVM_LOW);qB = uvm_queue#(string)::get_global_queue();s_name = qB.pop_front();`uvm_info(get_name(), $sformatf("pop_front = %s", s_name), UVM_LOW);`uvm_info(get_name(), $sformatf("Before delete: qB size = %0d", qB.size()), UVM_LOW);qB.delete(1);`uvm_info(get_name(), $sformatf("After delete: qB size = %0d", qB.size()), UVM_LOW);s_name = qB.pop_back();`uvm_info(get_name(), $sformatf("pop_back = %s", s_name), UVM_LOW);endtask
endclass
class base_test extends uvm_test;`uvm_component_utils(base_test)componentA comp_a;componentB comp_b;function new(string name = "base_test",uvm_component parent=null);super.new(name,parent);endfunction : newfunction void build_phase(uvm_phase phase);super.build_phase(phase);comp_a = componentA::type_id::create("comp_a", this);comp_b = componentB::type_id::create("comp_b", this);endfunction : build_phasefunction void end_of_elaboration();uvm_top.print_topology();endfunction
endclassmodule uvm_queue_example;initial beginrun_test("base_test");end
endmodule
Output:
UVM testbench topology:
-------------------------------------
Name Type Size Value
-------------------------------------
uvm_test_top base_test - @336 comp_a componentA - @349 comp_b componentB - @358
-------------------------------------UVM_INFO components.sv(31) @ 0: uvm_test_top.comp_b [comp_b] get_global: item = Paper
UVM_INFO components.sv(36) @ 0: uvm_test_top.comp_b [comp_b] pop_front = Rock
UVM_INFO components.sv(38) @ 0: uvm_test_top.comp_b [comp_b] Before delete: qB size = 2
UVM_INFO components.sv(40) @ 0: uvm_test_top.comp_b [comp_b] After delete: qB size = 1
UVM_INFO components.sv(43) @ 0: uvm_test_top.comp_b [comp_b] pop_back = Paper