System verilog 这是使用';新';在systemverilog类中运行?
现在我正在研究systemverilog的CLS 从许多例子中,我发现“新”有两种类型System verilog 这是使用';新';在systemverilog类中运行?,system-verilog,System Verilog,现在我正在研究systemverilog的CLS 从许多例子中,我发现“新”有两种类型 “新”的情况存在于课堂中 “新”的情况存在于初始阶段 构造函数的那些实现之间有什么区别吗 还有,函数new()中有什么? 我不确定函数new()的用途 更新 例如,示例1是。 xxx类 ... 函数new(); ... 端功能 末级 例2是 program class xxxx endclass Initial begin xxxx x = new; end endprogram 更
program
class xxxx
endclass
Initial begin
xxxx x = new;
end
endprogram
更新2
谢谢你让我知道。
我有个问题。两者的区别是什么
Class xxx
...
Function new();
(Variable initialization)
...
Endfunction
Endclass
及
但在本例中,在初始语句或任务中传递值。
函数new()endfunction中有什么?我不确定我应该初始化变量吗
更新3
这就是我的代码。
你可以看到,
有两种类型的功能块
1. is with new
function new(bit [31:0] addr,data,bit write,string pkt_type);
addr = addr;
data = data;
write = write;
pkt_type = pkt_type;
endfunction
2. is without new.
//method to display class prperties
function void display();
$display("---------------------------------------------------------");
$display("\t addr = %0h",addr);
$display("\t data = %0h",data);
$display("\t write = %0h",write);
$display("\t pkt_type = %0s",pkt_type);
$display("---------------------------------------------------------");
endfunction
调用类的new()方法是构造类对象的唯一方法。您可能希望定义一个类,并且永远不要对其调用new()方法,这有几个原因,但是您应该在以后更好地理解SystemVerilog时提出这个问题
更新
我想您可能会问,在类中声明函数new()的类之间有什么区别
class xxxx;
int x;
function new;
...
endfucntion
endclass
而不是一个没有它的班级
class xxxx;
int x;
endclass
如果不在类中声明函数new(),SystemVerilog将为您定义一个隐式函数。您可能希望在类中声明新函数的原因是,如果您希望将参数传递给构造函数,或者您有需要更复杂的过程代码来初始化的内容。请给出一个您发现的代码类型的示例,如果我只使用函数new()。。。endfunction是否改为使用函数new()endfunction?这只是为了初始化我想要指定的变量吗?我的意思是,除了函数new()中的initialize之外,还有什么特殊的含义吗?我更新了3,您可以看到函数的1和2类型声明之间的区别。
class xxxx;
int x;
function new;
...
endfucntion
endclass
class xxxx;
int x;
endclass