Jea*_*ean 4 verilog object system-verilog
有什么方法可以在SystemVerilog中获取它操作的对象的名称?
喜欢实施
object1.printName()
Run Code Online (Sandbox Code Playgroud)
应该打印字符串
object1
Run Code Online (Sandbox Code Playgroud)
不,语言中没有为类执行此操作的机制.
对于模块,可以使用%m格式说明符显示分层名称.但对于类,输出使用%m显示类类型名称,而不是实例名称.(至少那是Incisive和Questa观察到的行为.)另请注意,%m如果在函数内调用,则将包含函数名称.
例:
module test;
// Print %m in a module
function void printName();
$display("%m");
endfunction
class foo;
// Print %m in a class
virtual function void printName();
$display("%m");
endfunction
endclass
foo foo_inst = new;
endmodule
module top;
test test_inst();
initial begin
test_inst.foo_inst.printName();
test_inst.printName();
end
endmodule
Run Code Online (Sandbox Code Playgroud)
输出:
top.test_inst.foo.printName
top.test_inst.printName
Run Code Online (Sandbox Code Playgroud)
如果输出%m有用,您可以使用$sformatf然后修改字符串或使用它执行任何操作.
对于这么高水平的东西,我不确定是否有东西完全像你所描述的那样。
但是,有$typename系统任务。但是,我不知道它如何与类对象一起使用。我以前没有发现需要这个。
通常我看到所做的(以及我所做的,因为我发现它有用)是创建一个存储在由构造函数分配的类中的字符串,这是对象的“名称”。然后我可以在记录时使用它,这样我就知道不同的消息来自哪里。当然,这取决于您创建具有有用名称的新变量。