Fix dpi context functions (#5788)

This commit is contained in:
Ryszard Rozak 2025-02-20 10:15:09 +01:00 committed by GitHub
parent be1ace423e
commit 2a23ec74e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 2 deletions

View File

@ -221,7 +221,8 @@ class LinkResolveVisitor final : public VNVisitor {
letp->user2(false);
return;
}
if (nodep->taskp() && (nodep->taskp()->dpiContext() || nodep->taskp()->dpiExport())) {
if (nodep->taskp() && !nodep->scopeNamep()
&& (nodep->taskp()->dpiContext() || nodep->taskp()->dpiExport())) {
nodep->scopeNamep(new AstScopeName{nodep->fileline(), false});
}
}

View File

@ -11,7 +11,7 @@ import vltest_bootstrap
test.scenarios('simulator')
test.compile(v_flags2=["t/t_dpi_context_c.cpp"])
test.compile(v_flags2=["t/t_dpi_context_c.cpp", "--debug", "-no-dump-tree"])
test.execute()

View File

@ -32,6 +32,7 @@ module sub (input integer inst);
import "DPI-C" context function int dpic_save(int value);
import "DPI-C" context function int dpic_restore();
import "DPI-C" context function int unsigned dpic_getcontext();
import "DPI-C" context function int unsigned dpic_get1();
int result;
@ -63,6 +64,11 @@ module sub (input integer inst);
if (dpic_restore() != 23+inst) $stop;
endtask
function automatic int call_dpic_get1;
int res = dpic_get1();
return res;
endfunction
int unsigned cntxt1;
int unsigned cntxt2;
@ -74,6 +80,7 @@ module sub (input integer inst);
end
// svContext should be the context of the function declaration, not the context of the function call
if (cntxt1 != cntxt2) $stop;
if (call_dpic_get1() != 1) $stop;
end
endmodule

View File

@ -42,6 +42,7 @@ extern int dpic_line();
extern int dpic_save(int value);
extern int dpic_restore();
extern unsigned dpic_getcontext();
extern unsigned dpic_get1();
}
#endif
@ -151,6 +152,8 @@ unsigned dpic_getcontext() {
return (unsigned)(uintptr_t)scope;
}
unsigned dpic_get1() { return 1; }
void dpic_final() {
static int s_once = 0;
if (s_once++) return;