From fb856790688bf2f4a2c87b6736677287290557d8 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 12 May 2011 07:35:28 -0400 Subject: [PATCH] Fix DPI bit vector compile errors, bug347. --- Changes | 2 ++ src/V3Task.cpp | 8 +++++--- test_regress/t/t_dpi_export.v | 2 ++ test_regress/t/t_dpi_export_c.cpp | 3 +++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index 1dd472ad8..9dced9b36 100644 --- a/Changes +++ b/Changes @@ -9,6 +9,8 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix DPI undeclared svBitVecVal compile error, bug346. [Chandan Egbert] +**** Fix DPI bit vector compile errors, bug347. [Chandan Egbert] + **** Fix CDCRSTLOGIC report showing endpoint flops without resets. **** Fix compiler warnings on SPARC, bug288. [Ahmed El-Mahmoudy] diff --git a/src/V3Task.cpp b/src/V3Task.cpp index 7e4ae71d0..8b55882d4 100644 --- a/src/V3Task.cpp +++ b/src/V3Task.cpp @@ -605,7 +605,7 @@ private: return new AstCStmt(portp->fileline(), stmt); } - AstNode* createAssignDpiToInternal(AstVarScope* portvscp, const string& frName) { + AstNode* createAssignDpiToInternal(AstVarScope* portvscp, const string& frName, bool cvt) { // Create assignment from DPI temporary into internal format AstVar* portp = portvscp->varp(); string stmt; @@ -614,6 +614,8 @@ private: stmt += "VL_CVT_VP_Q("; ket += ")"; } + if (!cvt + && portp->basicp() && portp->basicp()->isBitLogic() && portp->widthMin() != 1) stmt += "*"; // it's a svBitVecVal stmt += frName; stmt += ket; // Use a AstCMath, as we want V3Clean to mask off bits that don't make sense. @@ -680,7 +682,7 @@ private: argnodesp = argnodesp->addNextNull(refp); if (portp->isInput()) { - dpip->addStmtsp(createAssignDpiToInternal(outvscp, portp->name())); + dpip->addStmtsp(createAssignDpiToInternal(outvscp, portp->name(), false)); } } } @@ -795,7 +797,7 @@ private: if (AstVar* portp = stmtp->castVar()) { if (portp->isIO() && (portp->isOutput() || portp->isFuncReturn())) { AstVarScope* portvscp = portp->user2p()->castNode()->castVarScope(); // Remembered when we created it earlier - cfuncp->addStmtsp(createAssignDpiToInternal(portvscp,portp->name()+"__Vcvt")); + cfuncp->addStmtsp(createAssignDpiToInternal(portvscp,portp->name()+"__Vcvt",true)); } } } diff --git a/test_regress/t/t_dpi_export.v b/test_regress/t/t_dpi_export.v index 87968f057..1601771de 100644 --- a/test_regress/t/t_dpi_export.v +++ b/test_regress/t/t_dpi_export.v @@ -23,6 +23,7 @@ module t; function int dpix_int123(); dpix_int123 = 32'h123; endfunction export "DPI-C" function dpix_f_bit; + export "DPI-C" function dpix_f_bit15; export "DPI-C" function dpix_f_int; export "DPI-C" function dpix_f_byte; export "DPI-C" function dpix_f_shortint; @@ -30,6 +31,7 @@ module t; export "DPI-C" function dpix_f_chandle; function bit dpix_f_bit (bit i); dpix_f_bit = ~i; endfunction + function bit [14:0] dpix_f_bit15 (bit [14:0] i); dpix_f_bit15 = ~i; endfunction function int dpix_f_int (int i); dpix_f_int = ~i; endfunction function byte dpix_f_byte (byte i); dpix_f_byte = ~i; endfunction function shortint dpix_f_shortint(shortint i); dpix_f_shortint = ~i; endfunction diff --git a/test_regress/t/t_dpi_export_c.cpp b/test_regress/t/t_dpi_export_c.cpp index e6d16f344..c6f8b6eab 100644 --- a/test_regress/t/t_dpi_export_c.cpp +++ b/test_regress/t/t_dpi_export_c.cpp @@ -123,8 +123,11 @@ int dpix_run_tests() { CHECK_RESULT (int, o, 0x458UL); #endif + svBitVecVal vec10[1] = {0x10}; + CHECK_RESULT (int, dpix_f_bit(1), 0x0); CHECK_RESULT (int, dpix_f_bit(0), 0x1); + CHECK_RESULT (int, dpix_f_bit15(vec10) & 0x7fUL, 0x6f); // Simulators disagree over the next three's sign extension unless we mask the upper bits CHECK_RESULT (int, dpix_f_int(1) & 0xffffffffUL, 0xfffffffeUL); CHECK_RESULT (int, dpix_f_byte(1) & 0xffUL, 0xfe);