Fix DPI import of null C-string (#5179).

This commit is contained in:
Wilson Snyder 2024-06-14 22:50:54 -04:00
parent 4695967185
commit ad2862ce3f
5 changed files with 28 additions and 15 deletions

View File

@ -72,6 +72,7 @@ Verilator 5.025 devel
* Fix SystemC BITS_PER_DIGIT in VL_ASSIGN_SBW (#5170). [Bartłomiej Chmiel, Antmicro Ltd.] * Fix SystemC BITS_PER_DIGIT in VL_ASSIGN_SBW (#5170). [Bartłomiej Chmiel, Antmicro Ltd.]
* Fix non-constant replication in concats (#5171). [Arkadiusz Kozdra, Antmicro Ltd.] * Fix non-constant replication in concats (#5171). [Arkadiusz Kozdra, Antmicro Ltd.]
* Fix table optimization when applied on real data type (#5172) (#5173). [Arthur Rosa] * Fix table optimization when applied on real data type (#5172) (#5173). [Arthur Rosa]
* Fix DPI import of null C-string (#5179).
Verilator 5.024 2024-04-05 Verilator 5.024 2024-04-05

View File

@ -219,6 +219,10 @@ static inline QData VL_CVT_Q_D(double lhs) VL_PURE {
return u.q; return u.q;
} }
// clang-format on // clang-format on
// Return string from DPI char*
static inline std::string VL_CVT_N_CSTR(const char* lhsp) VL_PURE {
return lhsp ? std::string{lhsp} : ""s;
}
// Return double from lhs (numeric) unsigned // Return double from lhs (numeric) unsigned
double VL_ITOR_D_W(int lbits, WDataInP const lwp) VL_PURE; double VL_ITOR_D_W(int lbits, WDataInP const lwp) VL_PURE;

View File

@ -305,6 +305,9 @@ struct TaskDpiUtils final {
if (portp->basicp() && portp->basicp()->keyword() == VBasicDTypeKwd::CHANDLE) { if (portp->basicp() && portp->basicp()->keyword() == VBasicDTypeKwd::CHANDLE) {
frstmt = "VL_CVT_VP_Q(" + frName; frstmt = "VL_CVT_VP_Q(" + frName;
ket = ")"; ket = ")";
} else if (portp->basicp() && portp->basicp()->keyword() == VBasicDTypeKwd::STRING) {
frstmt = "VL_CVT_N_CSTR(" + frName;
ket = ")";
} else if ((portp->basicp() && portp->basicp()->isDpiPrimitive())) { } else if ((portp->basicp() && portp->basicp()->isDpiPrimitive())) {
frstmt = frName; frstmt = frName;
} else { } else {

View File

@ -85,6 +85,8 @@ module t (/*AUTOARG*/
import "DPI-C" pure function int dpii_f_strlen(input string i); import "DPI-C" pure function int dpii_f_strlen(input string i);
import "DPI-C" function string dpii_f_null();
import "DPI-C" function void dpii_f_void(); import "DPI-C" function void dpii_f_void();
// Try a task // Try a task
@ -242,6 +244,7 @@ module t (/*AUTOARG*/
`endif `endif
if (dpii_f_strlen(string6) != 6) $stop; if (dpii_f_strlen(string6) != 6) $stop;
if (dpii_f_null() != "") $stop;
dpii_f_void(); dpii_f_void();
dpii_t_void(); dpii_t_void();
dpii_t_void_context(); dpii_t_void_context();

View File

@ -53,6 +53,7 @@ extern short int dpii_f_shortint(short int i);
extern long long dpii_f_longint(long long i); extern long long dpii_f_longint(long long i);
extern void* dpii_f_chandle(void* i); extern void* dpii_f_chandle(void* i);
extern const char* dpii_f_string(const char* i); extern const char* dpii_f_string(const char* i);
extern const char* dpii_f_null();
extern double dpii_f_real(double i); extern double dpii_f_real(double i);
extern float dpii_f_shortreal(float i); extern float dpii_f_shortreal(float i);
@ -113,6 +114,7 @@ short int dpii_f_shortint(short int i) { return ~i; }
long long dpii_f_longint(long long i) { return ~i; } long long dpii_f_longint(long long i) { return ~i; }
void* dpii_f_chandle(void* i) { return i; } void* dpii_f_chandle(void* i) { return i; }
const char* dpii_f_string(const char* i) { return i; } const char* dpii_f_string(const char* i) { return i; }
const char* dpii_f_null() { return nullptr; }
double dpii_f_real(double i) { return i + 1.5; } double dpii_f_real(double i) { return i + 1.5; }
float dpii_f_shortreal(float i) { return i + 1.5f; } float dpii_f_shortreal(float i) { return i + 1.5f; }