A function whose result depends solely on the values of its input arguments and with no side effects can be specified as pure. This can usually allow for more optimizations and thus can result in improved simulation performance.
A pure function call can be safely eliminated if its result is not needed or if the previous result for the same values of input arguments is available somehow and can be reused without needing to recalculate. Only nonvoid functions with no output or inout arguments can be specified as pure.
Specifically, a pure function is assumed not to directly or indirectly (i.e., by calling other functions) perform the following:
Perform any file operations.
Read or write anything in the broadest possible meaning, including input/output, environment variables, objects from the operating system or from the program or other processes, shared memory, sockets, etc.
Access any persistent data, like global or static variables.
Context Function
Some DPI imported tasks or functions or other interface functions called from them require that the context of their call be known. The SystemVerilog context of DPI export tasks and functions must be known when they are called, including when they are called by imports. When an import invokes the svSetScope utility prior to calling the export, it sets the context explicitly. Otherwise, the context will be the context of the instantiated scope where the import declaration is located.
CODE: SV_file_1.sv module module_1;
import "DPI-C" contextfunctionvoid import_func();
export "DPI-C" function export_func;
module_2 instance_1();
initial import_func();
functionvoid export_func();
$display("SV: My scope is %m \n");
endfunction
endmodule
CODE: SV_file_2.sv module module_2;
import "DPI-C" contextfunctionvoid import_func();
export "DPI-C" function export_func;
initial import_func();
functionvoid export_func();
$display("SV: My Scope is %m \n");
endfunction
endmodule CODE:C_file.c
#include "svdpi.h"
#include "stdio.h"
externvoid export_func(void);
void import_func()
{
printf(" C: Im called fronm Scope :: %s \n\n ",svGetNameFromScope(svGetScope() ));