什么是虚拟访问器?
What is a virtual accessor?
这个短语来自 "uvm users guide 1.1" 第 20 页:
“在 SystemVerilog 中,一个重要的使用模型是向事务类型添加随机化约束。这通常是通过继承完成的——采用派生对象并向基类添加约束 class。这些
可以通过派生新的 class 等进一步修改或扩展约束。为了支持这种使用
模型,访问函数是虚拟的,成员是受保护的而不是本地的。
什么是存取器?为什么它必须是虚拟的?
Accessor 表示一个 get_*
函数,它只是 returns 一个值,而不改变对象的状态。返回的值可以是成员变量,也可以是更复杂的表达式,具体取决于成员变量。一个例子是 point
class,它可以提供笛卡尔坐标和极坐标 (https://en.wikipedia.org/wiki/Polar_coordinate_system):
class point;
local int x;
local int y;
// Accessor for x coordinate, cartesian
function int get_x();
return x;
endfunction
// Accessor for r coordinate, polar
function int get_r();
return sqrt(x**2 + y**2);
endfunction
// accessors would also exist for y and phi
endclass
如果函数是虚函数,则可以在子函数中覆盖它class。
为什么您提到的访问器是虚拟的很重要,从您的问题中看不出。
这个短语来自 "uvm users guide 1.1" 第 20 页:
“在 SystemVerilog 中,一个重要的使用模型是向事务类型添加随机化约束。这通常是通过继承完成的——采用派生对象并向基类添加约束 class。这些 可以通过派生新的 class 等进一步修改或扩展约束。为了支持这种使用 模型,访问函数是虚拟的,成员是受保护的而不是本地的。
什么是存取器?为什么它必须是虚拟的?
Accessor 表示一个 get_*
函数,它只是 returns 一个值,而不改变对象的状态。返回的值可以是成员变量,也可以是更复杂的表达式,具体取决于成员变量。一个例子是 point
class,它可以提供笛卡尔坐标和极坐标 (https://en.wikipedia.org/wiki/Polar_coordinate_system):
class point;
local int x;
local int y;
// Accessor for x coordinate, cartesian
function int get_x();
return x;
endfunction
// Accessor for r coordinate, polar
function int get_r();
return sqrt(x**2 + y**2);
endfunction
// accessors would also exist for y and phi
endclass
如果函数是虚函数,则可以在子函数中覆盖它class。
为什么您提到的访问器是虚拟的很重要,从您的问题中看不出。