Support "unsigned int" DPI import functions, msg966.

This commit is contained in:
Wilson Snyder 2012-12-03 20:43:13 -05:00
parent 2238fa46ed
commit cc47ba2404
5 changed files with 30 additions and 0 deletions

View File

@ -3,6 +3,11 @@ Revision history for Verilator
The contributors that suggested a given feature are shown in []. [by ...]
indicates the contributor was also the author of the fix; Thanks!
* Verilator 3.84***
*** Support "unsigned int" DPI import functions, msg966. [Alex Lee]
* Verilator 3.843 2012/12/01
*** Add +1364-1995ext and similar language options, bug532. [Jeremy Bennett]

View File

@ -356,6 +356,9 @@ public:
bool isDpiUnsupported() const {
return (m_e==LOGIC || m_e==TIME);
}
bool isDpiUnsignable() const { // Can add "unsigned" to DPI
return (m_e==BYTE || m_e==SHORTINT || m_e==INT || m_e==LONGINT || m_e==INTEGER);
}
bool isOpaque() const { // IE not a simple number we can bit optimize
return (m_e==STRING || m_e==SCOPEPTR || m_e==CHARPTR || m_e==DOUBLE || m_e==FLOAT);
}

View File

@ -268,6 +268,9 @@ string AstVar::dpiArgType(bool named, bool forReturn) const {
}
} else {
arg = basicp()->keyword().dpiType();
if (basicp()->keyword().isDpiUnsignable() && !basicp()->isSigned()) {
arg = "unsigned "+arg;
}
if (!forReturn && isOutput()) arg += "*";
}
if (named) arg += " "+name();

View File

@ -56,6 +56,10 @@ module t (/*AUTOARG*/
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);
import "DPI-C" pure function void dpii_v_uint (input int unsigned i, output int unsigned o);
import "DPI-C" pure function void dpii_v_ushort (input shortint unsigned i, output shortint unsigned o);
import "DPI-C" pure function void dpii_v_ulong (input longint unsigned i, output longint unsigned o);
`ifndef NO_SHORTREAL
import "DPI-C" pure function void dpii_v_shortreal(input shortreal i, output shortreal o);
`endif
@ -92,6 +96,9 @@ module t (/*AUTOARG*/
byte i_y, o_y;
shortint i_s, o_s;
longint i_l, o_l;
int unsigned i_iu, o_iu;
shortint unsigned i_su, o_su;
longint unsigned i_lu, o_lu;
// verilator lint_off UNDRIVEN
chandle i_c, o_c;
string i_n, o_n;
@ -120,9 +127,12 @@ module t (/*AUTOARG*/
i_b96 = {1'b1,wide[96-2:0]};
i_i = {1'b1,wide[32-2:0]};
i_iu= {1'b1,wide[32-2:0]};
i_y = {1'b1,wide[8-2:0]};
i_s = {1'b1,wide[16-2:0]};
i_su= {1'b1,wide[16-2:0]};
i_l = {1'b1,wide[64-2:0]};
i_lu= {1'b1,wide[64-2:0]};
i_d = 32.1;
`ifndef NO_SHORTREAL
i_f = 30.2;
@ -160,6 +170,9 @@ module t (/*AUTOARG*/
dpii_v_byte (i_y,o_y); if (o_y !== ~i_y) $stop;
dpii_v_shortint (i_s,o_s); if (o_s !== ~i_s) $stop;
dpii_v_longint (i_l,o_l); if (o_l !== ~i_l) $stop;
dpii_v_uint (i_iu,o_iu); if (o_iu !== ~i_iu) $stop;
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_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

@ -52,9 +52,12 @@ extern "C" {
extern void dpii_v_bit (unsigned char i, unsigned char* o);
extern void dpii_v_int (int i, int *o);
extern void dpii_v_uint (unsigned int i, unsigned int *o);
extern void dpii_v_byte (char i, char *o);
extern void dpii_v_shortint (short int i, short int *o);
extern void dpii_v_ushort (unsigned short i, unsigned short *o);
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_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);
@ -93,9 +96,12 @@ float dpii_f_shortreal(float i) { return i+1.5; }
void dpii_v_bit (unsigned char i, unsigned char *o) { *o = SV_MASK(1) & ~i; }
void dpii_v_int (int i, int *o) { *o = ~i; }
void dpii_v_uint (unsigned int i, unsigned int *o) { *o = ~i; }
void dpii_v_byte (char i, char *o) { *o = ~i; }
void dpii_v_shortint (short int i, short int *o) { *o = ~i; }
void dpii_v_ushort (unsigned short i, unsigned short *o) { *o = ~i; }
void dpii_v_longint (long long i, long long *o) { *o = ~i; }
void dpii_v_ulong (unsigned long long i, unsigned long long *o) { *o = ~i; }
void dpii_v_chandle (void* i, void* *o) { *o = i; }
void dpii_v_string (const char* i, const char** o) { *o = i; }
void dpii_v_real (double i, double* o) { *o = i + 1.5; }