我们什么时候在uvm中使用"typedef class xxxxx"?
When do we use "typedef class xxxxx" in uvm?
对uvm不熟悉,正在努力了解学习
学习UVM时发现了下面的代码
typedef class driver;
typedef class monitor;
class env; driver d0;
monitor mon0;
function init_drvr ();
d0 = new (); // initialize endfunction
function init_mon ();
mon0 = new (); // initialize endfunction endclass
endfunction
endclass
特别是
typedef class driver;
typedef class monitor;
可能看起来像是在声明一些东西,但为什么那些 typedef 在那里?
你能告诉我为什么我们使用
typedef class driver;
typedef class monitor;
以及如何理解这个语法?
这称为前向声明,是大多数面向对象语言编译器的特性。它用于声明一个尚未定义的标识符。
基本上,您告诉编译器的是在编译范围的其他地方定义了一个名为 monitor
和 driver
的 class。这将在 运行 时解决。
有关详细信息,请参阅以下文章:(它是在 C++ 中,但概念适用)
https://www.learncpp.com/cpp-tutorial/17-forward-declarations/
在 SystemVerilog 中很少需要 typedef class name
。大多数编程语言都要求在语法上引用用作类型名称的标识符之前对其进行声明。发生的一个地方是如果你有周期性的 class 引用
class X;
Y has_a_Y;
endclass
class Y;
X has_a_X;
endclass
为了编译 class X
的代码,必须声明 class Y
。如果更改 classes 的编译顺序,则 X
变为未知。所以我们使用所谓的 forward typedef
typedef class Y;
class X;
Y has_a_Y;
endclass
现在只要 class Y
在关闭当前范围之前定义 class X
就可以编译。
但是,UVM 强烈反对这种编码,因为这些依赖项会降低代码的可重用性。
有时即使没有循环依赖,人们也会使用前向类型定义,因为他们懒得按照正确的依赖顺序编译代码。
对uvm不熟悉,正在努力了解学习
学习UVM时发现了下面的代码
typedef class driver;
typedef class monitor;
class env; driver d0;
monitor mon0;
function init_drvr ();
d0 = new (); // initialize endfunction
function init_mon ();
mon0 = new (); // initialize endfunction endclass
endfunction
endclass
特别是
typedef class driver;
typedef class monitor;
可能看起来像是在声明一些东西,但为什么那些 typedef 在那里?
你能告诉我为什么我们使用
typedef class driver;
typedef class monitor;
以及如何理解这个语法?
这称为前向声明,是大多数面向对象语言编译器的特性。它用于声明一个尚未定义的标识符。
基本上,您告诉编译器的是在编译范围的其他地方定义了一个名为 monitor
和 driver
的 class。这将在 运行 时解决。
有关详细信息,请参阅以下文章:(它是在 C++ 中,但概念适用)
https://www.learncpp.com/cpp-tutorial/17-forward-declarations/
在 SystemVerilog 中很少需要 typedef class name
。大多数编程语言都要求在语法上引用用作类型名称的标识符之前对其进行声明。发生的一个地方是如果你有周期性的 class 引用
class X;
Y has_a_Y;
endclass
class Y;
X has_a_X;
endclass
为了编译 class X
的代码,必须声明 class Y
。如果更改 classes 的编译顺序,则 X
变为未知。所以我们使用所谓的 forward typedef
typedef class Y;
class X;
Y has_a_Y;
endclass
现在只要 class Y
在关闭当前范围之前定义 class X
就可以编译。
但是,UVM 强烈反对这种编码,因为这些依赖项会降低代码的可重用性。
有时即使没有循环依赖,人们也会使用前向类型定义,因为他们懒得按照正确的依赖顺序编译代码。