Test for bug1191.

This commit is contained in:
Wilson Snyder 2017-08-28 22:41:38 -04:00
parent f13fb330ed
commit cb82c42e35
3 changed files with 38 additions and 12 deletions

View File

@ -58,31 +58,31 @@ const char* svDpiVersion() {
//======================================================================
// Bit-select utility functions.
svBit svGetBitselBit(const svBitVecVal* s, int i) {
_VL_SVDPI_UNIMP(); return 0;
svBit svGetBitselBit(const svBitVecVal* sp, int bit) {
return VL_BITISSET_W(sp,bit);
}
svLogic svGetBitselLogic(const svLogicVecVal* s, int i) {
svLogic svGetBitselLogic(const svLogicVecVal* sp, int bit) {
_VL_SVDPI_UNIMP(); return 0;
}
void svPutBitselBit(svBitVecVal* d, int i, svBit s) {
_VL_SVDPI_UNIMP();
void svPutBitselBit(svBitVecVal* dp, int bit, svBit s) {
VL_ASSIGNBIT_WI(32, bit, dp, s);
}
void svPutBitselLogic(svLogicVecVal* d, int i, svLogic s) {
void svPutBitselLogic(svLogicVecVal* dp, int bit, svLogic s) {
_VL_SVDPI_UNIMP();
}
void svGetPartselBit(svBitVecVal* d, const svBitVecVal* s, int i, int w) {
void svGetPartselBit(svBitVecVal* dp, const svBitVecVal* sp, int i, int w) {
_VL_SVDPI_UNIMP();
}
void svGetPartselLogic(svLogicVecVal* d, const svLogicVecVal* s, int i, int w) {
void svGetPartselLogic(svLogicVecVal* dp, const svLogicVecVal* sp, int i, int w) {
_VL_SVDPI_UNIMP();
}
void svPutPartselBit(svBitVecVal* d, const svBitVecVal s, int i, int w) {
void svPutPartselBit(svBitVecVal* dp, const svBitVecVal s, int i, int w) {
_VL_SVDPI_UNIMP();
}
void svPutPartselLogic(svLogicVecVal* d, const svLogicVecVal* s, int i, int w) {
void svPutPartselLogic(svLogicVecVal* dp, const svLogicVecVal* sp, int i, int w) {
_VL_SVDPI_UNIMP();
}

View File

@ -22,6 +22,7 @@ module t (/*AUTOARG*/
input clk;
typedef struct packed { bit [47:0] lo; bit [47:0] hi; } str_t;
typedef struct packed { int a; int b; } substr_t;
// Allowed import return types:
// void, byte, shortint, int, longint, real, shortreal, chandle, and string
@ -56,6 +57,7 @@ module t (/*AUTOARG*/
import "DPI-C" pure function void dpii_v_shortint (input shortint i, output shortint o);
import "DPI-C" pure function void dpii_v_longint (input longint i, output longint o);
import "DPI-C" pure function void dpii_v_struct (input str_t i, output str_t o);
import "DPI-C" pure function void dpii_v_substruct(input substr_t i, output int o);
import "DPI-C" pure function void dpii_v_chandle (input chandle i, output chandle o);
import "DPI-C" pure function void dpii_v_string (input string i, output string o);
import "DPI-C" pure function void dpii_v_real (input real i, output real o);
@ -100,6 +102,8 @@ module t (/*AUTOARG*/
shortint i_s, o_s;
longint i_l, o_l;
str_t i_t, o_t;
substr_t i_ss;
int o_ss;
int unsigned i_iu, o_iu;
shortint unsigned i_su, o_su;
longint unsigned i_lu, o_lu;
@ -139,6 +143,10 @@ module t (/*AUTOARG*/
i_lu= {1'b1,wide[64-2:0]};
i_t = {1'b1,wide[95-1:0]};
i_d = 32.1;
i_ss.a = 32'h054321ab;
i_ss.b = 32'h05a43b21;
`ifndef NO_SHORTREAL
i_f = 30.2;
`endif
@ -179,6 +187,7 @@ module t (/*AUTOARG*/
dpii_v_ushort (i_su,o_su); if (o_su !== ~i_su) $stop;
dpii_v_ulong (i_lu,o_lu); if (o_lu !== ~i_lu) $stop;
dpii_v_struct (i_t,o_t); if (o_t !== ~i_t) $stop;
dpii_v_substruct(i_ss,o_ss); if (o_ss !== i_ss.a - i_ss.b) $stop;
dpii_v_chandle (i_c,o_c); if (o_c !== i_c) $stop;
dpii_v_string (i_n,o_n); if (o_n != i_n) $stop;
dpii_v_real (i_d,o_d); if (o_d != i_d+1.5) $stop;

View File

@ -29,8 +29,12 @@
# error "Unknown simulator for DPI test"
#endif
typedef struct { int a; int b; } substruct_t;
#ifdef NEED_EXTERNS
extern "C" {
// If get ncsim: *F,NOFDPI: Function {foo} not found in default libdpi.
// Then probably forgot to list a function here.
extern unsigned char dpii_f_bit (unsigned char i);
extern svBitVecVal dpii_f_bit8 (const svBitVecVal* i);
@ -59,18 +63,25 @@ extern "C" {
extern void dpii_v_longint (long long i, long long *o);
extern void dpii_v_ulong (unsigned long long i, unsigned long long *o);
extern void dpii_v_struct (const svBitVecVal* i, svBitVecVal* o);
extern void dpii_v_substruct (const svBitVecVal* i, int* o);
extern void dpii_v_chandle (void* i, void* *o);
extern void dpii_v_string (const char* i, const char** o);
extern void dpii_v_real (double i, double* o);
extern void dpii_v_shortreal(float i, float* o);
extern void dpii_v_struct (const svBitVecVal* i, svBitVecVal* o);
extern void dpii_v_substruct (const svBitVecVal* i, int* o);
extern void dpii_v_bit64(const svBitVecVal* i, svBitVecVal* o);
extern void dpii_v_bit95(const svBitVecVal* i, svBitVecVal* o);
extern void dpii_v_bit96(const svBitVecVal* i, svBitVecVal* o);
extern int dpii_f_strlen (const char* i);
extern void dpii_f_void ();
extern int dpii_t_void ();
extern int dpii_t_void_context ();
extern int dpii_t_int (int i, int *o);
extern int dpii_f_strlen (const char* i);
extern int dpii_fa_bit(int i);
}
#endif
@ -115,6 +126,12 @@ void dpii_v_struct (const svBitVecVal* i, svBitVecVal* o) {
o[3] = ~i[3];
o[4] = ~i[4];
}
void dpii_v_substruct (const svBitVecVal* i, int* o) {
// To be most like other tools, this should automagically take the substruct_t
// as an argument, and not require this cast...
substruct_t* issp = (substruct_t*) i;
o[0] = issp->b - issp->a;
}
void dpii_v_bit64(const svBitVecVal* i, svBitVecVal* o) {
o[0] = ~i[0];
o[1] = ~i[1];