27 UVM queue

本文详细介绍了如何使用UVM(UniversalVerificationMethodology)中的uvm_queue类创建一个按需分配并通过引用传递的动态队列,展示了在组件A和组件B间添加、删除元素的操作过程。
摘要由CSDN通过智能技术生成

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);
  endfunction
  
  task 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
endclass

class 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);
  endfunction
  
  task 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 : new

  function 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_phase
  
  function void end_of_elaboration();
    uvm_top.print_topology();
  endfunction
endclass

module uvm_queue_example;
  initial begin
    run_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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值