No, there is no mechanism in the language for this for classes.
For modules, you can use the %m format specifier to display a hierarchical name. But for classes, exiting using %m shows the class type name, not the instance name. (At least it was an observable behavior with Incisive and Questa.) Also note that %m will include the name of the function if called from within the function.
Example:
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
Output:
top.test_inst.foo.printName top.test_inst.printName
If the result from %m is useful, you can write it to a string using $sformatf , and then change or do something with it.
source share