UVM 中的超级函数调用示例
Example with super function call in UVM
我遇到过这种说法,并且我在这个原型中使用了许多测试台组件。 super.run_phase(), super.build_phase, super.connect_phase.
谁能用一个简单的例子解释一下为什么我们每次都需要调用超级函数。我知道我们需要在构造子项之前构造父项,但为什么我们必须调用父项的 connect_phase 等?
谢谢
从 UVM component source code 开始,每个阶段都是 默认的空虚拟 function/task:
function void uvm_component::connect_phase(uvm_phase phase);
connect();
return;
endfunction
function void uvm_component::connect();
return;
endfunction
不强制调用super.connect_phase
或来自基础测试或基础驱动程序等的任何阶段
您可能在基础测试中实例化了环境,此后调用 super.build_phase
将创建所需的实例。类似地,您可以在基础 environment/agent 中连接一些端口导出,然后调用 super.connect_phase
应该连接它们。
但是,build_phase
是个例外。强烈推荐对用户定义的代码使用build_phase/connect_phase,而不是在构造函数中使用任何代码。
您可以根据最重要的要求在扩展 class 中调用 super.build_phase()
/super.connect_phase()
或在基础 class [=18= 中添加现有功能]/connect_phase()
.
您不能完全覆盖构造函数,因为 SystemVerilog 要求扩展的 class 构造函数调用 super.new()。
如果使用字段自动化宏,则对 super.build_phase()
的调用在基础 class 的 build_phase 中 是强制性的。
例如:
class base_test extends uvm_test;
`uvm_component_utils(base_test)
//...
function build_phase(uvm_phase phase);
super.build_phase(phase); // for automatic configuration of fields
endfunction
//...
function connect_phase(uvm_phase phase);
super.connect_phase(phase); // normal practice
endfunction
endclass
class my_test extends base_test;
`uvm_component_utils(my_test)
//...
function build_phase(uvm_phase phase);
super.build_phase(phase); // for environment creation
endfunction
//...
function connect_phase(uvm_phase phase);
// super.connect_phase(phase); // will compile even if not call-ed
endfunction
endclass
Any override should call super.build_phase(phase) to execute the
automatic configuration of fields registed in the component by calling
apply_config_settings. To turn off automatic configuration for a
component, do not call super.build_phase(phase).
apply_config_settings
用于将配置设置应用于 class 的每个字段。
如果您不想要为组件调用apply_config_settings
,那么应该重载build_phase()
方法并且您apply_config_settings呼叫 super.build_phase(phase)
.
我遇到过这种说法,并且我在这个原型中使用了许多测试台组件。 super.run_phase(), super.build_phase, super.connect_phase.
谁能用一个简单的例子解释一下为什么我们每次都需要调用超级函数。我知道我们需要在构造子项之前构造父项,但为什么我们必须调用父项的 connect_phase 等?
谢谢
从 UVM component source code 开始,每个阶段都是 默认的空虚拟 function/task:
function void uvm_component::connect_phase(uvm_phase phase);
connect();
return;
endfunction
function void uvm_component::connect();
return;
endfunction
不强制调用super.connect_phase
或来自基础测试或基础驱动程序等的任何阶段
您可能在基础测试中实例化了环境,此后调用 super.build_phase
将创建所需的实例。类似地,您可以在基础 environment/agent 中连接一些端口导出,然后调用 super.connect_phase
应该连接它们。
但是,build_phase
是个例外。强烈推荐对用户定义的代码使用build_phase/connect_phase,而不是在构造函数中使用任何代码。
您可以根据最重要的要求在扩展 class 中调用 super.build_phase()
/super.connect_phase()
或在基础 class [=18= 中添加现有功能]/connect_phase()
.
您不能完全覆盖构造函数,因为 SystemVerilog 要求扩展的 class 构造函数调用 super.new()。
如果使用字段自动化宏,则对 super.build_phase()
的调用在基础 class 的 build_phase 中 是强制性的。
例如:
class base_test extends uvm_test;
`uvm_component_utils(base_test)
//...
function build_phase(uvm_phase phase);
super.build_phase(phase); // for automatic configuration of fields
endfunction
//...
function connect_phase(uvm_phase phase);
super.connect_phase(phase); // normal practice
endfunction
endclass
class my_test extends base_test;
`uvm_component_utils(my_test)
//...
function build_phase(uvm_phase phase);
super.build_phase(phase); // for environment creation
endfunction
//...
function connect_phase(uvm_phase phase);
// super.connect_phase(phase); // will compile even if not call-ed
endfunction
endclass
Any override should call super.build_phase(phase) to execute the automatic configuration of fields registed in the component by calling apply_config_settings. To turn off automatic configuration for a component, do not call super.build_phase(phase).
apply_config_settings
用于将配置设置应用于 class 的每个字段。
如果您不想要为组件调用apply_config_settings
,那么应该重载build_phase()
方法并且您apply_config_settings呼叫 super.build_phase(phase)
.