uvm_component 构造函数中的父参数
The parent argument in the uvm_component constructor
我希望my_child
在下面的代码中继承my_parent
的say_hello
函数,但它没有。
谁能给我解释一下 parent
参数的作用?
class my_parent extends uvm_component;
`uvm_component_utils(my_parent);
function new(string name = "my_parent", uvm_component parent);
super.new(name, parent);
endfunction: new
function void say_hello;
$display("Hello, UVM!");
endfunction: say_hello
endclass: my_parent
/*========================================*/
class my_child extends uvm_component;
`uvm_component_utils(my_child);
function new(string name = "my_child", uvm_component parent);
super.new(name, parent);
endfunction: new
endclass: my_child
/*========================================*/
module top;
my_parent p;
my_child c;
initial begin
p = my_parent::type_id::create("p", null);
c = my_child::type_id::create("c", p);
c.say_hello;
end
endmodule: top
当您想从 my_parent
继承时,您应该从 my_parent
class 扩展 my_child
class 而不是 uvm_component
class。变化:
class my_child extends uvm_component;
至:
class my_child extends my_parent;
当您进行此更改并 运行 模拟时,它会按预期打印以下内容:
Hello, UVM!
parent
变量在 uvm_component
下的 UVM Class Reference 文档中有解释。
您混淆了术语 parent 和 child 与 [=29= 】 传承。它们是不同的 objects。一个 parent 创建 一个 child,而 uvm_component
代表数据库中的分层家谱。您创建的每个组件都有一个 parent 句柄,parent 有一个句柄列表,即 children.
class my_child extends uvm_component;
`uvm_component_utils(my_child);
function new(string name = "my_child", uvm_component parent);
super.new(name, parent);
endfunction: new
endclass: my_child
class my_parent extends uvm_component;
`uvm_component_utils(my_parent);
my_child child;
function new(string name = "my_parent", uvm_component parent);
super.new(name, parent);
endfunction: new
function void build_phase(uvm_phase phase;
child = my_child::type_id::create("child", this); // 'this' is the parent object
endfunction : build_phase
endclass: my_parent
module top;
my_parent p;
initial begin
p = my_parent::type_id::create("p", null);
end
endmodule: top
当使用继承时,我们有 entended 或 derived classes,它们不是 child基仁class.
import uvm_pkg::*;
`include "uvm_macros.svh"
class my_child extends uvm_component;
`uvm_component_utils(my_child);
function new(string name = "my_child", uvm_component parent);
super.new(name, parent);
endfunction: new
task run_phase(uvm_phase phase);
$display("Hello, UVM!, from base");
endtask: run_phase
endclass: my_child
class my_parent extends uvm_component;
`uvm_component_utils(my_parent);
my_child child;
function new(string name = "my_parent", uvm_component parent);
super.new(name, parent);
endfunction: new
function void build_phase(uvm_phase phase);
child = my_child::type_id::create("cchild", this); // 'this' is the parent object
endfunction : build_phase
endclass: my_parent
class my_child_extended extends my_child;
`uvm_component_utils(my_child_extended);
function new(string name = "my_child", uvm_component parent);
super.new(name, parent);
endfunction: new
endclass: my_child_extended
module top;
my_parent p;
initial begin
my_child::type_id::set_type_override(my_child_extended::get_type());
run_test("my_parent");
end
endmodule: top
我希望my_child
在下面的代码中继承my_parent
的say_hello
函数,但它没有。
谁能给我解释一下 parent
参数的作用?
class my_parent extends uvm_component;
`uvm_component_utils(my_parent);
function new(string name = "my_parent", uvm_component parent);
super.new(name, parent);
endfunction: new
function void say_hello;
$display("Hello, UVM!");
endfunction: say_hello
endclass: my_parent
/*========================================*/
class my_child extends uvm_component;
`uvm_component_utils(my_child);
function new(string name = "my_child", uvm_component parent);
super.new(name, parent);
endfunction: new
endclass: my_child
/*========================================*/
module top;
my_parent p;
my_child c;
initial begin
p = my_parent::type_id::create("p", null);
c = my_child::type_id::create("c", p);
c.say_hello;
end
endmodule: top
当您想从 my_parent
继承时,您应该从 my_parent
class 扩展 my_child
class 而不是 uvm_component
class。变化:
class my_child extends uvm_component;
至:
class my_child extends my_parent;
当您进行此更改并 运行 模拟时,它会按预期打印以下内容:
Hello, UVM!
parent
变量在 uvm_component
下的 UVM Class Reference 文档中有解释。
您混淆了术语 parent 和 child 与 [=29= 】 传承。它们是不同的 objects。一个 parent 创建 一个 child,而 uvm_component
代表数据库中的分层家谱。您创建的每个组件都有一个 parent 句柄,parent 有一个句柄列表,即 children.
class my_child extends uvm_component;
`uvm_component_utils(my_child);
function new(string name = "my_child", uvm_component parent);
super.new(name, parent);
endfunction: new
endclass: my_child
class my_parent extends uvm_component;
`uvm_component_utils(my_parent);
my_child child;
function new(string name = "my_parent", uvm_component parent);
super.new(name, parent);
endfunction: new
function void build_phase(uvm_phase phase;
child = my_child::type_id::create("child", this); // 'this' is the parent object
endfunction : build_phase
endclass: my_parent
module top;
my_parent p;
initial begin
p = my_parent::type_id::create("p", null);
end
endmodule: top
当使用继承时,我们有 entended 或 derived classes,它们不是 child基仁class.
import uvm_pkg::*;
`include "uvm_macros.svh"
class my_child extends uvm_component;
`uvm_component_utils(my_child);
function new(string name = "my_child", uvm_component parent);
super.new(name, parent);
endfunction: new
task run_phase(uvm_phase phase);
$display("Hello, UVM!, from base");
endtask: run_phase
endclass: my_child
class my_parent extends uvm_component;
`uvm_component_utils(my_parent);
my_child child;
function new(string name = "my_parent", uvm_component parent);
super.new(name, parent);
endfunction: new
function void build_phase(uvm_phase phase);
child = my_child::type_id::create("cchild", this); // 'this' is the parent object
endfunction : build_phase
endclass: my_parent
class my_child_extended extends my_child;
`uvm_component_utils(my_child_extended);
function new(string name = "my_child", uvm_component parent);
super.new(name, parent);
endfunction: new
endclass: my_child_extended
module top;
my_parent p;
initial begin
my_child::type_id::set_type_override(my_child_extended::get_type());
run_test("my_parent");
end
endmodule: top