调用函数时,该函数是否可以获取调用它的位置的分层范围?
让我举个例子。我有以下代码:
package some_pkg;
function void some_function();
$display("%m");
endfunction
endpackage
module top;
import some_pkg::*;
initial
some_function();
endmodule
运行时,它会显示" some_pkg :: some_function"。有什么方法可以让我的功能显示" top"?或者,如果我有一些其他子模块可以调用它,它是否可以显示" top.submodule"?
答案 0 :(得分:2)
这将是特定于工具的,需要额外的调试器信息才能动态跟踪范围。 Modelsim / Questa有$stacktrace
,它将显示范围和文件名/编号
答案 1 :(得分:0)
我有点使用宏了:
`timescale 1ns/1ns
`define here_str $sformatf("%s::%0d %m", `__FILE__, `__LINE__)
`define here(DUMMY="") $display("I am here: %s", `here_str);
package some_pkg;
function void some_function();
$display("%m");
endfunction
endpackage : some_pkg
module top;
import some_pkg::*;
initial begin
some_function(); // Gives the wrong scope https://stackoverflow.com/q/24454395/1219634
$stacktrace; // Does not return the stacktrace as a string value
`here() // This works, but I would rather not use a macro as I
// would like to make this portable in a package
$finish;
end
endmodule : top
在Cadence / Xcelium 18.09-s014上进行了测试。