Illegal location for a hierarchical name in a package

I have a function in the driver class (driver.sv) as the following:

function void set_data(input integer input_1 ,output integer output_1);
begin
`PATH_TO_RTL_MODEL_FUNCTION.function_name(input_1,output_1);
endfunction : set_data

where `PATH_TO_RTL_MODEL_FUNCTION is defined as a hierarchical path to a block in the RTL model.

when I compile the environment it gives “illegal location for a hierarchical name in a package”

I think the package the error means is agent_pkg.sv as it contains driver.sv

So how can I solve this ?

In reply to bassem yasser:

Packages must not contain any hierarchical references that reach outside the package. This is why SystemVerilog has virtual interface variables that can hold references to actual interface instances. If you need to access a something in a module, then you can use the bind construct to insert an indirect reference to your function. See this post and the link to my DVCon paper.

In reply to dave_59:

but the problem is that i want to call a function not to bind to a signal , so how can i do that ?

In reply to bassem yasser:

You can use the exact same upward reference to a signal on an upward reference to a function.

Hi,
I was struggling with the same issue.
My solution was to create an interface which is not inside a package.
From this interface you can call tasks, and those tasks can call RTL functions like:
`PATH_TO_RTL_MODEL_FUNCTION.function_name(input_1,output_1);

In reply to NB_A:

so if i did that , how can i call the function in the interface from the driver ?

In reply to bassem yasser:

If you want to stimulate internal signals in your DUT you should do this using an additional agent. Because you have to synchronize this setting with the behavior of the other interfaces. In the driver of this agent you can call your function.

In reply to bassem yasser:

In reply to NB_A:
so if i did that , how can i call the function in the interface from the driver ?

You should set this interface in you top_tb file with config_db.
Then get it from the driver. than you can call the function from the driver.

In reply to NB_A:

In reply to bassem yasser:
You should set this interface in you top_tb file with config_db.
Then get it from the driver. than you can call the function from the driver.

Aha , i got it , so if the interface instance for example vif_inst;
i will use vif_inst.function_name();
correct ?

In reply to bassem yasser:

correct