`__FILE__ and `__LINE__


How do you use __FILE__ and __LINE__?


__FILE__ and __LINE__ are SystemVerilog compiler directives that are typically used with display statements. They help you identify which file and line the execution it currently at.

Here’s an example … assume the following piece of code is within file utils.sv

program automatic utils;
`define debug(msg) \
    $display(">> %s, %d: %s", `__FILE__, `__LINE__, msg)

    initial begin
        `debug("At the beginning");
        `debug("At the end");

Output from above program

>> utils.sv,           7: At the beginning
>> utils.sv,           8: At the end